/** Interval objects are used readonly so share all with the * same single value a==b up to some max size. Use an array as a perfect hash. * Return shared object for 0..INTERVAL_POOL_MAX_VALUE or a new * Interval object with a..a in it. On Java.g, 218623 IntervalSets * have a..a (set with 1 element). */ public static Interval create(int a, int b) { //return new Interval(a,b); // cache just a..a if ( a!=b || a<0 || a>INTERVAL_POOL_MAX_VALUE ) { return new Interval(a,b); } if ( cache[a]==null ) { cache[a] = new Interval(a,a); } return cache[a]; }
/** Return the interval with elements from this not in other; * other must not be totally enclosed (properly contained) * within this, which would result in two disjoint intervals * instead of the single one returned by this method. */ public Interval differenceNotProperlyContained(Interval other) { Interval diff = null; // other.a to left of this.a (or same) if ( other.startsBeforeNonDisjoint(this) ) { diff = Interval.create(Math.max(this.a,other.b+1), this.b); } // other.a to right of this.a else if ( other.startsAfterNonDisjoint(this) ) { diff = Interval.create(this.a, other.a-1); } return diff; }
/** Are both ranges disjoint? I.e., no overlap? */ public boolean disjoint(Interval other) { return startsBeforeDisjoint(other) || startsAfterDisjoint(other); }
Interval theirs = theirIntervals.get(j); if ( mine.startsBeforeDisjoint(theirs) ) { else if ( theirs.startsBeforeDisjoint(mine) ) { else if ( mine.properlyContains(theirs) ) { intersection.add(mine.intersection(theirs)); j++; else if ( theirs.properlyContains(mine) ) { intersection.add(mine.intersection(theirs)); i++; else if ( !mine.disjoint(theirs) ) { intersection.add(mine.intersection(theirs)); if ( mine.startsAfterNonDisjoint(theirs) ) { j++; else if ( theirs.startsAfterNonDisjoint(mine) ) { i++;
/** Return the interval in common between this and o */ public Interval intersection(Interval other) { return Interval.create(Math.max(a,other.a), Math.min(b,other.b)); }
Interval theirs = (Interval)theirIntervals.get(j); if ( mine.startsBeforeDisjoint(theirs) ) { else if ( theirs.startsBeforeDisjoint(mine) ) { else if ( mine.properlyContains(theirs) ) { intersection.add(mine.intersection(theirs)); j++; else if ( theirs.properlyContains(mine) ) { intersection.add(mine.intersection(theirs)); i++; else if ( !mine.disjoint(theirs) ) { intersection.add(mine.intersection(theirs)); if ( mine.startsAfterNonDisjoint(theirs) ) { j++; else if ( theirs.startsAfterNonDisjoint(mine) ) { i++;
/** Return the interval in common between this and o */ public Interval intersection(Interval other) { return Interval.create(Math.max(a,other.a), Math.min(b,other.b)); }
if ( addition.equals(r) ) { return; if ( addition.adjacent(r) || !addition.disjoint(r) ) { Interval bigger = addition.union(r); iter.set(bigger); if ( !bigger.adjacent(next) && bigger.disjoint(next) ) { break; iter.set(bigger.union(next)); // set to 3 merged ones if ( addition.startsBeforeDisjoint(r) ) {
Interval theirs = (Interval)theirIntervals.get(j); if ( mine.startsBeforeDisjoint(theirs) ) { else if ( theirs.startsBeforeDisjoint(mine) ) { else if ( mine.properlyContains(theirs) ) { intersection.add(mine.intersection(theirs)); j++; else if ( theirs.properlyContains(mine) ) { intersection.add(mine.intersection(theirs)); i++; else if ( !mine.disjoint(theirs) ) { intersection.add(mine.intersection(theirs)); if ( mine.startsAfterNonDisjoint(theirs) ) { j++; else if ( theirs.startsAfterNonDisjoint(mine) ) { i++;
/** Return the interval with elements from this not in other; * other must not be totally enclosed (properly contained) * within this, which would result in two disjoint intervals * instead of the single one returned by this method. */ public Interval differenceNotProperlyContained(Interval other) { Interval diff = null; // other.a to left of this.a (or same) if ( other.startsBeforeNonDisjoint(this) ) { diff = Interval.create(Math.max(this.a,other.b+1), this.b); } // other.a to right of this.a else if ( other.startsAfterNonDisjoint(this) ) { diff = Interval.create(this.a, other.a-1); } return diff; }
/** Are both ranges disjoint? I.e., no overlap? */ public boolean disjoint(Interval other) { return startsBeforeDisjoint(other) || startsAfterDisjoint(other); }
/** Return the interval computed from combining this and other */ public Interval union(Interval other) { return Interval.create(Math.min(a,other.a), Math.max(b,other.b)); }
/** Interval objects are used readonly so share all with the * same single value a==b up to some max size. Use an array as a perfect hash. * Return shared object for 0..INTERVAL_POOL_MAX_VALUE or a new * Interval object with a..a in it. On Java.g, 218623 IntervalSets * have a..a (set with 1 element). */ public static Interval create(int a, int b) { //return new Interval(a,b); // cache just a..a if ( a!=b || a<0 || a>INTERVAL_POOL_MAX_VALUE ) { return new Interval(a,b); } if ( cache[a]==null ) { cache[a] = new Interval(a,a); } return cache[a]; }
if ( addition.equals(r) ) { return; if ( addition.adjacent(r) || !addition.disjoint(r) ) { Interval bigger = addition.union(r); iter.set(bigger); if ( !bigger.adjacent(next) && bigger.disjoint(next) ) { break; iter.set(bigger.union(next)); // set to 3 merged ones if ( addition.startsBeforeDisjoint(r) ) {
Interval theirs = theirIntervals.get(j); if ( mine.startsBeforeDisjoint(theirs) ) { else if ( theirs.startsBeforeDisjoint(mine) ) { else if ( mine.properlyContains(theirs) ) { intersection.add(mine.intersection(theirs)); j++; else if ( theirs.properlyContains(mine) ) { intersection.add(mine.intersection(theirs)); i++; else if ( !mine.disjoint(theirs) ) { intersection.add(mine.intersection(theirs)); if ( mine.startsAfterNonDisjoint(theirs) ) { j++; else if ( theirs.startsAfterNonDisjoint(mine) ) { i++;
/** Return the interval with elements from this not in other; * other must not be totally enclosed (properly contained) * within this, which would result in two disjoint intervals * instead of the single one returned by this method. */ public Interval differenceNotProperlyContained(Interval other) { Interval diff = null; // other.a to left of this.a (or same) if ( other.startsBeforeNonDisjoint(this) ) { diff = Interval.create(Math.max(this.a,other.b+1), this.b); } // other.a to right of this.a else if ( other.startsAfterNonDisjoint(this) ) { diff = Interval.create(this.a, other.a-1); } return diff; }
/** Are both ranges disjoint? I.e., no overlap? */ public boolean disjoint(Interval other) { return startsBeforeDisjoint(other) || startsAfterDisjoint(other); }
/** Return the interval computed from combining this and other */ public Interval union(Interval other) { return Interval.create(Math.min(a,other.a), Math.max(b,other.b)); }