protected virtual Single GetOverlap(NodeEntry insertionEntry, MinimumBoundingBox overlapMinimumBoundingBox, Node node)
 {
     foreach (NodeEntry nodeEntry in node.NodeEntries)
         if (nodeEntry != insertionEntry)
             overlapMinimumBoundingBox = IntersectMinimumBoundingBoxes(overlapMinimumBoundingBox, nodeEntry.MinimumBoundingBox);
     return
         (overlapMinimumBoundingBox.MaxX - overlapMinimumBoundingBox.MinX) *
         (overlapMinimumBoundingBox.MaxY - overlapMinimumBoundingBox.MinY);
 }
 protected virtual void Insert(NodeEntry entry, Int32 level)
 {
     Node nodeToInsertInto = ChooseNode(entry, level);
     nodeToInsertInto.AddNodeEntry(entry);
     if (!(nodeToInsertInto is Leaf))
     {
         Node child = Cache.LookupNode(entry.Child);
         child.Parent = nodeToInsertInto.Address;
         Cache.WritePageData(child);
     }
     if (nodeToInsertInto.NodeEntries.Count > Constants.MAXIMUM_ENTRIES_PER_NODE)
     {
         List<Node> splitNodes = OverFlowTreatment(nodeToInsertInto, level);
         if (splitNodes != null)
         {
             RemoveFromParent(nodeToInsertInto);
             AdjustTree(splitNodes[0], splitNodes[1], level);
         }
         return;
     }
     AdjustTree(nodeToInsertInto, level);
 }
 protected virtual Single GetFutureOverlap(NodeEntry entry, NodeEntry insertionEntry, Node node)
 {
     MinimumBoundingBox overlapMinimumBoundingBox =
         CombineMinimumBoundingBoxes(entry.MinimumBoundingBox, insertionEntry.MinimumBoundingBox);
     return GetOverlap(insertionEntry, overlapMinimumBoundingBox, node);
 }
 protected virtual Single GetOverlap(NodeEntry insertionEntry, Node node)
 {
     return GetOverlap(insertionEntry, insertionEntry.MinimumBoundingBox, node);
 }
 protected override Node ChooseNode(Node node)
 {
     NodeEntry nodeEntry = new NodeEntry(node.CalculateMinimumBoundingBox(), node.Address);
     return ChooseNode(nodeEntry, TreeHeight - CalculateHeight(node) + 1);
 }
 protected virtual Node ChooseNode(NodeEntry entry, Int32 targetLevel)
 {
     Node insertionNode = Cache.LookupNode(Root);
     Int32 currentLevel = 1;
     while (!(insertionNode is Leaf) && currentLevel++ < targetLevel)
     {
         if (insertionNode.ChildType.Equals(typeof(Leaf)))
         {
             NodeEntry minOverlap = insertionNode.NodeEntries[0];
             Single minOverlapIncrease = GetFutureOverlap(entry, minOverlap, insertionNode) -
                 GetOverlap(minOverlap, insertionNode);
             foreach (NodeEntry nodeEntry in insertionNode.NodeEntries)
             {
                 Single overlapIncrease = GetFutureOverlap(entry, nodeEntry, insertionNode) -
                 GetOverlap(nodeEntry, insertionNode);
                 if (overlapIncrease == minOverlapIncrease)
                 {
                     Single nodeEntryFutureSize = GetFutureSize(entry.MinimumBoundingBox, nodeEntry.MinimumBoundingBox),
                     nodeEntrySize = nodeEntry.MinimumBoundingBox.GetArea(),
                     minOverlapFutureSize = GetFutureSize(entry.MinimumBoundingBox, minOverlap.MinimumBoundingBox),
                     minOverlapSize = minOverlap.MinimumBoundingBox.GetArea();
                     if ((nodeEntryFutureSize - nodeEntrySize == minOverlapFutureSize - minOverlapSize &&
                         nodeEntryFutureSize < minOverlapFutureSize
                         ) ||
                         nodeEntryFutureSize - nodeEntrySize < minOverlapFutureSize - minOverlapSize)
                     {
                         minOverlapIncrease = overlapIncrease;
                         minOverlap = nodeEntry;
                     }
                 }
                 else if (overlapIncrease < minOverlapIncrease)
                 {
                     minOverlapIncrease = overlapIncrease;
                     minOverlap = nodeEntry;
                 }
             }
             insertionNode = Cache.LookupNode(minOverlap.Child);
         }
         else
         {
             NodeEntry minEnlagement = insertionNode.NodeEntries[0];
             Single minAreaIncrease = GetFutureSize(entry.MinimumBoundingBox, minEnlagement.MinimumBoundingBox) -
                         minEnlagement.MinimumBoundingBox.GetArea();
             foreach (NodeEntry nodeEntry in insertionNode.NodeEntries)
             {
                 Single nodeEntryFutureSize = GetFutureSize(entry.MinimumBoundingBox, nodeEntry.MinimumBoundingBox),
                         nodeEntrySize = nodeEntry.MinimumBoundingBox.GetArea(),
                         minEnlargementFutureSize = GetFutureSize(entry.MinimumBoundingBox, minEnlagement.MinimumBoundingBox),
                         minEnlargementSize = minEnlagement.MinimumBoundingBox.GetArea();
                 if ((nodeEntryFutureSize - nodeEntrySize == minEnlargementFutureSize - minEnlargementSize &&
                     nodeEntryFutureSize < minEnlargementFutureSize
                     ) ||
                     nodeEntryFutureSize - nodeEntrySize < minEnlargementFutureSize - minEnlargementSize)
                 {
                     minAreaIncrease = nodeEntryFutureSize - nodeEntrySize;
                     minEnlagement = nodeEntry;
                 }
             }
             insertionNode = Cache.LookupNode(minEnlagement.Child);
         }
     }
     return insertionNode;
 }
Пример #7
0
 public BufferItem(NodeEntry entry, Operation operation)
 {
     this.entry = entry;
     this.operation = operation;
 }
 public void InsertEntry(NodeEntry entry)
 {
     Buffer.Add(new BufferItem(entry, Operation.Insert));
 }
 public void DeleteEntry(NodeEntry entry)
 {
     Buffer.Add(new BufferItem(entry, Operation.Delete));
 }
Пример #10
0
 public void AddNodeEntry(NodeEntry child)
 {
     nodeEntries.Add(child);
 }
Пример #11
0
 public void RemoveNodeEntry(NodeEntry child)
 {
     nodeEntries.Remove(child);
 }