コード例 #1
0
        /// <summary>
        /// Insert an item into the tree this is the root of.
        /// </summary>
        /// <param name="itemInterval"></param>
        /// <param name="item"></param>
        public void Insert(Interval itemInterval, object item)
        {
            int index = GetSubnodeIndex(itemInterval, origin);

            // if index is -1, itemEnv must contain the origin.
            if (index == -1)
            {
                Add(item);
                return;
            }

            /*
             * the item must be contained in one interval, so insert it into the
             * tree for that interval (which may not yet exist)
             */
            Node node = subnode[index];

            /*
             *  If the subnode doesn't exist or this item is not contained in it,
             *  have to expand the tree upward to contain the item.
             */

            if (node == null || !node.Interval.Contains(itemInterval))
            {
                Node largerNode = Node.CreateExpanded(node, itemInterval);
                subnode[index] = largerNode;
            }

            /*
             * At this point we have a subnode which exists and must contain
             * contains the env for the item.  Insert the item into the tree.
             */
            InsertContained(subnode[index], itemInterval, item);
        }