public abstract class AbstractBitVector extends it.unimi.dsi.fastutil.booleans.AbstractBooleanList implements BitVector
BitVector.
 
 This abstract implementation provides almost all methods: you have to provide just
 BooleanList.getBoolean(int) and
 List.size(). No attributes are defined.
 
 
Note that the integer-set view provided by asLongSet() is not cached: if you
 want to cache the result of the first call, you must do your own caching.
 
 
Warning: this class has several optimised methods
 that assume that getLong(long, long) is implemented efficiently when its
 arguments are multiples of Long.SIZE (see, e.g., the implementation
 of compareTo(BitVector) and longestCommonPrefixLength(BitVector)).
 If you want speed up the processing of your own BitVector implementations,
 just implement getLong(long, long) so that it is fast under the above conditions.
| Modifier and Type | Class and Description | 
|---|---|
| static class  | AbstractBitVector.LongBigListViewA list-of-integers view of a bit vector. | 
| static class  | AbstractBitVector.LongSetViewAn integer sorted set view of a bit vector. | 
| static class  | AbstractBitVector.SubBitVectorA subvector of a given bit vector, specified by an initial and a final bit. | 
| Constructor and Description | 
|---|
| AbstractBitVector() | 
| Modifier and Type | Method and Description | 
|---|---|
| boolean | add(boolean value) | 
| void | add(int value)Adds a bit with specified value at the end of this bit vector. | 
| void | add(int index,
   boolean value) | 
| void | add(long index,
   boolean value)Adds a bit with specified value at the specified index (optional operation). | 
| void | add(long index,
   int value)Adds a bit with specified integer value at the specified index (optional operation). | 
| BitVector | and(BitVector v)Performs a logical and between this bit vector and another one, leaving the result in this vector. | 
| BitVector | append(BitVector bv)Appends another bit vector to this bit vector. | 
| BitVector | append(long value,
      int k)Appends the less significant bits of a long integer to this bit vector. | 
| LongBigList | asLongBigList(int width)Returns a view of this bit vector as a list of nonnegative integers of specified width. | 
| it.unimi.dsi.fastutil.longs.LongSortedSet | asLongSet()Returns a view of this bit vector as a sorted set of long integers. | 
| long[] | bits()Returns the bits in this bit vector as an array of longs, not to be modified. | 
| void | clear() | 
| void | clear(int index) | 
| void | clear(long index)Clears a bit in this bit vector (optional operation). | 
| int | compareTo(BitVector v) | 
| int | compareTo(List<? extends Boolean> list) | 
| BitVector | copy()Returns a copy of this bit vector. | 
| BitVector | copy(long from,
    long to)Returns a copy of a part of this bit vector. | 
| long | count()Counts the number of bits set to true in this bit vector. | 
| protected void | ensureIndex(long index) | 
| protected void | ensureRestrictedIndex(long index) | 
| boolean | equals(Object o) | 
| BitVector | fast()Returns an instance of  LongArrayBitVectorcontaining a copy of this bit vector. | 
| void | fill(boolean value)Sets all bits this bit vector to the given boolean value (optional operation). | 
| void | fill(int value)Sets all bits this bit vector to the given integer value (optional operation). | 
| void | fill(long from,
    long to,
    boolean value)Fills a range of bits in this bit vector (optional operation). | 
| void | fill(long from,
    long to,
    int value)Clears a range of bits in this bit vector (optional operation). | 
| long | firstOne()Returns the position of the first bit set in this vector. | 
| long | firstZero()Returns the position of the first bit unset in this vector. | 
| void | flip()Flips all bits in this bit vector (optional operation). | 
| void | flip(int index) | 
| void | flip(long index)Flips a bit in this bit vector (optional operation). | 
| void | flip(long from,
    long to)Flips a range of bits in this bit vector (optional operation). | 
| boolean | getBoolean(int index) | 
| int | getInt(long index)Returns the value of the specified bit as an integer. | 
| long | getLong(long from,
       long to)Returns the specified bit range as a long. | 
| int | hashCode()Returns a hash code for this bit vector. | 
| long | lastOne()Returns the position of the last bit set in this vector. | 
| long | lastZero()Returns the position of the last bit unset in this vector. | 
| BitVector | length(long newLength)Sets the number of bits in this bit vector. | 
| long | longestCommonPrefixLength(BitVector v)Returns the length of the greatest common prefix between this and the specified vector. | 
| long | nextOne(long index)Returns the position of the first bit set after the given position. | 
| long | nextZero(long index)Returns the position of the first bit unset after the given position. | 
| BitVector | or(BitVector v)Performs a logical or between this bit vector and another one, leaving the result in this vector. | 
| long | previousOne(long index)Returns the position of the first bit set before or at the given position. | 
| long | previousZero(long index)Returns the position of the first bit unset before or at the given position. | 
| boolean | removeBoolean(int index) | 
| boolean | removeBoolean(long index)Removes a bit with specified index (optional operation). | 
| BitVector | replace(BitVector bv)Replaces the content of this bit vector with another bit vector. | 
| void | set(int index) | 
| boolean | set(int index,
   boolean value) | 
