ht.h (959B)
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | /* `ht` Hashtable implementation */ #ifndef HT_H #define HT_H #include <stdio.h> #include <stdlib.h> #include <limits.h> #include <string.h> #include "var.h" #include "helper.h" typedef struct ht_entry { char* key; var_cont* value; struct ht_entry *next; } ht_entry; typedef struct ht_t { int size; ht_entry** table; } ht_t; /* Creates hashtable of @param int size */ ht_t* ht_init(int); /* Creates the table of empty buckets for the hashtable */ ht_entry** ht_init_table(int); /* Destroys hashtable */ void ht_destroy(ht_t*); /* Destroys the table of buckets for the hashtable */ void ht_destroy_table(ht_entry**, int); /* Destroys an entry. */ void ht_destroy_entry(ht_entry*); /* Set a key-value pair */ void ht_set(ht_t*, char*, var_cont*); /* Get a value */ var_cont* ht_get(ht_t*, char*); /* Make a new key-value pair */ ht_entry* ht_newpair(char*, var_cont*); /* Hash a string */ int ht_hash(ht_t*, char*); #endif // HT_H |