libcproject
C static library easier to use than libc (C standard library).
hash_map.h
Go to the documentation of this file.
1 #ifndef __LIBCPROJECT_HASH_MAP__
2 #define __LIBCPROJECT_HASH_MAP__
3 
4 #include <errno.h>
5 #include <stdbool.h>
6 #include <stdint.h>
7 #include <stdlib.h>
8 #include <string.h>
9 
10 #include "linked_list.h"
11 #include "string.h"
12 #include "types.h"
13 
14 #define HASH_MAP_INITIAL_CAPACITY 10
15 
20 struct hash_map {
21  struct linked_list **items;
22 
23  size_t length;
24  size_t capacity;
25 };
26 
31 struct hash_map_item {
32  void *data;
34 };
35 
46 uint64_t hash(string_t key, size_t capacity);
47 
55 
64 void hash_map_add(struct hash_map *hash_map, string_t key, void *data);
65 
73 
81 void *hash_map_get(struct hash_map *hash_map, string_t key);
82 
92 
101 
109 
110 #endif
bool hash_map_contains_key(struct hash_map *hash_map, string_t key)
Check if the hash map contains a key.
void hash_map_free(struct hash_map *hash_map)
Frees the hash map.
void * data
Definition: hash_map.h:32
string_t key
Definition: hash_map.h:33
struct linked_list ** items
Definition: hash_map.h:21
void hash_map_remove(struct hash_map *hash_map, string_t key)
Remove an item from the hash map.
size_t length
Definition: hash_map.h:23
void hash_map_add(struct hash_map *hash_map, string_t key, void *data)
Add an item to the hash map.
string_t * hash_map_get_keys(struct hash_map *hash_map)
Get the hash map keys.
size_t capacity
Definition: hash_map.h:24
struct hash_map * hash_map_initialization()
Hash map initialization.
void * hash_map_get(struct hash_map *hash_map, string_t key)
Get an item from the hash map.
uint64_t hash(string_t key, size_t capacity)
Hash function (using SipHash 1-3 algorithm).
Hash map data structure.
Definition: hash_map.h:20
Hash map item data structure.
Definition: hash_map.h:31
Linked list data structure.
Definition: linked_list.h:15
char * string_t
Definition: types.h:8