5 * Generic implementation of hash-based key-value mappings.
6 * See Documentation/technical/api-hashmap.txt.
11 extern unsigned int strhash(const char *buf
);
12 extern unsigned int strihash(const char *buf
);
13 extern unsigned int memhash(const void *buf
, size_t len
);
14 extern unsigned int memihash(const void *buf
, size_t len
);
18 struct hashmap_entry
{
19 struct hashmap_entry
*next
;
23 typedef int (*hashmap_cmp_fn
)(const void *entry
, const void *entry_or_key
,
27 struct hashmap_entry
**table
;
29 unsigned int size
, tablesize
, grow_at
, shrink_at
;
34 struct hashmap_entry
*next
;
35 unsigned int tablepos
;
38 /* hashmap functions */
40 extern void hashmap_init(struct hashmap
*map
, hashmap_cmp_fn equals_function
,
42 extern void hashmap_free(struct hashmap
*map
, int free_entries
);
44 /* hashmap_entry functions */
46 static inline void hashmap_entry_init(void *entry
, unsigned int hash
)
48 struct hashmap_entry
*e
= entry
;
52 extern void *hashmap_get(const struct hashmap
*map
, const void *key
,
54 extern void *hashmap_get_next(const struct hashmap
*map
, const void *entry
);
55 extern void hashmap_add(struct hashmap
*map
, void *entry
);
56 extern void *hashmap_put(struct hashmap
*map
, void *entry
);
57 extern void *hashmap_remove(struct hashmap
*map
, const void *key
,
60 /* hashmap_iter functions */
62 extern void hashmap_iter_init(struct hashmap
*map
, struct hashmap_iter
*iter
);
63 extern void *hashmap_iter_next(struct hashmap_iter
*iter
);
64 static inline void *hashmap_iter_first(struct hashmap
*map
,
65 struct hashmap_iter
*iter
)
67 hashmap_iter_init(map
, iter
);
68 return hashmap_iter_next(iter
);