aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-07-04 14:16:41 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-07-04 14:23:28 +0200
commit9e509673ef53e9a2aa412c16a9752afed1f98869 (patch)
treedecb2d0b7d619ca726b5fc9613c767bc8181273b
parent548c540989527b45b9152f9f21ab8cf5e53893a6 (diff)
server: Use u64 for keys in hashtable
-rw-r--r--hashtable.c9
-rw-r--r--hashtable.h8
2 files changed, 9 insertions, 8 deletions
diff --git a/hashtable.c b/hashtable.c
index bfda316..020d281 100644
--- a/hashtable.c
+++ b/hashtable.c
@@ -1,6 +1,5 @@
#include <limits.h>
#include "hashtable.h"
-#include "global.h"
// Generated by starting with 5, then repeatedly taking the smallest prime at
@@ -16,7 +15,7 @@ static const size_t doubling_primes[] = {
struct keyvalue {
- unsigned int key;
+ u64 key;
void *value;
};
@@ -90,7 +89,7 @@ void ht_free(struct hashtable *ht) {
free(ht);
}
-void ht_insert(struct hashtable *ht, unsigned int key, void *value) {
+void ht_insert(struct hashtable *ht, u64 key, void *value) {
struct bucket *bucket = &ht->table[key % ht->modulus];
if (bucket->cap == 0) {
@@ -117,7 +116,7 @@ void ht_insert(struct hashtable *ht, unsigned int key, void *value) {
}
}
-void* ht_find(const struct hashtable *ht, unsigned int key) {
+void* ht_find(const struct hashtable *ht, u64 key) {
struct bucket *bucket = &ht->table[key % ht->modulus];
for (int i = 0; i < bucket->len; i++) {
if (bucket->pairs[i].key == key) {
@@ -127,7 +126,7 @@ void* ht_find(const struct hashtable *ht, unsigned int key) {
return NULL;
}
-void ht_delete(struct hashtable *ht, unsigned int key) {
+void ht_delete(struct hashtable *ht, u64 key) {
struct bucket *bucket = &ht->table[key % ht->modulus];
for (int i = 0; i < bucket->len; i++) {
if (bucket->pairs[i].key == key) {
diff --git a/hashtable.h b/hashtable.h
index b85c2e0..21467a8 100644
--- a/hashtable.h
+++ b/hashtable.h
@@ -1,15 +1,17 @@
#pragma once
+#include "global.h"
+
struct hashtable;
struct hashtable* ht_alloc();
void ht_free(struct hashtable *ht);
-void ht_insert(struct hashtable *ht, unsigned int key, void *value);
+void ht_insert(struct hashtable *ht, u64 key, void *value);
// Returns NULL if key is not present in the table.
-void* ht_find(const struct hashtable *ht, unsigned int key);
+void* ht_find(const struct hashtable *ht, u64 key);
// Does nothing if the key is not present in the table.
-void ht_delete(struct hashtable *ht, unsigned int key);
+void ht_delete(struct hashtable *ht, u64 key);