public class SparseRank extends AbstractRank
Note that some data may be shared with SparseSelect: just use the factory method SparseSelect.getRank() to obtain an instance. In that
case, numBits() counts just the new data used to build the class, and not the shared part.
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
fromSelect
Whether this structure was built from a
SparseSelect structure, and thus shares part of its internal state. |
protected int |
l
The number of lower bits.
|
protected long[] |
lowerBits
The list of lower bits of the position of each one, stored explicitly.
|
protected long |
lowerLBitsMask
The mask for lower bits.
|
protected long |
m
The number of ones in the underlying bit array.
|
protected long |
n
The length of the underlying bit array.
|
protected SimpleSelectZero |
selectZeroUpper
The rank structure used to extract the upper bits.
|
protected BitVector |
upperBits
The upper bits.
|
| Modifier | Constructor and Description |
|---|---|
|
SparseRank(BitVector bitVector)
Creates a new rank structure using a bit vector.
|
|
SparseRank(long[] bits,
long length)
Creates a new rank structure using a long array.
|
protected |
SparseRank(long n,
long m,
int l,
long[] lowerBits,
BitVector upperBits) |
|
SparseRank(long n,
long m,
LongIterator iterator)
Creates a new rank structure using an iterator.
|
| Modifier and Type | Method and Description |
|---|---|
BitVector |
bitVector()
Returns the bit vector indexed; since the bits are not stored in this data structure,
a copy is built on purpose and returned.
|
SparseSelect |
getSelect()
Creates a new
SparseSelect structure sharing data with this instance. |
long |
numBits()
Returns the overall number of bits allocated by this structure.
|
long |
rank(long pos)
Returns the number of ones preceding the specified position.
|
count, rank, rankZero, rankZeroprotected final long n
protected final long m
protected final int l
protected final long lowerLBitsMask
protected final long[] lowerBits
protected final BitVector upperBits
protected final SimpleSelectZero selectZeroUpper
protected final boolean fromSelect
SparseSelect structure, and thus shares part of its internal state.public SparseRank(long[] bits,
long length)
The resulting structure keeps no reference to the original array.
bits - a long array containing the bits.length - the number of valid bits in bits.public SparseRank(BitVector bitVector)
The resulting structure keeps no reference to the original bit vector.
bitVector - the input bit vector.public SparseRank(long n,
long m,
LongIterator iterator)
This constructor is particularly useful if the positions of the ones are provided by some sequential source.
n - the number of bits in the underlying bit vector.m - the number of ones in the underlying bit vector.iterator - an iterator returning the positions of the ones in the underlying bit vector in increasing order.protected SparseRank(long n,
long m,
int l,
long[] lowerBits,
BitVector upperBits)
public long rank(long pos)
Rankpos - a position in the bit vector.pos.public long numBits()
Rankpublic SparseSelect getSelect()
SparseSelect structure sharing data with this instance.SparseSelect structure sharing data with this instance.public BitVector bitVector()
Warning: this method is very slow, as the only way to recover the original bit array is to rank each position in the bit vector.