@Override public long length(final BitVector v) { return v.length(); }
public PrefixFreeBitVector(final BitVector v) { this.v = v; length = v.length() * 2 + 1; }
@Override public long length(final CharSequence s) { final BitVector[] codeWord = this.codeWord; final Char2IntMap char2symbol = this.char2symbol; final int length = s.length(); int numBits = (int) (prefixFree ? codeWord[0].length() : 0); for(int i = length; i-- != 0;) numBits += codeWord[char2symbol.get(s.charAt(i))].length(); return numBits; }
@Override public BitVector replace(final BitVector bv) { clear(); final long fullBits = bv.length() - bv.length() % Long.SIZE; for(long i = 0; i < fullBits; i += Long.SIZE) append(bv.getLong(i, i + Long.SIZE), Long.SIZE); if (bv.length() % Long.SIZE != 0) append(bv.getLong(fullBits, bv.length()), (int)(bv.length() - fullBits)); return this; }
public SubBitVector( final BitVector l, final long from, final long to ) { BitVectors.ensureFromTo( l.length(), from, to ); this.from = from; this.to = to; bitVector = l; }
@Override public boolean contains(final long index) { if (index < 0) throw new IllegalArgumentException("The provided index (" + index + ") is negative"); if (index < from || index >= to) return false; return index < bitVector.length() && bitVector.getBoolean(index); }
@Override public boolean add(final long index) { if (index < 0) throw new IllegalArgumentException("The provided index (" + index + ") is negative"); if (index < from || index >= to) return false; final long length = bitVector.length(); if (index >= length) bitVector.length(index + 1); final boolean oldValue = bitVector.getBoolean(index); bitVector.set(index); return ! oldValue; }
@Override public boolean hasNext() { if (nextPos == -1 && pos < bitVector.length()) nextPos = bitVector.nextOne(pos); return nextPos != -1; }
public int size() { // This minimisation is necessary for implementations not supporting long indices. final long size = bitVector.subVector( from, Math.min( to, bitVector.length() ) ).count(); if ( size > Integer.MAX_VALUE ) throw new IllegalStateException( "Set is too large to return an integer size" ); return (int)size; }
public int size() { // This minimisation is necessary for implementations not supporting long indices. final long size = bitVector.subVector( from, Math.min( to, bitVector.length() ) ).count(); if ( size > Integer.MAX_VALUE ) throw new IllegalStateException( "Set is too large to return an integer size" ); return (int)size; }
@Override public boolean isProperPrefix(final BitVector v) { return isPrefix(v) && length() < v.length(); }
@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 add( final long index ) { if ( index < 0 ) throw new IllegalArgumentException( "The provided index (" + index + ") is negative" ); if ( index < from || index >= to ) return false; final int size = bitVector.size(); if ( index >= size ) bitVector.length( index + 1 ); final boolean oldValue = bitVector.getBoolean( index ); bitVector.set( index ); return ! oldValue; }
public boolean add( final long index ) { if ( index < 0 ) throw new IllegalArgumentException( "The provided index (" + index + ") is negative" ); if ( index < from || index >= to ) return false; final int size = bitVector.size(); if ( index >= size ) bitVector.length( index + 1 ); final boolean oldValue = bitVector.getBoolean( index ); bitVector.set( index ); return ! oldValue; }
@Override public BitVector or(final BitVector v) { for(long i = Math.min(length(), v.length()); i-- != 0;) if (v.getBoolean(i)) set(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 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 append( final BitVector bv ) { final long length = bv.length(); final long l = length - length % Long.SIZE; int i; for( i = 0; i < l; i += Long.SIZE ) append( bv.getLong( i, i + Long.SIZE ), Long.SIZE ); if ( i < length ) append( bv.getLong( i, length ), (int)( length - i ) ); return this; }
public BitVector append( final BitVector bv ) { final long length = bv.length(); final long l = length - length % Long.SIZE; int i; for( i = 0; i < l; i += Long.SIZE ) append( bv.getLong( i, i + Long.SIZE ), Long.SIZE ); if ( i < length ) append( bv.getLong( i, length ), (int)( length - i ) ); return this; }
@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); }