func (t *Mutable) ForEach(fn func(k, v []byte) bool) {
	var parents parentStack
	for node := t.root; node != nil; node = node.left {
		parents.Push(node)
	}
	for parents.Len() > 0 {
		node := parents.Pop()
		if !fn(node.key, node.value) {
			return
		}
		for node := node.right; node != nil; node = node.left {
			parents.Push(node)
		}
	}
}
ForEach invokes the passed function with every key/value pair in the treap
in ascending order.
package treap
import (
	"bytes"
	"math/rand"
)
type Mutable struct {
	root  *treapNode
	count int
	totalSize uint64
}
func (t *Mutable) Len() int {
	return t.count
}
func (t *Mutable) Size() uint64 {
	return t.totalSize
}
func (t *Mutable) get(key []byte) (*treapNode, *treapNode) {
	var parent *treapNode
	for node := t.root; node != nil; {
		compareResult := bytes.Compare(key, node.key)
		if compareResult < 0 {
			parent = node
			node = node.left
			continue
		}
		if compareResult > 0 {
			parent = node
			node = node.right
			continue
		}
		return node, parent
	}
	return nil, nil
}
func (t *Mutable) Has(key []byte) bool {
	if node, _ := t.get(key); node != nil {
		return true
	}
	return false
}
func (t *Mutable) Get(key []byte) []byte {
	if node, _ := t.get(key); node != nil {
		return node.value
	}
	return nil
}
func (t *Mutable) relinkGrandparent(node, parent, grandparent *treapNode) {
	if grandparent == nil {
		t.root = node
		return
	}
	if grandparent.left == parent {
		grandparent.left = node
	} else {
		grandparent.right = node
	}
}
func (t *Mutable) Put(key, value []byte) {
	if value == nil {
		value = emptySlice
	}
	if t.root == nil {
		node := newTreapNode(key, value, rand.Int())
		t.count = 1
		t.totalSize = nodeSize(node)
		t.root = node
		return
	}
	var parents parentStack
	var compareResult int
	for node := t.root; node != nil; {
		parents.Push(node)
		compareResult = bytes.Compare(key, node.key)
		if compareResult < 0 {
			node = node.left
			continue
		}
		if compareResult > 0 {
			node = node.right
			continue
		}
		t.totalSize -= uint64(len(node.value))
		t.totalSize += uint64(len(value))
		node.value = value
		return
	}
	node := newTreapNode(key, value, rand.Int())
	t.count++
	t.totalSize += nodeSize(node)
	parent := parents.At(0)
	if compareResult < 0 {
		parent.left = node
	} else {
		parent.right = node
	}
	for parents.Len() > 0 {
		parent = parents.Pop()
		if node.priority >= parent.priority {
			break
		}
		if parent.left == node {
			node.right, parent.left = parent, node.right
		} else {
			node.left, parent.right = parent, node.left
		}
		t.relinkGrandparent(node, parent, parents.At(0))
	}
}
func (t *Mutable) Delete(key []byte) {
	node, parent := t.get(key)
	if node == nil {
		return
	}
	if parent == nil && node.left == nil && node.right == nil {
		t.root = nil
		t.count = 0
		t.totalSize = 0
		return
	}
	var isLeft bool
	var child *treapNode
	for node.left != nil || node.right != nil {
		if node.left == nil {
			child = node.right
			isLeft = false
		} else if node.right == nil {
			child = node.left
			isLeft = true
		} else if node.left.priority >= node.right.priority {
			child = node.left
			isLeft = true
		} else {
			child = node.right
			isLeft = false
		}
		if isLeft {
			child.right, node.left = node, child.right
		} else {
			child.left, node.right = node, child.left
		}
		t.relinkGrandparent(child, node, parent)
		parent = child
	}
	if parent.right == node {
		parent.right = nil
	} else {
		parent.left = nil
	}
	t.count--
	t.totalSize -= nodeSize(node)
}