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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user