示例#1
0
        private int Split(NativeRowTreeNode sourceNode, NativeRowTreeNode targetNode)
        {
            int entryCount = sourceNode.EntryCount;
            int entryPivot = entryCount / 2;

            if (sourceNode.NodeType == NativeRowTreeNodeType.Data)
            {
                NativeRowTreeDataNode sourceDataNode = (NativeRowTreeDataNode)sourceNode;
                NativeRowTreeDataNode targetDataNode = (NativeRowTreeDataNode)targetNode;

                // Insert the upper half of the entries from ASourceNode into ATargetNode
                for (int entryIndex = entryPivot; entryIndex < entryCount; entryIndex++)
                {
                    targetDataNode.Insert(sourceDataNode.Keys[entryIndex], sourceDataNode.Rows[entryIndex], entryIndex - entryPivot);
                }

                // Remove the upper half of the entries from ASourceNode
                for (int entryIndex = entryCount - 1; entryIndex >= entryPivot; entryIndex--)
                {
                    sourceDataNode.Delete(entryIndex);                     // Don't dispose the values here, this is a move
                }
            }
            else
            {
                NativeRowTreeRoutingNode sourceRoutingNode = (NativeRowTreeRoutingNode)sourceNode;
                NativeRowTreeRoutingNode targetRoutingNode = (NativeRowTreeRoutingNode)targetNode;

                // Insert the upper half of the entries from ASourceNode into ATargetNode
                for (int entryIndex = entryPivot; entryIndex < entryCount; entryIndex++)
                {
                    targetRoutingNode.Insert(sourceRoutingNode.Keys[entryIndex], sourceRoutingNode.Nodes[entryIndex], entryIndex - entryPivot);
                }

                // Remove the upper half of the entries from ASourceNode
                for (int entryIndex = entryCount - 1; entryIndex >= entryPivot; entryIndex--)
                {
                    sourceRoutingNode.Delete(entryIndex);
                }
            }

            // Notify index clients of the data change
            RowsMoved(sourceNode, entryPivot, entryCount - 1, targetNode, -entryPivot);

            return(entryPivot);
        }
示例#2
0
        /// <summary>Inserts the given Key and Data streams into this node at the given index.</summary>
        public void InsertData(NativeRow key, NativeRow data, int entryNumber)
        {
            DataNode.Insert(key, data, entryNumber);

            Tree.RowsMoved(Node, entryNumber, Node.EntryCount - 2, Node, 1);
        }