From 22b4dd12c063090acc8a8a1297c41bde74e0de24 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Tue, 1 May 2018 18:34:07 +0200 Subject: quite some fixes --- minilib/hash.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'minilib') diff --git a/minilib/hash.c b/minilib/hash.c index 4d32305..ad26732 100644 --- a/minilib/hash.c +++ b/minilib/hash.c @@ -2,6 +2,7 @@ #include "arena.h" #include "string.h" #include "stddef.h" +#include "io.h" void inthash_init( intHashTable *ht, int size ) { @@ -18,11 +19,11 @@ void inthash_done( intHashTable *ht ) static int hash_string( char *s ) { - int h = 5381; + int h = 0; int c; while( ( c = *s++ ) ) { - h = ((h << 5) + h) + c; + h += c; } return h; @@ -37,7 +38,7 @@ void inthash_set( intHashTable *ht, char *key, int value ) h = hash_string( key ) % ht->capacity; entry = ht->table[h]; - while( entry != NULL && strcmp( key, entry->key ) > 0 ) { + while( entry != NULL && strcmp( key, entry->key ) != 0 ) { entry = entry->next; } @@ -50,6 +51,8 @@ void inthash_set( intHashTable *ht, char *key, int value ) new->next = ht->table[h]; ht->table[h] = new; } + + ht->size++; } int inthash_get( intHashTable *ht, char *key) -- cgit v1.2.3-54-g00ecf