From 2c4e26de0237c4c27f6fc071fc9419e0e4adfdf5 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Thu, 23 Apr 2015 01:46:42 -0500 Subject: [PATCH] Implement hashing for symbol table. --- src/assembler/state.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/assembler/state.c b/src/assembler/state.c index 7f6766f..de6b3ef 100644 --- a/src/assembler/state.c +++ b/src/assembler/state.c @@ -129,11 +129,16 @@ void asm_symtable_free(ASMSymbolTable *symtable) } /* - ... + Hash a string key into a symbol table bucket index. + + This uses the djb2 algorithm: http://www.cse.yorku.ca/~oz/hash.html */ static inline size_t hash_key(const char *key) { - return 0; + size_t hash = 5381; + while (*key) + hash = ((hash << 5) + hash) + *(key++); + return hash % SYMBOL_TABLE_BUCKETS; } /*