From c9c662dd0021e5f0fcbbda7745100789ef297044 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Fri, 20 May 2016 00:10:05 +0200 Subject: [PATCH] Finalize _set. --- src/hashtable-simple.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/hashtable-simple.c b/src/hashtable-simple.c index 7c72149..ac85a41 100644 --- a/src/hashtable-simple.c +++ b/src/hashtable-simple.c @@ -59,7 +59,7 @@ int hashtable_set(HASHTABLE* hashtable, char* key, void * value) { idx = hash_of_key(hashtable, key); hashtable->size += 1; - printf("hashtable_set -- search value [%d/%d]\n", idx, hashtable->capacity); + printf("hashtable_set -- index [%d/%d]\n", idx, hashtable->capacity); // search value cell = hashtable->data[idx]; while(cell) { @@ -70,6 +70,7 @@ int hashtable_set(HASHTABLE* hashtable, char* key, void * value) { if (cell) { // if cell exists, then change inner value printf("hashtable_set -- update value\n"); + cell->value = value; } else { printf("hashtable_set -- create value\n"); // create cell & prepend it to the chain @@ -128,10 +129,11 @@ int main(int argc, char** argv) { hashtable_set(hashtable, "alice", &x); printf("h['alice'] <- %d\n", x); hashtable_set(hashtable, "bob", &y); - printf("h['bob'] <- %d\n", x); + printf("h['bob'] <- %d\n", y); hashtable_set(hashtable, "charlie", &z); - printf("h['charlie'] <- %d\n", x); + printf("h['charlie'] <- %d\n", z); hashtable_set(hashtable, "alice", &y); + printf("h['alice'] <- %d\n", y); value = hashtable_get(hashtable, "alice"); printf("h['alice'] ? %d\n", *value); value = hashtable_get(hashtable, "bob");