adds (e, v) to the map, returns the current value when e already exists
(e Hashable, v interface{})
| 48 | |
| 49 | // adds (e, v) to the map, returns the current value when e already exists |
| 50 | func (m Map) Add(e Hashable, v interface{}) interface{} { |
| 51 | h := e.HashCode() |
| 52 | s, ok := m[h] |
| 53 | if !ok { |
| 54 | s = make([]mapEntry, 0, 1) |
| 55 | } else { |
| 56 | for _, x := range s { |
| 57 | if x.e.EqualI(e) { |
| 58 | return x.v |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | m[h] = append(s, mapEntry{ |
| 63 | e: e, |
| 64 | v: v, |
| 65 | }) |
| 66 | return v |
| 67 | } |
| 68 | |
| 69 | // filter (e, v) in the map using f(v), returns the keys |
| 70 | func (m Map) FilterKeys(f func(interface{}) bool) []Hashable { |