Interface OrderedKeys
- All Superinterfaces:
AutoCloseable
,LongSizedDataStructure
,SafeCloseable
- All Known Subinterfaces:
Index
,ReadOnlyIndex
,SingleRangeMixin
- All Known Implementing Classes:
CurrentOnlyIndex
,OrderedKeysAsChunkImpl
,OrderedKeysKeyIndicesChunkImpl
,OrderedKeysKeyRangesChunkImpl
,RspOrderedKeys
,ShiftedOrderedKeys
,SingleRangeOrderedKeys
,SortedIndex
,SortedRangesOrderedKeys
,TreeIndex
public interface OrderedKeys extends SafeCloseable, LongSizedDataStructure
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
OrderedKeys.Iterator
Iterator for consuming anOrderedKeys
by ordered subsets. -
Field Summary
Fields Modifier and Type Field Description static OrderedKeys
EMPTY
Immutable, re-usableOrderedKeys
instance. -
Method Summary
Modifier and Type Method Description Index
asIndex()
Get anIndex
representation of thisOrderedKeys
.LongChunk<Attributes.OrderedKeyIndices>
asKeyIndicesChunk()
Get aLongChunk
representation of the individual keys in thisOrderedKeys
.LongChunk<Attributes.OrderedKeyRanges>
asKeyRangesChunk()
Get aLongChunk
representation of key ranges in thisOrderedKeys
.default void
close()
Free any resources associated with this object.void
fillKeyIndicesChunk(WritableLongChunk<? extends Attributes.KeyIndices> chunkToFill)
Fill the suppliedWritableLongChunk
with individual keys from thisOrderedKeys
.void
fillKeyRangesChunk(WritableLongChunk<Attributes.OrderedKeyRanges> chunkToFill)
Fill the suppliedWritableLongChunk
with key ranges from thisOrderedKeys
.long
firstKey()
Get the first key in thisOrderedKeys
.default void
forAllLongRanges(LongRangeConsumer lrc)
default void
forAllLongs(LongConsumer lc)
boolean
forEachLong(LongAbortableConsumer lac)
For as long as the consumer wants more keys, call accept on the consumer with the individual key instances in this OrderedKeys, in increasing order.boolean
forEachLongRange(LongRangeAbortableConsumer larc)
For as long as the consumer wants more ranges, call accept on the consumer with the individual key ranges in this OrderedKeys, in increasing order.static OrderedKeys
forRange(long firstKey, long lastKey)
long
getAverageRunLengthEstimate()
Get an estimate of the average (mean) length of runs of adjacent keys in thisOrderedKeys
.OrderedKeys
getOrderedKeysByKeyRange(long startKeyInclusive, long endKeyInclusive)
Get an ordered subset of the keys in thisOrderedKeys
for a key range.OrderedKeys
getOrderedKeysByPosition(long startPositionInclusive, long length)
Get an ordered subset of the keys in thisOrderedKeys
for a position range.OrderedKeys.Iterator
getOrderedKeysIterator()
Get anOrderedKeys.Iterator
over thisOrderedKeys
.default boolean
isContiguous()
Helper to tell you if this is one contiguous range.boolean
isEmpty()
True if the size of thisOrderedkeys
is zero.long
lastKey()
Get the last key in thisOrderedKeys
.long
size()
Get the number of keys in thisOrderedKeys
.static OrderedKeys
takeKeyIndicesChunkAndMakeOrderedKeys(WritableLongChunk<Attributes.OrderedKeyIndices> longChunk)
Create and return a new OrderedKeys object from the provided WritableLongChunk.static OrderedKeys
takeKeyRangesChunkAndMakeOrderedKeys(WritableLongChunk<Attributes.OrderedKeyRanges> longChunk)
Create and return a new OrderedKeys object from the provided WritableLongChunk.static OrderedKeys
wrapKeyIndicesChunkAsOrderedKeys(LongChunk<Attributes.OrderedKeyIndices> longChunk)
Wrap a LongChunk as an OrderedKeys.static OrderedKeys
wrapKeyRangesChunkAsOrderedKeys(LongChunk<Attributes.OrderedKeyRanges> longChunk)
Wrap a LongChunk as an OrderedKeys.
-
Field Details
-
EMPTY
Immutable, re-usableOrderedKeys
instance.
-
-
Method Details
-
wrapKeyIndicesChunkAsOrderedKeys
static OrderedKeys wrapKeyIndicesChunkAsOrderedKeys(LongChunk<Attributes.OrderedKeyIndices> longChunk)Wrap a LongChunk as an OrderedKeys.- Parameters:
longChunk
- A chunk to wrap as a new OrderedKeys object.- Returns:
- A new OrderedKeys object, who does not own the passed chunk.
-
wrapKeyRangesChunkAsOrderedKeys
static OrderedKeys wrapKeyRangesChunkAsOrderedKeys(LongChunk<Attributes.OrderedKeyRanges> longChunk)Wrap a LongChunk as an OrderedKeys.- Parameters:
longChunk
- A chunk to wrap as a new OrderedKeys object.- Returns:
- A new OrderedKeys object, who does not own the passed chunk.
-
takeKeyIndicesChunkAndMakeOrderedKeys
static OrderedKeys takeKeyIndicesChunkAndMakeOrderedKeys(WritableLongChunk<Attributes.OrderedKeyIndices> longChunk)Create and return a new OrderedKeys object from the provided WritableLongChunk.- Parameters:
longChunk
- The input chunk. The returned object will take ownership of this chunk.- Returns:
- A new OrderedKeys object, who owns the passed chunk.
-
takeKeyRangesChunkAndMakeOrderedKeys
static OrderedKeys takeKeyRangesChunkAndMakeOrderedKeys(WritableLongChunk<Attributes.OrderedKeyRanges> longChunk)Create and return a new OrderedKeys object from the provided WritableLongChunk.- Parameters:
longChunk
- The input chunk. The returned object will take ownership of this chunk.- Returns:
- A new OrderedKeys object, who owns the passed chunk.
-
getOrderedKeysIterator
OrderedKeys.Iterator getOrderedKeysIterator()Get anOrderedKeys.Iterator
over thisOrderedKeys
.- Returns:
- A new iterator, positioned at the first key
-
getOrderedKeysByPosition
Get an ordered subset of the keys in this
OrderedKeys
for a position range. The result will contain the set of keys inthis
that 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.- Parameters:
startPositionInclusive
- The position of the first key to includelength
- The number of keys to include- Returns:
- The subset as an
OrderedKeys
, which may bethis
-
getOrderedKeysByKeyRange
Get an ordered subset of the keys in this
OrderedKeys
for a key range. The returned set will be the intersection of the keys inthis
with 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.- Parameters:
startKeyInclusive
- The minimum key to includeendKeyInclusive
- The maximum key to include- Returns:
- The subset as an
OrderedKeys
, which may bethis
-
asIndex
Index asIndex()Get anIndex
representation of thisOrderedKeys
.- Returns:
- An
Index
representation for the same keys in the same order - ApiNote:
- If you use the result across clock ticks, you may observe inconsistencies., You must not mutate the result.
-
asKeyIndicesChunk
LongChunk<Attributes.OrderedKeyIndices> asKeyIndicesChunk()Get aLongChunk
representation of the individual keys in thisOrderedKeys
.- Returns:
- A
LongChunk
containing the keys in thisOrderedKeys
- ApiNote:
- This
OrderedKeys
owns the result, which is valid only as long as thisOrderedKeys
remains valid., You must not mutate the result.
-
asKeyRangesChunk
LongChunk<Attributes.OrderedKeyRanges> asKeyRangesChunk()Get aLongChunk
representation of key ranges in thisOrderedKeys
.- Returns:
- A
LongChunk
containing the key ranges in thisOrderedKeys
- ApiNote:
- This
OrderedKeys
owns the result, which is valid only as long as thisOrderedKeys
remains valid., You must not mutate the result.
-
fillKeyIndicesChunk
Fill the supplied
WritableLongChunk
with individual keys from thisOrderedKeys
.The chunk's capacity is assumed to be big enough.
- Parameters:
chunkToFill
- A chunk to fill with individual keys
-
fillKeyRangesChunk
Fill the supplied
WritableLongChunk
with key ranges from thisOrderedKeys
.The chunk's capacity is assumed to be big enough.
- Parameters:
chunkToFill
- A chunk to fill with key ranges
-
isEmpty
boolean isEmpty()True if the size of thisOrderedkeys
is zero.- Returns:
- True if there are no elements in this
OrderedKeys
.
-
firstKey
long firstKey()Get the first key in thisOrderedKeys
.- Returns:
- The first key, or
ReadOnlyIndex.NULL_KEY
if there is none.
-
lastKey
long lastKey()Get the last key in thisOrderedKeys
.- Returns:
- The last key, or
ReadOnlyIndex.NULL_KEY
if there is none.
-
size
long size()Get the number of keys in thisOrderedKeys
.- Specified by:
size
in interfaceLongSizedDataStructure
- Returns:
- The size, in [0,
Long.MAX_VALUE
]
-
isContiguous
default boolean isContiguous()Helper to tell you if this is one contiguous range. -
getAverageRunLengthEstimate
long getAverageRunLengthEstimate()Get 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
OrderedKeys
should return an arbitrary valid value, usually 1.- Returns:
- An estimate of the average run length in this
OrderedKeys
, in [1,size()
]
-
forEachLong
For as long as the consumer wants more keys, call accept on the consumer with the individual key instances in this OrderedKeys, in increasing order.- Parameters:
lac
- a consumer to feed the individual key values to.- Returns:
- false if the consumer provided ever returned false, true otherwise.
-
forEachLongRange
For as long as the consumer wants more ranges, call accept on the consumer with the individual key ranges in this OrderedKeys, in increasing order.- Parameters:
larc
- a consumer to feed the individual key values to.- Returns:
- false if the consumer provided ever returned false, true otherwise.
-
forAllLongs
-
forAllLongRanges
-
close
default void close()Free any resources associated with this object.
Using any
OrderedKeys
methods afterclose()
is an error and may produce exceptions or undefined results.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceSafeCloseable
-
forRange
-