]> git.sommitrealweird.co.uk Git - onak.git/commitdiff
cscvs to tla changeset 10
authorJonathan McDowell <noodles@earth.li>
Mon, 31 May 2004 23:46:58 +0000 (23:46 +0000)
committerJonathan McDowell <noodles@earth.li>
Mon, 31 May 2004 23:46:58 +0000 (23:46 +0000)
Author: noodles
Date: 2002/09/08 10:35:44
Added destroyhash for cleanup when we're done using the hash.

hash.c
hash.h

diff --git a/hash.c b/hash.c
index 47ec2d8b099446fee0d033c5fad9fc15a5803e28..e29017cda8a98e286dbcb3ab1c7e81537276328b 100644 (file)
--- 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;
diff --git a/hash.h b/hash.h
index b7caa1a5d74f3fa0027d16654237e8fee6f4669b..284095d801700cee1c48f411d92b35e75f6fc7f2 100644 (file)
--- a/hash.h
+++ b/hash.h
  */
 void inithash(void);
 
+/**
+ *     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);
+
 /**
  *     addtohash - Adds a key to the hash.
  *     @key: The key to add.