public static float Proximity(Node a, Leaf b) { return Proximity(a.bb, b.bb); }
public override void MarkLeafQuery(Leaf leaf, bool left, cpBBTree tree, Func<object, object, ulong, object, ulong> func) { if (cp.bbTreeIntersectsNode(leaf, this)) { if (left) { tree.PairInsert(leaf, this); } else { if (this.stamp < leaf.stamp) tree.PairInsert(this, leaf); if (func != null) func(leaf.obj, this.obj, (ulong)leaf.stamp, null); } } }
public static float Proximity(Node a, Leaf b) { return(Proximity(a.bb, b.bb)); }
public Node SubtreeRemove(Node subtree, Leaf leaf) { if (leaf == subtree) { return null; } else { var parent = leaf.parent; if (parent == subtree) { var other = subtree.Other(leaf); other.parent = subtree.parent; //NodeRecycle(); subtree.Recycle(this); return other; } else { if (parent == null) return null; parent.parent.ReplaceChild(parent, parent.Other(leaf), this); return subtree; } } }
public bool TryGetValue(ulong key, out Leaf value) { return leaves.TryGetValue(key, out value); }
public void LeafUpdateWrap(Leaf leaf) { leaf.Update(this); }
public Node SubtreeInsert(Node subtree, Leaf leaf) { if (subtree == null) { return leaf; } else if (subtree.isLeaf) { return MakeNode(leaf, subtree); } else { var cost_a = subtree.B.bbArea() + subtree.A.bb.MergedArea(leaf.bb); var cost_b = subtree.A.bbArea() + subtree.B.bb.MergedArea(leaf.bb); if (cost_a == cost_b) { cost_a = subtree.A.bb.Proximity(leaf.bb); cost_b = subtree.B.bb.Proximity(leaf.bb); } if (cost_b < cost_a) { subtree.SetB(SubtreeInsert(subtree.B, leaf)); } else { subtree.SetA(SubtreeInsert(subtree.A, leaf)); } // subtree.bb = bbMerge(subtree.bb, leaf.bb); subtree.bb.l = Math.Min(subtree.bb.l, leaf.bb.l); subtree.bb.b = Math.Min(subtree.bb.b, leaf.bb.b); subtree.bb.r = Math.Max(subtree.bb.r, leaf.bb.r); subtree.bb.t = Math.Max(subtree.bb.t, leaf.bb.t); return subtree; } }
public Leaf Insert(ulong hashid, IObjectBox obj) { Leaf leaf = new Leaf(this, obj); this.leaves.Add(hashid, leaf); Node root = this.root; this.root = SubtreeInsert(root, leaf); //this.root = cp.subtreeInsert(root, leaf, this); leaf.STAMP = GetStamp(); leaf.AddPairs(this); //.AddPairs(this); IncrementStamp(); return leaf; }
public bool Contains(Leaf obj) { foreach (var item in leaves) { if (item.Value == obj) return true; } return false; }
public virtual void MarkLeafQuery(Leaf leaf, bool left, cpBBTree tree, Func<object, object, ulong, object, ulong> func) { if (cp.bbTreeIntersectsNode(leaf, this)) { this.A.MarkLeafQuery(leaf, left, tree, func); this.B.MarkLeafQuery(leaf, left, tree, func); } }
public bool TryGetValue(ulong key, out Leaf value) { return(leaves.TryGetValue(key, out value)); }