@Override public void intersectWith(IntSet set) { if (set instanceof MutableSharedBitVectorIntSet) { intersectWithInternal((MutableSharedBitVectorIntSet) set); } else if (set instanceof BitVectorIntSet) { intersectWithInternal(new MutableSharedBitVectorIntSet((BitVectorIntSet) set)); } else { // this is really slow. optimize as needed. for (IntIterator it = intIterator(); it.hasNext();) { int x = it.next(); if (!set.contains(x)) { remove(x); } } } if (DEBUG) { if (privatePart != null && sharedPart != null) assert privatePart.intersection(sharedPart).isEmpty(); } }
/** * Set a particular bit * @param b the bit to set */ public void set(int b) { if (b < 0) { throw new IllegalArgumentException("illegal b: " + b); } if (V == null) { V = new MutableSharedBitVectorIntSet(); } V.add(b); }
@Override public IntSet union(IntSet that) { MutableSharedBitVectorIntSet temp = new MutableSharedBitVectorIntSet(); temp.addAll(this); temp.addAll(that); return temp; }
@Override public boolean addAllInIntersection(IntSet other, IntSet filter) { if (other instanceof MutableSharedBitVectorIntSet) { return addAllInIntersectionInternal((MutableSharedBitVectorIntSet) other, filter); } return addAllInIntersectionGeneral(other, filter); }
boolean result = addAll((MutableSharedBitVectorIntSet) set); if (PARANOID) { checkIntegrity(); boolean result = addAllInternal((SparseIntSet) set); if (PARANOID) { checkIntegrity(); boolean result = addAllInternal((BitVectorIntSet) set); if (PARANOID) { checkIntegrity(); } else if (set instanceof DebuggingMutableIntSet) { SparseIntSet temp = new SparseIntSet(set); boolean result = addAllInternal(temp); if (PARANOID) { checkIntegrity(); for (IntIterator it = set.intIterator(); it.hasNext();) { int x = it.next(); if (!contains(x)) { result = true; add(x);
private boolean addAll(MutableSharedBitVectorIntSet set) { if (set.isEmpty()) { return false; if (isEmpty()) { if (set.privatePart != null) { privatePart = MutableSparseIntSet.make(set.privatePart); return addAllInternal(set.privatePart); } else { if (sameSharedPart(this, set)) { if (set.privatePart == null) { return false; } else { return addAllInternal(set.privatePart); int oldSize = size(); if (privatePart != null) { privatePart.removeAll(set.sharedPart); return size() > oldSize; } else { BitVectorIntSet temp = makeDenseCopy(); boolean b = temp.addAll(set.sharedPart); if (b) { this.sharedPart = set.sharedPart; } else { copyValue(temp);
/** */ private boolean addAllInIntersectionInternal(MutableSharedBitVectorIntSet other, IntSet filter) { if (other.sharedPart == null) { if (other.privatePart == null) { return false; } else { // other.sharedPart == null, other.privatePart != null return addAllInIntersectionInternal(other.privatePart, filter); } } else { // other.sharedPart != null if (sharedPart == other.sharedPart) { // no need to add in other.sharedPart if (other.privatePart == null) { return false; } else { return addAllInIntersectionInternal(other.privatePart, filter); } } else { MutableSharedBitVectorIntSet o = new MutableSharedBitVectorIntSet(other); o.intersectWith(filter); return addAll(o); } } }
private boolean sameValue(SparseIntSet that) { if (size() != that.size()) { return false; } if (sharedPart == null) { if (privatePart == null) /* both parts empty, and that has same (i.e. 0) size */ return true; else return privatePart.sameValue(that); } else { /* sharedPart != null */ return makeSparseCopy().sameValue(that); } }
@Override public IntSet intersection(IntSet that) { if (that == null) { throw new IllegalArgumentException("null that"); } if (that instanceof MutableSharedBitVectorIntSet) { return intersection((MutableSharedBitVectorIntSet) that); } else if (that instanceof BitVectorIntSet) { MutableSharedBitVectorIntSet m = new MutableSharedBitVectorIntSet((BitVectorIntSet) that); return intersection(m); } else if (that instanceof SparseIntSet) { BitVectorIntSet bv = new BitVectorIntSet(that); return intersection(bv); } else { // really slow. optimize as needed. BitVectorIntSet result = new BitVectorIntSet(); for (IntIterator it = intIterator(); it.hasNext();) { int x = it.next(); if (that.contains(x)) { result.add(x); } } return result; } }
privatePart = null; checkOverflow(); return size() > 0; } else { checkOverflow(); return result; sharedPart = null; boolean result = privatePart.addAllInIntersection(other, filter); checkOverflow(); return result; } else { return addAll(temp);
@Override public MutableSharedBitVectorIntSet make() { return new MutableSharedBitVectorIntSet(); }
@Override public void copySet(IntSet set) { if (set instanceof MutableSharedBitVectorIntSet) { MutableSharedBitVectorIntSet other = (MutableSharedBitVectorIntSet) set; if (other.privatePart != null) { this.privatePart = MutableSparseIntSet.make(other.privatePart); } else { this.privatePart = null; } this.sharedPart = other.sharedPart; } else { // really slow. optimize as needed. clear(); addAll(set); } if (PARANOID) { checkIntegrity(); } }
public IntSet intersection(MutableSharedBitVectorIntSet that) { MutableSparseIntSet t = makeSparseCopy(); t.intersectWith(that); MutableSharedBitVectorIntSet result = new MutableSharedBitVectorIntSet(t); if (PARANOID) { checkIntegrity(); } return result; }
@Override public boolean isSubset(IntSet that) { if (that == null) { throw new IllegalArgumentException("null that"); } if (that instanceof MutableSharedBitVectorIntSet) { return isSubset((MutableSharedBitVectorIntSet) that); } else { // really slow. optimize as needed. for (IntIterator it = intIterator(); it.hasNext();) { if (!that.contains(it.next())) { return false; } } return true; } }
private boolean sameValue(BitVectorIntSet that) { if (size() != that.size()) { return false; } if (sharedPart == null) { if (privatePart == null) /* both parts empty, and that has same (i.e. 0) size */ return true; else // shared part is null and size is same, so number of bits is low return that.makeSparseCopy().sameValue(privatePart); } else { if (privatePart == null) return sharedPart.sameValue(that); else /* sharedPart != null */ return makeDenseCopy().sameValue(that); } }
@Override public void copyState(BitVectorVariable other) { if (other == null) { throw new IllegalArgumentException("null other"); } if (V == null) { if (other.V == null) { return; } else { V = new MutableSharedBitVectorIntSet(other.V); return; } } if (other.V != null) { V.copySet(other.V); } else { V = null; } }
/** * Add all the bits from other to this bit vector */ public void addAll(BitVectorVariable other) { if (other == null) { throw new IllegalArgumentException("null other"); } if (V == null) { copyState(other); } else { if (other.V != null) { V.addAll(other.V); } } }
public void clear(int i) { if (V != null) { V.remove(i); } }
public int populationCount() { if (V == null) { return 0; } else { return V.size(); } }
/** * Is a particular bit set? * @param b the bit to check */ public boolean get(int b) { if (V == null) { return false; } else { return V.contains(b); } }