java.lang.Object
org.apache.lucene.util.BytesRefArray
- All Implemented Interfaces:
SortableBytesRefArray
A simple append only random-access
BytesRef array that stores full copies of the appended
bytes in a ByteBlockPool.
Note: This class is not Thread-Safe!
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAn extension ofBytesRefIteratorthat allows retrieving the index of the current elementstatic final classUsed to iterate the elements of an array in a given order. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Counterprivate intprivate intprivate int[]private final ByteBlockPool -
Constructor Summary
ConstructorsConstructorDescriptionBytesRefArray(Counter bytesUsed) Creates a newBytesRefArraywith a counter to track allocated bytes -
Method Summary
Modifier and TypeMethodDescriptionintAppends a copy of the givenBytesRefto thisBytesRefArray.voidclear()Clears thisBytesRefArrayget(BytesRefBuilder spare, int index) Returns the n'th element of thisBytesRefArrayiterator()sugar foriterator(Comparator)with anullcomparatoriterator(Comparator<BytesRef> comp) Returns aBytesRefIteratorwith point in time semantics.iterator(BytesRefArray.SortState sortState) Returns anBytesRefArray.IndexedBytesRefIteratorwith point in time semantics.private voidsetBytesRef(BytesRefBuilder spare, BytesRef result, int index) Used only by sort below, to set aBytesRefwith the specified slice, avoiding copying bytes in the common case when the slice is contained in a single block in the byte block pool.intsize()Returns the current size of thisBytesRefArraysort(Comparator<BytesRef> comp, boolean stable) Returns aBytesRefArray.SortStaterepresenting the order of elements in this array.
-
Field Details
-
pool
-
offsets
private int[] offsets -
lastElement
private int lastElement -
currentOffset
private int currentOffset -
bytesUsed
-
-
Constructor Details
-
BytesRefArray
Creates a newBytesRefArraywith a counter to track allocated bytes
-
-
Method Details
-
clear
public void clear()Clears thisBytesRefArray- Specified by:
clearin interfaceSortableBytesRefArray
-
append
Appends a copy of the givenBytesRefto thisBytesRefArray.- Specified by:
appendin interfaceSortableBytesRefArray- Parameters:
bytes- the bytes to append- Returns:
- the index of the appended bytes
-
size
public int size()Returns the current size of thisBytesRefArray- Specified by:
sizein interfaceSortableBytesRefArray- Returns:
- the current size of this
BytesRefArray
-
get
Returns the n'th element of thisBytesRefArray- Parameters:
spare- a spareBytesRefinstanceindex- the elements index to retrieve- Returns:
- the n'th element of this
BytesRefArray
-
setBytesRef
Used only by sort below, to set aBytesRefwith the specified slice, avoiding copying bytes in the common case when the slice is contained in a single block in the byte block pool. -
sort
Returns aBytesRefArray.SortStaterepresenting the order of elements in this array. This is a non-destructive operation.- Parameters:
comp- The comparator to compareBytesRefs. A radix sort optimization is available if the comparator implementsBytesRefComparatorstable- If the sort needs to be stable- Returns:
- A
BytesRefArray.SortStatethat could be used initerator(SortState)
-
iterator
sugar foriterator(Comparator)with anullcomparator -
iterator
Returns aBytesRefIteratorwith point in time semantics. The iterator provides access to all so far appendedBytesRefinstances.If a non
nullComparatoris 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.
- Specified by:
iteratorin interfaceSortableBytesRefArray
-
iterator
Returns anBytesRefArray.IndexedBytesRefIteratorwith point in time semantics. The iterator provides access to all so far appendedBytesRefinstances. If a non-null sortState is specified then the iterator will iterate the byte values in the order of the sortState; otherwise, the order is the same as the values were appended.
-