Package org.roaringbitmap
Class RunContainer
java.lang.Object
org.roaringbitmap.Container
org.roaringbitmap.RunContainer
- All Implemented Interfaces:
Externalizable,Serializable,Cloneable,Iterable<Character>,WordStorage<Container>
This container takes the form of runs of consecutive values (effectively, run-length encoding).
Adding and removing content from this container might make it wasteful so regular calls to
"runOptimize" might be warranted.
- See Also:
- Serialized Form
-
Field Summary
Fields inherited from class org.roaringbitmap.Container
ContainerNames -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreate a container with default capacityRunContainer(char[] array, int numRuns)Construct a new RunContainer backed by the provided array.RunContainer(int capacity)Create an array container with specified capacityRunContainer(int firstOfRun, int lastOfRun)Create an run container with a run of ones from firstOfRun to lastOfRun.protectedRunContainer(ArrayContainer arr, int nbrRuns)protectedRunContainer(BitmapContainer bc, int nbrRuns)Creates a new non-mappeable container from a mappeable one. -
Method Summary
Modifier and TypeMethodDescriptionadd(char k)Add a short to the container.add(int begin, int end)Return a new container with all shorts in [begin,end) added using an unsigned interpretation.and(ArrayContainer x)Computes the bitwise AND of this container with another (intersection).and(BitmapContainer x)Computes the bitwise AND of this container with another (intersection).and(RunContainer x)Computes the bitwise AND of this container with another (intersection).intintintandNot(ArrayContainer x)Computes the bitwise ANDNOT of this container with another (difference).Computes the bitwise ANDNOT of this container with another (difference).andNot(RunContainer x)Computes the bitwise ANDNOT of this container with another (difference).voidclear()Empties the containerclone()booleancontains(char x)Checks whether the contain contains the provided valuebooleancontains(int minimum, int supremum)Checks whether the container contains the entire rangeprotected booleancontains(ArrayContainer arrayContainer)protected booleancontains(BitmapContainer bitmapContainer)protected booleancontains(RunContainer runContainer)voiddeserialize(DataInput in)Deserialize (recover) the container.booleanvoidfillLeastSignificant16bits(int[] x, int i, int mask)Fill the least significant 16 bits of the integer array, starting at index i, with the short values from this container.intfirst()Get the first integer held in the containerflip(char x)Add a short to the container if it is not present, otherwise remove it.voidforAll(int offset, RelativeRangeConsumer rrc)Consume presence information for all values in this container.voidforAllFrom(char startValue, RelativeRangeConsumer rrc)Consume presence information for all values greater or equal to startValue in this container.voidforAllInRange(char startValue, char endValue, RelativeRangeConsumer rrc)Consumer presence information for all values in the range [startValue, endValue) in this container.voidforAllUntil(int offset, char endValue, RelativeRangeConsumer rrc)Consume presence information for all values smaller than endValue in this container.voidforEach(char msb, IntConsumer ic)Iterate through the values of this container and pass them along to the IntConsumer, using msb as the 16 most significant bits.static RunContainerfull()intSize of the underlying arrayGets an iterator to visit the contents of the container in batchesintComputes the distinct number of char values in the container.Iterator to visit the char values in the container in ascending order.Iterator to visit the short values in container and pre-compute rankschargetLength(int index)Gets the length of the run at the index.Iterator to visit the char values in the container in descending order.intComputes an estimate of the memory usage of this container.chargetValue(int index)Gets the value of the first element of the run at the index.inthashCode()iadd(int begin, int end)Add all shorts in [begin,end) using an unsigned interpretation.iand(ArrayContainer x)Computes the in-place bitwise AND of this container with another (intersection).iand(BitmapContainer x)Computes the in-place bitwise AND of this container with another (intersection).iand(RunContainer x)Computes the in-place bitwise AND of this container with another (intersection).Computes the in-place bitwise ANDNOT of this container with another (difference).Computes the in-place bitwise ANDNOT of this container with another (difference).iandNot(RunContainer x)Computes the in-place bitwise ANDNOT of this container with another (difference).inot(int rangeStart, int rangeEnd)Computes the in-place bitwise NOT of this container (complement).booleanintersects(int minimum, int supremum)Checks if the container intersects with a rangebooleanReturns true if the current container intersects the other container.booleanReturns true if the current container intersects the other container.booleanReturns true if the current container intersects the other container.ior(ArrayContainer x)Computes the in-place bitwise OR of this container with another (union).ior(BitmapContainer x)Computes the in-place bitwise OR of this container with another (union).ior(RunContainer x)Computes the in-place bitwise OR of this container with another (union).iremove(int begin, int end)Remove shorts in [begin,end) using an unsigned interpretation.booleanisEmpty()Checks whether the container is empty or not.booleanisFull()Checks whether the container is full or not.iterator()ixor(ArrayContainer x)Computes the in-place bitwise XOR of this container with another (symmetric difference).ixor(BitmapContainer x)Computes the in-place bitwise XOR of this container with another (symmetric difference).ixor(RunContainer x)Computes the in-place bitwise XOR of this container with another (symmetric difference).intlast()Get the last integer held in the containerprotected Containerlazyor(ArrayContainer x)limit(int maxcardinality)Create a new Container containing at most maxcardinality integers.intnextAbsentValue(char fromValue)Gets the first absent value greater than or equal to the lower bound.intnextValue(char fromValue)Gets the first value greater than or equal to the lower bound, or -1 if no such value exists.not(int rangeStart, int rangeEnd)Computes the bitwise NOT of this container (complement).intor(ArrayContainer x)Computes the bitwise OR of this container with another (union).or(BitmapContainer x)Computes the bitwise OR of this container with another (union).or(RunContainer x)Computes the bitwise OR of this container with another (union).intpreviousAbsentValue(char fromValue)Gets the last value less than or equal to the upper bound.intpreviousValue(char fromValue)Gets the last value less than or equal to the upper bound, or -1 if no such value exists.intrank(char lowbits)Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality()).voidreadExternal(ObjectInput in)remove(char x)Remove the char from this container.remove(int begin, int end)Return a new container with all chars in [begin,end) remove using an unsigned interpretation.The output of a lazyOR or lazyIOR might be an invalid container, this should be called on it.Convert to Array or Bitmap container if the serialized form would be shorter.charselect(int j)Return the jth valuevoidserialize(DataOutput out)Serialize the container.intReport the number of bytes required to serialize this container.protected static intserializedSizeInBytes(int numberOfRuns)Convert the current container to a BitmapContainer, if a conversion is needed.Return the content of this container as a ShortBuffer.Convert to a mappeable container.toString()voidtrim()If possible, recover wasted memory.voidwriteArray(DataOutput out)Write just the underlying array.voidwriteArray(ByteBuffer buffer)Write just the underlying array.voidwriteExternal(ObjectOutput out)xor(ArrayContainer x)Computes the bitwise XOR of this container with another (symmetric difference).xor(BitmapContainer x)Computes the bitwise XOR of this container with another (symmetric difference).xor(RunContainer x)Computes the bitwise XOR of this container with another (symmetric difference).Methods inherited from class org.roaringbitmap.Container
and, andCardinality, andNot, assertNonEmpty, contains, getContainerName, iand, iandNot, intersects, ior, iorNot, ixor, lazyIOR, lazyOR, or, orNot, rangeOfOnes, xor, xorCardinalityMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
RunContainer
public RunContainer()Create a container with default capacity -
RunContainer
-
RunContainer
public RunContainer(int firstOfRun, int lastOfRun)Create an run container with a run of ones from firstOfRun to lastOfRun.- Parameters:
firstOfRun- first indexlastOfRun- last index (range is exclusive)
-
RunContainer
-
RunContainer
public RunContainer(int capacity)Create an array container with specified capacity- Parameters:
capacity- The capacity of the container
-
RunContainer
Creates a new non-mappeable container from a mappeable one. This copies the data.- Parameters:
bc- the original container
-
RunContainer
public RunContainer(char[] array, int numRuns)Construct a new RunContainer backed by the provided array. Note that if you modify the RunContainer a new array may be produced.- Parameters:
array- array where the data is storednumRuns- number of runs (each using 2 shorts in the buffer)
-
-
Method Details
-
serializedSizeInBytes
protected static int serializedSizeInBytes(int numberOfRuns) -
add
Description copied from class:ContainerReturn a new container with all shorts in [begin,end) added using an unsigned interpretation. -
add
Description copied from class:ContainerAdd a short to the container. May generate a new container.- Specified by:
addin interfaceWordStorage<Container>- Specified by:
addin classContainer- Parameters:
k- short to be added- Returns:
- the new container
-
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. -
andCardinality
- Specified by:
andCardinalityin classContainer
-
andCardinality
- Specified by:
andCardinalityin classContainer
-
andCardinality
- Specified by:
andCardinalityin classContainer
-
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. -
clear
public void clear()Description copied from class:ContainerEmpties the container -
clone
-
isEmpty
public boolean isEmpty()Description copied from class:ContainerChecks whether the container is empty or not.- Specified by:
isEmptyin interfaceWordStorage<Container>- Specified by:
isEmptyin classContainer- Returns:
- true if the container is empty.
-
contains
public boolean contains(char x)Description copied from class:ContainerChecks whether the contain contains the provided value -
contains
public boolean contains(int minimum, int supremum)Description copied from class:ContainerChecks whether the container contains the entire range -
contains
-
contains
-
contains
-
deserialize
Description copied from class:ContainerDeserialize (recover) the container.- Specified by:
deserializein classContainer- Parameters:
in- the DataInput stream- Throws:
IOException- Signals that an I/O exception has occurred.
-
equals
-
fillLeastSignificant16bits
public void fillLeastSignificant16bits(int[] x, int i, int mask)Description copied from class:ContainerFill the least significant 16 bits of the integer array, starting at index i, with the short values from this container. The caller is responsible to allocate enough room. The most significant 16 bits of each integer are given by the most significant bits of the provided mask.- Specified by:
fillLeastSignificant16bitsin classContainer- Parameters:
x- provided arrayi- starting indexmask- indicates most significant bits
-
flip
Description copied from class:ContainerAdd a short to the container if it is not present, otherwise remove it. May generate a new container. -
getArraySizeInBytes
public int getArraySizeInBytes()Description copied from class:ContainerSize of the underlying array- Specified by:
getArraySizeInBytesin classContainer- Returns:
- size in bytes
-
getCardinality
public int getCardinality()Description copied from class:ContainerComputes the distinct number of char values in the container. Can be expected to run in constant time.- Specified by:
getCardinalityin classContainer- Returns:
- the cardinality
-
getLength
public char getLength(int index)Gets the length of the run at the index.- Parameters:
index- the index of the run.- Returns:
- the length of the run at the index.
- Throws:
ArrayIndexOutOfBoundsException- if index is negative or larger than the index of the last run.
-
getReverseCharIterator
Description copied from class:ContainerIterator to visit the char values in the container in descending order.- Specified by:
getReverseCharIteratorin classContainer- Returns:
- iterator
-
getCharIterator
Description copied from class:ContainerIterator to visit the char values in the container in ascending order.- Specified by:
getCharIteratorin classContainer- Returns:
- iterator
-
getCharRankIterator
Description copied from class:ContainerIterator to visit the short values in container and pre-compute ranks- Specified by:
getCharRankIteratorin classContainer- Returns:
- iterator
-
getBatchIterator
Description copied from class:ContainerGets an iterator to visit the contents of the container in batches- Specified by:
getBatchIteratorin classContainer- Returns:
- iterator
-
getSizeInBytes
public int getSizeInBytes()Description copied from class:ContainerComputes an estimate of the memory usage of this container. The estimate is not meant to be exact.- Specified by:
getSizeInBytesin classContainer- Returns:
- estimated memory usage in bytes
-
getValue
public char getValue(int index)Gets the value of the first element of the run at the index.- Parameters:
index- the index of the run.- Returns:
- the value of the first element of the run at the index.
- Throws:
ArrayIndexOutOfBoundsException- if index is negative or larger than the index of the last run.
-
hashCode
public int hashCode() -
iadd
Description copied from class:ContainerAdd all shorts in [begin,end) using an unsigned interpretation. 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. -
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. -
intersects
Description copied from class:ContainerReturns true if the current container intersects the other container.- Specified by:
intersectsin classContainer- Parameters:
x- other container- Returns:
- whether they intersect
-
intersects
Description copied from class:ContainerReturns true if the current container intersects the other container.- Specified by:
intersectsin classContainer- Parameters:
x- other container- Returns:
- whether they intersect
-
intersects
Description copied from class:ContainerReturns true if the current container intersects the other container.- Specified by:
intersectsin classContainer- Parameters:
x- other container- Returns:
- whether they intersect
-
intersects
public boolean intersects(int minimum, int supremum)Description copied from class:ContainerChecks if the container intersects with a range- Specified by:
intersectsin classContainer- Parameters:
minimum- the inclusive unsigned lower bound of the rangesupremum- the exclusive unsigned upper bound of the range- Returns:
- true if the container intersects the range
-
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. -
iremove
Description copied from class:ContainerRemove shorts in [begin,end) using an unsigned interpretation. May generate a new container. -
isFull
public boolean isFull()Description copied from class:ContainerChecks whether the container is full or not. -
full
-
iterator
-
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. -
lazyor
-
limit
Description copied from class:ContainerCreate a new Container containing at most maxcardinality integers. -
not
Description copied from class:ContainerComputes the bitwise NOT of this container (complement). Only those bits within the range are affected. The current container is left unaffected. -
numberOfRuns
public int numberOfRuns() -
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. -
rank
public int rank(char lowbits)Description copied from class:ContainerRank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality()). -
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOException
-
remove
Description copied from class:ContainerReturn a new container with all chars in [begin,end) remove using an unsigned interpretation. -
remove
Description copied from class:ContainerRemove the char from this container. May create a new container. -
repairAfterLazy
Description copied from class:ContainerThe output of a lazyOR or lazyIOR might be an invalid container, this should be called on it.- Specified by:
repairAfterLazyin classContainer- Returns:
- a new valid container
-
runOptimize
Convert to Array or Bitmap container if the serialized form would be shorter. Exactly the same functionality as toEfficientContainer.- Specified by:
runOptimizein interfaceWordStorage<Container>- Specified by:
runOptimizein classContainer- Returns:
- the new container
-
select
public char select(int j)Description copied from class:ContainerReturn the jth value -
serialize
Description copied from class:ContainerSerialize the container.- Specified by:
serializein classContainer- Parameters:
out- the DataOutput stream- Throws:
IOException- Signals that an I/O exception has occurred.
-
serializedSizeInBytes
public int serializedSizeInBytes()Description copied from class:ContainerReport the number of bytes required to serialize this container.- Specified by:
serializedSizeInBytesin classContainer- Returns:
- the size in bytes
-
toMappeableContainer
Description copied from class:ContainerConvert to a mappeable container.- Specified by:
toMappeableContainerin classContainer- Returns:
- the mappeable container
-
toCharBuffer
Return the content of this container as a ShortBuffer. This creates a copy and might be relatively slow.- Returns:
- the ShortBuffer
-
toString
-
trim
public void trim()Description copied from class:ContainerIf possible, recover wasted memory. -
writeArray
Description copied from class:ContainerWrite just the underlying array.- Specified by:
writeArrayin classContainer- Parameters:
out- output stream- Throws:
IOException- in case of failure
-
writeArray
Description copied from class:ContainerWrite just the underlying array.- Specified by:
writeArrayin classContainer- Parameters:
buffer- ByteBuffer to write to
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
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. -
forEach
Description copied from class:ContainerIterate through the values of this container and pass them along to the IntConsumer, using msb as the 16 most significant bits. -
forAll
Description copied from class:ContainerConsume presence information for all values in this container. -
forAllFrom
Description copied from class:ContainerConsume presence information for all values greater or equal to startValue in this container.- Specified by:
forAllFromin classContainer- Parameters:
startValue- First value to consume. Corresponds to relativePos=0 in the range consumer.rrc- consumer
-
forAllUntil
Description copied from class:ContainerConsume presence information for all values smaller than endValue in this container.- Specified by:
forAllUntilin classContainer- Parameters:
offset- First value in this container corresponds to this relativePos in the range consumer.endValue- First value greater than last value to consume.rrc- consumer
-
forAllInRange
Description copied from class:ContainerConsumer presence information for all values in the range [startValue, endValue) in this container.- Specified by:
forAllInRangein classContainer- Parameters:
startValue- First value to consume. Corresponds to relativePos=0 in the range consumer.endValue- First value greater than last value to consume.rrc- consumer
-
toBitmapContainer
Description copied from class:ContainerConvert the current container to a BitmapContainer, if a conversion is needed. If the container is already a bitmap, the container is returned unchanged.- Specified by:
toBitmapContainerin classContainer- Returns:
- a bitmap container
-
nextValue
public int nextValue(char fromValue)Description copied from class:ContainerGets the first value greater than or equal to the lower bound, or -1 if no such value exists. -
previousValue
public int previousValue(char fromValue)Description copied from class:ContainerGets the last value less than or equal to the upper bound, or -1 if no such value exists.- Specified by:
previousValuein classContainer- Parameters:
fromValue- the upper bound (inclusive)- Returns:
- the previous value
-
nextAbsentValue
public int nextAbsentValue(char fromValue)Description copied from class:ContainerGets the first absent value greater than or equal to the lower bound.- Specified by:
nextAbsentValuein classContainer- Parameters:
fromValue- the lower bound (inclusive)- Returns:
- the next absent value
-
previousAbsentValue
public int previousAbsentValue(char fromValue)Description copied from class:ContainerGets the last value less than or equal to the upper bound.- Specified by:
previousAbsentValuein classContainer- Parameters:
fromValue- the upper bound (inclusive)- Returns:
- the previous absent value
-
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
-