aboutsummaryrefslogtreecommitdiff
path: root/analyzer/structures/hashmap.c
diff options
context:
space:
mode:
authorMosder <xmosder12@gmail.com>2026-07-28 19:37:29 +0200
committerMosder <xmosder12@gmail.com>2026-07-28 19:37:29 +0200
commita30d6feab718a887edc7eb5b0470faa77677a8c3 (patch)
tree87c97ea0fe71f7d9adbdbe399dea39ae24e53fd6 /analyzer/structures/hashmap.c
parent9e874301350a70a1ba40b5508878d559f68f8f4a (diff)
feat: added a very-very basic total rewards thingy, still needs to do detection through the special packet sent by client and there's a lot of placeholder things and not the best code there. Also - normal items don't stack and they definitely should - that's gonna be a bit of refactoring :)))))))))))
Diffstat (limited to 'analyzer/structures/hashmap.c')
-rw-r--r--analyzer/structures/hashmap.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/analyzer/structures/hashmap.c b/analyzer/structures/hashmap.c
index 53fd5fc..0ef2ade 100644
--- a/analyzer/structures/hashmap.c
+++ b/analyzer/structures/hashmap.c
@@ -8,7 +8,7 @@
HashMap *hashmap_new(
size_t key_size,
size_t val_size,
- size_t (*hash)(void *key),
+ uint32_t (*hash)(void *key),
int (*compare)(void *key1, void *key2),
void (*key_cleanup)(void *key),
void (*val_cleanup)(void *val)
@@ -26,7 +26,7 @@ HashMap *hashmap_new(
}
void hashmap_put(HashMap *map, void *key, void *val) {
- size_t key_hash = map->hash(key);
+ size_t key_hash = map->hash(key) % HASHMAP_TABLE_SIZE;
HashMapNode *node = map->table[key_hash];
// check if it exists
@@ -56,7 +56,7 @@ void hashmap_put(HashMap *map, void *key, void *val) {
}
void *hashmap_get(HashMap *map, void *key) {
- size_t key_hash = map->hash(key);
+ size_t key_hash = map->hash(key) % HASHMAP_TABLE_SIZE;
HashMapNode *node = map->table[key_hash];
// check if it exists
@@ -85,7 +85,7 @@ void free_node_without_next(HashMap *map, HashMapNode *node) {
}
void hashmap_delete(HashMap *map, void *key) {
- size_t key_hash = map->hash(key);
+ size_t key_hash = map->hash(key) % HASHMAP_TABLE_SIZE;
HashMapNode **p_node = &map->table[key_hash];
// check if it exists
@@ -114,3 +114,21 @@ void hashmap_free(HashMap *map) {
}
free(map);
}
+
+// FNV hash
+uint32_t hash_str(void *str) {
+ char *s = str;
+ uint32_t hash = 2166136261;
+ while (*s) {
+ hash ^= (unsigned char)*s;
+ hash *= 16777619;
+ s++;
+ }
+ return hash;
+}
+
+int compare_strs(void *str1, void *str2) {
+ char *s1 = str1;
+ char *s2 = str2;
+ return !strcmp(s1, s2);
+}