Class TreeIndex
- All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable,LongSizedDataStructure,Index,OrderedKeys,ReadOnlyIndex,SafeCloseable,Externalizable,Serializable,AutoCloseable,Iterable<Long>
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.illumon.iris.db.v2.utils.Index
Index.AbstractRandomBuilder, Index.AdaptiveIndexBuilder, Index.Factory, Index.IndexUpdateCoalescer, Index.RandomBuilder, Index.SequentialBuilder, Index.ShiftInversionHelperNested classes/interfaces inherited from interface com.illumon.iris.db.v2.utils.OrderedKeys
OrderedKeys.IteratorNested classes/interfaces inherited from interface com.illumon.iris.db.v2.utils.ReadOnlyIndex
ReadOnlyIndex.Iterator, ReadOnlyIndex.RangeIterator, ReadOnlyIndex.SearchIterator, ReadOnlyIndex.TargetComparator -
Field Summary
Fields inherited from interface com.illumon.iris.db.v2.utils.Index
BAD_RANGES_AS_ERROR, CURRENT_FACTORY, FACTORY, USE_PRIORITY_QUEUE_RANDOM_BUILDERFields inherited from interface com.illumon.iris.db.v2.utils.OrderedKeys
EMPTYFields inherited from interface com.illumon.iris.db.v2.utils.ReadOnlyIndex
EMPTY_ITERATOR, NULL_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidadd(TreeIndexImpl.RandomBuilder builder, TreeIndex idx, boolean acquire) com.fishlib.base.log.LogOutputappend(com.fishlib.base.log.LogOutput logOutput) asIndex()Get anIndexrepresentation of thisOrderedKeys.voidclear()clone()Create a copy of this index.voidclose()Free any resources associated with this object.voidcompact()May reclaim some unused memory.booleancontainsRange(long start, long end) Queries whether this index contains every element in the range provided.booleanempty()Queries whether this index is empty (i.e.voidfillKeyIndicesChunk(WritableLongChunk<? extends Attributes.KeyIndices> chunkToFill) Fill the suppliedWritableLongChunkwith individual keys from thisOrderedKeys.voidfillKeyRangesChunk(WritableLongChunk<Attributes.OrderedKeyRanges> chunkToFill) Fill the suppliedWritableLongChunkwith key ranges from thisOrderedKeys.longfind(long key) Returns the position in [0..(size-1)] where the key is found.longfindPrev(long key) Returns the position in [0..(size-1)] where the key is found in the previous index.longfirstKey()Get the first key in thisIndex.longbooleanProvide each value contained in this index, in increased sorted order to the consumer.booleanFor as long as the consumer wants more ranges, call accept on the consumer with the individual key ranges in this OrderedKeys, in increasing order.longget(long pos) Returns the key at the given rank position.longGet an estimate of the average (mean) length of runs of adjacent keys in thisOrderedKeys.static SortedIndexfinal TreeIndexImplgetImpl()voidgetKeysForPositions(PrimitiveIterator.OfLong positions, LongConsumer outputKeys) Returns the sequence of (increasing) keys corresponding to the positions provided as input.getOrderedKeysByKeyRange(long startKeyInclusive, long endKeyInclusive) Get an ordered subset of the keys in thisOrderedKeysfor a key range.getOrderedKeysByPosition(long start, long len) Get an ordered subset of the keys in thisOrderedKeysfor a position range.Get anOrderedKeys.Iteratorover thisOrderedKeys.longgetPrev(long pos) voidInitializes our previous value from the current value.voidinsert(long key) Add a single key to this index if it's not already present.voidinsert(LongChunk<Attributes.OrderedKeyIndices> keys, int offset, int length) Add all of the (ordered) keys in a slice ofkeysto this index if they are not already present.voidinsert(ReadOnlyIndex added) Add all of the keys inaddedto this index if they are not already present.voidinsertRange(long startKey, long endKey) Add all keys in a closed range to this index if they are not already present.voidinsertWithShift(long shiftAmount, ReadOnlyIndex other) For each key in the provided index, shift it by shiftAmount and insert it in the current index.intersect(ReadOnlyIndex range) Returns a new index representing the intersection of the current index with the input indexinvert(ReadOnlyIndex keys, long maximumPosition) The only used implementation of invert is in the TreeIndex, really the guts of it are in BspNodeIndex.iterator()longlastKey()Get the last key in thisOrderedKeys.longstatic Index.RandomBuilderstatic Index.SequentialBuilderstatic TreeIndexstatic TreeIndexstatic Index.RandomBuilderstatic Index.SequentialBuilderstatic TreeIndexmakeSingleRange(long start, long end) minus(ReadOnlyIndex set) Returns a new index representing the keys of the current set not present inside indexToRemove This operation is equivalent to set difference.booleanoverlaps(ReadOnlyIndex range) Returns true if an index has any overlap.booleanoverlapsRange(long start, long end) Returns true if this index has any overlap with the provided range.longvoidintrefCount()voidremove(long key) Remove a single key from this index if it's present.voidremove(LongChunk<Attributes.OrderedKeyIndices> keys, int offset, int length) Remove all of the (ordered) keys in a slice ofkeysfrom this index if they are present.voidremove(ReadOnlyIndex removed) Remove all of the keys inremovedthat are present in this index.voidremoveRange(long startKey, long endKey) Remove all keys in a closed range from this index if they are present.voidretain(ReadOnlyIndex toIntersect) Modifies the index by removing any keys not in the indexToIntersect argument.voidretainRange(long startKey, long endKey) Modifies the index by keeping only keys in the interval [start, end]shift(long shiftAmount) Returns a new index representing the keys in this index shifted by the amount indicated.voidshiftInPlace(long shiftAmount) longsize()How many keys are in this index.longsizePrev()default Stringstrid()Override to improve index debug-tracing messages.subindexByKey(long startKey, long endKey) Get a subset of this index within this range of keys.subindexByPos(long startPos, long endPos) Get a subset of this index within this range of positionsbooleansubsetOf(ReadOnlyIndex range) Returns true if this index is a (possibly improper) subset of other.toString()toString(int maxNodes) static voidunion(ReadOnlyIndex set) Returns a new index representing the keys present in both this index and the argument index.voidupdate(ReadOnlyIndex added, ReadOnlyIndex removed) Simultaneously adds the keys from the first index and removes the keys from the second one.voidvoidvoidwriteImpl(ObjectOutput out) Methods inherited from class com.illumon.iris.db.v2.utils.SortedIndex
clearMappings, copyImmutableGroupings, equals, findMissing, getGrouping, getGroupingForKeySet, getPrevGrouping, getSubIndexForKeySet, hasGrouping, hashCode, invert, isFlat, isSorted, onClear, onInsert, onRemove, onRetain, onUpdate, updateGroupingOnInsert, updateGroupingOnInsert, updateGroupingOnRemove, updateGroupingOnRemove, updateGroupingOnRemoveRange, updateGroupingOnRetain, updateGroupingOnRetainRange, updateGroupOnInsertRangeMethods inherited from class com.illumon.iris.db.v2.utils.OrderedKeysAsChunkImpl
asKeyIndicesChunk, asKeyRangesChunk, closeOrderedKeysAsChunkImpl, invalidateOrderedKeysAsChunkImpl, runsUpperBoundMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface com.illumon.iris.db.util.LongSizedDataStructure
intSize, intSizeMethods inherited from interface com.illumon.iris.db.v2.utils.OrderedKeys
asKeyIndicesChunk, asKeyRangesChunk, forAllLongRanges, isContiguousMethods inherited from interface com.illumon.iris.db.v2.utils.ReadOnlyIndex
forAllLongs, isEmpty, nonempty, subindexByPos, subindexByPos, subIndexForReversePos, toLongArray, toLongArray, validate
-
Constructor Details
-
TreeIndex
public TreeIndex() -
TreeIndex
-
-
Method Details
-
getImpl
-
makeEmptyRsp
-
makeEmptySr
-
makeSingleRange
-
trace
-
close
public void close()Description copied from interface:OrderedKeysFree any resources associated with this object.
Using any
OrderedKeysmethods afterclose()is an error and may produce exceptions or undefined results.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceOrderedKeys- Specified by:
closein interfaceReadOnlyIndex- Specified by:
closein interfaceSafeCloseable- Overrides:
closein classOrderedKeysAsChunkImpl
-
refCount
- Specified by:
refCountin interfaceReadOnlyIndex
-
insert
public void insert(long key) Description copied from interface:IndexAdd a single key to this index if it's not already present. -
insertRange
public void insertRange(long startKey, long endKey) Description copied from interface:IndexAdd all keys in a closed range to this index if they are not already present.- Specified by:
insertRangein interfaceIndex- Parameters:
startKey- The first key to addendKey- The last key to add (inclusive)
-
insert
Description copied from interface:IndexAdd all of the (ordered) keys in a slice ofkeysto this index if they are not already present.- Specified by:
insertin interfaceIndex- Parameters:
keys- TheLongChunkofAttributes.OrderedKeyIndicesto insertoffset- The offset inkeysto begin inserting keys fromlength- The number of keys to insert
-
insert
Description copied from interface:IndexAdd all of the keys inaddedto this index if they are not already present.- Specified by:
insertin interfaceIndex- Overrides:
insertin classSortedIndex- Parameters:
added- The index to add
-
remove
public void remove(long key) Description copied from interface:IndexRemove a single key from this index if it's present. -
removeRange
public void removeRange(long startKey, long endKey) Description copied from interface:IndexRemove all keys in a closed range from this index if they are present.- Specified by:
removeRangein interfaceIndex- Parameters:
startKey- The first key to removeendKey- The last key to remove (inclusive)
-
remove
Description copied from interface:IndexRemove all of the (ordered) keys in a slice ofkeysfrom this index if they are present.- Specified by:
removein interfaceIndex- Parameters:
keys- TheLongChunkofAttributes.OrderedKeyIndicesto removeoffset- The offset inkeysto begin removing keys fromlength- The number of keys to remove
-
remove
Description copied from interface:IndexRemove all of the keys inremovedthat are present in this index.- Specified by:
removein interfaceIndex- Overrides:
removein classSortedIndex- Parameters:
removed- The index to remove
-
lastKey
public long lastKey()Description copied from interface:OrderedKeysGet the last key in thisOrderedKeys.- Specified by:
lastKeyin interfaceOrderedKeys- Specified by:
lastKeyin interfaceReadOnlyIndex- Specified by:
lastKeyin classOrderedKeysAsChunkImpl- Returns:
- The last key, or
ReadOnlyIndex.NULL_KEYif there is none.
-
firstKey
public long firstKey()Description copied from interface:ReadOnlyIndexGet the first key in thisIndex.- Specified by:
firstKeyin interfaceOrderedKeys- Specified by:
firstKeyin interfaceReadOnlyIndex- Returns:
- The first key, or
ReadOnlyIndex.NULL_KEYif there is none.
-
clear
public void clear() -
forEachLong
Description copied from interface:ReadOnlyIndexProvide each value contained in this index, in increased sorted order to the consumer. If the consumer returns false for a key, stops after that key (does not provide any keys after that key).- Specified by:
forEachLongin interfaceOrderedKeys- Specified by:
forEachLongin interfaceReadOnlyIndex- Parameters:
lc- the consumer.- Returns:
- false if the consumer returned false at some point, true if the consumer always returned true and all values in the index were consumed.
-
forEachLongRange
Description copied from interface:OrderedKeysFor as long as the consumer wants more ranges, call accept on the consumer with the individual key ranges in this OrderedKeys, in increasing order.- Specified by:
forEachLongRangein interfaceOrderedKeys- Parameters:
lrac- a consumer to feed the individual key values to.- Returns:
- false if the consumer provided ever returned false, true otherwise.
-
subindexByPos
Description copied from interface:ReadOnlyIndexGet a subset of this index within this range of positions- Specified by:
subindexByPosin interfaceReadOnlyIndex- Parameters:
startPos- The first position to included in the output (inclusive)endPos- The last position to included in the output (exclusive)- Returns:
- A new index, containing only positions >= startPos and < endPos
-
subindexByKey
Description copied from interface:ReadOnlyIndexGet a subset of this index within this range of keys.- Specified by:
subindexByKeyin interfaceReadOnlyIndex- Parameters:
startKey- The first key to include in the output.endKey- The last key (inclusive) to include in the output.- Returns:
- A new index, containing only values >= startKey and <= endKey.
-
get
public long get(long pos) Description copied from interface:ReadOnlyIndexReturns the key at the given rank position.- Specified by:
getin interfaceReadOnlyIndex- Parameters:
pos- a position in this index between 0 and size() - 1- Returns:
- the key at that rank.
-
getKeysForPositions
Description copied from interface:ReadOnlyIndexReturns the sequence of (increasing) keys corresponding to the positions provided as input.- Specified by:
getKeysForPositionsin interfaceReadOnlyIndex- Parameters:
positions- an iterator providing index positions in increasing order.outputKeys- a consumer of corresponding keys for the positions provided as input.
-
getPrev
public long getPrev(long pos) - Specified by:
getPrevin interfaceReadOnlyIndex
-
sizePrev
public long sizePrev()- Specified by:
sizePrevin interfaceReadOnlyIndex
-
getPrevIndex
- Specified by:
getPrevIndexin interfaceReadOnlyIndex
-
initializePreviousValue
public void initializePreviousValue()Description copied from interface:IndexInitializes our previous value from the current value. This call is used by operations that manipulate an Index while constructing it, but need to set the state at the end of the initial operation to the current state. Calling this in other circumstances will yield undefined results.- Specified by:
initializePreviousValuein interfaceIndex
-
find
public long find(long key) Description copied from interface:ReadOnlyIndexReturns the position in [0..(size-1)] where the key is found. If not found, then return (-(position it would be) - 1), a la Array.binarySearch.- Specified by:
findin interfaceReadOnlyIndex- Parameters:
key- the key to search for- Returns:
- a position from [0..(size-1)] if the key was found. If the key was not found, then (-position - 1) as in Array.binarySearch.
-
invert
Description copied from class:SortedIndexThe only used implementation of invert is in the TreeIndex, really the guts of it are in BspNodeIndex. This version is inefficient as it simply performs O(keys) find operations; which is O(keys * lg size), because there is no memory about what you've already found. It serves as a reasonable reference for what the invert operation is "meant" to do. Note maximumPosition is inclusive.- Specified by:
invertin interfaceReadOnlyIndex- Overrides:
invertin classSortedIndex- Parameters:
keys- the keys to find positions formaximumPosition- the largest position for which we will find a key- Returns:
- a new Index containing the positions of the keys in this index
-
findPrev
public long findPrev(long key) Description copied from interface:ReadOnlyIndexReturns the position in [0..(size-1)] where the key is found in the previous index. If not found, then return (-(position it would be) - 1), as in Array.binarySearch.- Specified by:
findPrevin interfaceReadOnlyIndex- Parameters:
key- the key to search for- Returns:
- a position from [0..(size-1)] if the key was found. If the key was not found, then (-position - 1) as in Array.binarySearch.
-
firstKeyPrev
public long firstKeyPrev()- Specified by:
firstKeyPrevin interfaceReadOnlyIndex
-
lastKeyPrev
public long lastKeyPrev()- Specified by:
lastKeyPrevin interfaceReadOnlyIndex
-
searchIterator
- Specified by:
searchIteratorin interfaceReadOnlyIndex
-
iterator
- Specified by:
iteratorin interfaceIterable<Long>- Specified by:
iteratorin interfaceReadOnlyIndex
-
reverseIterator
- Specified by:
reverseIteratorin interfaceReadOnlyIndex
-
rangeIterator
- Specified by:
rangeIteratorin interfaceReadOnlyIndex
-
size
public long size()Description copied from interface:ReadOnlyIndexHow many keys are in this index.- Specified by:
sizein interfaceLongSizedDataStructure- Specified by:
sizein interfaceOrderedKeys- Specified by:
sizein interfaceReadOnlyIndex- Returns:
- the number of keys in this index.
-
empty
public boolean empty()Description copied from interface:ReadOnlyIndexQueries whether this index is empty (i.e. has no keys).- Specified by:
emptyin interfaceReadOnlyIndex- Returns:
- true if the size() of this Index is zero, false if the size is greater than zero
-
containsRange
public boolean containsRange(long start, long end) Description copied from interface:ReadOnlyIndexQueries whether this index contains every element in the range provided.- Specified by:
containsRangein interfaceReadOnlyIndex- Parameters:
start- Start of the range, inclusive.end- End of the range, inclusive.- Returns:
- true if this index contains every element x in start <= x <= end.
-
compact
public void compact()Description copied from interface:IndexMay reclaim some unused memory. -
update
Description copied from interface:IndexSimultaneously adds the keys from the first index and removes the keys from the second one. API assumption: the intersection of added and removed is empty. -
retain
Description copied from interface:IndexModifies the index by removing any keys not in the indexToIntersect argument. -
retainRange
public void retainRange(long startKey, long endKey) Description copied from interface:IndexModifies the index by keeping only keys in the interval [start, end]- Specified by:
retainRangein interfaceIndex- Parameters:
startKey- beginning of interval of keys to keep.endKey- end of interval of keys to keep (inclusive).
-
intersect
Description copied from interface:ReadOnlyIndexReturns a new index representing the intersection of the current index with the input index- Specified by:
intersectin interfaceReadOnlyIndex
-
overlaps
Description copied from interface:ReadOnlyIndexReturns true if an index has any overlap.- Specified by:
overlapsin interfaceReadOnlyIndex
-
overlapsRange
public boolean overlapsRange(long start, long end) Description copied from interface:ReadOnlyIndexReturns true if this index has any overlap with the provided range.- Specified by:
overlapsRangein interfaceReadOnlyIndex- Parameters:
start- Start of range, inclusive.end- End of range, inclusive.- Returns:
- true if any value x in start <= x <= end is contained in this index.
-
subsetOf
Description copied from interface:ReadOnlyIndexReturns true if this index is a (possibly improper) subset of other.- Specified by:
subsetOfin interfaceReadOnlyIndex- Returns:
- true if every element of this exists within other
-
minus
Description copied from interface:ReadOnlyIndexReturns a new index representing the keys of the current set not present inside indexToRemove This operation is equivalent to set difference. This index is not modified.- Specified by:
minusin interfaceReadOnlyIndex
-
union
Description copied from interface:ReadOnlyIndexReturns a new index representing the keys present in both this index and the argument index.- Specified by:
unionin interfaceReadOnlyIndex- Parameters:
set- an index whose keys will be joined with our own to produce a new index.- Returns:
- a new index with the union of the keys in both this index and indexToAdd.
-
makeRandomBuilder
-
makeSequentialBuilder
-
makeCurrentRandomBuilder
-
makeCurrentSequentialBuilder
-
getEmptyIndex
-
toString
- Overrides:
toStringin classSortedIndex
-
toString
-
shift
Description copied from interface:ReadOnlyIndexReturns a new index representing the keys in this index shifted by the amount indicated.- Specified by:
shiftin interfaceReadOnlyIndex- Parameters:
shiftAmount- the amount to shift the keys in the index- Returns:
- a new index with the keys shifted by shiftAmount
-
shiftInPlace
public void shiftInPlace(long shiftAmount) - Specified by:
shiftInPlacein interfaceIndex
-
insertWithShift
Description copied from interface:IndexFor each key in the provided index, shift it by shiftAmount and insert it in the current index.- Specified by:
insertWithShiftin interfaceIndex- Parameters:
shiftAmount- the amount to add to each key in the index argument before insertion.other- the index with the keys to shift and insert.
-
validate
- Specified by:
validatein interfaceReadOnlyIndex
-
clone
Description copied from interface:ReadOnlyIndexCreate a copy of this index.- Specified by:
clonein interfaceReadOnlyIndex- Overrides:
clonein classSortedIndex- Returns:
- a copy of this index
-
add
-
append
public com.fishlib.base.log.LogOutput append(com.fishlib.base.log.LogOutput logOutput) - Specified by:
appendin interfacecom.fishlib.base.log.LogOutputAppendable
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
writeImpl
- Throws:
IOException
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
getAverageRunLengthEstimate
public long getAverageRunLengthEstimate()Description copied from interface:OrderedKeysGet an estimate of the average (mean) length of runs of adjacent keys in this
OrderedKeys.Implementations should strive to keep this method efficient (O(1) preferred) at the expense of accuracy.
Empty
OrderedKeysshould return an arbitrary valid value, usually 1.- Specified by:
getAverageRunLengthEstimatein interfaceOrderedKeys- Returns:
- An estimate of the average run length in this
OrderedKeys, in [1,size()]
-
getOrderedKeysIterator
Description copied from interface:OrderedKeysGet anOrderedKeys.Iteratorover thisOrderedKeys.- Specified by:
getOrderedKeysIteratorin interfaceOrderedKeys- Returns:
- A new iterator, positioned at the first key
-
getOrderedKeysByKeyRange
Description copied from interface:OrderedKeysGet an ordered subset of the keys in this
OrderedKeysfor a key range. The returned set will be the intersection of the keys inthiswith the keys in the closed interval [startKeyInclusive,endKeyInclusive]. The returned reference is owned by the caller, who should callclose()when it is done with it.- Specified by:
getOrderedKeysByKeyRangein interfaceOrderedKeys- Parameters:
startKeyInclusive- The minimum key to includeendKeyInclusive- The maximum key to include- Returns:
- The subset as an
OrderedKeys, which may bethis
-
getOrderedKeysByPosition
Description copied from interface:OrderedKeysGet an ordered subset of the keys in this
OrderedKeysfor a position range. The result will contain the set of keys inthisthat lie at positions in the half-open range [startPositionInclusive,startPositionInclusive + length). The returned reference is owned by the caller, who should callclose()when it is done with it.- Specified by:
getOrderedKeysByPositionin interfaceOrderedKeys- Parameters:
start- The position of the first key to includelen- The number of keys to include- Returns:
- The subset as an
OrderedKeys, which may bethis
-
asIndex
Description copied from interface:OrderedKeysGet anIndexrepresentation of thisOrderedKeys.- Specified by:
asIndexin interfaceOrderedKeys- Returns:
- An
Indexrepresentation for the same keys in the same order
-
fillKeyIndicesChunk
Description copied from interface:OrderedKeysFill the supplied
WritableLongChunkwith individual keys from thisOrderedKeys.The chunk's capacity is assumed to be big enough.
- Specified by:
fillKeyIndicesChunkin interfaceOrderedKeys- Parameters:
chunkToFill- A chunk to fill with individual keys
-
fillKeyRangesChunk
Description copied from interface:OrderedKeysFill the supplied
WritableLongChunkwith key ranges from thisOrderedKeys.The chunk's capacity is assumed to be big enough.
- Specified by:
fillKeyRangesChunkin interfaceOrderedKeys- Parameters:
chunkToFill- A chunk to fill with key ranges
-
rangesCountUpperBound
public long rangesCountUpperBound()- Specified by:
rangesCountUpperBoundin classOrderedKeysAsChunkImpl
-
strid
Override to improve index debug-tracing messages.
-