Пример #1
0
 public override void Clear(IndexList list)
 {
     // Nothing
 }
Пример #2
0
            public override bool Delete(IComparable key, IndexList list)
            {
                int  AClosestIndex;
                bool match = Search(0, key, out AClosestIndex);

                if (!match && AClosestIndex > 0)
                {
                    AClosestIndex--;
                }
                Node child = _nodes[AClosestIndex];

                match = child.Delete(key, list);
                if (match)
                {
                    int childCapacity = child._keys.Length;

                    // A Delete occurred, check for a possible merge
                    if (child._count < (childCapacity / 3))                     // if less than a third full
                    {
                        Node prior = (AClosestIndex == 0 ? null : _nodes[AClosestIndex - 1]);
                        Node next  = (AClosestIndex == (_count - 1) ? null : _nodes[AClosestIndex + 1]);
                        if
                        (                                                                                               // if there is enough room in the adjacent node(s) to handle this node's entries
                            (childCapacity * 2)
                            - ((prior == null ? 0 : prior._count) + (next == null ? 0 : next._count))
                            >= child._count
                        )
                        {
                            // Merge with adjacent nodes
                            if (prior != null)
                            {
                                int needed = (child._count / 2) + (child._count % 2);                                   // Assume half rounded up
                                child.AppendTo
                                (
                                    prior,
                                    Math.Min                                            // Append the lesser of the number of slots available in the prior node, and half of the items to allocate plus the number that the next will not be able to handle of its half
                                    (
                                        childCapacity - prior._count,
                                        needed + (next == null ? 0 : Math.Max(0, needed - (childCapacity - next._count)))
                                    )
                                );
                            }

                            if (next != null)
                            {
                                child.PrependTo(next);
                            }

                            DeleteNode(AClosestIndex);
                            RoutingNode routingChild = child as RoutingNode;
                            if (routingChild != null)
                            {
                                list.RelinquishRoutingNode(routingChild);
                            }
                            else
                            {
                                list.RelinquishDataNode((DataNode)child);
                            }
                        }
                    }
                }
                return(match);
            }
Пример #3
0
 public abstract bool Delete(IComparable key, IndexList list);
Пример #4
0
 /// <summary> Quickly relinquishes all of the nodes (recursively). </summary>
 public abstract void Clear(IndexList list);
Пример #5
0
 public abstract bool Insert(IComparable key, object data, IndexList list);