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 {
if key == m.leaf[i].k {
return m.leaf[i].v
return m.leaf[i]
}
}
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 {
// 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")
@ -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+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")
}