Ejemplo n.º 1
0
        public List <int> FindInterval(int lowerLimit, int upperLimit)
        {
            if (upperLimit <= lowerLimit)
            {
                return(null);
            }
            BpTreeNode nodeToTarget = FindNodeToInsertIn(Root, lowerLimit);
            int        index        = 0;

            while (index < nodeToTarget.KeysCount && nodeToTarget.Keys[index] < lowerLimit)
            {
                index++;
            }
            List <int> result = new List <int>();

            while (nodeToTarget.Keys[index] < upperLimit)
            {
                result.Add(nodeToTarget.Keys[index]);
                index++;
            }
            while (nodeToTarget.RightSibiling != default(BpTreeNode))
            {
                nodeToTarget = nodeToTarget.RightSibiling;
                index        = 0;
                while (nodeToTarget.Keys[index] < upperLimit)
                {
                    result.Add(nodeToTarget.Keys[index]);
                    index++;
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        private BpTreeNode FindNode(BpTreeNode subTreeRoot, int value)
        {
            int index = 0;

            while (index < subTreeRoot.KeysCount && value > subTreeRoot.Keys[index])
            {
                index++;
            }
            if (subTreeRoot.Keys[index] == value)
            {
                if (subTreeRoot.IsLeaf())
                {
                    return(subTreeRoot);
                }
                else
                {
                    return(FindNode(subTreeRoot.Children[index + 1], value));
                }
            }
            if (!subTreeRoot.IsLeaf())
            {
                return(FindNode(subTreeRoot.Children[index], value));
            }
            else
            {
                return(default(BpTreeNode));
            }
        }
Ejemplo n.º 3
0
        public BpTreeNode FindNewRoot()
        {
            BpTreeNode currentNode = Root;

            while (currentNode.Parent != null)
            {
                currentNode = currentNode.Parent;
            }
            return(currentNode);
        }
Ejemplo n.º 4
0
        public void Insert(int newValue)
        {
            BpTreeNode nodeToInsertTo = null;

            if (Root == null)
            {
                Root           = new BpTreeNode(maxOrder, null);
                nodeToInsertTo = Root;
            }
            else
            {
                nodeToInsertTo = FindNodeToInsertIn(Root, newValue);
            }
            nodeToInsertTo.InsertValue(newValue);
            Root = FindNewRoot();
        }
Ejemplo n.º 5
0
 public BpTreeNode FindNodeToInsertIn(BpTreeNode rootOfTree, int newValue)
 {
     if (rootOfTree.IsLeaf())
     {
         return(rootOfTree);
     }
     for (int i = 0; i < rootOfTree.KeysCount; i++)
     {
         if (newValue < rootOfTree.Keys[i])
         {
             return(FindNodeToInsertIn(rootOfTree.Children[i], newValue));
         }
         if (rootOfTree.KeysCount == i + 1)
         {
             return(FindNodeToInsertIn(rootOfTree.Children[i + 1], newValue));
         }
     }
     return(rootOfTree);
 }