it.unimi.dsi.bits
Class BitVectors

java.lang.Object
  extended by it.unimi.dsi.bits.BitVectors

public class BitVectors
extends java.lang.Object

A class providing static methods and objects that do useful things with bit vectors.

See Also:
BitVector

Nested Class Summary
static class BitVectors.OfflineBitVectorIterable
           
protected static class BitVectors.OfflineBitVectorIterator
           
 
Field Summary
static BitVector EMPTY_VECTOR
          An immutable, singleton empty bit vector.
static BitVector ONE
          An immutable bit vector of length one containing a one.
static BitVector ZERO
          An immutable bit vector of length one containing a zero.
 
Method Summary
static void ensureFromTo(long bitVectorLength, long from, long to)
           
static
<T extends BitVector>
TransformationStrategy<T>
identity()
          Deprecated. 
static BitVectors.OfflineBitVectorIterable makeOffline(java.util.Iterator<? extends BitVector> iterator)
          Makes an iterable object containing bit vectors offline.
static LongArrayBitVector readFast(java.io.DataInputStream dis)
          Reads quickly a bit vector from a DataInputStream.
static LongArrayBitVector readFast(java.io.DataInputStream dis, LongArrayBitVector bv)
          Reads quickly a bit vector from a DataInputStream.
static void writeFast(BitVector v, java.io.DataOutputStream dos)
          Writes quickly a bit vector to a DataOutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_VECTOR

public static final BitVector EMPTY_VECTOR
An immutable, singleton empty bit vector.


ZERO

public static final BitVector ZERO
An immutable bit vector of length one containing a zero.


ONE

public static final BitVector ONE
An immutable bit vector of length one containing a one.

Method Detail

identity

@Deprecated
public static <T extends BitVector> TransformationStrategy<T> identity()
Deprecated. 


ensureFromTo

public static void ensureFromTo(long bitVectorLength,
                                long from,
                                long to)

writeFast

public static void writeFast(BitVector v,
                             java.io.DataOutputStream dos)
                      throws java.io.IOException
Writes quickly a bit vector to a DataOutputStream.

This method writes a bit vector in a simple format: first, a long representing the length. Then, as many longs as necessary to write the bits in the bit vectors (i.e., LongArrayBitVector.numWords(long) of the bit vector length), obtained via BitVector.getLong(long, long).

The main purpose of this function is to support makeOffline(Iterator) and similar methods.

Parameters:
v - a bit vector.
dos - a data output stream.
Throws:
java.io.IOException

readFast

public static LongArrayBitVector readFast(java.io.DataInputStream dis)
                                   throws java.io.IOException
Reads quickly a bit vector from a DataInputStream.

This method is the dual of writeFast(BitVector, DataOutputStream). If you need to avoid creating a bit vector at each call, please have a look at readFast(DataInputStream, LongArrayBitVector).

Parameters:
dis - a data input stream.
Returns:
the next bit vector in the stream, as saved by writeFast(BitVector, DataOutputStream).
Throws:
java.io.IOException
See Also:
writeFast(BitVector, DataOutputStream), readFast(DataInputStream, LongArrayBitVector)

readFast

public static LongArrayBitVector readFast(java.io.DataInputStream dis,
                                          LongArrayBitVector bv)
                                   throws java.io.IOException
Reads quickly a bit vector from a DataInputStream.

This method is similar in purpose to readFast(DataInputStream), but it allows reuse of the bit vector.

Parameters:
dis - a data input stream.
bv - a long-array bit vector.
Returns:
bv, filled with the next bit vector in the stream, as saved by writeFast(BitVector, DataOutputStream).
Throws:
java.io.IOException
See Also:
writeFast(BitVector, DataOutputStream), readFast(DataInputStream)

makeOffline

public static BitVectors.OfflineBitVectorIterable makeOffline(java.util.Iterator<? extends BitVector> iterator)
                                                       throws java.io.IOException
Makes an iterable object containing bit vectors offline.

This method dumps an iterator object on disk and exposes the dumped file as a new iterable. It is useful whenever the iterable must be available, but it is not possible to keep it in core memory, or when the iterator must be scanned multiple times.

Warning: the BitVectors.OfflineBitVectorIterable returned by this method is SafelyCloseable, and should always be closed to delete the temporary file containing the iterable. The BitVectors.OfflineBitVectorIterator returned by the returned iterable is SafelyCloseable, and should always be closed to avoid exceeding the maximum number of open files; all exhausted iterators, however, will be closed automagically.

Parameters:
iterator - an iterator containing bit vectors.
Returns:
an offline iterable, stored on disk.
Throws:
java.io.IOException