Smart Home firewall
Profile-based Smart Home firewall
hashmap.h
1 // Copyright 2020 Joshua J Baker. All rights reserved.
2 // Use of this source code is governed by an MIT-style
3 // license that can be found in the LICENSE file.
4 
5 #ifndef HASHMAP_H
6 #define HASHMAP_H
7 
8 #include <stdbool.h>
9 #include <stddef.h>
10 #include <stdint.h>
11 
12 
13 #if defined(__cplusplus)
14 extern "C" {
15 #endif /* __cplusplus */
16 
17 typedef struct hashmap hashmap;
18 
19 struct hashmap *hashmap_new(size_t elsize, size_t cap, uint64_t seed0,
20  uint64_t seed1,
21  uint64_t (*hash)(const void *item, uint64_t seed0, uint64_t seed1),
22  int (*compare)(const void *a, const void *b, void *udata),
23  void (*elfree)(void *item),
24  void *udata);
25 
26 struct hashmap *hashmap_new_with_allocator(void *(*malloc)(size_t),
27  void *(*realloc)(void *, size_t), void (*free)(void*), size_t elsize,
28  size_t cap, uint64_t seed0, uint64_t seed1,
29  uint64_t (*hash)(const void *item, uint64_t seed0, uint64_t seed1),
30  int (*compare)(const void *a, const void *b, void *udata),
31  void (*elfree)(void *item),
32  void *udata);
33 
34 void hashmap_free(struct hashmap *map);
35 void hashmap_clear(struct hashmap *map, bool update_cap);
36 size_t hashmap_count(struct hashmap *map);
37 bool hashmap_oom(struct hashmap *map);
38 const void *hashmap_get(struct hashmap *map, const void *item);
39 const void *hashmap_set(struct hashmap *map, const void *item);
40 const void *hashmap_delete(struct hashmap *map, const void *item);
41 const void *hashmap_probe(struct hashmap *map, uint64_t position);
42 bool hashmap_scan(struct hashmap *map, bool (*iter)(const void *item, void *udata), void *udata);
43 bool hashmap_iter(struct hashmap *map, size_t *i, void **item);
44 
45 uint64_t hashmap_sip(const void *data, size_t len, uint64_t seed0, uint64_t seed1);
46 uint64_t hashmap_murmur(const void *data, size_t len, uint64_t seed0, uint64_t seed1);
47 uint64_t hashmap_xxhash3(const void *data, size_t len, uint64_t seed0, uint64_t seed1);
48 
49 const void *hashmap_get_with_hash(struct hashmap *map, const void *key, uint64_t hash);
50 const void *hashmap_delete_with_hash(struct hashmap *map, const void *key, uint64_t hash);
51 const void *hashmap_set_with_hash(struct hashmap *map, const void *item, uint64_t hash);
52 void hashmap_set_grow_by_power(struct hashmap *map, size_t power);
53 void hashmap_set_load_factor(struct hashmap *map, double load_factor);
54 
55 
56 // DEPRECATED: use `hashmap_new_with_allocator`
57 void hashmap_set_allocator(void *(*malloc)(size_t), void (*free)(void*));
58 
59 #if defined(__cplusplus)
60 }
61 #endif /* __cplusplus */
62 
63 #endif /* HASHMAP_H */
Definition: hashmap.c:37