fix collision nodes

master
magical 2022-01-23 00:24:21 +00:00
parent 9ed6f8c536
commit 223c046887
1 changed files with 4 additions and 4 deletions

View File

@ -95,7 +95,7 @@ func (m *collision) getNode(hash uint32, key Key) interface{} {
} }
for i := range m.leaf { for i := range m.leaf {
if key == m.leaf[i].k { if key == m.leaf[i].k {
return m.leaf[i].v return m.leaf[i]
} }
} }
return nil return nil
@ -157,7 +157,7 @@ func insert(n interface{}, shift, hash uint32, key Key, val Value, hashFn hashFu
} else if h := hashFn(n.k); h == hash { } else if h := hashFn(n.k); h == hash {
// collision // collision
added = true added = true
return collision{hash, []leaf{{key, val}, n}} return &collision{hash, []leaf{{key, val}, n}}
} else { } else {
if h>>shift == hash>>shift { if h>>shift == hash>>shift {
panic("pmap: infinite loop in insert") panic("pmap: infinite loop in insert")
@ -196,12 +196,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]...)
l = append(l, n.leaf[i+1:]...) l = append(l, n.leaf[i+1:]...)
added = false added = false
return collision{hash, l} return &collision{hash, l}
} }
} }
// new collision // new collision
added = true added = true
return collision{hash, append([]leaf{{key, val}}, n.leaf...)} return &collision{hash, append([]leaf{{key, val}}, n.leaf...)}
default: default:
panic("pmap: unhandled case in insert") panic("pmap: unhandled case in insert")
} }