make collision a value type

doesn't really matter, and it's basically just a slice header
master
magical 2022-01-23 01:39:18 +00:00
parent bb1aa352aa
commit 9553b9a9e4
1 changed files with 8 additions and 7 deletions

15
pmap.go
View File

@ -82,7 +82,7 @@ func (m *node) getNode(shift, hash uint32, key Key) interface{} {
return m.child[i]
}
func (m *collision) getNode(hash uint32, key Key) interface{} {
func (m collision) getNode(hash uint32, key Key) interface{} {
if hash != m.hash {
return nil
}
@ -109,7 +109,7 @@ func lookup(root interface{}, shift, hash uint32, key Key, zero Key) (Value, boo
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")
@ -148,7 +148,7 @@ func insert(n interface{}, shift, hash uint32, key Key, val Value, hashFn HashFu
} 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")
@ -172,7 +172,7 @@ func insert(n interface{}, shift, hash uint32, key Key, val Value, hashFn HashFu
x.child[idx] = c
x.bitmap |= 1 << idx
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
@ -187,12 +187,12 @@ func insert(n interface{}, shift, hash uint32, key Key, val Value, hashFn HashFu
l = append(l, n.leaf[:i]...)
l = append(l, 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")
}
@ -237,7 +237,8 @@ func (p pmap) stats() stats {
visit(n.child[i], h+1)
}
}
case *collision:
case collision:
s.count++
s.collisionCount++
s.collidedKeys += len(n.leaf)
default: