protected List<IntervalSet> makeEdgeSetsDisjoint(List<IntervalSet> edges) {
OrderedHashSet<IntervalSet> disjointSets = new OrderedHashSet<IntervalSet>();
// walk each incoming edge label/set and add to disjoint set
int numEdges = edges.size();
for (int e = 0; e < numEdges; e++) {
IntervalSet t = edges.get(e);
if ( disjointSets.contains(t) ) { // exact set present
continue;
}
// compare t with set i for disjointness
IntervalSet remainder = t; // remainder starts out as whole set to add
int numDisjointElements = disjointSets.size();
for (int i = 0; i < numDisjointElements; i++) {
IntervalSet s_i = disjointSets.get(i);
if ( t.and(s_i).isNil() ) { // nothing in common
continue;
}
//System.out.println(label+" collides with "+rl);
// For any (s_i, t) with s_i&t!=nil replace with (s_i-t, s_i&t)
// (ignoring s_i-t if nil; don't put in list)
// Replace existing s_i with intersection since we
// know that will always be a non nil character class
IntervalSet intersection = s_i.and(t);
disjointSets.set(i, intersection);
// Compute s_i-t to see what is in current set and not in incoming
IntervalSet existingMinusNewElements = s_i.subtract(t);
//System.out.println(s_i+"-"+t+"="+existingMinusNewElements);
if ( !existingMinusNewElements.isNil() ) {
// found a new character class, add to the end (doesn't affect
// outer loop duration due to n computation a priori.
disjointSets.add(existingMinusNewElements);
}