diff --git a/datastructure/hashmap/hashmap.go b/datastructure/hashmap/hashmap.go index a7e5cd7..36118de 100644 --- a/datastructure/hashmap/hashmap.go +++ b/datastructure/hashmap/hashmap.go @@ -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