@Test(groups = "1s", timeOut = 60000) public void testRemove() { IntIterableRangeSet is = new IntIterableRangeSet(); is.ELEMENTS = new int[]{1, 3, 5, 5, 7, 10}; is.SIZE = 6; is.CARDINALITY = 8; Assert.assertTrue(is.remove(1)); Assert.assertFalse(is.remove(1)); Assert.assertTrue(is.remove(3)); Assert.assertFalse(is.remove(3)); Assert.assertTrue(is.remove(2)); Assert.assertFalse(is.remove(2)); Assert.assertTrue(is.remove(5)); Assert.assertFalse(is.remove(5)); Assert.assertTrue(is.remove(8)); Assert.assertFalse(is.remove(8)); Assert.assertTrue(is.remove(9)); Assert.assertFalse(is.remove(9)); Assert.assertTrue(is.remove(7)); Assert.assertFalse(is.remove(7)); Assert.assertTrue(is.remove(10)); Assert.assertFalse(is.remove(10)); Assert.assertEquals(is.SIZE, 0); Assert.assertEquals(is.CARDINALITY, 0); Assert.assertEquals(Arrays.copyOf(is.ELEMENTS, is.SIZE), new int[]{}); }
@Override public boolean remove(int e) { if (lock) { throw new IllegalStateException("This set is immutable"); } boolean modified = false; int p = rangeOf(e); if (p >= 0) { int i = (p - 1) << 1; int c = ELEMENTS[i] == e ? 1 : 0; c += ELEMENTS[i + 1] == e ? 2 : 0; switch (c) { case 0: grow(SIZE + 2); System.arraycopy(ELEMENTS, i + 1, ELEMENTS, i + 3, SIZE - i - 1); ELEMENTS[i + 1] = e - 1; ELEMENTS[i + 2] = e + 1; SIZE += 2; break; case 1: ELEMENTS[i]++; break; case 2: ELEMENTS[i + 1]--; break; case 3: System.arraycopy(ELEMENTS, i + 2, ELEMENTS, i, SIZE - i - 2); SIZE -= 2; break; default: throw new SolverException("Unexpected mask " + c); } modified = true; CARDINALITY--; } return modified; }
IntIterableRangeSet implements IntIterableSet { @Override public boolean remove(int e) { if (lock) { throw new IllegalStateException("This set is immutable"); } boolean modified = false; int p = rangeOf(e); if (p >= 0) { int i = (p - 1) << 1; int c = ELEMENTS[i] == e ? 1 : 0; c += ELEMENTS[i + 1] == e ? 2 : 0; switch (c) { case 0: grow(SIZE + 2); System.arraycopy(ELEMENTS, i + 1, ELEMENTS, i + 3, SIZE - i - 1); ELEMENTS[i + 1] = e - 1; ELEMENTS[i + 2] = e + 1; SIZE += 2; break; case 1: ELEMENTS[i]++; break; case 2: ELEMENTS[i + 1]--; break; case 3: System.arraycopy(ELEMENTS, i + 2, ELEMENTS, i, SIZE - i - 2); SIZE -= 2; break; default: throw new SolverException("Unexpected mask " + c); } modified = true; CARDINALITY--; } return modified; } }
IntIterableRangeSet implements IntIterableSet { @Override public boolean remove(int e) { if (lock) { throw new IllegalStateException("This set is immutable"); } boolean modified = false; int p = rangeOf(e); if (p >= 0) { int i = (p - 1) << 1; int c = ELEMENTS[i] == e ? 1 : 0; c += ELEMENTS[i + 1] == e ? 2 : 0; switch (c) { case 0: grow(SIZE + 2); System.arraycopy(ELEMENTS, i + 1, ELEMENTS, i + 3, SIZE - i - 1); ELEMENTS[i + 1] = e - 1; ELEMENTS[i + 2] = e + 1; SIZE += 2; break; case 1: ELEMENTS[i]++; break; case 2: ELEMENTS[i + 1]--; break; case 3: System.arraycopy(ELEMENTS, i + 2, ELEMENTS, i, SIZE - i - 2); SIZE -= 2; break; default: throw new SolverException("Unexpected mask " + c); } modified = true; CARDINALITY--; } return modified; } IntIterableRangeSet();  IntIterableRangeSet(int a, int b);  IntIterableRangeSet(int e);  IntIterableRangeSet(int[] values);  IntIterableRangeSet(IntVar var); }
IntIterableRangeSet implements IntIterableSet { @Override public boolean remove(int e) { if (lock) { throw new IllegalStateException("This set is immutable"); } boolean modified = false; int p = rangeOf(e); if (p >= 0) { int i = (p - 1) << 1; int c = ELEMENTS[i] == e ? 1 : 0; c += ELEMENTS[i + 1] == e ? 2 : 0; switch (c) { case 0: grow(SIZE + 2); System.arraycopy(ELEMENTS, i + 1, ELEMENTS, i + 3, SIZE - i - 1); ELEMENTS[i + 1] = e - 1; ELEMENTS[i + 2] = e + 1; SIZE += 2; break; case 1: ELEMENTS[i]++; break; case 2: ELEMENTS[i + 1]--; break; case 3: System.arraycopy(ELEMENTS, i + 2, ELEMENTS, i, SIZE - i - 2); SIZE -= 2; break; default: throw new SolverException("Unexpected mask " + c); } modified = true; CARDINALITY--; } return modified; } IntIterableRangeSet();  IntIterableRangeSet(int a, int b);  IntIterableRangeSet(int e);  IntIterableRangeSet(int[] values);  IntIterableRangeSet(IntVar var); @Override String toString(); String toSmartString(); void lock(); void unlock(); int getNbRanges(); int cardinality(); int minOfRange(int r); int maxOfRange(int r); @Override int min(); @Override int max(); @Override boolean add(int e); @Override boolean addAll(int... values); @Override boolean addAll(IntIterableSet set); boolean addAll(IntVar var); boolean addAll(IntIterableRangeSet set); @Override boolean retainAll(IntIterableSet set); boolean retainAll(IntIterableRangeSet set); @Override boolean remove(int e); @Override boolean removeAll(IntIterableSet set); boolean removeAll(IntIterableRangeSet set); @Override void clear(); @Override SetType getSetType(); boolean addBetween(int a, int b); @Override boolean removeBetween(int f, int t); boolean retainBetween(int f, int t); @Override int nextValue(int e); @Override int nextValueOut(int e); @Override int previousValue(int e); @Override int previousValueOut(int e); @Override boolean contains(int o); @Override IntIterableRangeSet duplicate(); IntIterableRangeSet copyFrom(IntIterableRangeSet me); void copyFrom(IntVar var); @Override int size(); @Override ISetIterator newIterator(); void plus(int x); @Override ISetIterator iterator(); void minus(int x); void times(int x); int rangeOf(int x); void compact(); IntIterableRangeSet flip(); IntIterableRangeSet flip(int lb, int ub); @SuppressWarnings("Duplicates") boolean intersect(int lb, int ub); @SuppressWarnings("Duplicates") boolean intersectDichot(int lb, int ub); @SuppressWarnings("Duplicates") boolean intersect(IntIterableRangeSet set); @SuppressWarnings("Duplicates") boolean intersect(IntVar var); void forEachValueIn(IntConsumer c); void forEachValueOut(IntConsumer c); int[] toArray(); }
IntIterableRangeSet implements IntIterableSet { @Override public boolean remove(int e) { if (lock) { throw new IllegalStateException("This set is immutable"); } boolean modified = false; int p = rangeOf(e); if (p >= 0) { int i = (p - 1) << 1; int c = ELEMENTS[i] == e ? 1 : 0; c += ELEMENTS[i + 1] == e ? 2 : 0; switch (c) { case 0: grow(SIZE + 2); System.arraycopy(ELEMENTS, i + 1, ELEMENTS, i + 3, SIZE - i - 1); ELEMENTS[i + 1] = e - 1; ELEMENTS[i + 2] = e + 1; SIZE += 2; break; case 1: ELEMENTS[i]++; break; case 2: ELEMENTS[i + 1]--; break; case 3: System.arraycopy(ELEMENTS, i + 2, ELEMENTS, i, SIZE - i - 2); SIZE -= 2; break; default: throw new SolverException("Unexpected mask " + c); } modified = true; CARDINALITY--; } return modified; } IntIterableRangeSet();  IntIterableRangeSet(int a, int b);  IntIterableRangeSet(int e);  IntIterableRangeSet(int[] values);  IntIterableRangeSet(IntVar var); @Override String toString(); String toSmartString(); void lock(); void unlock(); int getNbRanges(); int cardinality(); int minOfRange(int r); int maxOfRange(int r); @Override int min(); @Override int max(); @Override boolean add(int e); @Override boolean addAll(int... values); @Override boolean addAll(IntIterableSet set); boolean addAll(IntVar var); boolean addAll(IntIterableRangeSet set); @Override boolean retainAll(IntIterableSet set); boolean retainAll(IntIterableRangeSet set); @Override boolean remove(int e); @Override boolean removeAll(IntIterableSet set); boolean removeAll(IntIterableRangeSet set); @Override void clear(); @Override SetType getSetType(); boolean addBetween(int a, int b); @Override boolean removeBetween(int f, int t); boolean retainBetween(int f, int t); @Override int nextValue(int e); @Override int nextValueOut(int e); @Override int previousValue(int e); @Override int previousValueOut(int e); @Override boolean contains(int o); @Override IntIterableRangeSet duplicate(); IntIterableRangeSet copyFrom(IntIterableRangeSet me); void copyFrom(IntVar var); @Override int size(); @Override ISetIterator newIterator(); void plus(int x); @Override ISetIterator iterator(); void minus(int x); void times(int x); int rangeOf(int x); void compact(); IntIterableRangeSet flip(); IntIterableRangeSet flip(int lb, int ub); @SuppressWarnings("Duplicates") boolean intersect(int lb, int ub); @SuppressWarnings("Duplicates") boolean intersectDichot(int lb, int ub); @SuppressWarnings("Duplicates") boolean intersect(IntIterableRangeSet set); @SuppressWarnings("Duplicates") boolean intersect(IntVar var); void forEachValueIn(IntConsumer c); void forEachValueOut(IntConsumer c); int[] toArray(); static final int MIN; static final int MAX; }