This change adds a method for computing a treap node's successor
to the treap, which will simplify the implementation of algorithms
used for heap growth scavenging.
For #14045.
Change-Id: If2af3f2707dbcbef5fb6e42cb2712061f9da5129
Reviewed-on: https://go-review.googlesource.com/c/144718
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
return t.parent
}
+func (t *treapNode) succ() *treapNode {
+ if t.right != nil {
+ // If it has a right child, its successor will be
+ // its left-most right (grand)child.
+ t = t.right
+ for t.left != nil {
+ t = t.left
+ }
+ return t
+ }
+ // See pred.
+ for t.parent != nil && t.parent.left != t {
+ if t.parent.right != t {
+ println("runtime: predecessor t=", t, "t.spanKey=", t.spanKey)
+ throw("node is not its parent's child")
+ }
+ t = t.parent
+ }
+ return t.parent
+}
+
// isSpanInTreap is handy for debugging. One should hold the heap lock, usually
// mheap_.lock().
func (t *treapNode) isSpanInTreap(s *mspan) bool {