mheap_.treapalloc.free(unsafe.Pointer(t))
}
-// find searches for, finds, and returns the treap node containing the
-// smallest span that can hold npages. If no span has at least npages
-// it returns nil.
+// find searches for, finds, and returns the treap iterator representing
+// the position of the smallest span that can hold npages. If no span has
+// at least npages it returns an invalid iterator.
// This is slightly more complicated than a simple binary tree search
// since if an exact match is not found the next larger node is
// returned.
-func (root *mTreap) find(npages uintptr) *treapNode {
+func (root *mTreap) find(npages uintptr) treapIter {
t := root.treap
for t != nil {
if t.spanKey == nil {
} else if t.left != nil && t.left.npagesKey >= npages {
t = t.left
} else {
- return t
+ return treapIter{t}
}
}
- return nil
+ return treapIter{}
}
// removeSpan searches for, finds, deletes span along with
// Note that we want the _smaller_ free span, i.e. the free span
// closer in size to the amount we requested (npage).
var s *mspan
- if tf != nil && (ts == nil || tf.spanKey.npages <= ts.spanKey.npages) {
- s = tf.spanKey
- h.free.removeNode(tf)
- } else if ts != nil && (tf == nil || tf.spanKey.npages > ts.spanKey.npages) {
- s = ts.spanKey
- h.scav.removeNode(ts)
+ if tf.valid() && (!ts.valid() || tf.span().npages <= ts.span().npages) {
+ s = tf.span()
+ h.free.erase(tf)
+ } else if ts.valid() && (!tf.valid() || tf.span().npages > ts.span().npages) {
+ s = ts.span()
+ h.scav.erase(ts)
}
return s
}