Remove removes a single entry from the store. Remove does nothing if key doesn't exist in the store.
(key K)
| 59 | // |
| 60 | // Remove does nothing if key doesn't exist in the store. |
| 61 | func (s *Store[K, T]) Remove(key K) { |
| 62 | s.mu.Lock() |
| 63 | defer s.mu.Unlock() |
| 64 | |
| 65 | delete(s.data, key) |
| 66 | s.deleted++ |
| 67 | |
| 68 | // reassign to a new map so that the old one can be gc-ed because it doesn't shrink |
| 69 | // |
| 70 | // @todo remove after https://github.com/golang/go/issues/20135 |
| 71 | if s.deleted >= ShrinkThreshold { |
| 72 | newData := make(map[K]T, len(s.data)) |
| 73 | for k, v := range s.data { |
| 74 | newData[k] = v |
| 75 | } |
| 76 | s.data = newData |
| 77 | s.deleted = 0 |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // Has checks if element with the specified key exist or not. |
| 82 | func (s *Store[K, T]) Has(key K) bool { |
no outgoing calls