// Insert to insert a key-payload pair into tree
Insert to insert a key-payload pair into tree
// Insert to insert a key - payload pair into tree
func (rb *RBTree) Insert(key int, payload interface{}) {
	newNode := &treeNode{rb.nil(), rb.nil(), rb.nil(), key, payload, rbRed}
	defer func() {
		rb.count++
		rb.insertFixup(newNode) 
	}()
	if rb.root == rb.nil() {
		rb.root = newNode
		return
	}
	node := rb.root
	for node != rb.nil() {
		if newNode.key < node.key {
			if node.leftChild == rb.nil() {
				node.leftChild = newNode
				break
			}
			node = node.leftChild
		} else { 
			if node.rightChild == rb.nil() {
				node.rightChild = newNode
				break
			}
			node = node.rightChild
		}
	}
	newNode.parent = node
}
func ( rb * RBTree ) Insert ( key int , payload interface { } ) { newNode := & treeNode { rb . nil ( ) , rb . nil ( ) , rb . nil ( ) , key , payload , rbRed } defer func ( ) { rb . count ++ rb . insertFixup ( newNode ) } ( ) if rb . root == rb . nil ( ) { rb . root = newNode return } node := rb . root for node != rb . nil ( ) { if newNode . key < node . key { if node . leftChild == rb . nil ( ) { node . leftChild = newNode break } node = node . leftChild } else { if node . rightChild == rb . nil ( ) { node . rightChild = newNode break } node = node . rightChild } } newNode . parent = node }
Insert to insert a key-payload pair into tree
Insert to insert a key - payload pair into tree
// fixup red-black tree before return // >= can allow multiple nodes have same key