/** * Return a new bit string as the AND of two others. */ public static OffsetBitVector andNot(OffsetBitVector b1, OffsetBitVector b2) { OffsetBitVector b = new OffsetBitVector(b1); b.andNot(b2); return b; } }
/** * Return a new bit string as the AND of two others. * * @throws IllegalArgumentException if b2 == null */ public static OffsetBitVector and(OffsetBitVector b1, OffsetBitVector b2) throws IllegalArgumentException { if (b2 == null) { throw new IllegalArgumentException("b2 == null"); } OffsetBitVector b = new OffsetBitVector(b1); b.and(b2); return b; }
/** * Compares this object against the specified object. * * @param obj the object to compare with * @return true if the objects are the same; false otherwise. */ @Override public boolean equals(Object obj) { if ((obj != null) && (obj instanceof OffsetBitVector)) { if (this == obj) { // should help alias analysis return true; } OffsetBitVector set = (OffsetBitVector) obj; return sameBits(set); } return false; }
/** * Return the NOT of a bit string */ public static OffsetBitVector not(OffsetBitVector s) { OffsetBitVector b = new OffsetBitVector(s); b.not(); return b; }
private void fixAfterSparseInsert() { if (sparsePart.size() % FIX_SPARSE_MOD == FIX_SPARSE_MOD - 1 && (densePart == null || (densePart != null && sparsePart.size() > FIX_SPARSE_RATIO * densePart.getSize()))) { assert assertDisjoint() : this.toString(); densePart = new OffsetBitVector(maxOffset, maxMax - maxOffset); sparseBits = sparsePart.intIterator(); int bit; densePart.set(bit); for (int i = 1; i < maxCount; i++) { densePart.set(sparseBits.next()); if (thisBit < densePart.getOffset()) { newOffset = thisBit; int bits = 32; while (sparseBits.hasNext()) { int nextBit = sparseBits.next(); if (nextBit >= densePart.getOffset() || !sparseBits.hasNext()) { if (nextBit < densePart.getOffset() && !sparseBits.hasNext()) { count++; if (densePart.getOffset() - newOffset < (32 * count)) { moveCount += count; } else { while (thisBit < densePart.length() && sparseBits.hasNext()) { thisBit = sparseBits.next();
@Test public void testSpecificBugsInOffsetBitVectors() { OffsetBitVector v1 = makeBigTestOffsetVector(); System.err.println(v1); OffsetBitVector v2 = new OffsetBitVector(50000128, 512); v2.set(50000137); v2.set(50000204); v2.set(50000278); v2.set(50000315); v2.set(50000362); v2.set(50000450); v2.set(50000455); v2.set(50000471); System.err.println(v2); v1.andNot(v2); System.err.println(v1); Assert.assertTrue(v1.intersectionEmpty(v2)); v1 = makeBigTestOffsetVector(); v1.and(v2); System.err.println(v1); Assert.assertTrue(v1.sameBits(v2)); Assert.assertTrue(v1.isSubset(v2)); Assert.assertTrue(v2.isSubset(v1)); }
for (IntIterator bits = A.sparsePart.intIterator(); bits.hasNext();) { int bit = bits.next(); if (B.densePart.get(bit)) { C.remove(bit); OffsetBitVector newDensePart = new OffsetBitVector(A.densePart); for (IntIterator bits = B.sparsePart.intIterator(); bits.hasNext();) { newDensePart.clear(bits.next()); OffsetBitVector newDensePart = new OffsetBitVector(A.densePart); newDensePart.andNot(B.densePart); for (IntIterator bits = B.sparsePart.intIterator(); bits.hasNext();) { newDensePart.clear(bits.next()); for (IntIterator bits = A.sparsePart.intIterator(); bits.hasNext();) { int bit = bits.next(); if (B.densePart.get(bit)) { C.remove(bit);
/** * Logically XORs this bit set with the specified set of bits. * * @param set the bit set to be XORed with * @throws IllegalArgumentException if set == null */ @Override public final void xor(OffsetBitVector set) throws IllegalArgumentException { if (set == null) { throw new IllegalArgumentException("set == null"); } if (this == set) { clearAll(); return; } int newOffset = Math.min(offset, set.offset); int newCapacity = Math.max(length(), set.length()) - newOffset; ensureCapacity(newOffset, newCapacity); int wordDiff = wordDiff(newOffset, set.offset); for (int i = 0; i < set.bits.length; i++) { bits[i - wordDiff] ^= set.bits[i]; } }
densePart = new OffsetBitVector(that.densePart); densePart.set(bit); int oldSize = size(); densePart.or(that.densePart); int bit = bits.next(); if (inDenseRange(bit)) { densePart.set(bit);
for (IntIterator bits = sparsePart.intIterator(); bits.hasNext();) { int bit = bits.next(); if (B.densePart.get(bit)) { C.remove(bit); if (B.densePart == null) { for (IntIterator bits = B.sparsePart.intIterator(); bits.hasNext();) { densePart.clear(bits.next()); densePart.andNot(B.densePart); for (IntIterator bits = B.sparsePart.intIterator(); bits.hasNext();) { densePart.clear(bits.next()); for (IntIterator bits = sparsePart.intIterator(); bits.hasNext();) { int bit = bits.next(); if (B.densePart.get(bit)) { C.remove(bit);
@Test public void testOffsetBitVectors35_25_20_10() { testBitVectors(new OffsetBitVector(35, 20), new OffsetBitVector(25, 10)); }
/** * Remove an integer from this set. * * @param i integer to remove * @return true iff the value of this changes. */ @Override public boolean remove(int i) { if (densePart != null && densePart.get(i)) { densePart.clear(i); if (densePart.nextSetBit(0) == -1) { densePart = null; } return true; } else if (sparsePart.contains(i)) { sparsePart.remove(i); return true; } else { return false; } }
/** * Logically ORs this bit set with the specified set of bits. * * @param set the bit set to be ORed with * @throws IllegalArgumentException if set == null */ @Override public final void or(OffsetBitVector set) throws IllegalArgumentException { if (set == null) { throw new IllegalArgumentException("set == null"); } if (this == set) { // should help alias analysis return; } int newOffset = Math.min(offset, set.offset); int newCapacity = Math.max(length(), set.length()) - newOffset; ensureCapacity(newOffset, newCapacity); int wordDiff = wordDiff(newOffset, set.offset); for (int i = 0; i < set.bits.length; i++) { bits[i - wordDiff] |= set.bits[i]; } }
/** * Return a new FixedSizeBitVector as the OR of two others * * @throws IllegalArgumentException if b2 == null */ public static OffsetBitVector or(OffsetBitVector b1, OffsetBitVector b2) throws IllegalArgumentException { if (b2 == null) { throw new IllegalArgumentException("b2 == null"); } OffsetBitVector b = new OffsetBitVector(b1); b.or(b2); return b; }
/** * Add an integer value to this set. * * @param i integer to add * @return true iff the value of this changes. */ @Override public boolean add(int i) { if (densePart != null && inDenseRange(i)) { if (!densePart.get(i)) { densePart.set(i); assert assertDisjoint() : this.toString(); return true; } } else if (!sparsePart.contains(i)) { sparsePart.add(i); assert assertDisjoint() : this.toString(); fixAfterSparseInsert(); return true; } return false; }
private static OffsetBitVector makeBigTestOffsetVector() { OffsetBitVector v1 = new OffsetBitVector(50000096, 1024); v1.set(50000101); v1.set(50000103); v1.set(50000112); v1.set(50000114); v1.set(50000116); v1.set(50000126); v1.set(50000128); v1.set(50000129); v1.set(50000135); v1.set(50000137); v1.set(50000143); v1.set(50000148); v1.set(50000151); v1.set(50000158); v1.set(50000163); v1.set(50000167); v1.set(50000170); v1.set(50000173); v1.set(50000180); v1.set(50000182); v1.set(50000185); v1.set(50000187); v1.set(50000190); v1.set(50000194); v1.set(50000199); v1.set(50000201); v1.set(50000204); v1.set(50000206);
/** * Interset this with another set. */ @Override public void intersectWith(IntSet set) { sparsePart.intersectWith(set); if (densePart != null) { for (int b = densePart.nextSetBit(0); b != -1; b = densePart.nextSetBit(b + 1)) { if (!set.contains(b)) { densePart.clear(b); } } } }
@Override public void andNot(OffsetBitVector set) throws IllegalArgumentException { if (set == null) { throw new IllegalArgumentException("set == null"); } if (this == set) { clearAll(); return; } int wordDiff = wordDiff(offset, set.offset); int maxWord = Math.min(bits.length, set.bits.length - wordDiff); int i = Math.max(0, -wordDiff); for (; i < maxWord; i++) { bits[i] &= ~set.bits[i + wordDiff]; } }