in jflex/src/main/java/jflex/core/unicode/IntCharSet.java [314:355]
public IntCharSet and(IntCharSet set) {
if (DEBUG) {
Out.dump("intersection");
Out.dump("this : " + this);
Out.dump("other : " + set);
}
IntCharSet result = new IntCharSet();
int i = 0; // index in this.intervals
int j = 0; // index in set.intervals
int size = intervals.size();
int setSize = set.intervals.size();
while (i < size && j < setSize) {
Interval x = this.intervals.get(i);
Interval y = set.intervals.get(j);
if (x.end < y.start) {
i++;
continue;
}
if (y.end < x.start) {
j++;
continue;
}
result.intervals.add(new Interval(max(x.start, y.start), min(x.end, y.end)));
if (x.end >= y.end) j++;
if (y.end >= x.end) i++;
}
if (DEBUG) {
Out.dump("result: " + result);
assert result.invariants();
}
return result;
}