public WTreeGraph <T, TOp, WTreeNode <T, WEdge <T> >, WEdge <T> > ToTree(int root = 0)
        {
            Contract.Assert(!edgeContainer.IsDirected, "木には無向グラフをしたほうが良い");
            var res      = new WTreeNode <T, WEdge <T> > [edgeContainer.Length];
            var children = new SimpleList <WEdge <T> > [res.Length];

            foreach (var(from, e) in edgeContainer.edges)
            {
                var to = e.To;
                if (children[from] == null)
                {
                    children[from] = new SimpleList <WEdge <T> >();
                }
                if (children[to] == null)
                {
                    children[to] = new SimpleList <WEdge <T> >();
                }
                children[from].Add(e);
                children[to].Add(e.Reversed(from));
            }

            if (edgeContainer.Length == 1)
            {
                return(new WTreeGraph <T, TOp, WTreeNode <T, WEdge <T> >, WEdge <T> >(
                           new WTreeNode <T, WEdge <T> >[1] {
                    new WTreeNode <T, WEdge <T> >(root, WEdge <T> .None, 0, default, Array.Empty <WEdge <T> >())
Пример #2
0
 public bool Equals(WTreeNode <T, TEdge> other) => other != null && this.Index == other.Index;