Lines Matching refs:map
33 static void sys_hashmap_sc_insert_entry(struct sys_hashmap *map, struct sys_hashmap_sc_entry *entry) in sys_hashmap_sc_insert_entry() argument
35 sys_dlist_t *buckets = map->data->buckets; in sys_hashmap_sc_insert_entry()
36 uint32_t hash = map->hash_func(&entry->key, sizeof(entry->key)); in sys_hashmap_sc_insert_entry()
38 sys_dlist_append(&buckets[hash % map->data->n_buckets], &entry->node); in sys_hashmap_sc_insert_entry()
39 ++map->data->size; in sys_hashmap_sc_insert_entry()
42 static void sys_hashmap_sc_insert_all(struct sys_hashmap *map, sys_dlist_t *list) in sys_hashmap_sc_insert_all() argument
49 sys_hashmap_sc_insert_entry(map, entry); in sys_hashmap_sc_insert_all()
53 static void sys_hashmap_sc_to_list(struct sys_hashmap *map, sys_dlist_t *list) in sys_hashmap_sc_to_list() argument
57 sys_dlist_t *buckets = map->data->buckets; in sys_hashmap_sc_to_list()
61 for (size_t i = 0; i < map->data->n_buckets; ++i) { in sys_hashmap_sc_to_list()
71 static int sys_hashmap_sc_rehash(struct sys_hashmap *map, bool grow) in sys_hashmap_sc_rehash() argument
78 if (!sys_hashmap_should_rehash(map, grow, 0, &new_n_buckets)) { in sys_hashmap_sc_rehash()
83 sys_hashmap_sc_to_list(map, &list); in sys_hashmap_sc_rehash()
86 new_buckets = (sys_dlist_t *)map->alloc_func(map->data->buckets, in sys_hashmap_sc_rehash()
90 sys_hashmap_sc_insert_all(map, &list); in sys_hashmap_sc_rehash()
95 map->data->size = 0; in sys_hashmap_sc_rehash()
96 map->data->buckets = new_buckets; in sys_hashmap_sc_rehash()
97 map->data->n_buckets = new_n_buckets; in sys_hashmap_sc_rehash()
99 bucket = &((sys_dlist_t *)(map->data->buckets))[i]; in sys_hashmap_sc_rehash()
104 sys_hashmap_sc_insert_all(map, &list); in sys_hashmap_sc_rehash()
109 static struct sys_hashmap_sc_entry *sys_hashmap_sc_find(const struct sys_hashmap *map, uint64_t key) in sys_hashmap_sc_find() argument
116 if (map->data->n_buckets == 0) { in sys_hashmap_sc_find()
120 __ASSERT_NO_MSG(map->data->size > 0); in sys_hashmap_sc_find()
122 hash = map->hash_func(&key, sizeof(key)); in sys_hashmap_sc_find()
123 buckets = (sys_dlist_t *)map->data->buckets; in sys_hashmap_sc_find()
124 bucket = &buckets[hash % map->data->n_buckets]; in sys_hashmap_sc_find()
140 const struct sys_hashmap *map = it->map; in sys_hashmap_sc_iter_next() local
141 sys_dlist_t *buckets = map->data->buckets; in sys_hashmap_sc_iter_next()
143 __ASSERT(it->size == map->data->size, "Concurrent modification!"); in sys_hashmap_sc_iter_next()
152 for (bucket = it->state; bucket < &buckets[map->data->n_buckets]; ++bucket) { in sys_hashmap_sc_iter_next()
180 static void sys_hashmap_sc_iter(const struct sys_hashmap *map, struct sys_hashmap_iterator *it) in sys_hashmap_sc_iter() argument
182 it->map = map; in sys_hashmap_sc_iter()
184 it->state = map->data->buckets; in sys_hashmap_sc_iter()
188 *((size_t *)&it->size) = map->data->size; in sys_hashmap_sc_iter()
191 static void sys_hashmap_sc_clear(struct sys_hashmap *map, sys_hashmap_callback_t cb, void *cookie) in sys_hashmap_sc_clear() argument
196 sys_hashmap_sc_to_list(map, &list); in sys_hashmap_sc_clear()
199 if (map->data->buckets != NULL) { in sys_hashmap_sc_clear()
200 map->alloc_func(map->data->buckets, 0); in sys_hashmap_sc_clear()
201 map->data->buckets = NULL; in sys_hashmap_sc_clear()
204 map->data->n_buckets = 0; in sys_hashmap_sc_clear()
205 map->data->size = 0; in sys_hashmap_sc_clear()
216 map->alloc_func(entry, 0); in sys_hashmap_sc_clear()
220 static int sys_hashmap_sc_insert(struct sys_hashmap *map, uint64_t key, uint64_t value, in sys_hashmap_sc_insert() argument
226 entry = sys_hashmap_sc_find(map, key); in sys_hashmap_sc_insert()
237 ret = sys_hashmap_sc_rehash(map, true); in sys_hashmap_sc_insert()
242 entry = map->alloc_func(NULL, sizeof(*entry)); in sys_hashmap_sc_insert()
248 sys_hashmap_sc_insert_entry(map, entry); in sys_hashmap_sc_insert()
253 static bool sys_hashmap_sc_remove(struct sys_hashmap *map, uint64_t key, uint64_t *value) in sys_hashmap_sc_remove() argument
258 entry = sys_hashmap_sc_find(map, key); in sys_hashmap_sc_remove()
268 --map->data->size; in sys_hashmap_sc_remove()
270 ret = sys_hashmap_sc_rehash(map, false); in sys_hashmap_sc_remove()
275 map->alloc_func(entry, 0); in sys_hashmap_sc_remove()
280 static bool sys_hashmap_sc_get(const struct sys_hashmap *map, uint64_t key, uint64_t *value) in sys_hashmap_sc_get() argument
284 entry = sys_hashmap_sc_find(map, key); in sys_hashmap_sc_get()