]> andersk Git - moira.git/commitdiff
make it work with negative keys
authormar <mar>
Tue, 14 Nov 1989 18:12:05 +0000 (18:12 +0000)
committermar <mar>
Tue, 14 Nov 1989 18:12:05 +0000 (18:12 +0000)
lib/hash.c

index 200fae56116c65ff200299cc9c576cc49affa9f7..aedd5e46f6c9b1d4fa99cf4dd6470e8545d09da5 100644 (file)
@@ -12,7 +12,7 @@
 #include <sms.h>
 
 #define NULL 0
-
+#define hash_func(h, key) (key >= 0 ? (key % h->size) : (-key % h->size))
 
 /* Create a hash table.  The size is just a hint, not a maximum. */
 
@@ -38,7 +38,7 @@ register int key;
 {
     register struct bucket *b;
 
-    b = h->data[key % h->size];
+    b = h->data[hash_func(h, key)];
     while (b && b->key != key)
       b = b->next;
     if (b && b->key == key)
@@ -59,7 +59,7 @@ char *value;
 {
     register struct bucket *b;
 
-    b = h->data[key % h->size];
+    b = h->data[hash_func(h, key)];
     while (b && b->key != key)
       b = b->next;
     if (b && b->key == key) {
@@ -81,7 +81,7 @@ char *value;
 {
     register struct bucket *b, **p;
 
-    p = &(h->data[key % h->size]);
+    p = &(h->data[hash_func(h, key)]);
     if (*p == NULL) {
        b = *p = (struct bucket *) malloc(sizeof(struct bucket));
        b->next = NULL;
This page took 0.054289 seconds and 5 git commands to generate.