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; }
/** Creates a node representing a word. * * <p>Note that the long array contained in <code>path</code> will be stored inside the node. * * @param path the path compacted in this node, or {@code null} for the empty path. * @param word the index of the word represented by this node. */ public Node(final BitVector path, final int word) { if (path == null) { this.path = null; this.pathLength = 0; } else { this.path = path.bits(); this.pathLength = (int) path.length(); } this.word = word; }
public void add( final long index, final boolean value ) { bitVector.add( from + index, value ); to++; } public void add( final long index, final int value ) { add( index, value != 0 ); to++; }
@Override public LongBigList subList(long from, long to) { return bitVector.subVector(from * width, to * width).asLongBigList(width); } }
public boolean remove( final long index ) { final int size = bitVector.size(); if ( index >= size ) return false; final boolean oldValue = bitVector.getBoolean( index ); bitVector.clear( index ); return oldValue; }
final long length = getNodeStringLength(v, state); if (DDDEBUG) System.err.println("getNodeStringLength(v)=" + length); if (length >= v.length()) return -1; final BitVector key = v.subVector(0, length).copy(); final boolean bit = v.getBoolean(length); if (bit) key.add(true); else key.length(key.lastOne() + 1); final long pos = ranker.getLong(key); if (DDDEBUG) System.err.println(key.length() + " " + pos + " " + leaves.bitVector()); return leaves.rank(pos); if (DDDEBUG) System.err.println("RIGHT: " + bit); if (bit) { final long lastZero = key.lastZero(); key.length(lastZero + 1).set(lastZero); final long pos = ranker.getLong(key); key.add(true); final long pos = ranker.getLong(key); return leaves.rank(pos);
@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; }
@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); }
/** Populates the codeword vector by scanning recursively * the decoding tree. * * @param node a subtree of the decoding tree. * @param prefix the path leading to <code>n</code>. */ private void buildCodes( final BitVector[] codeWord, final TreeDecoder.Node node, final BitVector prefix ) { if ( node instanceof TreeDecoder.LeafNode ) { codeWord[ ((TreeDecoder.LeafNode)node).symbol ] = prefix; return; } BitVector bitVector = prefix.copy(); bitVector.length( bitVector.length() + 1 ); buildCodes( codeWord, node.left, bitVector ); bitVector = prefix.copy(); bitVector.length( bitVector.length() + 1 ); bitVector.set( bitVector.size() - 1 ); buildCodes( codeWord, node.right, bitVector ); }
@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; }
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 boolean set( final long index, final boolean value ) { return bitVector.set( from + index, value ); } public void set( final long index, final int value ) { set( index, value != 0 ); }
/** Populates the codeword vector by scanning recursively * the decoding tree. * * @param node a subtree of the decoding tree. * @param prefix the path leading to <code>n</code>. */ private void buildCodes(final BitVector[] codeWord, final TreeDecoder.Node node, final BitVector prefix) { if (node instanceof TreeDecoder.LeafNode) { codeWord[((TreeDecoder.LeafNode)node).symbol] = prefix; return; } BitVector bitVector = prefix.copy(); bitVector.length(bitVector.length() + 1); buildCodes(codeWord, node.left, bitVector); bitVector = prefix.copy(); bitVector.length(bitVector.length() + 1); bitVector.set(bitVector.length() - 1); buildCodes(codeWord, node.right, bitVector); }
if (v.getBoolean((long) k)) { final long nextZero = v.nextZero((long) k); if (nextZero != -1L) { k = (int) nextZero; } else { final long priorZero = v.previousZero((long) k); if (priorZero != -1L) { k = (int) priorZero; assert !v.getBoolean(k); v.add(k, true); assert v.getBoolean(k);
private void readObject(final ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); bits = bitVector.bits(); }
rankers.add(LongArrayBitVector.copy(bv.subVector(0, bv.lastOne() + 1))); rankers.add(LongArrayBitVector.copy(bv).append(1, 1)); final LongArrayBitVector plus1 = LongArrayBitVector.copy(bv); int mistakes = 0; while(iterator.hasNext()) { final BitVector curr = iterator.next().fast(); if (DEBUG) System.err.println("Checking element number " + c + ((c + 1) % (1L << log2BucketSize) == 0 ? " (bucket)" : "")); if (getNodeStringLength(curr) != intermediateTrie.externalParentRepresentations.getInt(c)){ final long h = Hashes.spooky4(curr, seed); if (mistakeSignatures.contains((int)h)) { positives.add(curr.copy()); results.add(intermediateTrie.externalParentRepresentations.getInt(c)); LOGGER.debug("Actual ranker bits per element: " + (double)ranker.numBits() / size); LOGGER.debug("Forecast leaves bits per element: " + (3.0 / bucketSize)); LOGGER.debug("Actual leaves bits per element: " + (double)leaves.bitVector().length() / size); LOGGER.debug("Forecast mistake bits per element: " + (log2(bucketSize) / bucketSize + 2 * GOV3Function.C / bucketSize)); LOGGER.debug("Actual mistake bits per element: " + (double)numBitsForMistakes() / size);
/** Creates a new select structure using a bit vector. * * <p>The resulting structure keeps no reference to the original bit vector. * * @param bitVector the input bit vector. */ public SparseSelect(final BitVector bitVector) { this(bitVector.length(), bitVector.count(), bitVector.asLongSet().iterator()); }
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.size() && bitVector.getBoolean( index ); }
if (v > upperBound) throw new IllegalArgumentException("Too large value: " + v + " > " + upperBound); if (l != 0) lowerBitsList.set(i, v & lowerBitsMask); upperBitsVector.set((v >>> l) + i); upperBits = upperBitsVector.bits(); simpleSelectZero = new SimpleSelectZero(upperBitsVector); currentIndex = -1;