/** {@inheritDoc} * <p>This implementation just returns {@link #length()}. */ @Override public long size64() { return length(); }
public int size() { final long length = length(); if ( length > Integer.MAX_VALUE ) throw new IllegalStateException( "The number of bits of this bit vector (" + length + ") exceeds Integer.MAX_INT" ); return (int)length; }
public long[] bits() { final long[] bits = new long[ (int)( ( length() + LongArrayBitVector.BITS_PER_WORD - 1 ) >> LongArrayBitVector.LOG2_BITS_PER_WORD ) ]; final long length = length(); for( int i = 0; i < length; i++ ) if ( getBoolean( i ) ) bits[ i >> LongArrayBitVector.LOG2_BITS_PER_WORD ] |= 1L << ( i & LongArrayBitVector.WORD_MASK ); return bits; }
public long nextOne( final long index ) { final long length = length(); for( long i = index; i < length; i++ ) if ( getBoolean( i ) ) return i; return -1; }
@Override public long count() { long c = 0; for(long i = length(); i-- != 0;) c += getInt(i); return c; }
public long count() { long c = 0; for( long i = length(); i-- != 0; ) c += getInt( i ); return c; }
@Override public long nextZero(final long index) { final long length = length(); for(long i = index; i < length; i++) if (! getBoolean(i)) return i; return -1; }
public long nextZero( final long index ) { final long length = length(); for( long i = index; i < length; i++ ) if ( ! getBoolean( i ) ) return i; return -1; }
@Override public long nextOne(final long index) { final long length = length(); for(long i = index; i < length; i++) if (getBoolean(i)) return i; return -1; }
@Override public BitVector length(long newLength) { final long length = length(); if (length < newLength) for(long i = newLength - length; i-- != 0;) add(false); else for(long i = length; i-- != newLength;) removeBoolean(i); return this; }
public BitVector length( long newLength ) { final long length = length(); if ( length < newLength ) for( long i = newLength - length; i-- != 0; ) add( false ); else for( long i = length; i-- != newLength; ) removeBoolean( i ); return this; }
public int hashCode() { 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 ); return (int)( ( h >>> 32 ) ^ h ); }
public int hashCode() { 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 ); return (int)( ( h >>> 32 ) ^ h ); }
@Override public BitVector xor(final BitVector v) { for(long i = Math.min(length(), v.length()); i-- != 0;) if (v.getBoolean(i)) flip(i); return this; }
@Override public BitVector and(final BitVector v) { for(long i = Math.min(length(), v.length()); i-- != 0;) if (! v.getBoolean(i)) clear(i); return this; }
public boolean equals( final Object o ) { if ( ! ( o instanceof BitVector ) ) return false; BitVector v = (BitVector)o; long length = length(); if ( length != v.length() ) return false; while( length-- != 0 ) if ( getBoolean( length ) != v.getBoolean( length ) ) return false; return true; }
public BitVector copy( final long from, final long to ) { BitVectors.ensureFromTo( length(), from, to ); final long length = to - from; final long l = length - length % Long.SIZE; final long bits[] = new long[ (int)( ( length + Long.SIZE - 1 ) / Long.SIZE ) ]; int i; for( i = 0; i < l; i += Long.SIZE ) bits[ i / Long.SIZE ] = getLong( from + i, from + i + Long.SIZE ); if ( i < length ) bits[ i / Long.SIZE ] = getLong( from + i, to ); return LongArrayBitVector.wrap( bits, length ); }
@Override public boolean equals(final Object o) { if (! (o instanceof BitVector)) return false; final BitVector v = (BitVector)o; final long length = length(); if (length != v.length()) return false; final long fullLength = length - length % Long.SIZE; for(long i = 0; i < fullLength; i += Long.SIZE) if (getLong(i, i + Long.SIZE) != v.getLong(i, i + Long.SIZE)) return false; return getLong(fullLength, length) == v.getLong(fullLength, length); }