Exemplo n.º 1
0
        public static MemoryTreeNode FindFirstLeaf(TreeFile TreeFile, MemoryTreeNode currentNode = null)
        {
            if (currentNode == null)
            {
                currentNode = TreeFile.RootCache;
            }

            NodePointer pointer = new NodePointer();

            pointer.PointerBytes = currentNode.TreeNode.PreviousPointer;

            if (pointer.PositionPointer == 0)
            {
                var key = KeyFinder.FindFirstKey(currentNode.TreeNode.KeyArray, TreeFile.comparer);
                if (key == null)
                {
                    return(null);
                }
                pointer = currentNode.TreeNode.FindPointer(key);
            }

            if (pointer.PointerBytes != null && pointer.PositionPointer > 0 && pointer.Indicator != EnumValues.TypeIndicator.leaf)
            {
                var newcachenode = GetOrLoadNode(TreeFile, currentNode, pointer);
                return(FindFirstLeaf(TreeFile, newcachenode));
            }

            ///find the leaf that contains the key.
            if (pointer.PointerBytes != null && pointer.PositionPointer > 0 && pointer.Indicator == EnumValues.TypeIndicator.leaf)
            {
                MemoryTreeNode newcacheleaf = GetOrLoadNode(TreeFile, currentNode, pointer);
                return(newcacheleaf);
            }

            return(null);
        }