示例#1
0
 public bool Equals(Tags tags)
 {
     return(_Id == tags._Id);
 }
示例#2
0
 public DirectedEdge(Tags target)
 {
     Target         = target;
     Directionality = 0;
 }
示例#3
0
 public void Add(Tags to)
 {
     Add(new DownwardEdge(From, to));
 }
示例#4
0
 public DownwardEdges(Tags from)
 {
     From = from;
 }
示例#5
0
 public DownwardEdge(Tags from, Tags to)
 {
     From = from;
     To   = to;
 }
示例#6
0
        private static Tags?ToposortVisit(Dictionary <Tags, DownwardEdges> allEdges, Tags tag, bool isTopLevel, int[] result, Dictionary <int, bool> state, ref int nextIndex)
        {
            var id = tag.Id;

            bool visiting;

            if (state.TryGetValue(id, out visiting))
            {
                if (visiting)
                {
                    if (Tracing)
                    {
                        Console.WriteLine("{0}Cycle @{1}", new string('.', Depth + 1), tag);
                    }

                    // HACK: Break this cycle.
                    return(tag);
                }
                else
                {
                    return(null);
                }
            }

            if (Tracing)
            {
                Console.WriteLine("{0}{1}", new string('.', Depth), tag);
            }

            Depth++;
            state[id] = true;

            bool          aborted = false;
            DownwardEdges downwardEdges;

            Tags?cycle = null;

            if (allEdges.TryGetValue(tag, out downwardEdges))
            {
                foreach (var edge in downwardEdges)
                {
                    cycle = ToposortVisit(allEdges, edge.To, false, result, state, ref nextIndex);

                    // We hit a cycle, so we bail out.
                    if (cycle.HasValue)
                    {
                        if (state[id] == true)
                        {
                            state.Remove(id);
                        }

                        Depth--;
                        // We don't propagate the cycle, though.
                        return(null);
                    }
                }
            }

            Assign(tag, result, state, ref nextIndex);
            Depth--;

            return(cycle);
        }