| void | set(long index)Sets a bit in this bit vector (optional operation). | 
| boolean | set(long index,
   boolean value)Sets the value of the specified bit (optional operation). | 
| void | set(long index,
   int value)Sets the value of the specified bit as an integer (optional operation). | 
| int | size() | 
| void | size(int newSize) | 
| AbstractBitVector.SubBitVector | subList(int from,
       int to) | 
| BitVector | subVector(long from)Returns a subvector view specified by initial index and running up to the end of this vector. | 
| BitVector | subVector(long from,
         long to)Returns a subvector view specified by initial and final index. | 
| String | toString()Returns a string representation of this vector. | 
| BitVector | xor(BitVector v)Performs a logical xor between this bit vector and another one, leaving the result in this vector. | 
add, addAll, addAll, addAll, addAll, addAll, addAll, addElements, addElements, booleanListIterator, booleanListIterator, booleanSubList, contains, ensureIndex, ensureRestrictedIndex, get, getElements, indexOf, indexOf, iterator, lastIndexOf, lastIndexOf, listIterator, listIterator, peek, peekBoolean, pop, popBoolean, push, push, rem, remove, remove, removeElements, set, top, topBooleanadd, booleanIterator, contains, containsAll, containsAll, isEmpty, rem, removeAll, removeAll, retainAll, retainAll, toArray, toArray, toArray, toBooleanArray, toBooleanArrayclone, finalize, getClass, notify, notifyAll, wait, wait, waitgetBoolean, lengthaddAll, addAll, addAll, addElements, addElements, booleanListIterator, booleanListIterator, booleanSubList, getElements, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeElementsadd, add, addAll, addAll, contains, containsAll, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeAll, retainAll, set, toArray, toArrayprotected void ensureRestrictedIndex(long index)
protected void ensureIndex(long index)
public void set(int index)
public void clear(int index)
public void flip(int index)
public void set(long index)
BitVectorpublic void clear(long index)
BitVectorpublic void flip(long index)
BitVectorpublic void fill(boolean value)
BitVectorpublic void fill(int value)
BitVectorpublic void flip()
BitVectorpublic void fill(long from,
        long to,
        boolean value)
BitVectorpublic void fill(long from,
        long to,
        int value)
BitVectorpublic void flip(long from,
        long to)
BitVectorpublic int getInt(long index)
BitVectorThis method is a useful synonym for BitVector.getBoolean(long).
public long getLong(long from,
           long to)
BitVectorNote that bit 0 of the returned long will be bit from
 of this bit vector.
 
 
Implementations are invited to provide high-speed implementations for
 the case in which from is a multiple of Long.SIZE
 and to is from + Long.SIZE (or less,
 in case the vector length is exceeded). This behaviour make it possible to
 implement high-speed hashing, copies, etc.
public boolean getBoolean(int index)
getBoolean in interface it.unimi.dsi.fastutil.booleans.BooleanListpublic boolean removeBoolean(int index)
removeBoolean in interface it.unimi.dsi.fastutil.booleans.BooleanListremoveBoolean in class it.unimi.dsi.fastutil.booleans.AbstractBooleanListpublic boolean set(int index,
          boolean value)
set in interface it.unimi.dsi.fastutil.booleans.BooleanListset in class it.unimi.dsi.fastutil.booleans.AbstractBooleanListpublic void add(int index,
       boolean value)
add in interface it.unimi.dsi.fastutil.booleans.BooleanListadd in class it.unimi.dsi.fastutil.booleans.AbstractBooleanListpublic boolean removeBoolean(long index)
BitVectorThis method is semantically equivalent to BooleanList.removeBoolean(int),
 but it gives access to long indices.
removeBoolean in interface BitVectorindex - the index of a bit.public boolean set(long index,
          boolean value)
BitVectorThis method is semantically equivalent to BooleanList.set(int,boolean),
 but it gives access to long indices.
public void add(long index,
       boolean value)
BitVectorThis method is semantically equivalent to BooleanList.add(int,boolean),
 but it gives access to long indices.
public void set(long index,
       int value)
BitVectorThis method is a useful synonym for BitVector.set(long, boolean).
public void add(long index,
       int value)
