]> git.ipfire.org Git - thirdparty/git.git/blame - hashmap.h
test-hashmap.c: drop unnecessary #includes
[thirdparty/git.git] / hashmap.h
CommitLineData
6a364ced
KB
1#ifndef HASHMAP_H
2#define HASHMAP_H
3
4/*
5 * Generic implementation of hash-based key-value mappings.
6 * See Documentation/technical/api-hashmap.txt.
7 */
8
9/* FNV-1 functions */
10
11extern unsigned int strhash(const char *buf);
12extern unsigned int strihash(const char *buf);
13extern unsigned int memhash(const void *buf, size_t len);
14extern unsigned int memihash(const void *buf, size_t len);
15
16/* data structures */
17
18struct hashmap_entry {
19 struct hashmap_entry *next;
20 unsigned int hash;
21};
22
23typedef int (*hashmap_cmp_fn)(const void *entry, const void *entry_or_key,
24 const void *keydata);
25
26struct hashmap {
27 struct hashmap_entry **table;
28 hashmap_cmp_fn cmpfn;
29 unsigned int size, tablesize, grow_at, shrink_at;
30};
31
32struct hashmap_iter {
33 struct hashmap *map;
34 struct hashmap_entry *next;
35 unsigned int tablepos;
36};
37
38/* hashmap functions */
39
40extern void hashmap_init(struct hashmap *map, hashmap_cmp_fn equals_function,
41 size_t initial_size);
42extern void hashmap_free(struct hashmap *map, int free_entries);
43
44/* hashmap_entry functions */
45
46static inline void hashmap_entry_init(void *entry, int hash)
47{
48 struct hashmap_entry *e = entry;
49 e->hash = hash;
50 e->next = NULL;
51}
52extern void *hashmap_get(const struct hashmap *map, const void *key,
53 const void *keydata);
54extern void *hashmap_get_next(const struct hashmap *map, const void *entry);
55extern void hashmap_add(struct hashmap *map, void *entry);
56extern void *hashmap_put(struct hashmap *map, void *entry);
57extern void *hashmap_remove(struct hashmap *map, const void *key,
58 const void *keydata);
59
60/* hashmap_iter functions */
61
62extern void hashmap_iter_init(struct hashmap *map, struct hashmap_iter *iter);
63extern void *hashmap_iter_next(struct hashmap_iter *iter);
64static inline void *hashmap_iter_first(struct hashmap *map,
65 struct hashmap_iter *iter)
66{
67 hashmap_iter_init(map, iter);
68 return hashmap_iter_next(iter);
69}
70
71#endif