in jflex/src/main/java/jflex/core/unicode/IntCharSet.java [365:439]
public void sub(IntCharSet set) {
if (DEBUG) {
Out.dump("complement");
Out.dump("this : " + this);
Out.dump("other : " + set);
assert invariants();
// not asserting non-null, because we'll already get an exception and it confuses lgtm.com
assert set.invariants();
assert isSubSet(set, this);
assert set != this; // reference comparison intended, must supply different object
}
int i = 0; // index in this.intervals
int j = 0; // index in set.intervals
int setSize = set.intervals.size();
while (i < intervals.size() && j < setSize) {
Interval x = this.intervals.get(i);
Interval y = set.intervals.get(j);
if (DEBUG) {
Out.dump("this : " + this);
Out.dump("this [" + i + "] : " + x);
Out.dump("other [" + j + "] : " + y);
}
if (x.end < y.start) {
i++;
continue;
}
if (y.end < x.start) {
j++;
continue;
}
// x.end >= y.start && y.end >= x.start ->
// x.end <= y.end && x.start >= y.start (prec)
if (x.start == y.start && x.end == y.end) {
intervals.remove(i);
j++;
continue;
}
// x.end <= y.end && x.start >= y.start &&
// (x.end < y.end || x.start > y.start) ->
// x.start < x.end
if (x.start == y.start) {
x.start = y.end + 1;
j++;
continue;
}
if (x.end == y.end) {
x.end = y.start - 1;
i++;
j++;
continue;
}
intervals.add(i, new Interval(x.start, y.start - 1));
x.start = y.end + 1;
i++;
j++;
}
if (DEBUG) {
Out.dump("result: " + this);
assert invariants();
}
}