Package org.apache.lucene.util
Class BytesRefArray
- java.lang.Object
-
- org.apache.lucene.util.BytesRefArray
-
- All Implemented Interfaces:
SortableBytesRefArray
public final class BytesRefArray extends java.lang.Object implements SortableBytesRefArray
A simple append only random-accessBytesRefarray that stores full copies of the appended bytes in aByteBlockPool. Note: This class is not Thread-Safe!
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceBytesRefArray.IndexedBytesRefIteratorAn extension ofBytesRefIteratorthat allows retrieving the index of the current elementstatic classBytesRefArray.SortStateUsed to iterate the elements of an array in a given order.
-
Field Summary
Fields Modifier and Type Field Description private CounterbytesUsedprivate intcurrentOffsetprivate intlastElementprivate int[]offsetsprivate ByteBlockPoolpool
-
Constructor Summary
Constructors Constructor Description BytesRefArray(Counter bytesUsed)Creates a newBytesRefArraywith a counter to track allocated bytes
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intappend(BytesRef bytes)Appends a copy of the givenBytesRefto thisBytesRefArray.voidclear()Clears thisBytesRefArrayBytesRefget(BytesRefBuilder spare, int index)Returns the n'th element of thisBytesRefArrayBytesRefIteratoriterator()sugar foriterator(Comparator)with anullcomparatorBytesRefIteratoriterator(java.util.Comparator<BytesRef> comp)Returns aBytesRefIteratorwith point in time semantics.BytesRefArray.IndexedBytesRefIteratoriterator(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 thisBytesRefArrayBytesRefArray.SortStatesort(java.util.Comparator<BytesRef> comp, java.util.function.IntBinaryOperator tieComparator)Returns aBytesRefArray.SortStaterepresenting the order of elements in this array.
-
-
-
Field Detail
-
pool
private final ByteBlockPool pool
-
offsets
private int[] offsets
-
lastElement
private int lastElement
-
currentOffset
private int currentOffset
-
bytesUsed
private final Counter bytesUsed
-
-
Constructor Detail
-
BytesRefArray
public BytesRefArray(Counter bytesUsed)
Creates a newBytesRefArraywith a counter to track allocated bytes
-
-
Method Detail
-
clear
public void clear()
Clears thisBytesRefArray- Specified by:
clearin interfaceSortableBytesRefArray
-
append
public int append(BytesRef bytes)
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
public BytesRef get(BytesRefBuilder spare, int index)
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
private void setBytesRef(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.
-
sort
public BytesRefArray.SortState sort(java.util.Comparator<BytesRef> comp, java.util.function.IntBinaryOperator tieComparator)
Returns aBytesRefArray.SortStaterepresenting the order of elements in this array. This is a non-destructive operation.
-
iterator
public BytesRefIterator iterator()
sugar foriterator(Comparator)with anullcomparator
-
iterator
public BytesRefIterator iterator(java.util.Comparator<BytesRef> comp)
Returns a
BytesRefIteratorwith 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
public BytesRefArray.IndexedBytesRefIterator iterator(BytesRefArray.SortState sortState)
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.
-
-