Lines Matching +full:initial +full:- +full:key

4  * SPDX-License-Identifier: Apache-2.0
37 * entries and does not interact with any user-provided keys or values.
45 * @param ... Variant-specific details for @p _config_type.
65 * entries and does not interact with any user-provided keys or values.
73 * @param ... Variant-specific details for @p _config_type.
143 * @param cookie User-specified variable
150 for (map->api->iter(map, &it); sys_hashmap_iterator_has_next(&it);) { in sys_hashmap_foreach()
152 cb(it.key, it.value, cookie); in sys_hashmap_foreach()
163 * @param cookie User-specified variable
168 map->api->clear(map, cb, cookie); in sys_hashmap_clear()
174 * Insert a new @p key - @p value pair into @p map.
177 * @param key Key to associate with @p value
178 * @param value Value to associate with @p key
179 * @param old_value Location to store the value previously associated with @p key or `NULL`
180 * @retval 0 if @p value was inserted for an existing key, in which case @p old_value will contain
182 * @retval 1 if a new entry was inserted for the @p key - @p value pair
183 * @retval -ENOMEM if memory allocation failed
184 * @retval -ENOSPC if the size limit has been reached
186 static inline int sys_hashmap_insert(struct sys_hashmap *map, uint64_t key, uint64_t value, in sys_hashmap_insert() argument
189 return map->api->insert(map, key, value, old_value); in sys_hashmap_insert()
195 * Erase the entry associated with key @p key, if one exists.
198 * @param key Key to remove from @p map
199 * @param value Location to store a potential value associated with @p key or `NULL`
202 * @retval false if @p map does not contain a value associated with @p key.
204 static inline bool sys_hashmap_remove(struct sys_hashmap *map, uint64_t key, uint64_t *value) in sys_hashmap_remove() argument
206 return map->api->remove(map, key, value); in sys_hashmap_remove()
212 * Look-up the @ref uint64_t associated with @p key, if one exists.
215 * @param key Key with which to search @p map
216 * @param value Location to store a potential value associated with @p key or `NULL`
218 * @retval true if @p map contains a value associated with @p key.
219 * @retval false if @p map does not contain a value associated with @p key.
221 static inline bool sys_hashmap_get(const struct sys_hashmap *map, uint64_t key, uint64_t *value) in sys_hashmap_get() argument
223 return map->api->get(map, key, value); in sys_hashmap_get()
227 * @brief Check if @p map contains a value associated with @p key
230 * @param key Key with which to search @p map
232 * @retval true if @p map contains a value associated with @p key.
233 * @retval false if @p map does not contain a value associated with @p key.
235 static inline bool sys_hashmap_contains_key(const struct sys_hashmap *map, uint64_t key) in sys_hashmap_contains_key() argument
237 return sys_hashmap_get(map, key, NULL); in sys_hashmap_contains_key()
249 return map->data->size; in sys_hashmap_size()
262 return map->data->size == 0; in sys_hashmap_is_empty()
268 * @note To convert the load factor to a floating-point value use
277 if (map->data->n_buckets == 0) { in sys_hashmap_load_factor()
281 return (map->data->size * 100) / map->data->n_buckets; in sys_hashmap_load_factor()
292 return map->data->n_buckets; in sys_hashmap_num_buckets()
303 * @note Users should call this prior to inserting a new key-value pair and after removing a
304 * key-value pair.
306 * @note The number of reserved entries is implementation-defined, but it is only considered
324 struct sys_hashmap_oa_lp_data *const data = (struct sys_hashmap_oa_lp_data *)map->data; in sys_hashmap_should_rehash()
325 const struct sys_hashmap_config *const config = map->config; in sys_hashmap_should_rehash()
327 /* All branchless calculations, so very cache-friendly */ in sys_hashmap_should_rehash()
330 size = data->size; in sys_hashmap_should_rehash()
336 n_buckets = data->n_buckets; in sys_hashmap_should_rehash()
337 /* initial number of buckets */ in sys_hashmap_should_rehash()
338 n_buckets += grow * (size == 1) * config->initial_n_buckets; in sys_hashmap_should_rehash()
348 __ASSERT_NO_MSG(new_num_buckets != &data->n_buckets); in sys_hashmap_should_rehash()
352 grow && (data->n_buckets == 0 || in sys_hashmap_should_rehash()
353 (size + num_reserved) * 100 / data->n_buckets > map->config->load_factor); in sys_hashmap_should_rehash()
355 shrink && (n_buckets == 0 || (size * 100) / n_buckets <= map->config->load_factor); in sys_hashmap_should_rehash()