Get retrieves an element from the map under given hash key.
(key Key)
| 45 | |
| 46 | // Get retrieves an element from the map under given hash key. |
| 47 | func (m *Map[Key, Value]) Get(key Key) (Value, bool) { |
| 48 | hash := m.hasher(key) |
| 49 | |
| 50 | for element := m.store.Load().item(hash); element != nil; element = element.Next() { |
| 51 | if element.keyHash == hash && element.key == key { |
| 52 | return element.Value(), true |
| 53 | } |
| 54 | |
| 55 | if element.keyHash > hash { |
| 56 | return *new(Value), false |
| 57 | } |
| 58 | } |
| 59 | return *new(Value), false |
| 60 | } |
| 61 | |
| 62 | // GetOrInsert returns the existing value for the key if present. |
| 63 | // Otherwise, it stores and returns the given value. |