BitVectorThis method is a useful synonym for BitVector.add(long, boolean).
public boolean add(boolean value)
add in interface it.unimi.dsi.fastutil.booleans.BooleanCollectionadd in interface it.unimi.dsi.fastutil.booleans.BooleanListadd in class it.unimi.dsi.fastutil.booleans.AbstractBooleanListpublic void add(int value)
BitVectorThis method is a useful synonym for BooleanList.add(boolean).
public BitVector append(long value, int k)
BitVectorpublic BitVector append(BitVector bv)
BitVectorpublic BitVector copy()
BitVectorpublic BitVector copy(long from, long to)
BitVectorpublic BitVector fast()
LongArrayBitVector containing a copy of this bit vector.fast in interface BitVectorLongArrayBitVector containing a copy of this bit vector.public long count()
BitVectorpublic long firstOne()
BitVectorpublic long lastOne()
BitVectorpublic long firstZero()
BitVectorpublic long lastZero()
BitVectorpublic long nextOne(long index)
BitVectorpublic long previousOne(long index)
BitVectorpreviousOne in interface BitVectorpublic long nextZero(long index)
BitVectorpublic long previousZero(long index)
BitVectorpreviousZero in interface BitVectorpublic long longestCommonPrefixLength(BitVector v)
BitVectorlongestCommonPrefixLength in interface BitVectorv - a bit vector.public BitVector and(BitVector v)
BitVectorpublic BitVector or(BitVector v)
BitVectorpublic BitVector xor(BitVector v)
BitVectorpublic int size()
size in interface Collection<Boolean>size in interface List<Boolean>size in class AbstractCollection<Boolean>public void size(int newSize)
size in interface it.unimi.dsi.fastutil.booleans.BooleanListsize in class it.unimi.dsi.fastutil.booleans.AbstractBooleanListpublic void clear()
clear in interface Collection<Boolean>clear in interface List<Boolean>clear in class AbstractCollection<Boolean>public BitVector replace(BitVector bv)
BitVectorpublic boolean equals(Object o)
public int hashCode()
BitVectorHash codes for bit vectors are defined as follows:
final long length = length(); long fullLength = length - length % Long.SIZE; long h = 0x9e3779b97f4a7c13L ^ length; for( long i = 0; i < fullLength; i += Long.SIZE ) h ^= ( h << 5 ) + getLong( i, i + Long.SIZE ) + ( h >>> 2 ); if ( length != fullLength ) h ^= ( h << 5 ) + getLong( fullLength, length ) + ( h >>> 2 ); (int)( ( h >>> 32 ) ^ h );
The last value is the hash code of the bit vector. This hashing is based on shift-add-xor hashing (M.V. Ramakrishna and Justin Zobel, “Performance in practice of string hashing functions”, Proc. of the Fifth International Conference on Database Systems for Advanced Applications, 1997, pages 215−223).
The returned value is not a high-quality hash such as Jenkins's, but it can be computed very quickly; in any case, 32 bits are too few for a high-quality hash to be used in large-scale applications.
Important: all bit vector implementations are required to return the value defined here.
 The simplest way to obtain this result is to subclass AbstractBitVector.
public long[] bits()
BitVectorbits in interface BitVectorBitVector.length() bits contain the bits of
 this bit vector. The array cannot be modified.public BitVector length(long newLength)
BitVectorIt is expected that this method will try to allocate exactly the necessary space.
If the number of bits in this vector is smaller than 
 or equal to Integer.MAX_VALUE, this
 method is semantically equivalent to BooleanList.size(int).
public it.unimi.dsi.fastutil.longs.LongSortedSet asLongSet()
BitVectorMore formally, this bit vector is infinitely extended to the
 left with zeros (e.g., all bits beyond BitVector.length(long) are
 considered zeroes). The resulting infinite string is interpreted as the
 characteristic function of a set of integers.
 
 
Note that, in particular, the resulting string representation is
 exactly that of a BitSet.
public LongBigList asLongBigList(int width)
BitVectorMore formally, getLong(p) will return
 the nonnegative integer defined by the bits starting at p * width (bit 0, inclusive)
 and ending at (p + 1) * width (bit width − 1, exclusive).
asLongBigList in interface BitVectorpublic AbstractBitVector.SubBitVector subList(int from, int to)
public BitVector subVector(long from, long to)
BitVectorThe object returned by this method is a bit vector representing a view of this bit vector restricted to the given indices. Changes to the subvector will be reflected in the main vector.
public BitVector subVector(long from)
BitVectorsubVector in interface BitVectorfrom - the first index (inclusive).BitVector.subVector(long, long)public int compareTo(List<? extends Boolean> list)
compareTo in interface Comparable<List<? extends Boolean>>compareTo in class it.unimi.dsi.fastutil.booleans.AbstractBooleanListpublic int compareTo(BitVector v)
public String toString()
Note that this string representation shows the bit of index 0 at the leftmost position.
toString in class it.unimi.dsi.fastutil.booleans.AbstractBooleanListCopyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.