get value if found, otherwise return default_value. @param key The key to look up @param default_value Value to return if key not found @return The stored value or default_value
| 241 | /// @param default_value Value to return if key not found |
| 242 | /// @return The stored value or default_value |
| 243 | FORY_ALWAYS_INLINE V get_or_default(K key, V default_value) const { |
| 244 | if (FORY_PREDICT_FALSE(key == k_empty)) |
| 245 | return default_value; |
| 246 | Entry *entries = entries_.get(); |
| 247 | size_t mask = mask_; |
| 248 | size_t idx = place(key); |
| 249 | while (true) { |
| 250 | Entry *entry = &entries[idx]; |
| 251 | K k = entry->key; |
| 252 | if (k == key) |
| 253 | return entry->value; |
| 254 | if (k == k_empty) |
| 255 | return default_value; |
| 256 | idx = (idx + 1) & mask; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | FORY_ALWAYS_INLINE bool contains(K key) const { |
| 261 | if (FORY_PREDICT_FALSE(key == k_empty)) |