export RBTree

master
Chakib Benziane 7 years ago
parent 53ecaf0d62
commit 1ac30a6923

@ -26,17 +26,17 @@ type rbTreeNode struct {
collisions map[interface{}]interface{} collisions map[interface{}]interface{}
} }
type rbTree struct { type RBTree struct {
root *rbTreeNode root *rbTreeNode
hashFunc func(interface{}) uint64 hashFunc func(interface{}) uint64
} }
// New creates a new hash map with supplied hashing function // New creates a new hash map with supplied hashing function
func New(hashFunc func(i interface{}) uint64) *rbTree { func New(hashFunc func(i interface{}) uint64) *RBTree {
return &rbTree{hashFunc: hashFunc} return &RBTree{hashFunc: hashFunc}
} }
func (rb *rbTree) Insert(key, value interface{}) { func (rb *RBTree) Insert(key, value interface{}) {
keyHash := rb.hashFunc(key) keyHash := rb.hashFunc(key)
child := &rbTreeNode{ child := &rbTreeNode{
@ -144,7 +144,7 @@ func insertCase5(node *rbTreeNode) {
} }
} }
func (rb *rbTree) Get(key interface{}) (value interface{}, found bool) { func (rb *RBTree) Get(key interface{}) (value interface{}, found bool) {
if rb.root == nil { if rb.root == nil {
return nil, false return nil, false
} }
@ -164,7 +164,7 @@ func (rb *rbTree) Get(key interface{}) (value interface{}, found bool) {
return return
} }
func (rb *rbTree) Remove(key interface{}) (found bool) { func (rb *RBTree) Remove(key interface{}) (found bool) {
keyHash := rb.hashFunc(key) keyHash := rb.hashFunc(key)
node, found := findByKeyHash(rb.root, key, keyHash) node, found := findByKeyHash(rb.root, key, keyHash)
if !found { if !found {

Loading…
Cancel
Save