t9902: mingw-specific fix for gitfile link files
[alt-git.git] / hashmap.h
bloba816ad47b14d2d377ba0e03a3f401ed36a56efa8
1 #ifndef HASHMAP_H
2 #define HASHMAP_H
4 /*
5 * Generic implementation of hash-based key-value mappings.
6 * See Documentation/technical/api-hashmap.txt.
7 */
9 /* FNV-1 functions */
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);
16 /* data structures */
18 struct hashmap_entry {
19 struct hashmap_entry *next;
20 unsigned int hash;
23 typedef int (*hashmap_cmp_fn)(const void *entry, const void *entry_or_key,
24 const void *keydata);
26 struct hashmap {
27 struct hashmap_entry **table;
28 hashmap_cmp_fn cmpfn;
29 unsigned int size, tablesize, grow_at, shrink_at;
32 struct hashmap_iter {
33 struct hashmap *map;
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,
41 size_t initial_size);
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;
49 e->hash = hash;
50 e->next = NULL;
52 extern void *hashmap_get(const struct hashmap *map, const void *key,
53 const void *keydata);
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,
58 const void *keydata);
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);
71 #endif