1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-15 10:12:29 +08:00

feat: add Delete method for hashmap

This commit is contained in:
dudaodong
2022-08-23 15:05:32 +08:00
parent 0cb89f4f46
commit 312dcab369
2 changed files with 45 additions and 1 deletions

View File

@@ -78,6 +78,28 @@ func (hm *HashMap) putValue(hash uint64, key, value any) any {
return value
}
// Delete key value in hashmap
// func (hm *HashMap) Delete(key any) {
// hm.deleteValue(hm.hash(key))
// }
func (hm *HashMap) Delete(key any) {
hash := hm.hash(key)
node := hm.table[hash]
if node == nil {
return
}
hm.table = append(hm.table[:hash], hm.table[hash+1:]...)
hm.size--
}
// Contains checks if given key is in hashmap or not
func (hm *HashMap) Contains(key any) bool {
node := hm.table[hm.hash(key)]
return node != nil
}
func (hm *HashMap) resize() {
hm.capacity <<= 1