Antlr3.Tool.Grammar.MakeEdgeSetsDisjoint C# (CSharp) Method

MakeEdgeSetsDisjoint() protected method

protected MakeEdgeSetsDisjoint ( IList edges ) : IList
edges IList
return IList
        protected virtual IList<IIntSet> MakeEdgeSetsDisjoint( IList<IIntSet> edges )
        {
            OrderedHashSet<IIntSet> disjointSets = new OrderedHashSet<IIntSet>();
            // walk each incoming edge label/set and add to disjoint set
            int numEdges = edges.Count;
            for ( int e = 0; e < numEdges; e++ )
            {
                IntervalSet t = (IntervalSet)edges[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.Count;
                for ( int i = 0; i < numDisjointElements; i++ )
                {
                    IntervalSet s_i = (IntervalSet)disjointSets[i];

                    if ( t.And( s_i ).IsNil )
                    { // nothing in common
                        continue;
                    }
                    //[email protected](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 = (IntervalSet)s_i.And( t );
                    disjointSets[i] = intersection;

                    // Compute s_i-t to see what is in current set and not in incoming
                    IIntSet existingMinusNewElements = s_i.Subtract( t );
                    //[email protected](s_i+"-"+t+"="+existingMinusNewElements);
                    if ( existingMinusNewElements != null && !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 );
                    }

                    // anything left to add to the reachableLabels?
                    remainder = (IntervalSet)t.Subtract( s_i );
                    if ( remainder.IsNil )
                    {
                        break; // nothing left to add to set.  done!
                    }

                    t = remainder;
                }
                if ( !remainder.IsNil )
                {
                    disjointSets.Add( remainder );
                }
            }
            return disjointSets.GetElements();
        }
Grammar