Example #1
0
        /// <summary>Make a specified node a top node and reorganize hierarchy around it while keeping all connections untouched.</summary><param name="topNode">Node to make top node.</param>
        public void MakeTopNode(RankedNode topNode)
        {
            TopNode = topNode;
            if (topNode.Leader != null)                   // Do nothing if specified node is already top node.
            {
                topNode.Leader = null;
                Recursion(topNode);
            }

            void Recursion(RankedNode startNode)
            {
                foreach (var node in startNode.Peers.Keys)
                {
                    if (node != startNode?.Leader)    // Must leave its leader alone.
                    {
                        node.Leader = startNode;      // Make all of its peers subordinates.

                        if (node.Peers.Count > 1)     // Lowest node has only 1 peer - its leader.
                        {
                            Recursion(node);
                        }
                    }
                }
            }
        }
Example #2
0
 public ValueNode(RankedNode leader, T value) : base(leader)
 {
     _Value = value;
 }
Example #3
0
 public Hierarchy(RankedNode topNode)
 {
     TopNode = topNode;
 }