-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash_map.h
More file actions
42 lines (30 loc) · 919 Bytes
/
hash_map.h
File metadata and controls
42 lines (30 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef HASH_MAP_H
#define HASH_MAP_H
#define TABLE_SIZE 101 // prime number for better hashing
// Entry in the key-value store
typedef struct Entry{
char *key;
char *value;
struct Entry *next; // for chaining
} Entry;
// Hash table
typedef struct {
Entry *buckets[TABLE_SIZE];
} HashMap;
// Create a new HashMap
HashMap *hm_create(void);
// Insert or update key-value pair
void hm_put(HashMap *hm, const char *key, const char *value);
// Get value by key (NULL if not found)
char *hm_get(const HashMap *hm, const char *key);
// Delete Entry with given Key
void hm_delete(HashMap *hm, const char *key);
// Print the Key Value pairs in the HashMap
void hm_print(const HashMap *hm);
// Print the Key Value pairs in sorted order by Key
void hm_print_sorted(const HashMap *hm);
// Reset HashMap
void hm_reset(HashMap *hm);
// Free whole HashMap
void hm_free(HashMap *hm);
#endif // HASH_MAP_H