@Test(groups = "10s", timeOut = 60000) public void testIntersect() { Random rnd = new Random(); for (int i = 0; i < 2000; i++) { rnd.setSeed(i); IntIterableRangeSet t1 = makeItv(rnd, 50); IntIterableRangeSet t2 = makeItv(rnd, 50); IntIterableRangeSet s1 = intersect1(t1, t2); IntIterableRangeSet s2 = IntIterableSetUtils.intersection(t1, t2); Assert.assertEquals(s2.SIZE, s1.SIZE); Assert.assertEquals(s2.CARDINALITY, s1.CARDINALITY); Assert.assertEquals(Arrays.copyOf(s2.ELEMENTS, s2.SIZE), Arrays.copyOf(s1.ELEMENTS, s1.SIZE)); } }
@SuppressWarnings("Duplicates") public boolean intersect(int lb, int ub) { if(CARDINALITY > 100) return intersectDichot(lb, ub); int s1 = this.SIZE >> 1; int s2 = ub - lb + 1; if (s1 > 0 && s2 > 0) { int i = 0; int lbi, ubi; lbi = this.ELEMENTS[0]; ubi = this.ELEMENTS[1]; while (true) { if ((lbi <= lb && lb <= ubi) || (lb <= lbi && lbi <= ub)) { return true; } else if (ubi <= ub && ++i < s1) { lbi = this.ELEMENTS[i << 1]; ubi = this.ELEMENTS[(i << 1) + 1]; } else { break; } } } return false; }
IntIterableRangeSet implements IntIterableSet { @SuppressWarnings("Duplicates") public boolean intersect(int lb, int ub) { if(CARDINALITY > 100) return intersectDichot(lb, ub); int s1 = this.SIZE >> 1; int s2 = ub - lb + 1; if (s1 > 0 && s2 > 0) { int i = 0; int lbi, ubi; lbi = this.ELEMENTS[0]; ubi = this.ELEMENTS[1]; while (true) { if ((lbi <= lb && lb <= ubi) || (lb <= lbi && lbi <= ub)) { return true; } else if (ubi <= ub && ++i < s1) { lbi = this.ELEMENTS[i << 1]; ubi = this.ELEMENTS[(i << 1) + 1]; } else { break; } } } return false; } }
IntIterableRangeSet implements IntIterableSet { @SuppressWarnings("Duplicates") public boolean intersect(int lb, int ub) { if(CARDINALITY > 100) return intersectDichot(lb, ub); int s1 = this.SIZE >> 1; int s2 = ub - lb + 1; if (s1 > 0 && s2 > 0) { int i = 0; int lbi, ubi; lbi = this.ELEMENTS[0]; ubi = this.ELEMENTS[1]; while (true) { if ((lbi <= lb && lb <= ubi) || (lb <= lbi && lbi <= ub)) { return true; } else if (ubi <= ub && ++i < s1) { lbi = this.ELEMENTS[i << 1]; ubi = this.ELEMENTS[(i << 1) + 1]; } else { break; } } } return false; } IntIterableRangeSet();  IntIterableRangeSet(int a, int b);  IntIterableRangeSet(int e);  IntIterableRangeSet(int[] values);  IntIterableRangeSet(IntVar var); }
IntIterableRangeSet implements IntIterableSet { @SuppressWarnings("Duplicates") public boolean intersect(int lb, int ub) { if(CARDINALITY > 100) return intersectDichot(lb, ub); int s1 = this.SIZE >> 1; int s2 = ub - lb + 1; if (s1 > 0 && s2 > 0) { int i = 0; int lbi, ubi; lbi = this.ELEMENTS[0]; ubi = this.ELEMENTS[1]; while (true) { if ((lbi <= lb && lb <= ubi) || (lb <= lbi && lbi <= ub)) { return true; } else if (ubi <= ub && ++i < s1) { lbi = this.ELEMENTS[i << 1]; ubi = this.ELEMENTS[(i << 1) + 1]; } else { break; } } } return false; } 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 { @SuppressWarnings("Duplicates") public boolean intersect(int lb, int ub) { if(CARDINALITY > 100) return intersectDichot(lb, ub); int s1 = this.SIZE >> 1; int s2 = ub - lb + 1; if (s1 > 0 && s2 > 0) { int i = 0; int lbi, ubi; lbi = this.ELEMENTS[0]; ubi = this.ELEMENTS[1]; while (true) { if ((lbi <= lb && lb <= ubi) || (lb <= lbi && lbi <= ub)) { return true; } else if (ubi <= ub && ++i < s1) { lbi = this.ELEMENTS[i << 1]; ubi = this.ELEMENTS[(i << 1) + 1]; } else { break; } } } return false; } 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; }