-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash-table.h
More file actions
38 lines (26 loc) · 858 Bytes
/
hash-table.h
File metadata and controls
38 lines (26 loc) · 858 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
#ifndef HASH_TABLE_H
#define HASH_TABLE_H
#define NUM_BUCKETS 16
/* Misc */
void fatal_error(char* msg);
/* Linked List */
typedef struct _hash_table_entry {
struct _hash_table_entry* next;
char* key;
char* value;
} hash_table_entry;
void linked_list_append(hash_table_entry* entry, char* key, char* value);
hash_table_entry* linked_list_new(char* key, char* value);
void linked_list_destroy(hash_table_entry** list);
char* linked_list_lookup(hash_table_entry* entries, char* key);
/* Hash Table */
typedef struct _hash_table {
hash_table_entry* buckets[NUM_BUCKETS];
} hash_table;
hash_table* hash_table_new();
void hash_table_destroy(hash_table** table);
void hash_table_insert(hash_table* table, char* key, char* value);
char* hash_table_lookup(hash_table* table, char* key);
/* Hash Function */
int hashfunc(char* key);
#endif