public final class BytesRefArray extends java.lang.Object implements SortableBytesRefArray
BytesRef
array that stores full
copies of the appended bytes in a ByteBlockPool
.
Note: This class is not Thread-Safe!Modifier and Type | Field and Description |
---|---|
private Counter |
bytesUsed |
private int |
currentOffset |
private int |
lastElement |
private int[] |
offsets |
private ByteBlockPool |
pool |
Constructor and Description |
---|
BytesRefArray(Counter bytesUsed)
Creates a new
BytesRefArray with a counter to track allocated bytes |
Modifier and Type | Method and Description |
---|---|
int |
append(BytesRef bytes)
Appends a copy of the given
BytesRef to this BytesRefArray . |
void |
clear()
Clears this
BytesRefArray |
BytesRef |
get(BytesRefBuilder spare,
int index)
Returns the n'th element of this
BytesRefArray |
BytesRefIterator |
iterator()
sugar for
iterator(Comparator) with a null comparator |
BytesRefIterator |
iterator(java.util.Comparator<BytesRef> comp)
Returns a
BytesRefIterator with point in time semantics. |
private void |
setBytesRef(BytesRefBuilder spare,
BytesRef result,
int index)
Used only by sort below, to set a
BytesRef with the specified slice, avoiding copying bytes in the common case when the slice
is contained in a single block in the byte block pool. |
int |
size()
Returns the current size of this
BytesRefArray |
private int[] |
sort(java.util.Comparator<BytesRef> comp) |
private final ByteBlockPool pool
private int[] offsets
private int lastElement
private int currentOffset
private final Counter bytesUsed
public BytesRefArray(Counter bytesUsed)
BytesRefArray
with a counter to track allocated bytespublic void clear()
BytesRefArray
clear
in interface SortableBytesRefArray
public int append(BytesRef bytes)
BytesRef
to this BytesRefArray
.append
in interface SortableBytesRefArray
bytes
- the bytes to appendpublic int size()
BytesRefArray
size
in interface SortableBytesRefArray
BytesRefArray
public BytesRef get(BytesRefBuilder spare, int index)
BytesRefArray
spare
- a spare BytesRef
instanceindex
- the elements index to retrieveBytesRefArray
private void setBytesRef(BytesRefBuilder spare, BytesRef result, int index)
BytesRef
with the specified slice, avoiding copying bytes in the common case when the slice
is contained in a single block in the byte block pool.private int[] sort(java.util.Comparator<BytesRef> comp)
public BytesRefIterator iterator()
iterator(Comparator)
with a null
comparatorpublic BytesRefIterator iterator(java.util.Comparator<BytesRef> comp)
Returns a BytesRefIterator
with point in time semantics. The
iterator provides access to all so far appended BytesRef
instances.
If a non null
Comparator
is provided the iterator will
iterate the byte values in the order specified by the comparator. Otherwise
the order is the same as the values were appended.
This is a non-destructive operation.
iterator
in interface SortableBytesRefArray