From e4f0311afa1c4547cfcd26555d1b7ac558a7789a Mon Sep 17 00:00:00 2001 From: magical Date: Sun, 23 Jan 2022 05:38:36 +0000 Subject: [PATCH] change collision back to a pointer type this is better for inplace_insert --- pmap.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pmap.go b/pmap.go index 9f7183d..88ff72d 100644 --- a/pmap.go +++ b/pmap.go @@ -100,7 +100,7 @@ func (n *node) getNode(shift, hash uint32, key Key) interface{} { return n.child[n.index(m)] } -func (n collision) getNode(hash uint32, key Key) interface{} { +func (n *collision) getNode(hash uint32, key Key) interface{} { if hash != n.hash { return nil } @@ -128,7 +128,7 @@ func lookup(root interface{}, hash uint32, key Key, zero Value) (Value, bool) { case *node: cur = n.getNode(shift, hash, key) shift += nodeShift - case collision: + case *collision: cur = n.getNode(hash, key) default: panic("pmap: unhandled case in lookup") @@ -168,7 +168,7 @@ func insert(n interface{}, hash uint32, key Key, val Value, hashFn HashFunc) (ne } else if h := hashFn(n.k); h == hash { // collision added = true - return collision{hash, []leaf{{key, val}, n}} + return &collision{hash, []leaf{{key, val}, n}} } else { if h>>shift == hash>>shift { panic("pmap: infinite loop in insert") @@ -206,7 +206,7 @@ func insert(n interface{}, hash uint32, key Key, val Value, hashFn HashFunc) (ne x.check() return x } - case collision: + case *collision: if n.hash != hash { // not a collision, so we must still have some hash bits left // split the trie @@ -221,12 +221,12 @@ func insert(n interface{}, hash uint32, key Key, val Value, hashFn HashFunc) (ne copy(l[1:], n.leaf[:i]) copy(l[1+i:], n.leaf[i+1:]) added = false - return collision{hash, l} + return &collision{hash, l} } } // new collision added = true - return collision{hash, append([]leaf{{key, val}}, n.leaf...)} + return &collision{hash, append([]leaf{{key, val}}, n.leaf...)} default: panic("pmap: unhandled case in insert") } @@ -272,7 +272,7 @@ func (p pmap) stats() stats { s.emptySlots++ } } - case collision: + case *collision: s.count++ s.collisionCount++ s.collidedKeys += len(n.leaf)