summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-08-03 17:50:08 -0600
committermo khan <mo.khan@gmail.com>2020-08-03 17:50:08 -0600
commit83718e496d670cb2ae02236630b0ba24a06d523b (patch)
treea96b22386cbe96df8dbf2dcea1ce80bc7336fb79
parent1a22ef17fa7056b2be7fecd3eecad2a5a36c780d (diff)
Ensure hash function returns positive value
-rw-r--r--src/02/04/hash.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/02/04/hash.c b/src/02/04/hash.c
index 06fa63d..cc0089d 100644
--- a/src/02/04/hash.c
+++ b/src/02/04/hash.c
@@ -11,7 +11,7 @@ Hash *hash_init(int size) {
return hash;
}
-int hash_index(Hash *hash, int key) { return key % hash->size; }
+unsigned int hash_index(Hash *hash, int key) { return key % hash->size; }
void *search(Node *list, int key) {
Node *current = list;
@@ -27,13 +27,13 @@ void *search(Node *list, int key) {
}
void *hash_get(Hash *hash, int key) {
- int bucket = hash_index(hash, key);
+ unsigned int bucket = hash_index(hash, key);
Node *n = hash->buckets + bucket;
return (n->data) ? search(n, key) : NULL;
}
void hash_set(Hash *hash, int key, void *value) {
- int bucket = hash_index(hash, key);
+ unsigned int bucket = hash_index(hash, key);
Tuple *tuple = tuple_initialize(key, value);
Node *n = hash->buckets + bucket;