Package it.unimi.dsi.sux4j.bits
Class SparseRank
java.lang.Object
it.unimi.dsi.sux4j.bits.AbstractRank
it.unimi.dsi.sux4j.bits.SparseRank
- All Implemented Interfaces:
Rank
,Serializable
A rank implementation for sparse bit arrays based on the Elias–Fano representation of monotone functions.
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.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected final boolean
Whether this structure was built from aSparseSelect
structure, and thus shares part of its internal state.protected final int
The number of lower bits.protected long[]
The list of lower bits of the position of each one, stored explicitly.protected final long
The mask for lower bits.protected final long
The number of ones in the underlying bit array.protected final long
The length of the underlying bit array.protected final SimpleSelectZero
The rank structure used to extract the upper bits.protected final BitVector
The upper bits. -
Constructor Summary
ModifierConstructorDescriptionSparseRank
(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.SparseRank
(BitVector bitVector) Creates a new rank structure using a bit vector. -
Method Summary
Modifier and TypeMethodDescriptionReturns the bit vector indexed; since the bits are not stored in this data structure, a copy is built on purpose and returned.Creates a newSparseSelect
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.Methods inherited from class it.unimi.dsi.sux4j.bits.AbstractRank
count, rank, rankZero, rankZero
-
Field Details
-
n
protected final long nThe length of the underlying bit array. -
m
protected final long mThe number of ones in the underlying bit array. -
l
protected final int lThe number of lower bits. -
lowerLBitsMask
protected final long lowerLBitsMaskThe mask for lower bits. -
lowerBits
protected long[] lowerBitsThe list of lower bits of the position of each one, stored explicitly. -
upperBits
The upper bits. -
selectZeroUpper
The rank structure used to extract the upper bits. -
fromSelect
protected final boolean fromSelectWhether this structure was built from aSparseSelect
structure, and thus shares part of its internal state.
-
-
Constructor Details
-
SparseRank
public SparseRank(long[] bits, long length) Creates a new rank structure using a long array.The resulting structure keeps no reference to the original array.
- Parameters:
bits
- a long array containing the bits.length
- the number of valid bits inbits
.
-
SparseRank
Creates a new rank structure using a bit vector.The resulting structure keeps no reference to the original bit vector.
- Parameters:
bitVector
- the input bit vector.
-
SparseRank
Creates a new rank structure using an iterator.This constructor is particularly useful if the positions of the ones are provided by some sequential source.
- Parameters:
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.
-
SparseRank
-
-
Method Details
-
rank
public long rank(long pos) Description copied from interface:Rank
Returns the number of ones preceding the specified position.- Parameters:
pos
- a position in the bit vector between 0 (inclusive) and the length of the bit vector (inclusive).- Returns:
- the number of ones preceding position
pos
; ifpos
is out of bounds, behavior is undefined.
-
numBits
public long numBits()Description copied from interface:Rank
Returns the overall number of bits allocated by this structure.- Returns:
- the overall number of bits allocated by this structure (not including the bits of the indexed vector).
-
getSelect
Creates a newSparseSelect
structure sharing data with this instance.- Returns:
- a new
SparseSelect
structure sharing data with this instance.
-
bitVector
Returns the bit vector indexed; since the bits are not stored in this data structure, a copy is built on purpose and returned.Warning: this method is quite slow, as it has to rebuild all bit positions.
- Returns:
- a copy of the underlying bit vector.
-