Class Container
java.lang.Object
com.illumon.iris.db.v2.utils.rsp.container.Container
- Direct Known Subclasses:
ArrayContainer,BitmapContainer,ImmutableContainer,RunContainer
Base container class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String[]Name of the various possible containersstatic final booleanstatic final intThe maximum possible cardinality of a container, as an int.static final intThe maxumum possible value that can be stored in a container, as an int.protected static final ThreadLocal<short[]> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Containeradd(int begin, int end) Return a new container with all shorts in [begin,end) added using an unsigned interpretation.abstract ContainerComputes the bitwise AND of this container with another (intersection).abstract ContainerComputes the bitwise AND of this container with another (intersection).Computes the bitwise AND of this container with another (intersection).abstract Containerand(RunContainer x) Computes the bitwise AND of this container with another (intersection).abstract ContainerComputes the bitwise ANDNOT of this container with another (difference).abstract ContainerComputes the bitwise ANDNOT of this container with another (difference).Computes the bitwise ANDNOT of this container with another (difference).abstract ContainerComputes the bitwise ANDNOT of this container with another (difference).abstract ContainerandRange(int start, int end) Calculate the intersection of this container and a range, in a new container.abstract intabstract intcheck()abstract booleancontains(int rangeStart, int rangeEnd) Checks whether the container contains the entire rangeabstract booleancontains(short x) Checks whether the contain contains the provided valueprotected abstract booleancontains(ArrayContainer arrayContainer) protected abstract booleancontains(BitmapContainer bitmapContainer) booleanChecks whether the container is a subset of this container or notprotected abstract booleancontains(RunContainer runContainer) abstract ContainercowRef()Get a shared, copy-on-write copy of an existing container.abstract ContainerdeepCopy()Get a full deep copy of the container in a new container object.static Containerempty()abstract intfind(short x) Searches for the specified short valueabstract booleanfindRanges(RangeConsumer outPositions, RangeIterator inValues, int maxPos) As find but for all the values in a range.abstract intfirst()Get the first integer held in the containerabstract booleanforEach(int rankOffset, ShortConsumer sc) Like forEach, but skipping the first rankOffset elements.abstract booleanforEach(ShortConsumer sc) Iterate through the values of this container in order and pass them along to the ShortConsumer.abstract booleanforEachRange(int rankOffset, ShortRangeConsumer sc) static Containerfull()abstract intComputes the distinct number of short values in the container.Get the name of this container.abstract ShortAdvanceIteratorIterator to visit the short values in the container in descending order.abstract ContainerShortBatchIteratorgetShortBatchIterator(int skipFromStartCount) Gets an iterator to visit the contents of the container in batches of short valuesabstract ShortIteratorIterator to visit the short values in the container in ascending order.abstract SearchRangeIteratorgetShortRangeIterator(int skipFromStartCount) Iterator to visit the short values in container in [start, end) ranges, in increasing order of start values.abstract Containeriadd(int begin, int end) Add all shorts in [begin,end) using an unsigned interpretation.abstract ContainerComputes the in-place bitwise AND of this container with another (intersection).abstract ContainerComputes the in-place bitwise AND of this container with another (intersection).Computes the in-place bitwise AND of this container with another (intersection).abstract Containeriand(RunContainer x) Computes the in-place bitwise AND of this container with another (intersection).abstract ContainerComputes the in-place bitwise ANDNOT of this container with another (difference).abstract ContainerComputes the in-place bitwise ANDNOT of this container with another (difference).Computes the in-place bitwise ANDNOT of this container with another (difference).abstract ContainerComputes the in-place bitwise ANDNOT of this container with another (difference).abstract ContaineriandRange(int start, int end) Calculate the intersection of this container and a range; may overwrite the existing container or return a new one.abstract Containeriappend(int begin, int end) Add all shorts in [begin,end) using an unsigned interpretation.final voidabstract Containeriflip(short x) Add a short to the container if it is not present, otherwise remove it.abstract Containerinot(int rangeStart, int rangeEnd) Computes the in-place bitwise NOT of this container (complement).final booleanintersects(int start, int end) final booleanabstract ContainerComputes the in-place bitwise OR of this container with another (union).abstract ContainerComputes the in-place bitwise OR of this container with another (union).Computes the in-place bitwise OR of this container with another (union).abstract Containerior(RunContainer x) Computes the in-place bitwise OR of this container with another (union).abstract Containeriremove(int begin, int end) Remove shorts in [begin,end) using an unsigned interpretation.abstract booleanChecks 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).abstract booleanisEmpty()Checks whether the container is empty or not.abstract Containeriset(short x) Insert a short to the container.final booleanisFull()Deprecated.abstract booleanisShared()booleanChecks whether the container has exactly one element (meaningful since cardinality may not be cached in some Container types, eg, Run).abstract Containeriunset(short x) Create a new container with the short removed.abstract ContainerComputes the in-place bitwise XOR of this container with another (symmetric difference).abstract ContainerComputes the in-place bitwise XOR of this container with another (symmetric difference).Computes the in-place bitwise XOR of this container with another.abstract Containerixor(RunContainer x) Computes the in-place bitwise XOR of this container with another (symmetric difference).abstract intlast()Get the last integer held in the containerabstract intnextValue(short fromValue) Gets the first value greater than or equal to the lower bound, or -1 if no such value exists.abstract Containernot(int rangeStart, int rangeEnd) Computes the bitwise NOT of this container (complement).intComputes the number of ranges that a RangeIterator would provide on this container.abstract Containeror(ArrayContainer x) Computes the bitwise OR of this container with another (union).abstract ContainerComputes the bitwise OR of this container with another (union).Computes the bitwise OR of this container with another (union).abstract Containeror(RunContainer x) Computes the bitwise OR of this container with another (union).abstract booleanabstract booleanbooleanabstract booleanabstract booleanoverlapsRange(int start, int end) static ContainerrangeOfOnes(int start, int end) Create a container initialized with a range of consecutive valuesabstract intrank(short lowbits) Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality()).abstract Containerremove(int begin, int end) Return a new container with all shorts in [begin,end) remove using an unsigned interpretation.final Containerremove(short x) Deprecated.abstract ContainerConvert to RunContainers, when the result is smaller.abstract shortselect(int j) Return the jth valueabstract Containerselect(int startRank, int endRank) Returns a new container with all values between ranks startPos and endPos.abstract voidselectRanges(RangeConsumer outValues, RangeIterator inPositions) As select but for all the positions in a range.abstract Containerset(short x) Return a new container with the short given as parameter added.abstract voidstatic ContainersingleRange(int start, int end) static Containersingleton(short v) abstract booleanabstract booleanbooleanabstract booleanabstract BitmapContainerConvert the current container to a BitmapContainer, if a conversion is needed.toString()abstract voidtrim()If possible, recover wasted memory.static ContainertwoRanges(int start1, int end1, int start2, int end2) Returns a new Container containing the two provided ranges.static ContainertwoValues(short v1, short v2) abstract Containerunset(short x) Remove the short from this container.abstract voidvalidate()abstract ContainerComputes the bitwise XOR of this container with another (symmetric difference).abstract ContainerComputes the bitwise XOR of this container with another (symmetric difference).Computes the bitwise OR of this container with another (symmetric difference).abstract Containerxor(RunContainer x) Computes the bitwise XOR of this container with another (symmetric difference).
-
Field Details
-
DEBUG
public static final boolean DEBUG -
MAX_RANGE
public static final int MAX_RANGEThe maximum possible cardinality of a container, as an int. Also the maximum possible exclusive end for a range that can be stored in a container.- See Also:
-
MAX_VALUE
public static final int MAX_VALUEThe maxumum possible value that can be stored in a container, as an int.- See Also:
-
threadLocalBuf
-
ContainerNames
Name of the various possible containers
-
-
Constructor Details
-
Container
public Container()
-
-
Method Details
-
ifDebugValidate
public final void ifDebugValidate() -
check
-
validate
public abstract void validate() -
singleton
-
singleRange
-
full
-
rangeOfOnes
Create a container initialized with a range of consecutive values- Parameters:
start- first indexend- last index (range is exclusive)- Returns:
- a new container initialized with the specified values
-
twoValues
-
twoRanges
Returns a new Container containing the two provided ranges. The ranges provided should be nonempty, disjoint and provided in appearance order, ie, start2 > start1.- Parameters:
start1- start of first range, inclusive.end1- end of first range, exclusive.start2- start of second range, inclusive.end2- end of second range, exclusive.- Returns:
- A new Container containing the provided ranges.
-
empty
- Returns:
- An empty container.
-
add
Return a new container with all shorts in [begin,end) added using an unsigned interpretation.- Parameters:
begin- start of range (inclusive)end- end of range (exclusive)- Returns:
- the new container
-
iset
Insert a short to the container. May generate a new container.- Parameters:
x- short to be added- Returns:
- the resulting container
-
set
Return a new container with the short given as parameter added.- Parameters:
x- a short to be added- Returns:
- a new container with x added
-
and
Computes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected.- Parameters:
x- Another container- Returns:
- aggregated container
-
and
Computes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected.- Parameters:
x- Another container- Returns:
- aggregated container
-
and
Computes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected.- Parameters:
x- Another container- Returns:
- aggregated container
-
and
Computes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected.- Parameters:
x- Another container- Returns:
- aggregated container
-
andRange
Calculate the intersection of this container and a range, in a new container. The existing container is not modified.- Parameters:
start- start of rangeend- end of range, exclusive.- Returns:
- a new Container containing the intersction of this container and the given range.
-
iandRange
Calculate the intersection of this container and a range; may overwrite the existing container or return a new one.- Parameters:
start- start of rangeend- end of range, exclusive.- Returns:
- a Container containing the intersction of this container and the given range.
-
andNot
Computes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected.- Parameters:
x- Another container- Returns:
- aggregated container
-
andNot
Computes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected.- Parameters:
x- Another container- Returns:
- aggregated container
-
andNot
Computes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected.- Parameters:
x- Another container- Returns:
- aggregated container
-
andNot
Computes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected.- Parameters:
x- Another container- Returns:
- aggregated container
-
deepCopy
Get a full deep copy of the container in a new container object.- Returns:
- A copy of the container as a new object.
-
cowRef
Get 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.
- Returns:
- A copy-on-write reference to the container.
-
isEmpty
public abstract boolean isEmpty()Checks whether the container is empty or not.- Returns:
- true if the container is empty.
-
isAllOnes
public abstract boolean isAllOnes()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).- Returns:
- true if the container does not miss any single short value.
-
isSingleElement
public boolean isSingleElement()Checks whether the container has exactly one element (meaningful since cardinality may not be cached in some Container types, eg, Run).- Returns:
- true if the container contains exactly one element, false otherwise.
-
isFull
Deprecated.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).- Returns:
- true if the container does not miss any single short value. This method is deprecated, prefer isAllOnes instead.
-
contains
public abstract boolean contains(short x) Checks whether the contain contains the provided value- Parameters:
x- value to check- Returns:
- whether the value is in the container
-
contains
public abstract boolean contains(int rangeStart, int rangeEnd) Checks whether the container contains the entire range- Parameters:
rangeStart- the inclusive lower bound of the rangerangeEnd- the exclusive upper bound of the range- Returns:
- true if the container contains the range
-
contains
-
contains
-
contains
-
contains
Checks whether the container is a subset of this container or not- Parameters:
subset- the container to be tested- Returns:
- true if the parameter is a subset of this container
-
iflip
Add a short to the container if it is not present, otherwise remove it. May generate a new container.- Parameters:
x- short to be added- Returns:
- the new container
-
getCardinality
public abstract int getCardinality()Computes the distinct number of short values in the container. Can be expected to run in constant time.- Returns:
- the cardinality
-
getContainerName
Get the name of this container.- Returns:
- name of the container
-
forEach
Iterate through the values of this container in order and pass them along to the ShortConsumer.- Parameters:
sc- a shortConsumer- Returns:
- false if the consumer returned false at some point, true otherwise.
-
forEach
Like forEach, but skipping the first rankOffset elements.- Parameters:
rankOffset- the position (rank) offset of the element where to startsc- a ShortConsumer- Returns:
- false if the consumer returned false at some point, true otherwise.
-
forEachRange
-
getReverseShortIterator
Iterator to visit the short values in the container in descending order.- Returns:
- iterator
-
getShortIterator
Iterator to visit the short values in the container in ascending order.- Returns:
- iterator
-
getShortBatchIterator
Gets an iterator to visit the contents of the container in batches of short values- Parameters:
skipFromStartCount- number of elements to skip from the start of the container.- Returns:
- iterator
-
getShortRangeIterator
Iterator to visit the short values in container in [start, end) ranges, in increasing order of start values.- Returns:
- iterator
-
iadd
Add all shorts in [begin,end) using an unsigned interpretation. May generate a new container.- Parameters:
begin- start of range (inclusive)end- end of range (exclusive)- Returns:
- the new container
-
iappend
Add 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.- Parameters:
begin- start of range (inclusive)end- end of range (exclusive)- Returns:
- the new container
-
iand
Computes 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.- Parameters:
x- Another container- Returns:
- aggregated container
-
iand
Computes 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.- Parameters:
x- Another container- Returns:
- aggregated container
-
iand
Computes 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.- Parameters:
x- Another container- Returns:
- aggregated container
-
iand
Computes 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.- Parameters:
x- Another container- Returns:
- aggregated container
-
iandNot
Computes 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.- Parameters:
x- Another container- Returns:
- aggregated container
-
iandNot
Computes 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.- Parameters:
x- Another container- Returns:
- aggregated container
-
iandNot
Computes 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.- Parameters:
x- Another container- Returns:
- aggregated container
-
iandNot
Computes 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.- Parameters:
x- Another container- Returns:
- aggregated container
-
inot
Computes 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.- Parameters:
rangeStart- beginning of range (inclusive); 0 is beginning of this container.rangeEnd- ending of range (exclusive)- Returns:
- (partially) complemented container
-
ior
Computes 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.- Parameters:
x- Another container- Returns:
- aggregated container
-
ior
Computes 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.- Parameters:
x- Another container- Returns:
- aggregated container
-
ior
Computes 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.- Parameters:
x- Another container- Returns:
- aggregated container
-
ior
Computes 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.- Parameters:
x- Another container- Returns:
- aggregated container
-
iremove
Remove shorts in [begin,end) using an unsigned interpretation. May generate a new container.- Parameters:
begin- start of range (inclusive)end- end of range (exclusive)- Returns:
- the new container
-
ixor
Computes 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.- Parameters:
x- Another container- Returns:
- aggregated container
-
ixor
Computes 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.- Parameters:
x- Another container- Returns:
- aggregated container
-
ixor
Computes 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.- Parameters:
x- Another container- Returns:
- aggregated container
-
ixor
Computes the in-place bitwise XOR of this container with another. The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.- Parameters:
x- Another container- Returns:
- xor result as a new container reference
-
not
Computes 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.- Parameters:
rangeStart- beginning of range (inclusive); 0 is beginning of this container.rangeEnd- ending of range (exclusive)- Returns:
- (partially) complemented container
-
numberOfRanges
public int numberOfRanges()Computes the number of ranges that a RangeIterator would provide on this container.- Returns:
- The number of ranges that a RangeIterator would provide on this container.
-
or
Computes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected.- Parameters:
x- Another container- Returns:
- aggregated container
-
or
Computes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected.- Parameters:
x- Another container- Returns:
- aggregated container
-
or
Computes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected.- Parameters:
x- Another container- Returns:
- aggregated container
-
or
Computes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected.- Parameters:
x- Another container- Returns:
- aggregated container
-
rank
public abstract int rank(short lowbits) Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality()).- Parameters:
lowbits- upper limit- Returns:
- the rank
-
remove
Return a new container with all shorts in [begin,end) remove using an unsigned interpretation.- Parameters:
begin- start of range (inclusive)end- end of range (exclusive)- Returns:
- the new container
-
remove
Deprecated.Remove the short from this container. May create a new container. Note this legacy method does not respect the naming convention of an i prefix for inplace operations; prefer iunset.- Parameters:
x- to be removed- Returns:
- resulting container.
-
unset
Remove the short from this container. May create a new container.- Parameters:
x- to be removed- Returns:
- resulting container.
-
iunset
Create a new container with the short removed.- Parameters:
x- to be removed- Returns:
- New container without x.
-
runOptimize
Convert 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.- Returns:
- the new container
-
select
public abstract short select(int j) Return the jth value- Parameters:
j- index of the value- Returns:
- the value
-
select
Returns a new container with all values between ranks startPos and endPos.- Parameters:
startRank- rank for the start of the rangeendRank- rank for the end of the range, exclusive- Returns:
- a new Container with all the values between ranks [startPos, endPos)
-
find
public abstract int find(short x) Searches for the specified short value- 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
contains(short)returns true, this method returns the same value asrank(short).
-
selectRanges
As select but for all the positions in a range.- Parameters:
outValues- accept is called in this consumer for each resulting range.inPositions- input iterator that provides the position ranges.
-
findRanges
As find but for all the values in a range.- 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.
-
trim
public abstract void trim()If possible, recover wasted memory. -
xor
Computes the bitwise XOR of this container with another (symmetric difference). This container as well as the provided container are left unaffected.- Parameters:
x- Another container- Returns:
- aggregated container
-
xor
Computes the bitwise XOR of this container with another (symmetric difference). This container as well as the provided container are left unaffected.- Parameters:
x- Another container- Returns:
- aggregated container
-
xor
Computes the bitwise XOR of this container with another (symmetric difference). This container as well as the provided container are left unaffected.- Parameters:
x- Another container- Returns:
- aggregated container
-
xor
Computes the bitwise OR of this container with another (symmetric difference). This container as well as the provided container are left unaffected.- Parameters:
x- other parameter- Returns:
- aggregated container
-
toBitmapContainer
Convert the current container to a BitmapContainer, if a conversion is needed. If the container is already a bitmap, the container is returned unchanged.When multiple container "merge" operations are done it might be more efficient to convert to bitmap first, and then at the end convert to the efficient container type, to avoid multiple container type conversions, since bitmap can always stay a bitmap.
- Returns:
- a bitmap container
-
nextValue
public abstract int nextValue(short fromValue) Gets the first value greater than or equal to the lower bound, or -1 if no such value exists.- Parameters:
fromValue- the lower bound (inclusive)- Returns:
- the next value
-
first
public abstract int first()Get the first integer held in the container- Returns:
- the first integer in the container
- Throws:
NoSuchElementException- if empty
-
last
public abstract int last()Get the last integer held in the container- Returns:
- the last integer in the container
- Throws:
NoSuchElementException- if empty
-
subsetOf
- Parameters:
x- Another container- Returns:
- true if every key in this container is also a key in x.
-
subsetOf
- Parameters:
x- Another container- Returns:
- true if every key in this container is also a key in x.
-
subsetOf
- Parameters:
x- Another container- Returns:
- true if every key in this container is also a key in x.
-
subsetOf
- Parameters:
x- Another container- Returns:
- true if every key in this container is also a key in x.
-
intersects
- Parameters:
x- Another container- Returns:
- true if some key in this container is also a key in x.
-
intersects
public final boolean intersects(int start, int end) - Parameters:
start- the beginning of the range, as an int.end- the end of the range (exclusive), as an int.- Returns:
- true if there is any element in this container in the range provided.
-
overlaps
- Parameters:
x- Another container- Returns:
- true if at least one key in this container is also a key in x.
-
overlaps
- Parameters:
x- Another container- Returns:
- true if at least one key in this container is also a key in x.
-
overlaps
- Parameters:
x- Another container- Returns:
- true if at least one key in this container is also a key in x.
-
overlapsRange
public abstract boolean overlapsRange(int start, int end) - Parameters:
start- the beginning of the range, as an int.end- the end of the range (exclusive), as an int.- Returns:
- true if there is any element in this container in the range provided.
-
overlaps
- Parameters:
x- Another container- Returns:
- true if some key in this container is also a key in x.
-
setCopyOnWrite
public abstract void setCopyOnWrite() -
bytesAllocated
public abstract int bytesAllocated()- Returns:
- The allocated size in bytes of the underlying array backing store used by this container.
-
bytesUsed
public abstract int bytesUsed()- Returns:
- The size in bytes of the used portion out of the total allocated bytes for the underlying array backing store used by this container.
-
toString
-