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
FieldsModifier and TypeFieldDescriptionprotected final booleanWhether this structure was built from aSparseSelectstructure, and thus shares part of its internal state.protected final intThe number of lower bits.protected long[]The list of lower bits of the position of each one, stored explicitly.protected final longThe mask for lower bits.protected final longThe number of ones in the underlying bit array.protected final longThe length of the underlying bit array.protected final SimpleSelectZeroThe rank structure used to extract the upper bits.protected final it.unimi.dsi.bits.BitVectorThe upper bits. -
Constructor Summary
ConstructorsModifierConstructorDescriptionSparseRank(long[] bits, long length) Creates a new rank structure using a long array.protectedSparseRank(long n, long m, int l, long[] lowerBits, it.unimi.dsi.bits.BitVector upperBits) SparseRank(long n, long m, it.unimi.dsi.fastutil.longs.LongIterator iterator) Creates a new rank structure using an iterator.SparseRank(it.unimi.dsi.bits.BitVector bitVector) Creates a new rank structure using a bit vector. -
Method Summary
Modifier and TypeMethodDescriptionit.unimi.dsi.bits.BitVectorReturns the bit vector indexed; since the bits are not stored in this data structure, a copy is built on purpose and returned.Creates a newSparseSelectstructure sharing data with this instance.longnumBits()Returns the overall number of bits allocated by this structure.longrank(long pos) Returns the number of ones preceding the specified position.Methods inherited from class 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
protected final it.unimi.dsi.bits.BitVector upperBitsThe upper bits. -
selectZeroUpper
The rank structure used to extract the upper bits. -
fromSelect
protected final boolean fromSelectWhether this structure was built from aSparseSelectstructure, 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
public SparseRank(it.unimi.dsi.bits.BitVector bitVector) 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
public SparseRank(long n, long m, it.unimi.dsi.fastutil.longs.LongIterator iterator) 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
protected SparseRank(long n, long m, int l, long[] lowerBits, it.unimi.dsi.bits.BitVector upperBits)
-
-
Method Details
-
rank
public long rank(long pos) Description copied from interface:RankReturns 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; ifposis out of bounds, behavior is undefined.
-
numBits
public long numBits()Description copied from interface:RankReturns 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 newSparseSelectstructure sharing data with this instance.- Returns:
- a new
SparseSelectstructure sharing data with this instance.
-
bitVector
public it.unimi.dsi.bits.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.Warning: this method is quite slow, as it has to rebuild all bit positions.
- Returns:
- a copy of the underlying bit vector.
-