parent
a67e1d12db
commit
e4f0311afa
14
pmap.go
14
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)
|
||||
|
|
Loading…
Reference in New Issue