Holds a timestamp (integer) for a given item
		private static void Visit(IVertex node, ColorsSet colors,
								  TimestampSet discovery, TimestampSet finish, LinkedList<IVertex> list, ref int time)
		{
			colors.Set(node, VertexColor.Gray);

			discovery.Register(node, time++);

			foreach(IVertex child in node.Adjacencies)
			{
				if (colors.ColorOf(child) == VertexColor.White)
				{
					Visit(child, colors, discovery, finish, list, ref time);
				}
			}

			finish.Register(node, time++);

#if DEBUG
			Debug.Assert(discovery.TimeOf(node) < finish.TimeOf(node));
#endif

			list.AddFirst(node);

			colors.Set(node, VertexColor.Black);
		}
Пример #2
0
		public static IVertex[] Sort(IVertex[] graphNodes)
		{
			ColorsSet colors = new ColorsSet(graphNodes);
			TimestampSet discovery = new TimestampSet();
			TimestampSet finish = new TimestampSet();
			LinkedList list = new LinkedList();

			int time = 0;

			foreach(IVertex node in graphNodes)
			{
				if (colors.ColorOf(node) == VertexColor.White)
				{
					Visit(node, colors, discovery, finish, list, ref time);
				}
			}

			return (IVertex[]) list.ToArray(typeof(IVertex));
		}
		public static IVertex[] Sort(IVertex[] graphNodes)
		{
			ColorsSet colors = new ColorsSet(graphNodes);
			TimestampSet discovery = new TimestampSet();
			TimestampSet finish = new TimestampSet();
			LinkedList<IVertex> list = new LinkedList<IVertex>();

			int time = 0;

			foreach(IVertex node in graphNodes)
			{
				if (colors.ColorOf(node) == VertexColor.White)
				{
					Visit(node, colors, discovery, finish, list, ref time);
				}
			}

			IVertex[] vertices = new IVertex[list.Count];
			list.CopyTo(vertices, 0);
			return vertices;
		}
Пример #4
0
        private static void Visit(IVertex node, ColorsSet colors, TimestampSet discovery, TimestampSet finish, LinkedList <IVertex> list, ref int time)
        {
            colors.Set(node, VertexColor.Gray);

            discovery.Register(node, time++);

            foreach (var child in node.Adjacencies)
            {
                if (colors.ColorOf(child) == VertexColor.White)
                {
                    Visit(child, colors, discovery, finish, list, ref time);
                }
            }

            finish.Register(node, time++);

            Debug.Assert(discovery.TimeOf(node) < finish.TimeOf(node));

            list.AddFirst(node);

            colors.Set(node, VertexColor.Black);
        }
Пример #5
0
        public static IVertex[] Sort(IVertex[] graphNodes)
        {
            var colors    = new ColorsSet(graphNodes);
            var discovery = new TimestampSet();
            var finish    = new TimestampSet();
            var list      = new LinkedList <IVertex>();

            var time = 0;

            foreach (var node in graphNodes)
            {
                if (colors.ColorOf(node) == VertexColor.White)
                {
                    Visit(node, colors, discovery, finish, list, ref time);
                }
            }

            var vertices = new IVertex[list.Count];

            list.CopyTo(vertices, 0);
            return(vertices);
        }