summaryrefslogtreecommitdiff
path: root/minilib
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2018-05-01 18:34:07 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2018-05-01 18:34:07 +0200
commit22b4dd12c063090acc8a8a1297c41bde74e0de24 (patch)
treeb6ec00abb9c88162f60c02a1c2adc76a3e1bd47d /minilib
parent669f2c250379779f1b9bb7129d5909baef3df2e0 (diff)
downloadcompilertests-22b4dd12c063090acc8a8a1297c41bde74e0de24.tar.gz
compilertests-22b4dd12c063090acc8a8a1297c41bde74e0de24.tar.bz2
quite some fixes
Diffstat (limited to 'minilib')
-rw-r--r--minilib/hash.c9
1 files changed, 6 insertions, 3 deletions
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)