Package org.infinispan.protostream.impl
Class SparseBitSet
java.lang.Object
org.infinispan.protostream.impl.SparseBitSet
- All Implemented Interfaces:
Iterable<Long>,ReservedNumbers
A sparse bit set for storing occurrences of bits where a large amount of the stored bits are expected to be zero.
This implementation uses a simplistic indexing scheme which provides
log(n) performance for accessing
individual bits. Memory usage is roughly proportional to bitCount(). The bit set can set any bit between
0 and Long.MAX_VALUE, inclusive. However, the maximum number of sparse 64-bit words in use by the
set bits in the bit set is limited by the int length limit of arrays.-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstruct aSparseBitSet.SparseBitSet(int capacity) Construct aSparseBitSetwith the given initial capacity.SparseBitSet(long... values) Construct aSparseBitSetwith the given values.SparseBitSet(SparseBitSet other) -
Method Summary
Modifier and TypeMethodDescriptionprivate intadjustBase(int fromIndex, int wordIndex) longbitCount()voidclear()Reset thisSparseBitSetto the empty state, i.e.booleanclear(long i) Clear the bit at indexi.private intfindWord(long x) longbooleanget(long i) Get the bit at indexi.private voidinsert(long x, int insertionPoint) booleanisEmpty()iterator()longlastLong()intnextClearBit(int fromIndex) intnextSetBit(int fromIndex) voidremoveAll(ReservedNumbers that) private voidremoveBit(int wordIndex, long bitIndex) private voidremoveWord(int index) booleanset(long i) Set the bit at indexi.booleanset(long i, boolean value) Set the bit at indexito the givenvalue.voidset(long fromIndex, long toIndex) Sets the bits from the specified fromIndex (inclusive) to the specified toIndex (exclusive) to true.intsize()toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
words
private long[] words -
indices
private long[] indices -
size
private int size -
modCount
private int modCount
-
-
Constructor Details
-
SparseBitSet
public SparseBitSet()Construct aSparseBitSet. -
SparseBitSet
public SparseBitSet(long... values) Construct aSparseBitSetwith the given values. -
SparseBitSet
public SparseBitSet(int capacity) Construct aSparseBitSetwith the given initial capacity. -
SparseBitSet
-
-
Method Details
-
set
public boolean set(long i) Set the bit at indexi.- Returns:
trueif this bit set changed as a result of setting the bit, i.e. the bit was clear,falseotherwise.
-
clear
public boolean clear(long i) Clear the bit at indexi.- Returns:
trueif this bit set changed as a result of setting the bit, i.e. the bit was set,falseotherwise.
-
set
public boolean set(long i, boolean value) Set the bit at indexito the givenvalue.- Returns:
trueif this bit set changed as a result of changing the bit, false otherwise.
-
set
public void set(long fromIndex, long toIndex) Sets the bits from the specified fromIndex (inclusive) to the specified toIndex (exclusive) to true. Params:- Parameters:
fromIndex- – index of the first bit to be settoIndex- – index after the last bit to be set- Throws:
IndexOutOfBoundsException- – if fromIndex is negative, or toIndex is negative, or fromIndex is larger than toIndex
-
get
public boolean get(long i) Get the bit at indexi.- Specified by:
getin interfaceReservedNumbers- Returns:
trueif the bit at indexiis set, false otherwise.
-
bitCount
public long bitCount()- Returns:
- the number of set bits in this
SparseBitSet.
-
size
public int size()- Specified by:
sizein interfaceReservedNumbers- Returns:
- the size of this
SparseBitSet, i.e. the number of set bits. - See Also:
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceReservedNumbers- Returns:
- true if this
SparseBitSetcontains no set bits, false otherwise.
-
nextSetBit
public int nextSetBit(int fromIndex) - Specified by:
nextSetBitin interfaceReservedNumbers
-
adjustBase
private int adjustBase(int fromIndex, int wordIndex) -
nextClearBit
public int nextClearBit(int fromIndex) - Specified by:
nextClearBitin interfaceReservedNumbers
-
clear
public void clear()Reset thisSparseBitSetto the empty state, i.e. with no bits set. -
firstLong
public long firstLong() -
lastLong
public long lastLong() -
iterator
-
descendingIterator
-
toString
- Overrides:
toStringin classObject- Returns:
- a string representation of this
BitSetin the same format asBitSet.toString(), e.g. the indices of all the set bits in ascending order surrounded by curly brackets"{}".
-
findWord
private int findWord(long x) -
insert
private void insert(long x, int insertionPoint) -
removeBit
private void removeBit(int wordIndex, long bitIndex) -
removeWord
private void removeWord(int index) -
removeAll
-