Class RankedBitVectorImpl
java.lang.Object
org.wikidata.wdtk.storage.datastructures.RankedBitVectorImpl
- All Implemented Interfaces:
Iterable<Boolean>
,BitVector
,RankedBitVector
Default implementation of
RankedBitVector
. This implementation uses
auxiliary classes to have efficient performance for the methods of a ranked
bit vector. Hence, countBits(boolean, long)
uses an instance of
CountBitsArray
and findPosition(boolean, long)
uses two
instances of FindPositionArray
.- Author:
- Julian Mendez
- See Also:
-
CountBitsArray
FindPositionArray
-
Field Summary
Fields inherited from interface org.wikidata.wdtk.storage.datastructures.RankedBitVector
NOT_FOUND
-
Constructor Summary
ConstructorDescriptionConstructor of a ranked bit vector of size 0.RankedBitVectorImpl
(long initialSize) Constructor of a ranked bit vector of size initialSize.RankedBitVectorImpl
(long initialSize, int countBlockSize, int findPositionBlockSize) Constructor of a ranked bit vector of size initialSize and block size blockSize.RankedBitVectorImpl
(BitVector bitVector) Copy constructor of a ranked bit vector. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addBit
(boolean bit) Appends a bit to this bit vector.long
countBits
(boolean bit, long position) This is the "rank" method of bit vectors.boolean
Returnstrue
if and only if the specified object is also a BitVector and both contain the same bits in the same order.long
findPosition
(boolean bit, long nOccurrence) This is the "select" method of bit vectors.boolean
getBit
(long position) This is the "access" method of bit vectors.int
hashCode()
iterator()
void
setBit
(long position, boolean bit) Sets a bit at a particular position.long
size()
toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
RankedBitVectorImpl
public RankedBitVectorImpl()Constructor of a ranked bit vector of size 0. -
RankedBitVectorImpl
Copy constructor of a ranked bit vector.- Parameters:
bitVector
- bit vector
-
RankedBitVectorImpl
public RankedBitVectorImpl(long initialSize) Constructor of a ranked bit vector of size initialSize. The bit vector containsfalse
at all indexes.- Parameters:
initialSize
- initial size of this ranked bit vector
-
RankedBitVectorImpl
public RankedBitVectorImpl(long initialSize, int countBlockSize, int findPositionBlockSize) Constructor of a ranked bit vector of size initialSize and block size blockSize. The bit vector containsfalse
at all indexes.- Parameters:
initialSize
- initial size of this ranked bit vectorcountBlockSize
- block size to count number of occurrences of a value; this value must be a positive numberfindPositionBlockSize
- block size to find the position of the n-th occurrence of a value; this value must be greater than or equal to 64- Throws:
IllegalArgumentException
- if any of the block sizes is too small
-
-
Method Details
-
addBit
public boolean addBit(boolean bit) Description copied from interface:BitVector
Appends a bit to this bit vector. -
countBits
public long countBits(boolean bit, long position) Description copied from interface:RankedBitVector
This is the "rank" method of bit vectors. This method returns the number of occurrences of bit up to position.- Specified by:
countBits
in interfaceRankedBitVector
- Parameters:
bit
- bitposition
- position- Returns:
- number of occurrences of bit at position
-
equals
Description copied from interface:BitVector
Returnstrue
if and only if the specified object is also a BitVector and both contain the same bits in the same order. -
findPosition
public long findPosition(boolean bit, long nOccurrence) Description copied from interface:RankedBitVector
This is the "select" method of bit vectors. This method returns the position of the n-th occurrence (nOccurrence) of bit or NOT_FOUND if there are not enough occurrences.- Specified by:
findPosition
in interfaceRankedBitVector
- Parameters:
bit
- bitnOccurrence
- number of occurrences- Returns:
- position of the n-th occurrence (nOccurrence) of bit or NOT_FOUND if there are not enough occurrences
-
getBit
public boolean getBit(long position) Description copied from interface:BitVector
This is the "access" method of bit vectors. -
hashCode
public int hashCode() -
iterator
-
setBit
public void setBit(long position, boolean bit) Description copied from interface:BitVector
Sets a bit at a particular position. -
size
public long size() -
toString
-