• Home
  • Raw
  • Download

Lines Matching +full:key +full:- +full:value

1 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
4 * Generic non-thread safe hash map implementation.
23 return (h * 11400714819323198485llu) >> (__SIZEOF_LONG_LONG__ * 8 - bits); in hash_bits()
25 return (h * 2654435769lu) >> (__SIZEOF_LONG__ * 8 - bits); in hash_bits()
31 /* generic C-string hashing function */
43 typedef size_t (*hashmap_hash_fn)(const void *key, void *ctx);
47 const void *key; member
48 void *value; member
86 * - HASHMAP_ADD - only add key/value if key doesn't exist yet;
87 * - HASHMAP_SET - add key/value pair if key doesn't exist yet; otherwise,
88 * update value;
89 * - HASHMAP_UPDATE - update value, if key already exists; otherwise, do
90 * nothing and return -ENOENT;
91 * - HASHMAP_APPEND - always add key/value pair, even if key already exists.
93 * associated with the same key. Most useful read API for such hashmap is
95 * used, it will return last inserted key/value entry (first in a bucket
106 * hashmap__insert() adds key/value entry w/ various semantics, depending on
107 * provided strategy value. If a given key/value pair replaced already
108 * existing key/value pair, both old key and old value will be returned
112 int hashmap__insert(struct hashmap *map, const void *key, void *value,
117 const void *key, void *value) in hashmap__add() argument
119 return hashmap__insert(map, key, value, HASHMAP_ADD, NULL, NULL); in hashmap__add()
123 const void *key, void *value, in hashmap__set() argument
126 return hashmap__insert(map, key, value, HASHMAP_SET, in hashmap__set()
131 const void *key, void *value, in hashmap__update() argument
134 return hashmap__insert(map, key, value, HASHMAP_UPDATE, in hashmap__update()
139 const void *key, void *value) in hashmap__append() argument
141 return hashmap__insert(map, key, value, HASHMAP_APPEND, NULL, NULL); in hashmap__append()
144 bool hashmap__delete(struct hashmap *map, const void *key,
147 bool hashmap__find(const struct hashmap *map, const void *key, void **value);
150 * hashmap__for_each_entry - iterate over all entries in hashmap
156 for (bkt = 0; bkt < map->cap; bkt++) \
157 for (cur = map->buckets[bkt]; cur; cur = cur->next)
160 * hashmap__for_each_entry_safe - iterate over all entries in hashmap, safe
168 for (bkt = 0; bkt < map->cap; bkt++) \
169 for (cur = map->buckets[bkt]; \
170 cur && ({tmp = cur->next; true; }); \
174 * hashmap__for_each_key_entry - iterate over entries associated with given key
177 * @key: key to iterate entries for
180 for (cur = map->buckets \
181 ? map->buckets[hash_bits(map->hash_fn((_key), map->ctx), map->cap_bits)] \
184 cur = cur->next) \
185 if (map->equal_fn(cur->key, (_key), map->ctx))
188 for (cur = map->buckets \
189 ? map->buckets[hash_bits(map->hash_fn((_key), map->ctx), map->cap_bits)] \
191 cur && ({ tmp = cur->next; true; }); \
193 if (map->equal_fn(cur->key, (_key), map->ctx))