X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/blobdiff_plain/e02c731dfbb288c736f2cd09a9b6df0507c59ddd..4179d4a97b3a242b14ed023c2c3e8935a6e3e1e4:/hash.c?ds=inline diff --git a/hash.c b/hash.c index 47ec2d8..e29017c 100644 --- a/hash.c +++ b/hash.c @@ -38,6 +38,41 @@ void inithash(void) elements = 0; } +/** + * destroyhash - Clean up the hash after use. + * + * This function destroys the hash after use, freeing any memory that was + * used during its lifetime. + */ +void destroyhash(void) +{ + int i; + struct ll *curll = NULL; + struct ll *nextll = NULL; + + for (i = 0; i < HASHSIZE; i++) { + curll = hashtable[i]; + while (curll != NULL) { + nextll = curll->next; + /* + * TODO: The problem is the object has pointers that + * need freed too. + */ + free(curll->object); + free(curll); + curll = nextll; + } + hashtable[i] = NULL; + } + elements = 0; +} + +/** + * addtohash - Adds a key to the hash. + * @key: The key to add. + * + * Takes a key and stores it in the hash. + */ void addtohash(struct stats_key *key) { ++elements;