Class BitmapContainer
java.lang.Object
com.illumon.iris.db.v2.utils.rsp.container.Container
com.illumon.iris.db.v2.utils.rsp.container.BitmapContainer
- All Implemented Interfaces:
Cloneable
public final class BitmapContainer extends Container implements Cloneable
Simple bitset-like container.
-
Field Summary
Fields Modifier and Type Field Description protected static int
BITMAP_CAPACITY
protected static int
BITMAP_SIZE_IN_BYTES
static boolean
USE_BRANCHLESS
optimization flag: whether the cardinality of the bitmaps is maintained through branchless operationsFields inherited from class com.illumon.iris.db.v2.utils.rsp.container.Container
ContainerNames, DEBUG, MAX_RANGE, MAX_VALUE, threadLocalBuf
-
Constructor Summary
Constructors Constructor Description BitmapContainer()
Create a bitmap container with all bits set to false -
Method Summary
Modifier and Type Method Description Container
add(int begin, int end)
Return a new container with all shorts in [begin,end) added using an unsigned interpretation.ArrayContainer
and(ArrayContainer value2)
Computes the bitwise AND of this container with another (intersection).Container
and(BitmapContainer value2)
Computes the bitwise AND of this container with another (intersection).Container
and(RunContainer x)
Computes the bitwise AND of this container with another (intersection).Container
andNot(ArrayContainer value2)
Computes the bitwise ANDNOT of this container with another (difference).Container
andNot(BitmapContainer value2)
Computes the bitwise ANDNOT of this container with another (difference).Container
andNot(RunContainer x)
Computes the bitwise ANDNOT of this container with another (difference).Container
andRange(int rangeStart, int rangeEnd)
Calculate the intersection of this container and a range, in a new container.protected long
bitValue(short i)
int
bytesAllocated()
int
bytesUsed()
protected int
cardinalityInRange(int start, int end)
boolean
contains(int rangeStart, int rangeEnd)
Checks whether the container contains the entire rangeboolean
contains(short i)
Checks whether the contain contains the provided valueprotected boolean
contains(ArrayContainer arrayContainer)
protected boolean
contains(BitmapContainer bitmapContainer)
protected boolean
contains(RunContainer runContainer)
BitmapContainer
cowRef()
Get a shared, copy-on-write copy of an existing container.BitmapContainer
deepCopy()
Get a full deep copy of the container in a new container object.protected void
fillArray(short[] array)
Fill the array with set bitsint
find(short x)
Searches for the specified short valueboolean
findRanges(RangeConsumer outPositions, RangeIterator inValues, int maxPos)
As find but for all the values in a range.int
first()
Get the first integer held in the containerboolean
forEach(int rankOffset, ShortConsumer sc)
Like forEach, but skipping the first rankOffset elements.boolean
forEach(ShortConsumer sc)
Iterate through the values of this container in order and pass them along to the ShortConsumer.boolean
forEachRange(int rankOffset, ShortRangeConsumer sc)
int
getCardinality()
Computes the distinct number of short values in the container.ShortAdvanceIterator
getReverseShortIterator()
Iterator to visit the short values in the container in descending order.static ShortAdvanceIterator
getReverseShortIterator(long[] bitmap)
Return a bitmap iterator over this arrayContainerShortBatchIterator
getShortBatchIterator(int skipCount)
Gets an iterator to visit the contents of the container in batches of short valuesShortIterator
getShortIterator()
Iterator to visit the short values in the container in ascending order.static ShortIterator
getShortIterator(long[] bitmap)
Return a bitmap iterator over this arraySearchRangeIterator
getShortRangeIterator(int initialSeek)
Iterator to visit the short values in container in [start, end) ranges, in increasing order of start values.Container
iadd(int begin, int end)
Add all shorts in [begin,end) using an unsigned interpretation.Container
iand(ArrayContainer b2)
Computes the in-place bitwise AND of this container with another (intersection).Container
iand(BitmapContainer b2)
Computes the in-place bitwise AND of this container with another (intersection).Container
iand(RunContainer x)
Computes the in-place bitwise AND of this container with another (intersection).Container
iandNot(ArrayContainer b2)
Computes the in-place bitwise ANDNOT of this container with another (difference).Container
iandNot(BitmapContainer b2)
Computes the in-place bitwise ANDNOT of this container with another (difference).Container
iandNot(RunContainer x)
Computes the in-place bitwise ANDNOT of this container with another (difference).Container
iandRange(int rangeStart, int rangeEnd)
Calculate the intersection of this container and a range; may overwrite the existing container or return a new one.Container
iappend(int begin, int end)
Add all shorts in [begin,end) using an unsigned interpretation.Container
iflip(short x)
Add a short to the container if it is not present, otherwise remove it.Container
inot(int firstOfRange, int lastOfRange)
Computes the in-place bitwise NOT of this container (complement).Container
ior(ArrayContainer value2)
Computes the in-place bitwise OR of this container with another (union).Container
ior(BitmapContainer b2)
Computes the in-place bitwise OR of this container with another (union).Container
ior(RunContainer x)
Computes the in-place bitwise OR of this container with another (union).Container
iremove(int begin, int end)
Remove shorts in [begin,end) using an unsigned interpretation.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).boolean
isEmpty()
Checks whether the container is empty or not.Container
iset(short x)
Insert a short to the container.boolean
isShared()
Container
iunset(short v)
Create a new container with the short removed.Container
ixor(ArrayContainer value2)
Computes the in-place bitwise XOR of this container with another (symmetric difference).Container
ixor(BitmapContainer b2)
Computes the in-place bitwise XOR of this container with another (symmetric difference).Container
ixor(RunContainer x)
Computes the in-place bitwise XOR of this container with another (symmetric difference).int
last()
Get the last integer held in the containerprotected void
loadData(ArrayContainer arrayContainer)
int
nextSetBit(int i)
Find the index of the next set bit greater or equal to i, returns -1 if none found.int
nextValue(short fromValue)
Gets the first value greater than or equal to the lower bound, or -1 if no such value exists.Container
not(int firstOfRange, int lastOfRange)
Computes the bitwise NOT of this container (complement).Container
or(ArrayContainer value2)
Computes the bitwise OR of this container with another (union).Container
or(BitmapContainer value2)
Computes the bitwise OR of this container with another (union).Container
or(RunContainer x)
Computes the bitwise OR of this container with another (union).boolean
overlaps(ArrayContainer c)
boolean
overlaps(BitmapContainer c)
boolean
overlaps(RunContainer c)
boolean
overlapsRange(int rangeStart, int rangeEnd)
int
prevSetBit(int i)
Find the index of the previous set bit less than or equal to i, returns -1 if none found.int
rank(short lowbits)
Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality()).Container
remove(int begin, int end)
Return a new container with all shorts in [begin,end) remove using an unsigned interpretation.Container
runOptimize()
Convert to RunContainers, when the result is smaller.short
select(int j)
Return the jth valueContainer
select(int startRank, int endRank)
Returns a new container with all values between ranks startPos and endPos.void
selectRanges(RangeConsumer outValues, RangeIterator inPositions)
As select but for all the positions in a range.Container
set(short x)
Return a new container with the short given as parameter added.void
setCopyOnWrite()
static BitmapContainer
singleRange(int start, int end)
Create a bitmap container with a run of ones from start to end.boolean
subsetOf(ArrayContainer c)
boolean
subsetOf(BitmapContainer c)
boolean
subsetOf(RunContainer c)
ArrayContainer
toArrayContainer()
Copies the data to an array containerBitmapContainer
toBitmapContainer()
Convert the current container to a BitmapContainer, if a conversion is needed.Container
toLargeContainer()
RunContainer
toRunContainer()
void
trim()
If possible, recover wasted memory.Container
unset(short v)
Remove the short from this container.protected void
updateCardinality(int prevOnes, int newOnes)
void
validate()
Container
xor(ArrayContainer value2)
Computes the bitwise XOR of this container with another (symmetric difference).Container
xor(BitmapContainer value2)
Computes the bitwise XOR of this container with another (symmetric difference).Container
xor(RunContainer x)
Computes the bitwise XOR of this container with another (symmetric difference).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, singleton, subsetOf, toString, twoRanges, twoValues, xor
-
Field Details
-
BITMAP_CAPACITY
protected static final int BITMAP_CAPACITY- See Also:
- Constant Field Values
-
BITMAP_SIZE_IN_BYTES
protected static final int BITMAP_SIZE_IN_BYTES- See Also:
- Constant Field Values
-
USE_BRANCHLESS
public static final boolean USE_BRANCHLESSoptimization flag: whether the cardinality of the bitmaps is maintained through branchless operations- See Also:
- Constant Field Values
-
-
Constructor Details
-
BitmapContainer
public BitmapContainer()Create a bitmap container with all bits set to false
-
-
Method Details
-
getReverseShortIterator
Return a bitmap iterator over this array- Parameters:
bitmap
- array to be iterated over- Returns:
- an iterator
-
getShortIterator
Return a bitmap iterator over this array- Parameters:
bitmap
- array to be iterated over- Returns:
- an iterator
-
singleRange
Create a bitmap container with a run of ones from start to end. Caller must ensure that the range isn't so small that an ArrayContainer should have been created instead- Parameters:
start
- first indexend
- end index (exclusive)- Returns:
- the new container.
-
add
Description copied from class:Container
Return a new container with all shorts in [begin,end) added using an unsigned interpretation. -
iset
Description copied from class:Container
Insert a short to the container. May generate a new container. -
set
Description copied from class:Container
Return a new container with the short given as parameter added. -
and
Description copied from class:Container
Computes 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:Container
Computes 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:Container
Computes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected. -
andRange
Description copied from class:Container
Calculate the intersection of this container and a range, in a new container. The existing container is not modified. -
iandRange
Description copied from class:Container
Calculate the intersection of this container and a range; may overwrite the existing container or return a new one. -
andNot
Description copied from class:Container
Computes 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:Container
Computes 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:Container
Computes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected. -
cowRef
Description copied from class:Container
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.
-
deepCopy
Description copied from class:Container
Get a full deep copy of the container in a new container object. -
isEmpty
public boolean isEmpty()Description copied from class:Container
Checks whether the container is empty or not. -
isAllOnes
public boolean isAllOnes()Description copied from class:Container
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). -
cardinalityInRange
protected int cardinalityInRange(int start, int end) -
updateCardinality
protected void updateCardinality(int prevOnes, int newOnes) -
contains
public boolean contains(short i)Description copied from class:Container
Checks whether the contain contains the provided value -
contains
public boolean contains(int rangeStart, int rangeEnd)Description copied from class:Container
Checks whether the container contains the entire range -
contains
-
contains
-
contains
-
bitValue
protected long bitValue(short i) -
fillArray
protected void fillArray(short[] array)Fill the array with set bits- Parameters:
array
- container (should be sufficiently large)
-
iflip
Description copied from class:Container
Add 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:Container
Computes the distinct number of short values in the container. Can be expected to run in constant time.- Specified by:
getCardinality
in classContainer
- Returns:
- the cardinality
-
getReverseShortIterator
Description copied from class:Container
Iterator to visit the short values in the container in descending order.- Specified by:
getReverseShortIterator
in classContainer
- Returns:
- iterator
-
getShortIterator
Description copied from class:Container
Iterator to visit the short values in the container in ascending order.- Specified by:
getShortIterator
in classContainer
- Returns:
- iterator
-
getShortBatchIterator
Description copied from class:Container
Gets an iterator to visit the contents of the container in batches of short values- Specified by:
getShortBatchIterator
in classContainer
- Parameters:
skipCount
- number of elements to skip from the start of the container.- Returns:
- iterator
-
getShortRangeIterator
Description copied from class:Container
Iterator to visit the short values in container in [start, end) ranges, in increasing order of start values.- Specified by:
getShortRangeIterator
in classContainer
- Returns:
- iterator
-
iadd
Description copied from class:Container
Add all shorts in [begin,end) using an unsigned interpretation. May generate a new container. -
iappend
Description copied from class:Container
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. -
iand
Description copied from class:Container
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. -
iand
Description copied from class:Container
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. -
iand
Description copied from class:Container
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. -
iandNot
Description copied from class:Container
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. -
iandNot
Description copied from class:Container
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. -
iandNot
Description copied from class:Container
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. -
inot
Description copied from class:Container
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. -
ior
Description copied from class:Container
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. -
ior
Description copied from class:Container
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. -
ior
Description copied from class:Container
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. -
iremove
Description copied from class:Container
Remove shorts in [begin,end) using an unsigned interpretation. May generate a new container. -
ixor
Description copied from class:Container
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. -
ixor
Description copied from class:Container
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. -
ixor
Description copied from class:Container
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. -
loadData
-
nextSetBit
public int nextSetBit(int i)Find the index of the next set bit greater or equal to i, returns -1 if none found.- Parameters:
i
- starting index- Returns:
- index of the next set bit
-
not
Description copied from class:Container
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. -
or
Description copied from class:Container
Computes 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:Container
Computes 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:Container
Computes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected. -
prevSetBit
public int prevSetBit(int i)Find the index of the previous set bit less than or equal to i, returns -1 if none found.- Parameters:
i
- starting index- Returns:
- index of the previous set bit
-
rank
public int rank(short lowbits)Description copied from class:Container
Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality()). -
remove
Description copied from class:Container
Return a new container with all shorts in [begin,end) remove using an unsigned interpretation. -
iunset
Description copied from class:Container
Create a new container with the short removed. -
unset
Description copied from class:Container
Remove the short from this container. May create a new container. -
runOptimize
Description copied from class:Container
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.- Specified by:
runOptimize
in classContainer
- Returns:
- the new container
-
select
public short select(int j)Description copied from class:Container
Return the jth value -
select
Description copied from class:Container
Returns a new container with all values between ranks startPos and endPos. -
find
public int find(short x)Description copied from class:Container
Searches for the specified short value- Specified by:
find
in 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:Container
As select but for all the positions in a range.- Specified by:
selectRanges
in classContainer
- Parameters:
outValues
- accept is called in this consumer for each resulting range.inPositions
- input iterator that provides the position ranges.
-
findRanges
Description copied from class:Container
As find but for all the values in a range.- Specified by:
findRanges
in 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.
-
toArrayContainer
Copies the data to an array container- Returns:
- the array container
-
toRunContainer
-
trim
public void trim()Description copied from class:Container
If possible, recover wasted memory. -
xor
Description copied from class:Container
Computes 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:Container
Computes 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:Container
Computes the bitwise XOR of this container with another (symmetric difference). This container as well as the provided container are left unaffected. -
forEach
Description copied from class:Container
Iterate through the values of this container in order and pass them along to the ShortConsumer. -
forEach
Description copied from class:Container
Like forEach, but skipping the first rankOffset elements. -
forEachRange
- Specified by:
forEachRange
in classContainer
-
toBitmapContainer
Description copied from class:Container
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.
- Specified by:
toBitmapContainer
in classContainer
- Returns:
- a bitmap container
-
nextValue
public int nextValue(short fromValue)Description copied from class:Container
Gets 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:Container
Get the first integer held in the container -
last
public int last()Description copied from class:Container
Get the last integer held in the container -
subsetOf
-
subsetOf
-
subsetOf
-
overlapsRange
public boolean overlapsRange(int rangeStart, int rangeEnd)- Specified by:
overlapsRange
in 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 void setCopyOnWrite()- Specified by:
setCopyOnWrite
in classContainer
-
bytesAllocated
public int bytesAllocated()- Specified by:
bytesAllocated
in 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()
-