fx.collections: dict: remove duplicate cstr hash function
This commit is contained in:
+3
-17
@@ -1,4 +1,5 @@
|
|||||||
#include <fx/collections/dict.h>
|
#include <fx/collections/dict.h>
|
||||||
|
#include <fx/hash.h>
|
||||||
#include <fx/status.h>
|
#include <fx/status.h>
|
||||||
#include <fx/stream.h>
|
#include <fx/stream.h>
|
||||||
#include <fx/string.h>
|
#include <fx/string.h>
|
||||||
@@ -47,21 +48,6 @@ static FX_BST_DEFINE_SIMPLE_INSERT(
|
|||||||
bk_hash,
|
bk_hash,
|
||||||
put_bucket);
|
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 ********************************************************/
|
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
static struct fx_dict_bucket *create_bucket(void)
|
static struct fx_dict_bucket *create_bucket(void)
|
||||||
@@ -91,7 +77,7 @@ static fx_status dict_put(
|
|||||||
const char *key,
|
const char *key,
|
||||||
fx_object *value)
|
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);
|
struct fx_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
|
||||||
if (!bucket) {
|
if (!bucket) {
|
||||||
bucket = create_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)
|
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);
|
struct fx_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
|
||||||
if (!bucket) {
|
if (!bucket) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user