]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add successor method to treap
authorMichael Anthony Knyszek <mknyszek@google.com>
Thu, 25 Oct 2018 18:18:53 +0000 (18:18 +0000)
committerMichael Knyszek <mknyszek@google.com>
Tue, 30 Oct 2018 15:27:42 +0000 (15:27 +0000)
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>
src/runtime/mgclarge.go

index 7bc56259aea621c7859c0a6aa51121f153ba6163..ec4f7ead7102cb48a3985aeca3eb301da4f4210f 100644 (file)
@@ -78,6 +78,27 @@ func (t *treapNode) pred() *treapNode {
        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 {