/** Creates a new empty bit vector. No allocation is actually performed. * @return a new bit vector with no capacity. */ public static LongArrayBitVector getInstance() { return new LongArrayBitVector( 0 ); }
/** Creates a new empty bit vector. No allocation is actually performed. * @return a new bit vector with no capacity. */ public static LongArrayBitVector getInstance() { return new LongArrayBitVector( 0 ); }
/** Creates a new empty bit vector. No allocation is actually performed. * @return a new bit vector with no capacity. */ public static LongArrayBitVector getInstance() { return new LongArrayBitVector(0); }
/** Creates a new empty bit vector of given length. * * @param length the size (in bits) of the new bit vector. */ public static LongArrayBitVector ofLength(final long length) { final LongArrayBitVector bv = new LongArrayBitVector(length); bv.length = length; return bv; }
/** Creates a new empty bit vector of given capacity. The * resulting vector will be able to contain <code>capacity</code> * bits without reallocations of the backing array. * * <P>Note that this constructor creates an <em>empty</em> bit vector. * If you want a cleared bit vector of a specified size, please * use the {@link #ofLength(long)} factory method. * * @param capacity the capacity (in bits) of the new bit vector. * @return a new bit vector of given capacity. */ public static LongArrayBitVector getInstance( final long capacity ) { return new LongArrayBitVector( capacity ); }
/** Creates a new empty bit vector of given capacity. The * resulting vector will be able to contain <code>capacity</code> * bits without reallocations of the backing array. * * <P>Note that this constructor creates an <em>empty</em> bit vector. * If you want a cleared bit vector of a specified size, please * use the {@link #ofLength(long)} factory method. * * @param capacity the capacity (in bits) of the new bit vector. * @return a new bit vector of given capacity. */ public static LongArrayBitVector getInstance(final long capacity) { return new LongArrayBitVector(capacity); }
/** Creates a new empty bit vector of given capacity. The * resulting vector will be able to contain <code>capacity</code> * bits without reallocations of the backing array. * * <P>Note that this constructor creates an <em>empty</em> bit vector. * If you want a cleared bit vector of a specified size, please * use the {@link #ofLength(long)} factory method. * * @param capacity the capacity (in bits) of the new bit vector. * @return a new bit vector of given capacity. */ public static LongArrayBitVector getInstance( final long capacity ) { return new LongArrayBitVector( capacity ); }
@Override public LongArrayBitVector copy() { final LongArrayBitVector copy = new LongArrayBitVector(length); copy.length = length; System.arraycopy(bits, 0, copy.bits, 0, numWords(length)); return copy; }
/** Wraps the given array of longs in a bit vector for the given number of bits. * * <p>Note that all bits in <code>array</code> beyond that of index * <code>size</code> must be unset, or an exception will be thrown. * * @param array an array of longs. * @param size the number of bits of the newly created bit vector. * @return a bit vector of size <code>size</code> using <code>array</code> as backing array. */ public static LongArrayBitVector wrap(final long[] array, final long size) { if (size > (long)array.length << LOG2_BITS_PER_WORD) throw new IllegalArgumentException("The provided array is too short (" + array.length + " elements) for the given size (" + size + ")"); final LongArrayBitVector result = new LongArrayBitVector(0); result.length = size; result.bits = array; final int arrayLength = array.length; final int lastWord = (int)(size / Long.SIZE); if (lastWord < arrayLength && (array[lastWord] & ~ ((1L << size % Long.SIZE) - 1)) != 0) throw new IllegalArgumentException("Garbage beyond size in bit array"); for(int i = lastWord + 1; i < arrayLength; i++) if (array[i] != 0) throw new IllegalArgumentException("Garbage beyond size in bit array"); return result; }
public LongArrayBitVector copy() { LongArrayBitVector copy = new LongArrayBitVector( length ); copy.length = length; System.arraycopy( bits, 0, copy.bits, 0, numWords( length ) ); return copy; }
/** Wraps the given array of longs in a bit vector for the given number of bits. * * <p>Note that all bits in <code>array</code> beyond that of index * <code>size</code> must be unset, or an exception will be thrown. * * @param array an array of longs. * @param size the number of bits of the newly created bit vector. * @return a bit vector of size <code>size</code> using <code>array</code> as backing array. */ public static LongArrayBitVector wrap( final long[] array, final long size ) { if ( size > array.length << LOG2_BITS_PER_WORD ) throw new IllegalArgumentException( "The provided array is too short (" + array.length + " elements) for the given size (" + size + ")" ); final LongArrayBitVector result = new LongArrayBitVector( 0 ); result.length = size; result.bits = array; final int arrayLength = array.length; final int lastWord = (int)( size / Long.SIZE ); if ( lastWord < arrayLength && ( array[ lastWord ] & ~ ( ( 1L << size % Long.SIZE ) - 1 ) ) != 0 ) throw new IllegalArgumentException( "Garbage beyond size in bit array" ); for( int i = lastWord + 1; i < arrayLength; i++ ) if ( array[ i ] != 0 ) throw new IllegalArgumentException( "Garbage beyond size in bit array" ); return result; }
public LongArrayBitVector copy() { LongArrayBitVector copy = new LongArrayBitVector( length ); copy.length = length; System.arraycopy( bits, 0, copy.bits, 0, numWords( length ) ); return copy; }
/** Creates a new empty bit vector of given length. * * @param length the size (in bits) of the new bit vector. */ public static LongArrayBitVector ofLength( final long length ) { return new LongArrayBitVector( length ).length( length ); }
/** Creates a new bit vector with given bits. * * @param bit a list of bits that will be set in the newly created bit vector. */ public static LongArrayBitVector of( final int... bit ) { final LongArrayBitVector bitVector = new LongArrayBitVector( bit.length ); for( int b : bit ) bitVector.add( b ); return bitVector; }
/** Creates a new bit vector with given bits. * * @param bit a list of bits that will be set in the newly created bit vector. */ public static LongArrayBitVector of(final int... bit) { final LongArrayBitVector bitVector = new LongArrayBitVector(bit.length); for(final int b : bit) { if (b != 0 && b != 1) throw new IllegalArgumentException("Illegal bit value: " + b); bitVector.add(b); } return bitVector; }
/** Creates a new empty bit vector of given length. * * @param length the size (in bits) of the new bit vector. */ public static LongArrayBitVector ofLength( final long length ) { return new LongArrayBitVector( length ).length( length ); }
/** Creates a new bit vector with given bits. * * @param bit a list of bits that will be set in the newly created bit vector. */ public static LongArrayBitVector of( final int... bit ) { final LongArrayBitVector bitVector = new LongArrayBitVector( bit.length ); for( int b : bit ) bitVector.add( b ); return bitVector; }
/** Returns a copy of the given bit vector. * * <p>This method uses {@link BitVector#getLong(long, long)} on {@link Long#SIZE} boundaries to copy at high speed. * * @param bv a bit vector. * @return an instance of this class containing a copy of the given vector. */ public static LongArrayBitVector copy(final BitVector bv) { final long length = bv.length(); final LongArrayBitVector copy = new LongArrayBitVector(length); final long fullBits = length - length % Long.SIZE; for(long i = 0; i < fullBits; i += Long.SIZE) copy.bits[(int)(i / Long.SIZE)] = bv.getLong(i, i + Long.SIZE); if (length % Long.SIZE != 0) copy.bits[(int)(fullBits / Long.SIZE)] = bv.getLong(fullBits, length); copy.length = length; return copy; }
/** Returns a copy of the given bit vector. * * <p>This method uses {@link BitVector#getLong(long, long)} on {@link Long#SIZE} boundaries to copy at high speed. * * @param bv a bit vector. * @return an instance of this class containing a copy of the given vector. */ public static LongArrayBitVector copy( final BitVector bv ) { final long length = bv.length(); final LongArrayBitVector copy = new LongArrayBitVector( length ); final long fullBits = length - length % Long.SIZE; for( long i = 0; i < fullBits; i += Long.SIZE ) copy.bits[ (int)( i / Long.SIZE ) ] = bv.getLong( i, i + Long.SIZE ); if ( length % Long.SIZE != 0 ) copy.bits[ (int)( fullBits / Long.SIZE ) ] = bv.getLong( fullBits, length ); copy.length = length; return copy; }
/** Returns a copy of the given bit vector. * * <p>This method uses {@link BitVector#getLong(long, long)} on {@link Long#SIZE} boundaries to copy at high speed. * * @param bv a bit vector. * @return an instance of this class containing a copy of the given vector. */ public static LongArrayBitVector copy( final BitVector bv ) { final long length = bv.length(); final LongArrayBitVector copy = new LongArrayBitVector( length ); final long fullBits = length - length % Long.SIZE; for( long i = 0; i < fullBits; i += Long.SIZE ) copy.bits[ (int)( i / Long.SIZE ) ] = bv.getLong( i, i + Long.SIZE ); if ( length % Long.SIZE != 0 ) copy.bits[ (int)( fullBits / Long.SIZE ) ] = bv.getLong( fullBits, length ); copy.length = length; return copy; }