Commit 239341f3 authored by Michael Anthony Knyszek's avatar Michael Anthony Knyszek Committed by Michael Knyszek

runtime: add successor method to treap

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: default avatarAustin Clements <austin@google.com>
parent 5dd4d1f8
...@@ -78,6 +78,27 @@ func (t *treapNode) pred() *treapNode { ...@@ -78,6 +78,27 @@ func (t *treapNode) pred() *treapNode {
return t.parent 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 // isSpanInTreap is handy for debugging. One should hold the heap lock, usually
// mheap_.lock(). // mheap_.lock().
func (t *treapNode) isSpanInTreap(s *mspan) bool { func (t *treapNode) isSpanInTreap(s *mspan) bool {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment