コード例 #1
0
        /// <summary>
        /// Searches the SplitTree for a node that matches the given TreeNode.
        /// </summary>
        /// <param name="other">the node to match</param>
        /// <returns>the TreeNode in this tree that matches the given node</returns>
        /// <exception cref="Exception">if the tree does not contain a match for the given node</exception>
        public TreeNode GetMatch(TreeNode other)
        {
            if (this.parentless[0].Matches(other)) {
                return this.parentless[0]; }

            List<TreeNode> currentLevel = new List<TreeNode>();
            currentLevel.Add(this.parentless[0]);

            while (currentLevel.Count > 0) {
                List<TreeNode> nextLevel = new List<TreeNode>();

                foreach (TreeNode currentNode in currentLevel) {
                    foreach (TreeNode nextNode in currentNode.GetChildren()) {
                        if (other.Matches(nextNode)) {
                            return nextNode; }
                        nextLevel.Add(nextNode); } }

                currentLevel = nextLevel; }

            throw new Exception("Error: attempted to find a node in a split tree matching a given node. The join tree did not contain a match.");
        }