1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

feat: add Iterate for hashmap datastructure

This commit is contained in:
dudaodong
2022-10-10 15:25:30 +08:00
parent 604acd9b07
commit fab24c8d12

View File

@@ -93,6 +93,28 @@ func (hm *HashMap) Contains(key any) bool {
return node != nil
}
// Iterate executes iteratee funcation for every key and value pair of hashmap
func (hm *HashMap) Iterate(iteratee func(key, value any)) {
if hm.size > 0 {
for _, item := range hm.table {
iteratee(item.key, item.value)
}
}
}
// Keys returns a slice of the hashmap's keys
// func (hm *HashMap) Keys() []any {
// keys := make([]any, int(hm.size))
// var i int
// for k := range m {
// keys[i] = k
// i++
// }
// return keys
// }
func (hm *HashMap) resize() {
hm.capacity <<= 1