Class ArrayContainer
java.lang.Object
com.illumon.iris.db.v2.utils.rsp.container.Container
com.illumon.iris.db.v2.utils.rsp.container.ArrayContainer
- Direct Known Subclasses:
RspArray.SpanView
public class ArrayContainer extends Container
Simple container made of an array of 16-bit integers
-
Field Summary
Fields Modifier and Type Field Description protected intcardinalityprotected short[]contentprotected booleansharedstatic intSWITCH_CONTAINER_CARDINALITY_THRESHOLDFields inherited from class com.illumon.iris.db.v2.utils.rsp.container.Container
ContainerNames, DEBUG, MAX_RANGE, MAX_VALUE, threadLocalBuf -
Constructor Summary
Constructors Modifier Constructor Description ArrayContainer()Create an array container with default capacityArrayContainer(int capacity)Create an array container with specified capacityArrayContainer(short[] newContent)ArrayContainer(short[] arr, int sz)protectedArrayContainer(short[] content, int cardinality, boolean shared) -
Method Summary
Modifier and Type Method Description Containeradd(int begin, int end)Return a new container with all shorts in [begin,end) added using an unsigned interpretation.Containerand(ArrayContainer value2)Computes the bitwise AND of this container with another (intersection).Containerand(BitmapContainer x)Computes the bitwise AND of this container with another (intersection).Containerand(RunContainer x)Computes the bitwise AND of this container with another (intersection).ContainerandNot(ArrayContainer value2)Computes the bitwise ANDNOT of this container with another (difference).ContainerandNot(BitmapContainer value2)Computes the bitwise ANDNOT of this container with another (difference).ContainerandNot(RunContainer x)Computes the bitwise ANDNOT of this container with another (difference).ContainerandRange(int start, int end)Calculate the intersection of this container and a range, in a new container.intbytesAllocated()intbytesUsed()booleancontains(int rangeStart, int rangeEnd)Checks whether the container contains the entire rangebooleancontains(short x)Checks whether the contain contains the provided valueprotected booleancontains(ArrayContainer arrayContainer)protected booleancontains(BitmapContainer bitmapContainer)protected booleancontains(RunContainer runContainer)ArrayContainercowRef()Get a shared, copy-on-write copy of an existing container.ArrayContainerdeepCopy()Get a full deep copy of the container in a new container object.intfind(short x)Searches for the specified short valuebooleanfindRanges(RangeConsumer outPositions, RangeIterator inValues, int maxPos)As find but for all the values in a range.intfirst()Get the first integer held in the containerbooleanforEach(int rankOffset, ShortConsumer sc)Like forEach, but skipping the first rankOffset elements.booleanforEach(ShortConsumer sc)Iterate through the values of this container in order and pass them along to the ShortConsumer.booleanforEachRange(int rankOffset, ShortRangeConsumer sc)intgetCardinality()Computes the distinct number of short values in the container.short[]getContent()ShortAdvanceIteratorgetReverseShortIterator()Iterator to visit the short values in the container in descending order.ContainerShortBatchIteratorgetShortBatchIterator(int skipCount)Gets an iterator to visit the contents of the container in batches of short valuescom.illumon.iris.db.v2.utils.rsp.container.ArrayContainer.ShortForwardIteratorgetShortIterator()Iterator to visit the short values in the container in ascending order.SearchRangeIteratorgetShortRangeIterator(int initialSeek)Iterator to visit the short values in container in [start, end) ranges, in increasing order of start values.Containeriadd(int begin, int end)Add all shorts in [begin,end) using an unsigned interpretation.Containeriand(ArrayContainer value2)Computes the in-place bitwise AND of this container with another (intersection).Containeriand(BitmapContainer value2)Computes the in-place bitwise AND of this container with another (intersection).Containeriand(RunContainer x)Computes the in-place bitwise AND of this container with another (intersection).ContaineriandNot(ArrayContainer value2)Computes the in-place bitwise ANDNOT of this container with another (difference).ContaineriandNot(BitmapContainer value2)Computes the in-place bitwise ANDNOT of this container with another (difference).ContaineriandNot(RunContainer x)Computes the in-place bitwise ANDNOT of this container with another (difference).ContaineriandRange(int start, int end)Calculate the intersection of this container and a range; may overwrite the existing container or return a new one.Containeriappend(int begin, int end)Add all shorts in [begin,end) using an unsigned interpretation.Containeriflip(short x)Add a short to the container if it is not present, otherwise remove it.Containerinot(int firstOfRange, int exclusiveEndOfRange)Computes the in-place bitwise NOT of this container (complement).Containerior(ArrayContainer value2)Computes the in-place bitwise OR of this container with another (union).Containerior(BitmapContainer x)Computes the in-place bitwise OR of this container with another (union).Containerior(RunContainer x)Computes the in-place bitwise OR of this container with another (union).Containeriremove(int begin, int end)Remove shorts in [begin,end) using an unsigned interpretation.booleanisAllOnes()Checks whether the container spans the full 2^16 range (ie, contains every short value) This is an O(1) operation in all container types (some do not cache cardinality).booleanisEmpty()Checks whether the container is empty or not.Containeriset(short x)Insert a short to the container.booleanisShared()Containeriunset(short x)Create a new container with the short removed.Containerixor(ArrayContainer value2)Computes the in-place bitwise XOR of this container with another (symmetric difference).Containerixor(BitmapContainer x)Computes the in-place bitwise XOR of this container with another (symmetric difference).Containerixor(RunContainer x)Computes the in-place bitwise XOR of this container with another (symmetric difference).intlast()Get the last integer held in the containerprotected voidloadData(BitmapContainer bitmapContainer)protected voidloadDataWithSkipValue(BitmapContainer bitmapContainer, short valueToSkip, PositionHint positionHintOut)static ArrayContainermakeByCopying(int newCapacity, short[] arr, int offset, int sz)static ArrayContainermakeByCopying(short[] arr, int offset, int sz)Construct a new ArrayContainer from values copied from the provided array.static ArrayContainermakeByWrapping(short[] arr, int sz)Construct a new ArrayContainer using the provided array.intnextValue(short fromValue)Gets the first value greater than or equal to the lower bound, or -1 if no such value exists.Containernot(int firstOfRange, int lastOfRange)Computes the bitwise NOT of this container (complement).protected voidonCopyOnWrite()Containeror(ArrayContainer value2)Computes the bitwise OR of this container with another (union).Containeror(BitmapContainer x)Computes the bitwise OR of this container with another (union).Containeror(RunContainer x)Computes the bitwise OR of this container with another (union).protected Containeror(ShortIterator it)booleanoverlaps(ArrayContainer c)booleanoverlaps(BitmapContainer c)booleanoverlaps(RunContainer c)booleanoverlapsRange(int rangeStart, int rangeEnd)intrank(short lowbits)Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality()).Containerremove(int begin, int end)Return a new container with all shorts in [begin,end) remove using an unsigned interpretation.ContainerrunOptimize()Convert to RunContainers, when the result is smaller.shortselect(int j)Return the jth valueContainerselect(int startRank, int endRank)Returns a new container with all values between ranks startPos and endPos.voidselectRanges(RangeConsumer outValues, RangeIterator inPositions)As select but for all the positions in a range.Containerset(short x)Return a new container with the short given as parameter added.voidsetCopyOnWrite()booleansubsetOf(ArrayContainer c)booleansubsetOf(BitmapContainer c)booleansubsetOf(RunContainer c)BitmapContainertoBitmapContainer()Copies the data in a bitmap container.ContainertoLargeContainer()voidtrim()If possible, recover wasted memory.Containerunset(short x)Remove the short from this container.voidvalidate()Containerxor(ArrayContainer value2)Computes the bitwise XOR of this container with another (symmetric difference).Containerxor(BitmapContainer x)Computes the bitwise XOR of this container with another (symmetric difference).Containerxor(RunContainer x)Computes the bitwise XOR of this container with another (symmetric difference).protected Containerxor(ShortIterator it)Methods inherited from class com.illumon.iris.db.v2.utils.rsp.container.Container
and, andNot, check, contains, empty, full, getContainerName, iand, iandNot, ifDebugValidate, intersects, intersects, ior, isFull, isSingleElement, ixor, numberOfRanges, or, overlaps, rangeOfOnes, remove, singleRange, singleton, subsetOf, toString, twoRanges, twoValues, xor
-
Field Details
-
SWITCH_CONTAINER_CARDINALITY_THRESHOLD
public static final int SWITCH_CONTAINER_CARDINALITY_THRESHOLD- See Also:
- Constant Field Values
-
cardinality
protected int cardinality -
content
protected short[] content -
shared
protected boolean shared
-
-
Constructor Details
-
ArrayContainer
protected ArrayContainer(short[] content, int cardinality, boolean shared) -
ArrayContainer
public ArrayContainer()Create an array container with default capacity -
ArrayContainer
public ArrayContainer(int capacity)Create an array container with specified capacity- Parameters:
capacity- The capacity of the container
-
ArrayContainer
public ArrayContainer(short[] arr, int sz) -
ArrayContainer
public ArrayContainer(short[] newContent)
-
-
Method Details
-
getContent
public short[] getContent() -
makeByCopying
Construct a new ArrayContainer from values copied from the provided array.- Parameters:
arr- array with values in increasing unsigned short order.offset- index position for the first element to take.sz- number of elements to read from the array.
-
makeByCopying
-
makeByWrapping
Construct a new ArrayContainer using the provided array. The container takes ownership of the array.- Parameters:
arr- array with values in increasing unsigned short order. The container takes ownership of this array.sz- number of elements in arr.
-
add
Description copied from class:ContainerReturn a new container with all shorts in [begin,end) added using an unsigned interpretation. -
iset
Description copied from class:ContainerInsert a short to the container. May generate a new container. -
set
Description copied from class:ContainerReturn a new container with the short given as parameter added. -
and
Description copied from class:ContainerComputes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected. -
and
Description copied from class:ContainerComputes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected. -
and
Description copied from class:ContainerComputes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected. -
andNot
Description copied from class:ContainerComputes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected. -
andNot
Description copied from class:ContainerComputes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected. -
andNot
Description copied from class:ContainerComputes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected. -
deepCopy
Description copied from class:ContainerGet a full deep copy of the container in a new container object. -
cowRef
Description copied from class:ContainerGet a shared, copy-on-write copy of an existing container. Mutations on the returned container will always return a copy and leave the original container unchanged.This operation allows for cheap read-only references to the same values, at the cost of an additional copy for any first mutation.
-
isEmpty
public boolean isEmpty()Description copied from class:ContainerChecks whether the container is empty or not. -
isAllOnes
public boolean isAllOnes()Description copied from class:ContainerChecks whether the container spans the full 2^16 range (ie, contains every short value) This is an O(1) operation in all container types (some do not cache cardinality). -
contains
public boolean contains(short x)Description copied from class:ContainerChecks whether the contain contains the provided value -
contains
public boolean contains(int rangeStart, int rangeEnd)Description copied from class:ContainerChecks whether the container contains the entire range -
contains
-
contains
-
contains
-
iflip
Description copied from class:ContainerAdd a short to the container if it is not present, otherwise remove it. May generate a new container. -
getCardinality
public int getCardinality()Description copied from class:ContainerComputes the distinct number of short values in the container. Can be expected to run in constant time.- Specified by:
getCardinalityin classContainer- Returns:
- the cardinality
-
getReverseShortIterator
Description copied from class:ContainerIterator to visit the short values in the container in descending order.- Specified by:
getReverseShortIteratorin classContainer- Returns:
- iterator
-
getShortIterator
public com.illumon.iris.db.v2.utils.rsp.container.ArrayContainer.ShortForwardIterator getShortIterator()Description copied from class:ContainerIterator to visit the short values in the container in ascending order.- Specified by:
getShortIteratorin classContainer- Returns:
- iterator
-
getShortBatchIterator
Description copied from class:ContainerGets an iterator to visit the contents of the container in batches of short values- Specified by:
getShortBatchIteratorin classContainer- Parameters:
skipCount- number of elements to skip from the start of the container.- Returns:
- iterator
-
getShortRangeIterator
Description copied from class:ContainerIterator to visit the short values in container in [start, end) ranges, in increasing order of start values.- Specified by:
getShortRangeIteratorin classContainer- Returns:
- iterator
-
iadd
Description copied from class:ContainerAdd all shorts in [begin,end) using an unsigned interpretation. May generate a new container. -
iappend
Description copied from class:ContainerAdd all shorts in [begin,end) using an unsigned interpretation. May generate a new container. The beginning of the range should be strictly greater than the last value already present in the container, if there is one. -
iand
Description copied from class:ContainerComputes the in-place bitwise AND of this container with another (intersection). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container. -
iand
Description copied from class:ContainerComputes the in-place bitwise AND of this container with another (intersection). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container. -
iand
Description copied from class:ContainerComputes the in-place bitwise AND of this container with another (intersection). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container. -
iandNot
Description copied from class:ContainerComputes the in-place bitwise ANDNOT of this container with another (difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container. -
iandNot
Description copied from class:ContainerComputes the in-place bitwise ANDNOT of this container with another (difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container. -
iandNot
Description copied from class:ContainerComputes the in-place bitwise ANDNOT of this container with another (difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container. -
inot
Description copied from class:ContainerComputes the in-place bitwise NOT of this container (complement). Only those bits within the range are affected. The current container is generally modified. May generate a new container. -
ior
Description copied from class:ContainerComputes the in-place bitwise OR of this container with another (union). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container. -
ior
Description copied from class:ContainerComputes the in-place bitwise OR of this container with another (union). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container. -
ior
Description copied from class:ContainerComputes the in-place bitwise OR of this container with another (union). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container. -
remove
Description copied from class:ContainerReturn a new container with all shorts in [begin,end) remove using an unsigned interpretation. -
iremove
Description copied from class:ContainerRemove shorts in [begin,end) using an unsigned interpretation. May generate a new container. -
ixor
Description copied from class:ContainerComputes the in-place bitwise XOR of this container with another (symmetric difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container. -
ixor
Description copied from class:ContainerComputes the in-place bitwise XOR of this container with another (symmetric difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container. -
ixor
Description copied from class:ContainerComputes the in-place bitwise XOR of this container with another (symmetric difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container. -
loadData
-
loadDataWithSkipValue
protected void loadDataWithSkipValue(BitmapContainer bitmapContainer, short valueToSkip, PositionHint positionHintOut) -
not
Description copied from class:ContainerComputes the bitwise NOT of this container (complement). Only those bits within the range are affected. This is equivalent to an xor with a range of ones for the given range. The current container is left unaffected. -
or
Description copied from class:ContainerComputes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected. -
or
Description copied from class:ContainerComputes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected. -
or
Description copied from class:ContainerComputes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected. -
or
-
rank
public int rank(short lowbits)Description copied from class:ContainerRank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality()). -
iunset
Description copied from class:ContainerCreate a new container with the short removed. -
unset
Description copied from class:ContainerRemove the short from this container. May create a new container. -
runOptimize
Description copied from class:ContainerConvert to RunContainers, when the result is smaller. Overridden by RunContainer to possibility switch from RunContainer to a smaller alternative. Overridden by BitmapContainer with a more efficient approach.- Specified by:
runOptimizein classContainer- Returns:
- the new container
-
select
public short select(int j)Description copied from class:ContainerReturn the jth value -
select
Description copied from class:ContainerReturns a new container with all values between ranks startPos and endPos. -
find
public int find(short x)Description copied from class:ContainerSearches for the specified short value- Specified by:
findin classContainer- Parameters:
x- value to search for- Returns:
- Relative position of the value in the sorted set of elements in this container,
in the range [0 .. cardinality - 1]. If not present, (-(insertion point) - 1) similar to Array.binarySearch.
For values of x that
Container.contains(short)returns true, this method returns the same value asContainer.rank(short).
-
selectRanges
Description copied from class:ContainerAs select but for all the positions in a range.- Specified by:
selectRangesin classContainer- Parameters:
outValues- accept is called in this consumer for each resulting range.inPositions- input iterator that provides the position ranges.
-
iandRange
Description copied from class:ContainerCalculate the intersection of this container and a range; may overwrite the existing container or return a new one. -
andRange
Description copied from class:ContainerCalculate the intersection of this container and a range, in a new container. The existing container is not modified. -
findRanges
Description copied from class:ContainerAs find but for all the values in a range.- Specified by:
findRangesin classContainer- Parameters:
outPositions- accept is called in this consumer for each resulting position range.inValues- input iterator that provides the key ranges; these must each exist in the container.maxPos- maximum position to add to outPositions; values of position > maxPos are not added.- Returns:
- true if maxPos was reached, false otherwise.
-
toBitmapContainer
Copies the data in a bitmap container.- Specified by:
toBitmapContainerin classContainer- Returns:
- the bitmap container
-
nextValue
public int nextValue(short fromValue)Description copied from class:ContainerGets the first value greater than or equal to the lower bound, or -1 if no such value exists. -
first
public int first()Description copied from class:ContainerGet the first integer held in the container -
last
public int last()Description copied from class:ContainerGet the last integer held in the container -
trim
public void trim()Description copied from class:ContainerIf possible, recover wasted memory. -
xor
Description copied from class:ContainerComputes the bitwise XOR of this container with another (symmetric difference). This container as well as the provided container are left unaffected. -
xor
Description copied from class:ContainerComputes the bitwise XOR of this container with another (symmetric difference). This container as well as the provided container are left unaffected. -
xor
Description copied from class:ContainerComputes the bitwise XOR of this container with another (symmetric difference). This container as well as the provided container are left unaffected. -
xor
-
forEach
Description copied from class:ContainerIterate through the values of this container in order and pass them along to the ShortConsumer. -
forEach
Description copied from class:ContainerLike forEach, but skipping the first rankOffset elements. -
forEachRange
- Specified by:
forEachRangein classContainer
-
subsetOf
-
subsetOf
-
subsetOf
-
overlapsRange
public boolean overlapsRange(int rangeStart, int rangeEnd)- Specified by:
overlapsRangein classContainer- Parameters:
rangeStart- the beginning of the range, as an int.rangeEnd- the end of the range (exclusive), as an int.- Returns:
- true if there is any element in this container in the range provided.
-
overlaps
-
overlaps
-
overlaps
-
setCopyOnWrite
public final void setCopyOnWrite()- Specified by:
setCopyOnWritein classContainer
-
onCopyOnWrite
protected void onCopyOnWrite() -
bytesAllocated
public int bytesAllocated()- Specified by:
bytesAllocatedin classContainer- Returns:
- The allocated size in bytes of the underlying array backing store used by this container.
-
bytesUsed
public int bytesUsed() -
toLargeContainer
-
validate
public void validate() -
isShared
public boolean isShared()
-