예제 #1
0
        private BTreeNode Split(Transaction trans)
        {
            var res = new BTreeNode
                          (_btree, _btree._halfNodeSize, _isLeaf, _parentID, GetID(), _nextID);

            Array.Copy(_keys, _btree._halfNodeSize, res._keys, 0, _btree._halfNodeSize
                       );
            for (var i = _btree._halfNodeSize; i < _keys.Length; i++)
            {
                _keys[i] = null;
            }
            if (_children != null)
            {
                res._children = new object[_btree.NodeSize()];
                Array.Copy(_children, _btree._halfNodeSize, res._children, 0, _btree._halfNodeSize
                           );
                for (var i = _btree._halfNodeSize; i < _children.Length; i++)
                {
                    _children[i] = null;
                }
            }
            _count = _btree._halfNodeSize;
            res.Write(trans.SystemTransaction());
            _btree.AddNode(res);
            var splitID = res.GetID();

            PointNextTo(trans, splitID);
            SetNextID(trans, splitID);
            if (_children != null)
            {
                for (var i = 0; i < _btree._halfNodeSize; i++)
                {
                    if (res._children[i] == null)
                    {
                        break;
                    }
                    res.Child(i).SetParentID(trans, splitID);
                }
            }
            _btree.NotifySplit(trans, this, res);
            return(res);
        }