]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - util.c
Filling up remaining gotos at the end of a function for when the label is defined...
[xonotic/gmqcc.git] / util.c
diff --git a/util.c b/util.c
index 3065607d970d837e44f236a234a33020aa11af94..6853393e0487f384dfe602d331db5027b345a785 100644 (file)
--- a/util.c
+++ b/util.c
@@ -526,7 +526,7 @@ typedef struct hash_node_t {
 } hash_node_t;
 
 
-size_t _util_hthash(hash_table_t *ht, const char *key) {
+size_t util_hthash(hash_table_t *ht, const char *key) {
     uint64_t val = 0;
     size_t   len = strlen(key);
     size_t   itr = 0;
@@ -584,20 +584,18 @@ hash_table_t *util_htnew(size_t size) {
     return hashtable;
 }
 
-void util_htset(hash_table_t *ht, const char *key, void *value) {
-    size_t bin = 0;
+void util_htseth(hash_table_t *ht, const char *key, size_t bin, void *value) {
     hash_node_t *newnode = NULL;
     hash_node_t *next    = NULL;
     hash_node_t *last    = NULL;
     
-    bin  = _util_hthash(ht, key);
     next = ht->table[bin];
     
     while (next && next->key && strcmp(key, next->key) > 0)
         last = next, next = next->next;
     
     /* already in table, do a replace */
-    if (next && next->key && !strcmp(key, next->key) == 0) {
+    if (next && next->key && strcmp(key, next->key) == 0) {
         next->value = value;
     } else {
         /* not found, grow a pair man :P */
@@ -614,8 +612,11 @@ void util_htset(hash_table_t *ht, const char *key, void *value) {
     }
 }
 
-void *util_htget(hash_table_t *ht, const char *key) {
-    size_t       bin  = _util_hthash(ht, key);
+void util_htset(hash_table_t *ht, const char *key, void *value) {
+    util_htseth(ht, key, util_hthash(ht, key), value);
+}
+
+void *util_htgeth(hash_table_t *ht, const char *key, size_t bin) {
     hash_node_t *pair = ht->table[bin];
     
     while (pair && pair->key && strcmp(key, pair->key) > 0)
@@ -627,6 +628,10 @@ void *util_htget(hash_table_t *ht, const char *key) {
     return pair->value;
 }
 
+void *util_htget(hash_table_t *ht, const char *key) {
+    return util_htgeth(ht, key, util_hthash(ht, key));
+}
+
 /*
  * Free all allocated data in a hashtable, this is quite the amount
  * of work.
@@ -635,12 +640,15 @@ void util_htdel(hash_table_t *ht) {
     size_t i = 0;
     for (; i < ht->size; i++) {
         hash_node_t *n = ht->table[i];
+        hash_node_t *p;
         
         /* free in list */
         while (n) {
             if (n->key)
                 mem_d(n->key);
+            p = n;
             n = n->next;
+            mem_d(p);
         }
         
     }