示例#1
0
        /// <summary>
        /// Creates temporaty graph with a new sequence and try to perform topological sorting
        /// </summary>
        /// <param name="sequence"></param>
        /// <returns></returns>
        public bool CanSort(IEnumerable <T> sequence)
        {
            var tempGraph = new GraphFast <T>(this);

            tempGraph.AddSequence(sequence);
            return(tempGraph.CanSort());
        }
        internal InternalNodeFast(T publicNode, GraphFast <T> graph)
        {
            Edges   = new List <InternalNodeFast <T> >();
            Parents = new List <InternalNodeFast <T> >();

            Value  = publicNode;
            _graph = graph;
        }
        internal InternalNodeFast(T publicNode, GraphFast <T> graph)
        {
            this.Edges   = new List <InternalNodeFast <T> >();
            this.Parents = new List <InternalNodeFast <T> >();

            this.Value  = publicNode;
            this._graph = graph;
        }
示例#4
0
        /// <summary>
        /// Creates temporary light-weight copy which is used by CanSort(sequence) method
        /// </summary>
        /// <param name="initialGraph"></param>
        private GraphFast(GraphFast <T> initialGraph)
            : this(initialGraph.CountNodes)
        {
            if (initialGraph._isDirty)
            {
                initialGraph.ReinitializeKeys();
            }

            var nodeKeys = new InternalNodeFast <T> [initialGraph.CountNodes];

            foreach (var node in initialGraph._nodes)
            {
                nodeKeys[node.Value.Key] = new InternalNodeFast <T>(node.Value.Value, this, node.Value.Key);
                this._nodes[node.Key]    = node.Value;
            }
            foreach (var node in initialGraph._nodes.Values)
            {
                foreach (var edge in node.Edges)
                {
                    nodeKeys[node.Key].Edges.Add(nodeKeys[edge.Key]);
                }
            }
        }
 internal InternalNodeFast(T publicNode, GraphFast <T> graph, int key)
     : this(publicNode, graph)
 {
     this.Key = key;
 }