Whamcloud - gitweb
tst_libext2fs: Avoid multiple definition of global variables
[tools/e2fsprogs.git] / lib / ext2fs / hashmap.h
1 #ifndef HASHMAP_H
2 # define HASHMAP_H
3
4 # include <stdlib.h>
5 # include <stdint.h>
6
7 #ifndef __GNUC_PREREQ
8 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
9 #define __GNUC_PREREQ(maj, min) \
10         ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
11 #else
12 #define __GNUC_PREREQ(maj, min) 0
13 #endif
14 #endif
15
16 struct ext2fs_hashmap;
17
18 struct ext2fs_hashmap_entry {
19         void *data;
20         const void *key;
21         size_t key_len;
22         struct ext2fs_hashmap_entry *next;
23         struct ext2fs_hashmap_entry *list_next;
24         struct ext2fs_hashmap_entry *list_prev;
25 };
26
27 struct ext2fs_hashmap *ext2fs_hashmap_create(
28                                 uint32_t(*hash_fct)(const void*, size_t),
29                                 void(*free_fct)(void*), size_t size);
30 void ext2fs_hashmap_add(struct ext2fs_hashmap *h, void *data, const void *key,
31                         size_t key_len);
32 void *ext2fs_hashmap_lookup(struct ext2fs_hashmap *h, const void *key,
33                             size_t key_len);
34 void *ext2fs_hashmap_iter_in_order(struct ext2fs_hashmap *h,
35                                    struct ext2fs_hashmap_entry **it);
36 void ext2fs_hashmap_del(struct ext2fs_hashmap *h,
37                         struct ext2fs_hashmap_entry *e);
38 void ext2fs_hashmap_free(struct ext2fs_hashmap *h);
39
40 uint32_t ext2fs_djb2_hash(const void *str, size_t size);
41
42 #endif /* !HASHMAP_H */