using System.Collections.Generic; using Microsoft.Msagl.Core.Layout; namespace Microsoft.Msagl.Prototype.Phylo { /// /// Implements a phylogenetic tree /// public class PhyloTree : GeometryGraph { Node root; //used in the other solution [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Node Root { get { return root != null ? root : root = GetRoot(); } } private Node GetRoot() { Node ret = null; foreach (Node n in this.Nodes) { ret = n; break; } Node oldVal; do { oldVal = ret; foreach (Edge e in ret.InEdges) ret = e.Source; } while (oldVal != ret); return ret; } /// /// the leaves of the tree /// public IEnumerable Leaves { get { foreach (Node node in this.Nodes) if (NodeIsALeaf(node)) yield return node; } } static private bool NodeIsALeaf(Node node) { return !node.OutEdges.GetEnumerator().MoveNext(); } } }