osurs  0.0.1
hashmap.h
Go to the documentation of this file.
1 
17 #ifndef OSURS_DS_HASHMAP_H_
18 #define OSURS_DS_HASHMAP_H_
19 
20 #include <stddef.h>
21 
28 typedef struct HashMapEntry {
29  char* key;
30  void* value;
31  struct HashMapEntry* next;
33 
39 typedef struct HashMap {
41  size_t size;
42  size_t capacity;
45 
51 void hash_map_init(HashMap* map);
52 
59 
72 void hash_map_put(HashMap* map, const char* key, void* value);
73 
84 void* hash_map_get(HashMap* map, const char* key);
85 
94 void* hash_map_get_random(HashMap* map);
95 
102 void hash_map_remove(HashMap* map, const char* key);
103 
112 void hash_map_print(HashMap* map);
113 
123 void hash_map_clear(HashMap* map);
124 
133 void hash_map_free(HashMap* map);
134 
135 #endif // OSURS_DS_HASHMAP_H_
void hash_map_remove(HashMap *map, const char *key)
Remove an entry from the hashmap.
Definition: hashmap.c:101
void hash_map_free(HashMap *map)
Free hashmap and entries.
Definition: hashmap.c:150
void hash_map_init(HashMap *map)
Initialize the hashmap.
Definition: hashmap.c:27
void * hash_map_get_random(HashMap *map)
Get a random value.
Definition: hashmap.c:87
void * hash_map_get(HashMap *map, const char *key)
Get a value from a key.
Definition: hashmap.c:75
void hash_map_print(HashMap *map)
Print the hashmap content.
Definition: hashmap.c:125
HashMap * hash_map_create()
Create a hashmap on the heap.
Definition: hashmap.c:39
void hash_map_clear(HashMap *map)
Clear all values in the hashmap.
Definition: hashmap.c:136
struct HashMapEntry HashMapEntry
Entry of the hashmap.
void hash_map_put(HashMap *map, const char *key, void *value)
Put a new entry into the hashmap.
Definition: hashmap.c:50
struct HashMap HashMap
A hashmap.
Entry of the hashmap.
Definition: hashmap.h:28
struct HashMapEntry * next
Definition: hashmap.h:31
void * value
Definition: hashmap.h:30
char * key
Definition: hashmap.h:29
A hashmap.
Definition: hashmap.h:39
size_t capacity
Definition: hashmap.h:42
int dynamic_alloc
Definition: hashmap.h:43
HashMapEntry ** entries
Definition: hashmap.h:40
size_t size
Definition: hashmap.h:41