@Override public SemiSparseMutableIntSet parse(String string) throws NumberFormatException { int[] data = SparseIntSet.parseIntArray(string); SemiSparseMutableIntSet result = new SemiSparseMutableIntSet(); for (int element : data) result.add(element); return result; }
@Override public IntSet union(IntSet that) { SemiSparseMutableIntSet temp = new SemiSparseMutableIntSet(); temp.addAll(this); temp.addAll(that); return temp; }
/** * 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; }
@Override public SemiSparseMutableIntSet makeCopy(IntSet x) { SemiSparseMutableIntSet y = new SemiSparseMutableIntSet(); y.copySet(x); return y; }
int oldSize = size(); densePart = new OffsetBitVector(that.densePart); if (inDenseRange(bit)) { densePart.set(bit); sparsePart.addAll(that.sparsePart); change = size() != oldSize; fixAfterSparseInsert(); int oldSize = size(); if (inDenseRange(bit)) { densePart.set(bit); change = size() != oldSize; change |= add(bs.next()); change |= add(bs.next()); assert assertDisjoint() : this.toString();
@Test public void testCase1() { final SemiSparseMutableIntSet ssmIntSet = new SemiSparseMutableIntSet(); ssmIntSet.add(1); final SemiSparseMutableIntSet ssmIntSet2 = SemiSparseMutableIntSet.diff(ssmIntSet, ssmIntSet); ssmIntSet2.max(); }
/** * This implementation must not despoil the original value of "this" * * @return a new IntSet which is the intersection of this and that */ @Override public IntSet intersection(IntSet that) { if (that == null) { throw new IllegalArgumentException("null that"); } SemiSparseMutableIntSet newThis = new SemiSparseMutableIntSet(); for (IntIterator bits = intIterator(); bits.hasNext();) { int bit = bits.next(); if (that.contains(bit)) { newThis.add(bit); } } return newThis; }
@Override public SemiSparseMutableIntSet make() { return new SemiSparseMutableIntSet(); }
/** * @throws IllegalArgumentException if other is null */ @Override public boolean addAllInIntersection(IntSet other, IntSet filter) { if (other == null) { throw new IllegalArgumentException("other is null"); } if (filter == null) { throw new IllegalArgumentException("null filter"); } boolean change = false; for (IntIterator bits = other.intIterator(); bits.hasNext();) { int bit = bits.next(); if (filter.contains(bit)) { change |= add(bit); } } return change; }
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(); assert assertDisjoint() : this.toString() + ", maxOffset=" + maxOffset + ", maxMax=" + maxMax + ", maxCount=" + maxCount; assert assertDisjoint() : this.toString() + ", densePart.length()=" + densePart.length() + ", newOffset=" + newOffset + ", newLength=" + newLength + ", newCount=" + newCount + ", moveCount=" + moveCount;
/** * Compute the asymmetric difference of two sets, a \ b. */ public static IntSet diff(IntSet A, IntSet B, MutableIntSetFactory<?> factory) { if (factory == null) { throw new IllegalArgumentException("null factory"); } if (A == null) { throw new IllegalArgumentException("null A"); } if (B == null) { throw new IllegalArgumentException("null B"); } if (A instanceof SparseIntSet && B instanceof SparseIntSet) { return SparseIntSet.diff((SparseIntSet) A, (SparseIntSet) B); } else if (A instanceof SemiSparseMutableIntSet && B instanceof SemiSparseMutableIntSet) { IntSet d = SemiSparseMutableIntSet.diff((SemiSparseMutableIntSet) A, (SemiSparseMutableIntSet) B); return d; } else { return defaultSlowDiff(A, B, factory); } }
/** * @return true iff this set contains integer i */ @Override public boolean contains(int i) { if (densePart != null && inDenseRange(i)) { return densePart.contains(i); } else { return sparsePart.contains(i); } }
public SemiSparseMutableIntSet(SemiSparseMutableIntSet set) throws IllegalArgumentException { if (set == null) { throw new IllegalArgumentException("set == null"); } copySet(set); }
System.err.println("call SemiSparseMutableIntSet.removeAll"); return ((SemiSparseMutableIntSet) A).removeAll((SemiSparseMutableIntSet) B); } else { for (IntIterator it = B.intIterator(); it.hasNext();) {
int oldSize = size(); densePart = new OffsetBitVector(that.densePart); if (inDenseRange(bit)) { densePart.set(bit); sparsePart.addAll(that.sparsePart); change = size() != oldSize; fixAfterSparseInsert(); int oldSize = size(); if (inDenseRange(bit)) { densePart.set(bit); change = size() != oldSize; change |= add(bs.next()); change |= add(bs.next()); assert assertDisjoint() : this.toString();
/** * This implementation must not despoil the original value of "this" * * @return a new IntSet which is the intersection of this and that */ @Override public IntSet intersection(IntSet that) { if (that == null) { throw new IllegalArgumentException("null that"); } SemiSparseMutableIntSet newThis = new SemiSparseMutableIntSet(); for (IntIterator bits = intIterator(); bits.hasNext();) { int bit = bits.next(); if (that.contains(bit)) { newThis.add(bit); } } return newThis; }
@Override public SemiSparseMutableIntSet make() { return new SemiSparseMutableIntSet(); }
@Override public SemiSparseMutableIntSet makeCopy(IntSet x) { SemiSparseMutableIntSet y = new SemiSparseMutableIntSet(); y.copySet(x); return y; }
/** * @throws IllegalArgumentException if other is null */ @Override public boolean addAllInIntersection(IntSet other, IntSet filter) { if (other == null) { throw new IllegalArgumentException("other is null"); } if (filter == null) { throw new IllegalArgumentException("null filter"); } boolean change = false; for (IntIterator bits = other.intIterator(); bits.hasNext();) { int bit = bits.next(); if (filter.contains(bit)) { change |= add(bit); } } return change; }
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(); assert assertDisjoint() : this.toString() + ", maxOffset=" + maxOffset + ", maxMax=" + maxMax + ", maxCount=" + maxCount; assert assertDisjoint() : this.toString() + ", densePart.length()=" + densePart.length() + ", newOffset=" + newOffset + ", newLength=" + newLength + ", newCount=" + newCount + ", moveCount=" + moveCount;