示例#1
0
        /// <summary>
        /// Inserts data into given node.
        /// </summary>
        /// <param name="node">
        /// Node in which element will be added.
        /// </param>
        /// <param name="data">
        /// Element to be added.
        /// </param>
        /// <returns>
        /// </returns>
        private BPlusTreeNode <T> Insert(BPlusTreeNode <T> node, T data)
        {
            if (!node.IsLeaf)
            {
                // Look for child to go to
                for (int i = 0; i < node.Values.Count; i++)
                {
                    int result = this._comparer.Compare(node.Values[i], data);
                    if (result > 0)
                    {
                        return(this.Insert(node.ChildAt(i), data));
                    }

                    if (i + 1 == node.Values.Count)
                    {
                        return(this.Insert(node.ChildAt(i + 1), data));
                    }
                }

                return(null);
            }

            if (!node.IsFull)
            {
                return(node.Add(data));
            }

            // return node.Split(data);
            if (node == this._root)
            {
                this._root = node.Split(data);
                return(this._root);
            }

            node.Parent = node.Split(data);
            return((BPlusTreeNode <T>)node.Parent);
        }