Ejemplo n.º 1
0
        public WGraph <T, TOp, WGraphNode <T, WEdge <T> >, WEdge <T> > ToGraph()
        {
            var res         = new WGraphNode <T, WEdge <T> > [edgeContainer.Length];
            var csr         = edgeContainer.ToCSR();
            var counter     = new int[res.Length];
            var rootCounter = edgeContainer.IsDirected ? new int[res.Length] : counter;
            var children    = new WEdge <T> [res.Length][];
            var roots       = edgeContainer.IsDirected ? new WEdge <T> [res.Length][] : children;

            for (int i = 0; i < res.Length; i++)
            {
                if (children[i] == null)
                {
                    children[i] = new WEdge <T> [edgeContainer.sizes[i]];
                }
                if (roots[i] == null)
                {
                    roots[i] = new WEdge <T> [edgeContainer.rootSizes[i]];
                }
                res[i] = new WGraphNode <T, WEdge <T> >(i, roots[i], children[i]);
                foreach (ref var e in csr.EList.AsSpan(csr.Start[i], csr.Start[i + 1] - csr.Start[i]))
                {
                    var to = e.To;
                    if (roots[to] == null)
                    {
                        roots[to] = new WEdge <T> [edgeContainer.rootSizes[to]];
                    }
                    children[i][counter[i]++]    = e;
                    roots[to][rootCounter[to]++] = e.Reversed(i);
                }
            }
            return(new WGraph <T, TOp, WGraphNode <T, WEdge <T> >, WEdge <T> >(res, csr));
        }
Ejemplo n.º 2
0
 public bool Equals(WGraphNode <T, TEdge> other) => this.Index == other.Index;