#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. */
{
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)
{
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) {
{
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;