fx.collections: dict: remove duplicate cstr hash function

This commit is contained in:
2026-05-03 20:36:50 +01:00
parent dab3fec6b8
commit 85ff8b7eaa
+3 -17
View File
@@ -1,4 +1,5 @@
#include <fx/collections/dict.h>
#include <fx/hash.h>
#include <fx/status.h>
#include <fx/stream.h>
#include <fx/string.h>
@@ -47,21 +48,6 @@ static FX_BST_DEFINE_SIMPLE_INSERT(
bk_hash,
put_bucket);
uint64_t fx_cstr_hash(const char *s)
{
#define FNV1_OFFSET_BASIS 0xcbf29ce484222325
#define FNV1_PRIME 0x100000001b3
uint64_t hash = FNV1_OFFSET_BASIS;
size_t i = 0;
for (i = 0; s[i]; i++) {
hash ^= s[i];
hash *= FNV1_PRIME;
}
return hash;
}
/*** PRIVATE FUNCTIONS ********************************************************/
static struct fx_dict_bucket *create_bucket(void)
@@ -91,7 +77,7 @@ static fx_status dict_put(
const char *key,
fx_object *value)
{
uint64_t hash = fx_cstr_hash(key);
uint64_t hash = fx_hash_cstr(key);
struct fx_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
if (!bucket) {
bucket = create_bucket();
@@ -148,7 +134,7 @@ static fx_status dict_put_sk(
static fx_object *dict_at(const struct fx_dict_p *dict, const char *key)
{
uint64_t hash = fx_cstr_hash(key);
uint64_t hash = fx_hash_cstr(key);
struct fx_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
if (!bucket) {
return NULL;