Package org.roaringbitmap.buffer
Class MappeableRunContainer
- java.lang.Object
-
- org.roaringbitmap.buffer.MappeableContainer
-
- org.roaringbitmap.buffer.MappeableRunContainer
-
- All Implemented Interfaces:
java.io.Externalizable
,java.io.Serializable
,java.lang.Cloneable
,java.lang.Iterable<java.lang.Character>
,WordStorage<MappeableContainer>
public final class MappeableRunContainer extends MappeableContainer implements java.lang.Cloneable
This container takes the form of runs of consecutive values (effectively, run-length encoding). Uses a CharBuffer to store data, unlike org.roaringbitmap.RunContainer. Otherwise similar. 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 Modifier and Type Field Description private static int
DEFAULT_INIT_SIZE
protected int
nbrruns
private static long
serialVersionUID
protected java.nio.CharBuffer
valueslength
-
Fields inherited from class org.roaringbitmap.buffer.MappeableContainer
ContainerNames
-
-
Constructor Summary
Constructors Modifier Constructor Description MappeableRunContainer()
Create a container with default capacityMappeableRunContainer(int capacity)
Create an array container with specified capacityMappeableRunContainer(int firstOfRun, int lastOfRun)
Create an run container with a run of ones from firstOfRun to lastOfRun.private
MappeableRunContainer(int nbrruns, java.nio.CharBuffer valueslength)
MappeableRunContainer(java.nio.CharBuffer array, int numRuns)
Construct a new RunContainer backed by the provided CharBuffer.protected
MappeableRunContainer(MappeableArrayContainer arr, int nbrRuns)
protected
MappeableRunContainer(MappeableBitmapContainer bc, int nbrRuns)
MappeableRunContainer(RunContainer bc)
Creates a new container from a non-mappeable one.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MappeableContainer
add(char k)
Add a char to the container.MappeableContainer
add(int begin, int end)
Return a new container with all chars in [begin,end) added using an unsigned interpretation.MappeableContainer
and(MappeableArrayContainer x)
Computes the bitwise AND of this container with another (intersection).MappeableContainer
and(MappeableBitmapContainer x)
Computes the bitwise AND of this container with another (intersection).MappeableContainer
and(MappeableRunContainer x)
Computes the bitwise AND of this container with another (intersection).int
andCardinality(MappeableArrayContainer x)
int
andCardinality(MappeableBitmapContainer x)
int
andCardinality(MappeableRunContainer x)
void
andInto(long[] bits)
Computes the intersection of this container with the bits present in the array, modifying the array.MappeableContainer
andNot(MappeableArrayContainer x)
Computes the bitwise ANDNOT of this container with another (difference).MappeableContainer
andNot(MappeableBitmapContainer x)
Computes the bitwise ANDNOT of this container with another (difference).MappeableContainer
andNot(MappeableRunContainer x)
Computes the bitwise ANDNOT of this container with another (difference).private void
appendValueLength(int value, int index)
private static int
branchyBufferedUnsignedInterleavedBinarySearch(java.nio.ByteBuffer sb, int position, int begin, int end, char k)
private static int
branchyBufferedUnsignedInterleavedBinarySearch(java.nio.CharBuffer sb, int begin, int end, char k)
private static int
bufferedUnsignedInterleavedBinarySearch(java.nio.ByteBuffer sb, int position, int begin, int end, char k)
private static int
bufferedUnsignedInterleavedBinarySearch(java.nio.CharBuffer sb, int begin, int end, char k)
private boolean
canPrependValueLength(int value, int index)
void
clear()
Empties the containerMappeableContainer
clone()
private void
closeValueLength(int value, int index)
boolean
contains(char x)
Checks whether the contain contains the provided valueboolean
contains(int minimum, int supremum)
Checks whether the container contains the entire rangestatic boolean
contains(java.nio.ByteBuffer buf, int position, char x, int numRuns)
Checks whether the run container contains x.protected boolean
contains(MappeableArrayContainer arrayContainer)
protected boolean
contains(MappeableBitmapContainer bitmapContainer)
protected boolean
contains(MappeableRunContainer runContainer)
private MappeableContainer
convertToLazyBitmapIfNeeded()
private void
copyToOffset(int offset)
private void
copyValuesLength(java.nio.CharBuffer src, int srcIndex, java.nio.CharBuffer dst, int dstIndex, int length)
private void
decrementLength(int index)
private void
decrementValue()
private void
ensureCapacity(int minNbRuns)
boolean
equals(java.lang.Object o)
private boolean
equals(MappeableArrayContainer arrayContainer)
private boolean
equals(MappeableRunContainer runContainer)
void
fillLeastSignificant16bits(int[] x, int i, int mask)
Fill the least significant 16 bits of the integer array, starting at index index, with the char values from this container.int
first()
Get the first integer held in the containerMappeableContainer
flip(char x)
Add a char to the container if it is not present, otherwise remove it.void
forEach(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 MappeableRunContainer
full()
protected int
getArraySizeInBytes()
Size of the underlying arrayprotected static int
getArraySizeInBytes(int nbrruns)
ContainerBatchIterator
getBatchIterator()
Gets an iterator to visit the contents of the container in batchesint
getCardinality()
Computes the distinct number of char values in the container.PeekableCharIterator
getCharIterator()
Iterator to visit the char values in the container in ascending order.private static char
getLength(char[] vl, int index)
char
getLength(int index)
Gets the length of the run at the index.CharIterator
getReverseCharIterator()
Iterator to visit the char values in the container in descending order.int
getSizeInBytes()
Computes an estimate of the memory usage of this container.private static char
getValue(char[] vl, int index)
char
getValue(int index)
Gets the value of the first element of the run at the index.int
hashCode()
MappeableContainer
iadd(int begin, int end)
Add all chars in [begin,end) using an unsigned interpretation.MappeableContainer
iand(MappeableArrayContainer x)
Computes the in-place bitwise AND of this container with another (intersection).MappeableContainer
iand(MappeableBitmapContainer x)
Computes the in-place bitwise AND of this container with another (intersection).MappeableContainer
iand(MappeableRunContainer x)
Computes the in-place bitwise AND of this container with another (intersection).MappeableContainer
iandNot(MappeableArrayContainer x)
Computes the in-place bitwise ANDNOT of this container with another (difference).MappeableContainer
iandNot(MappeableBitmapContainer x)
Computes the in-place bitwise ANDNOT of this container with another (difference).MappeableContainer
iandNot(MappeableRunContainer x)
Computes the in-place bitwise ANDNOT of this container with another (difference).(package private) MappeableContainer
ilazyor(MappeableArrayContainer x)
private MappeableContainer
ilazyorToRun(MappeableArrayContainer x)
private void
increaseCapacity()
private void
incrementLength(int index)
private void
incrementValue(int index)
private void
initValueLength(int value, int index)
MappeableContainer
inot(int rangeStart, int rangeEnd)
Computes the in-place bitwise NOT of this container (complement).boolean
intersects(int minimum, int supremum)
Checks if the container intersects with a rangeboolean
intersects(MappeableArrayContainer x)
Returns true if the current container intersects the other container.boolean
intersects(MappeableBitmapContainer x)
Returns true if the current container intersects the other container.boolean
intersects(MappeableRunContainer x)
Returns true if the current container intersects the other container.MappeableContainer
ior(MappeableArrayContainer x)
Computes the in-place bitwise OR of this container with another (union).MappeableContainer
ior(MappeableBitmapContainer x)
Computes the in-place bitwise OR of this container with another (union).MappeableContainer
ior(MappeableRunContainer x)
Computes the in-place bitwise OR of this container with another (union).MappeableContainer
iremove(int begin, int end)
Remove chars in [begin,end) using an unsigned interpretation.protected boolean
isArrayBacked()
boolean
isEmpty()
Checks whether the container is empty or not.boolean
isFull()
Checks whether the container is full or not.java.util.Iterator<java.lang.Character>
iterator()
MappeableContainer
ixor(MappeableArrayContainer x)
Computes the in-place bitwise XOR of this container with another (symmetric difference).MappeableContainer
ixor(MappeableBitmapContainer x)
Computes the in-place bitwise XOR of this container with another (symmetric difference).MappeableContainer
ixor(MappeableRunContainer x)
Computes the in-place bitwise XOR of this container with another (symmetric difference).int
last()
Get the last integer held in the containerprivate MappeableRunContainer
lazyandNot(MappeableArrayContainer x)
protected MappeableContainer
lazyor(MappeableArrayContainer x)
private MappeableContainer
lazyorToRun(MappeableArrayContainer x)
private MappeableContainer
lazyxor(MappeableArrayContainer x)
MappeableContainer
limit(int maxcardinality)
Create a new MappeableContainer containing at most maxcardinality integers.private void
makeRoomAtIndex(int index)
private void
mergeValuesLength(int begin, int end)
int
nextAbsentValue(char fromValue)
Gets the first absent value greater than or equal to the lower bound.int
nextValue(char fromValue)
Gets the first value greater than or equal to the lower bound, or -1 if no such value exists.MappeableContainer
not(int rangeStart, int rangeEnd)
Computes the bitwise NOT of this container (complement).int
numberOfRuns()
MappeableContainer
or(MappeableArrayContainer x)
Computes the bitwise OR of this container with another (union).MappeableContainer
or(MappeableBitmapContainer x)
Computes the bitwise OR of this container with another (union).MappeableContainer
or(MappeableRunContainer x)
Computes the bitwise OR of this container with another (union).void
orInto(long[] bits)
Computes the union of this container with the bits present in the array, modifying the array.private void
prependValueLength(int value, int index)
int
previousAbsentValue(char fromValue)
Gets the last value less than or equal to the upper bound.int
previousValue(char fromValue)
Gets the last value less than or equal to the upper bound, or -1 if no such value exists.int
rank(char lowbits)
Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality()).void
readExternal(java.io.ObjectInput in)
private void
recoverRoomAtIndex(int index)
private void
recoverRoomsInRange(int begin, int end)
MappeableContainer
remove(char x)
Remove the char from this container.MappeableContainer
remove(int begin, int end)
Return a new container with all chars in [begin,end) remove using an unsigned interpretation.void
removeFrom(long[] bits)
Computes the intersection of the negation of this container with the bits present in the array, modifying the array.MappeableContainer
repairAfterLazy()
The output of a lazyOR or lazyIOR might be an invalid container, this should be called on it.MappeableContainer
runOptimize()
Convert to Array or Bitmap container if the serialized form would be shorterchar
select(int j)
Return the jth valueint
serializedSizeInBytes()
Report the number of bytes required to serialize this container.protected static int
serializedSizeInBytes(int numberOfRuns)
private void
setLength(int index, char v)
private void
setLength(java.nio.CharBuffer valueslength, int index, char v)
private void
setValue(int index, char v)
private void
setValue(java.nio.CharBuffer valueslength, int index, char v)
private void
smartAppend(char[] vl, char val)
private void
smartAppend(char[] vl, char start, char length)
(package private) void
smartAppend(char start, char length)
private void
smartAppendExclusive(char[] vl, char val)
private void
smartAppendExclusive(char[] vl, char start, char length)
MappeableBitmapContainer
toBitmapContainer()
Convert the current container to a BitmapContainer, if a conversion is needed.private MappeableContainer
toBitmapIfNeeded()
(package private) MappeableContainer
toBitmapOrArrayContainer(int card)
Convert the container to either a Bitmap or an Array Container, depending on the cardinality.char[]
toCharArray()
Create a copy of the content of this container as a char array.Container
toContainer()
Convert to a non-mappeable container.private MappeableContainer
toEfficientContainer()
java.lang.String
toString()
void
trim()
If possible, recover wasted memory.private boolean
valueLengthContains(int value, int index)
protected void
writeArray(java.io.DataOutput out)
Write just the underlying array.protected void
writeArray(java.nio.ByteBuffer buffer)
Write just the underlying array.void
writeExternal(java.io.ObjectOutput out)
MappeableContainer
xor(MappeableArrayContainer x)
Computes the bitwise XOR of this container with another (symmetric difference).MappeableContainer
xor(MappeableBitmapContainer x)
Computes the bitwise XOR of this container with another (symmetric difference).MappeableContainer
xor(MappeableRunContainer x)
Computes the bitwise XOR of this container with another (symmetric difference).-
Methods inherited from class org.roaringbitmap.buffer.MappeableContainer
and, andCardinality, andNot, assertNonEmpty, contains, getContainerName, iand, iandNot, intersects, ior, iorNot, ixor, lazyIOR, lazyOR, or, orNot, rangeOfOnes, xor, xorCardinality
-
-
-
-
Field Detail
-
DEFAULT_INIT_SIZE
private static final int DEFAULT_INIT_SIZE
- See Also:
- Constant Field Values
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
valueslength
protected java.nio.CharBuffer valueslength
-
nbrruns
protected int nbrruns
-
-
Constructor Detail
-
MappeableRunContainer
public MappeableRunContainer()
Create a container with default capacity
-
MappeableRunContainer
public MappeableRunContainer(int capacity)
Create an array container with specified capacity- Parameters:
capacity
- The capacity of the container
-
MappeableRunContainer
private MappeableRunContainer(int nbrruns, java.nio.CharBuffer valueslength)
-
MappeableRunContainer
protected MappeableRunContainer(MappeableArrayContainer arr, int nbrRuns)
-
MappeableRunContainer
public MappeableRunContainer(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)
-
MappeableRunContainer
protected MappeableRunContainer(MappeableBitmapContainer bc, int nbrRuns)
-
MappeableRunContainer
public MappeableRunContainer(RunContainer bc)
Creates a new container from a non-mappeable one. This copies the data.- Parameters:
bc
- the original container
-
MappeableRunContainer
public MappeableRunContainer(java.nio.CharBuffer array, int numRuns)
Construct a new RunContainer backed by the provided CharBuffer. Note that if you modify the RunContainer a new CharBuffer may be produced.- Parameters:
array
- CharBuffer where the data is storednumRuns
- number of runs (each using 2 chars in the buffer)
-
-
Method Detail
-
branchyBufferedUnsignedInterleavedBinarySearch
private static int branchyBufferedUnsignedInterleavedBinarySearch(java.nio.CharBuffer sb, int begin, int end, char k)
-
branchyBufferedUnsignedInterleavedBinarySearch
private static int branchyBufferedUnsignedInterleavedBinarySearch(java.nio.ByteBuffer sb, int position, int begin, int end, char k)
-
bufferedUnsignedInterleavedBinarySearch
private static int bufferedUnsignedInterleavedBinarySearch(java.nio.CharBuffer sb, int begin, int end, char k)
-
bufferedUnsignedInterleavedBinarySearch
private static int bufferedUnsignedInterleavedBinarySearch(java.nio.ByteBuffer sb, int position, int begin, int end, char k)
-
getArraySizeInBytes
protected static int getArraySizeInBytes(int nbrruns)
-
getLength
private static char getLength(char[] vl, int index)
-
getValue
private static char getValue(char[] vl, int index)
-
serializedSizeInBytes
protected static int serializedSizeInBytes(int numberOfRuns)
-
add
public MappeableContainer add(int begin, int end)
Description copied from class:MappeableContainer
Return a new container with all chars in [begin,end) added using an unsigned interpretation.- Specified by:
add
in classMappeableContainer
- Parameters:
begin
- start of range (inclusive)end
- end of range (exclusive)- Returns:
- the new container
-
add
public MappeableContainer add(char k)
Description copied from class:MappeableContainer
Add a char to the container. May generate a new container.- Specified by:
add
in interfaceWordStorage<MappeableContainer>
- Specified by:
add
in classMappeableContainer
- Parameters:
k
- char to be added- Returns:
- the new container
-
isEmpty
public boolean isEmpty()
Description copied from class:MappeableContainer
Checks whether the container is empty or not.- Specified by:
isEmpty
in interfaceWordStorage<MappeableContainer>
- Specified by:
isEmpty
in classMappeableContainer
- Returns:
- true if the container is empty.
-
and
public MappeableContainer and(MappeableArrayContainer x)
Description copied from class:MappeableContainer
Computes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected.- Specified by:
and
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
and
public MappeableContainer and(MappeableBitmapContainer x)
Description copied from class:MappeableContainer
Computes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected.- Specified by:
and
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
and
public MappeableContainer and(MappeableRunContainer x)
Description copied from class:MappeableContainer
Computes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected.- Specified by:
and
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
andNot
public MappeableContainer andNot(MappeableArrayContainer x)
Description copied from class:MappeableContainer
Computes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected.- Specified by:
andNot
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
andNot
public MappeableContainer andNot(MappeableBitmapContainer x)
Description copied from class:MappeableContainer
Computes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected.- Specified by:
andNot
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
andNot
public MappeableContainer andNot(MappeableRunContainer x)
Description copied from class:MappeableContainer
Computes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected.- Specified by:
andNot
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
appendValueLength
private void appendValueLength(int value, int index)
-
canPrependValueLength
private boolean canPrependValueLength(int value, int index)
-
clear
public void clear()
Description copied from class:MappeableContainer
Empties the container- Specified by:
clear
in classMappeableContainer
-
clone
public MappeableContainer clone()
- Specified by:
clone
in classMappeableContainer
-
closeValueLength
private void closeValueLength(int value, int index)
-
contains
public boolean contains(char x)
Description copied from class:MappeableContainer
Checks whether the contain contains the provided value- Specified by:
contains
in classMappeableContainer
- Parameters:
x
- value to check- Returns:
- whether the value is in the container
-
contains
public static boolean contains(java.nio.ByteBuffer buf, int position, char x, int numRuns)
Checks whether the run container contains x.- Parameters:
buf
- underlying ByteBufferposition
- starting position of the container in the ByteBufferx
- target 16-bit valuenumRuns
- number of runs- Returns:
- whether the run container contains x
-
convertToLazyBitmapIfNeeded
private MappeableContainer convertToLazyBitmapIfNeeded()
-
copyToOffset
private void copyToOffset(int offset)
-
copyValuesLength
private void copyValuesLength(java.nio.CharBuffer src, int srcIndex, java.nio.CharBuffer dst, int dstIndex, int length)
-
decrementLength
private void decrementLength(int index)
-
decrementValue
private void decrementValue()
-
ensureCapacity
private void ensureCapacity(int minNbRuns)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
equals
private boolean equals(MappeableRunContainer runContainer)
-
equals
private boolean equals(MappeableArrayContainer arrayContainer)
-
fillLeastSignificant16bits
public void fillLeastSignificant16bits(int[] x, int i, int mask)
Description copied from class:MappeableContainer
Fill the least significant 16 bits of the integer array, starting at index index, with the char 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:
fillLeastSignificant16bits
in classMappeableContainer
- Parameters:
x
- provided arrayi
- starting indexmask
- indicates most significant bits
-
flip
public MappeableContainer flip(char x)
Description copied from class:MappeableContainer
Add a char to the container if it is not present, otherwise remove it. May generate a new container.- Specified by:
flip
in classMappeableContainer
- Parameters:
x
- char to be added- Returns:
- the new container
-
getArraySizeInBytes
protected int getArraySizeInBytes()
Description copied from class:MappeableContainer
Size of the underlying array- Specified by:
getArraySizeInBytes
in classMappeableContainer
- Returns:
- size in bytes
-
getCardinality
public int getCardinality()
Description copied from class:MappeableContainer
Computes the distinct number of char values in the container. Can be expected to run in constant time.- Specified by:
getCardinality
in classMappeableContainer
- 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:
java.lang.ArrayIndexOutOfBoundsException
- if index is negative or larger than the index of the last run.
-
getReverseCharIterator
public CharIterator getReverseCharIterator()
Description copied from class:MappeableContainer
Iterator to visit the char values in the container in descending order.- Specified by:
getReverseCharIterator
in classMappeableContainer
- Returns:
- iterator
-
getCharIterator
public PeekableCharIterator getCharIterator()
Description copied from class:MappeableContainer
Iterator to visit the char values in the container in ascending order.- Specified by:
getCharIterator
in classMappeableContainer
- Returns:
- iterator
-
getBatchIterator
public ContainerBatchIterator getBatchIterator()
Description copied from class:MappeableContainer
Gets an iterator to visit the contents of the container in batches- Specified by:
getBatchIterator
in classMappeableContainer
- Returns:
- iterator
-
getSizeInBytes
public int getSizeInBytes()
Description copied from class:MappeableContainer
Computes an estimate of the memory usage of this container. The estimate is not meant to be exact.- Specified by:
getSizeInBytes
in classMappeableContainer
- 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:
java.lang.ArrayIndexOutOfBoundsException
- if index is negative or larger than the index of the last run.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
iadd
public MappeableContainer iadd(int begin, int end)
Description copied from class:MappeableContainer
Add all chars in [begin,end) using an unsigned interpretation. May generate a new container.- Specified by:
iadd
in classMappeableContainer
- Parameters:
begin
- start of range (inclusive)end
- end of range (exclusive)- Returns:
- the new container
-
iand
public MappeableContainer iand(MappeableArrayContainer x)
Description copied from class:MappeableContainer
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.- Specified by:
iand
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
iand
public MappeableContainer iand(MappeableBitmapContainer x)
Description copied from class:MappeableContainer
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.- Specified by:
iand
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
iand
public MappeableContainer iand(MappeableRunContainer x)
Description copied from class:MappeableContainer
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.- Specified by:
iand
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
iandNot
public MappeableContainer iandNot(MappeableArrayContainer x)
Description copied from class:MappeableContainer
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.- Specified by:
iandNot
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
iandNot
public MappeableContainer iandNot(MappeableBitmapContainer x)
Description copied from class:MappeableContainer
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.- Specified by:
iandNot
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
iandNot
public MappeableContainer iandNot(MappeableRunContainer x)
Description copied from class:MappeableContainer
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.- Specified by:
iandNot
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
ilazyor
MappeableContainer ilazyor(MappeableArrayContainer x)
-
ilazyorToRun
private MappeableContainer ilazyorToRun(MappeableArrayContainer x)
-
increaseCapacity
private void increaseCapacity()
-
incrementLength
private void incrementLength(int index)
-
incrementValue
private void incrementValue(int index)
-
initValueLength
private void initValueLength(int value, int index)
-
inot
public MappeableContainer inot(int rangeStart, int rangeEnd)
Description copied from class:MappeableContainer
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.- Specified by:
inot
in classMappeableContainer
- Parameters:
rangeStart
- beginning of range (inclusive); 0 is beginning of this container.rangeEnd
- ending of range (exclusive)- Returns:
- (partially) completmented container
-
intersects
public boolean intersects(MappeableArrayContainer x)
Description copied from class:MappeableContainer
Returns true if the current container intersects the other container.- Specified by:
intersects
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- whether they intersect
-
intersects
public boolean intersects(MappeableBitmapContainer x)
Description copied from class:MappeableContainer
Returns true if the current container intersects the other container.- Specified by:
intersects
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- whether they intersect
-
intersects
public boolean intersects(MappeableRunContainer x)
Description copied from class:MappeableContainer
Returns true if the current container intersects the other container.- Specified by:
intersects
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- whether they intersect
-
ior
public MappeableContainer ior(MappeableArrayContainer x)
Description copied from class:MappeableContainer
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.- Specified by:
ior
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
ior
public MappeableContainer ior(MappeableBitmapContainer x)
Description copied from class:MappeableContainer
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.- Specified by:
ior
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
ior
public MappeableContainer ior(MappeableRunContainer x)
Description copied from class:MappeableContainer
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.- Specified by:
ior
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
iremove
public MappeableContainer iremove(int begin, int end)
Description copied from class:MappeableContainer
Remove chars in [begin,end) using an unsigned interpretation. May generate a new container.- Specified by:
iremove
in classMappeableContainer
- Parameters:
begin
- start of range (inclusive)end
- end of range (exclusive)- Returns:
- the new container
-
isArrayBacked
protected boolean isArrayBacked()
- Specified by:
isArrayBacked
in classMappeableContainer
-
isFull
public boolean isFull()
Description copied from class:MappeableContainer
Checks whether the container is full or not.- Specified by:
isFull
in classMappeableContainer
- Returns:
- true if the container is full.
-
orInto
public void orInto(long[] bits)
Description copied from class:MappeableContainer
Computes the union of this container with the bits present in the array, modifying the array.- Specified by:
orInto
in classMappeableContainer
- Parameters:
bits
- a 1024 element array to be interpreted as a bit set
-
andInto
public void andInto(long[] bits)
Description copied from class:MappeableContainer
Computes the intersection of this container with the bits present in the array, modifying the array.- Specified by:
andInto
in classMappeableContainer
- Parameters:
bits
- a 1024 element array to be interpreted as a bit set
-
removeFrom
public void removeFrom(long[] bits)
Description copied from class:MappeableContainer
Computes the intersection of the negation of this container with the bits present in the array, modifying the array.- Specified by:
removeFrom
in classMappeableContainer
- Parameters:
bits
- a 1024 element array to be interpreted as a bit set
-
full
public static MappeableRunContainer full()
-
iterator
public java.util.Iterator<java.lang.Character> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<java.lang.Character>
-
ixor
public MappeableContainer ixor(MappeableArrayContainer x)
Description copied from class:MappeableContainer
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.- Specified by:
ixor
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
ixor
public MappeableContainer ixor(MappeableBitmapContainer x)
Description copied from class:MappeableContainer
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.- Specified by:
ixor
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
ixor
public MappeableContainer ixor(MappeableRunContainer x)
Description copied from class:MappeableContainer
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.- Specified by:
ixor
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
lazyandNot
private MappeableRunContainer lazyandNot(MappeableArrayContainer x)
-
lazyor
protected MappeableContainer lazyor(MappeableArrayContainer x)
-
lazyorToRun
private MappeableContainer lazyorToRun(MappeableArrayContainer x)
-
lazyxor
private MappeableContainer lazyxor(MappeableArrayContainer x)
-
limit
public MappeableContainer limit(int maxcardinality)
Description copied from class:MappeableContainer
Create a new MappeableContainer containing at most maxcardinality integers.- Specified by:
limit
in classMappeableContainer
- Parameters:
maxcardinality
- maximal cardinality- Returns:
- a new bitmap with cardinality no more than maxcardinality
-
makeRoomAtIndex
private void makeRoomAtIndex(int index)
-
mergeValuesLength
private void mergeValuesLength(int begin, int end)
-
not
public MappeableContainer not(int rangeStart, int rangeEnd)
Description copied from class:MappeableContainer
Computes the bitwise NOT of this container (complement). Only those bits within the range are affected. The current container is left unaffected.- Specified by:
not
in classMappeableContainer
- Parameters:
rangeStart
- beginning of range (inclusive); 0 is beginning of this container.rangeEnd
- ending of range (exclusive)- Returns:
- (partially) completmented container
-
numberOfRuns
public int numberOfRuns()
- Specified by:
numberOfRuns
in classMappeableContainer
-
or
public MappeableContainer or(MappeableArrayContainer x)
Description copied from class:MappeableContainer
Computes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected.- Specified by:
or
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
or
public MappeableContainer or(MappeableBitmapContainer x)
Description copied from class:MappeableContainer
Computes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected.- Specified by:
or
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
or
public MappeableContainer or(MappeableRunContainer x)
Description copied from class:MappeableContainer
Computes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected.- Specified by:
or
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
prependValueLength
private void prependValueLength(int value, int index)
-
rank
public int rank(char lowbits)
Description copied from class:MappeableContainer
Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality()).- Specified by:
rank
in classMappeableContainer
- Parameters:
lowbits
- upper limit- Returns:
- the rank
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException
- Specified by:
readExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
-
recoverRoomAtIndex
private void recoverRoomAtIndex(int index)
-
recoverRoomsInRange
private void recoverRoomsInRange(int begin, int end)
-
remove
public MappeableContainer remove(int begin, int end)
Description copied from class:MappeableContainer
Return a new container with all chars in [begin,end) remove using an unsigned interpretation.- Specified by:
remove
in classMappeableContainer
- Parameters:
begin
- start of range (inclusive)end
- end of range (exclusive)- Returns:
- the new container
-
remove
public MappeableContainer remove(char x)
Description copied from class:MappeableContainer
Remove the char from this container. May create a new container.- Specified by:
remove
in classMappeableContainer
- Parameters:
x
- to be removed- Returns:
- New container
-
repairAfterLazy
public MappeableContainer repairAfterLazy()
Description copied from class:MappeableContainer
The output of a lazyOR or lazyIOR might be an invalid container, this should be called on it.- Specified by:
repairAfterLazy
in classMappeableContainer
- Returns:
- a new valid container
-
runOptimize
public MappeableContainer runOptimize()
Convert to Array or Bitmap container if the serialized form would be shorter- Specified by:
runOptimize
in interfaceWordStorage<MappeableContainer>
- Specified by:
runOptimize
in classMappeableContainer
- Returns:
- the new container
-
select
public char select(int j)
Description copied from class:MappeableContainer
Return the jth value- Specified by:
select
in classMappeableContainer
- Parameters:
j
- index of the value- Returns:
- the value
-
serializedSizeInBytes
public int serializedSizeInBytes()
Description copied from class:MappeableContainer
Report the number of bytes required to serialize this container.- Specified by:
serializedSizeInBytes
in classMappeableContainer
- Returns:
- the size in bytes
-
setLength
private void setLength(int index, char v)
-
setLength
private void setLength(java.nio.CharBuffer valueslength, int index, char v)
-
setValue
private void setValue(int index, char v)
-
setValue
private void setValue(java.nio.CharBuffer valueslength, int index, char v)
-
smartAppend
private void smartAppend(char[] vl, char val)
-
smartAppend
void smartAppend(char start, char length)
-
smartAppend
private void smartAppend(char[] vl, char start, char length)
-
smartAppendExclusive
private void smartAppendExclusive(char[] vl, char val)
-
smartAppendExclusive
private void smartAppendExclusive(char[] vl, char start, char length)
-
toBitmapIfNeeded
private MappeableContainer toBitmapIfNeeded()
-
toBitmapOrArrayContainer
MappeableContainer toBitmapOrArrayContainer(int card)
Convert the container to either a Bitmap or an Array Container, depending on the cardinality.- Parameters:
card
- the current cardinality- Returns:
- new container
-
toContainer
public Container toContainer()
Description copied from class:MappeableContainer
Convert to a non-mappeable container.- Specified by:
toContainer
in classMappeableContainer
- Returns:
- the non-mappeable container
-
toEfficientContainer
private MappeableContainer toEfficientContainer()
-
toCharArray
public char[] toCharArray()
Create a copy of the content of this container as a char array. This creates a copy.- Returns:
- copy of the content as a char array
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
trim
public void trim()
Description copied from class:MappeableContainer
If possible, recover wasted memory.- Specified by:
trim
in classMappeableContainer
-
valueLengthContains
private boolean valueLengthContains(int value, int index)
-
writeArray
protected void writeArray(java.io.DataOutput out) throws java.io.IOException
Description copied from class:MappeableContainer
Write just the underlying array.- Specified by:
writeArray
in classMappeableContainer
- Parameters:
out
- output stream- Throws:
java.io.IOException
- in case of failure
-
writeArray
protected void writeArray(java.nio.ByteBuffer buffer)
Description copied from class:MappeableContainer
Write just the underlying array.- Specified by:
writeArray
in classMappeableContainer
- Parameters:
buffer
- the buffer to write to
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
- Specified by:
writeExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
-
xor
public MappeableContainer xor(MappeableArrayContainer x)
Description copied from class:MappeableContainer
Computes the bitwise XOR of this container with another (symmetric difference). This container as well as the provided container are left unaffected.- Specified by:
xor
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
xor
public MappeableContainer xor(MappeableBitmapContainer x)
Description copied from class:MappeableContainer
Computes the bitwise XOR of this container with another (symmetric difference). This container as well as the provided container are left unaffected.- Specified by:
xor
in classMappeableContainer
- Parameters:
x
- other container- Returns:
- aggregated container
-
xor
public MappeableContainer xor(MappeableRunContainer x)
Description copied from class:MappeableContainer
Computes the bitwise XOR of this container with another (symmetric difference). This container as well as the provided container are left unaffected.- Specified by:
xor
in classMappeableContainer
- Parameters:
x
- other parameter- Returns:
- aggregated container
-
forEach
public void forEach(char msb, IntConsumer ic)
Description copied from class:MappeableContainer
Iterate through the values of this container and pass them along to the IntConsumer, using msb as the 16 most significant bits.- Specified by:
forEach
in classMappeableContainer
- Parameters:
msb
- 16 most significant bitsic
- consumer
-
andCardinality
public int andCardinality(MappeableArrayContainer x)
- Specified by:
andCardinality
in classMappeableContainer
-
andCardinality
public int andCardinality(MappeableBitmapContainer x)
- Specified by:
andCardinality
in classMappeableContainer
-
andCardinality
public int andCardinality(MappeableRunContainer x)
- Specified by:
andCardinality
in classMappeableContainer
-
toBitmapContainer
public MappeableBitmapContainer toBitmapContainer()
Description copied from class:MappeableContainer
Convert 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:
toBitmapContainer
in classMappeableContainer
- Returns:
- a bitmap container
-
first
public int first()
Description copied from class:MappeableContainer
Get the first integer held in the container- Specified by:
first
in classMappeableContainer
- Returns:
- the first integer in the container
-
last
public int last()
Description copied from class:MappeableContainer
Get the last integer held in the container- Specified by:
last
in classMappeableContainer
- Returns:
- the last integer in the container
-
nextValue
public int nextValue(char fromValue)
Description copied from class:MappeableContainer
Gets the first value greater than or equal to the lower bound, or -1 if no such value exists.- Specified by:
nextValue
in classMappeableContainer
- Parameters:
fromValue
- the lower bound (inclusive)- Returns:
- the next value
-
previousValue
public int previousValue(char fromValue)
Description copied from class:MappeableContainer
Gets the last value less than or equal to the upper bound, or -1 if no such value exists.- Specified by:
previousValue
in classMappeableContainer
- Parameters:
fromValue
- the upper bound (inclusive)- Returns:
- the previous value
-
nextAbsentValue
public int nextAbsentValue(char fromValue)
Description copied from class:MappeableContainer
Gets the first absent value greater than or equal to the lower bound.- Specified by:
nextAbsentValue
in classMappeableContainer
- Parameters:
fromValue
- the lower bound (inclusive)- Returns:
- the next absent value
-
previousAbsentValue
public int previousAbsentValue(char fromValue)
Description copied from class:MappeableContainer
Gets the last value less than or equal to the upper bound.- Specified by:
previousAbsentValue
in classMappeableContainer
- Parameters:
fromValue
- the upper bound (inclusive)- Returns:
- the previous absent value
-
contains
protected boolean contains(MappeableRunContainer runContainer)
- Specified by:
contains
in classMappeableContainer
-
contains
protected boolean contains(MappeableArrayContainer arrayContainer)
- Specified by:
contains
in classMappeableContainer
-
contains
protected boolean contains(MappeableBitmapContainer bitmapContainer)
- Specified by:
contains
in classMappeableContainer
-
intersects
public boolean intersects(int minimum, int supremum)
Description copied from class:MappeableContainer
Checks if the container intersects with a range- Specified by:
intersects
in classMappeableContainer
- 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
-
contains
public boolean contains(int minimum, int supremum)
Description copied from class:MappeableContainer
Checks whether the container contains the entire range- Specified by:
contains
in classMappeableContainer
- Parameters:
minimum
- the inclusive lower bound of the rangesupremum
- the exclusive upper bound of the range- Returns:
- true if the container contains the range
-
-