hash fnv from seed

This commit is contained in:
jacob 2024-03-14 13:28:31 -05:00
parent fd486bb71b
commit 1d2e7c0b9f
4 changed files with 12 additions and 8 deletions

View File

@ -96,7 +96,7 @@ INTERNAL struct asset *asset_cache_get_slot_assume_locked(struct string key, u64
u64 asset_cache_hash(struct string key)
{
/* TODO: Better hash */
return hash_fnv64(BUFFER_FROM_STRING(key));
return hash_fnv64(HASH_FNV64_SEED, BUFFER_FROM_STRING(key));
}
/* `key` text is copied by this function

View File

@ -711,7 +711,7 @@ INTERNAL struct json_val json_format_internal(struct arena *arena, const struct
.value = json_format_internal(arena, cur)
};
u64 hash = hash_fnv64(BUFFER_FROM_STRING(cur->key));
u64 hash = hash_fnv64(HASH_FNV64_SEED, BUFFER_FROM_STRING(cur->key));
u32 slot_index_home = hash % capacity;
u32 slot_index = slot_index_home;
while (true) {
@ -862,7 +862,7 @@ const struct json_val *json_object_get(const struct json_val *obj, struct string
u32 *hash_table = (u32 *)obj->val.object_table;
const struct json_object_entry *entries = get_object_entries(obj);
u64 hash = hash_fnv64(BUFFER_FROM_STRING(key));
u64 hash = hash_fnv64(HASH_FNV64_SEED, BUFFER_FROM_STRING(key));
u32 slot_index_home = hash % capacity;
u32 slot_index = slot_index_home;
while (true) {

View File

@ -40,6 +40,7 @@ GLOBAL struct {
struct sys_window *window;
struct renderer_canvas *world_canvas;
struct renderer_canvas *screen_canvas;
struct xform world_view_last_frame;
struct xform world_view;
struct blend_tick *head_free_blend_tick;
@ -512,9 +513,11 @@ INTERNAL void user_update(void)
}
/* ========================== *
* Update view from debug camera
* Update view
* ========================== */
L.world_view_last_frame = L.world_view;
if (L.bind_states[USER_BIND_KIND_DEBUG_DRAW].num_presses > 0) {
L.debug_draw = !L.debug_draw;
}

View File

@ -18,9 +18,10 @@ struct string util_file_name_from_path(struct string path);
/* FNV-1a hash function
* TODO: Something faster if necessary */
INLINE u64 hash_fnv64(struct buffer buff)
#define HASH_FNV64_SEED 0xcbf29ce484222325
INLINE u64 hash_fnv64(u64 seed, struct buffer buff)
{
u64 hash = 0xcbf29ce484222325;
u64 hash = seed;
for (u64 i = 0; i < buff.size; ++i) {
hash ^= (u8)buff.data[i];
hash *= 0x100000001b3;
@ -79,7 +80,7 @@ INLINE void fixed_dict_set(struct arena *arena, struct fixed_dict *dict, struct
{
__prof;
u64 hash = hash_fnv64(BUFFER_FROM_STRING(key));
u64 hash = hash_fnv64(HASH_FNV64_SEED, BUFFER_FROM_STRING(key));
u64 index = hash % dict->buckets_count;
struct fixed_dict_bucket *bucket = &dict->buckets[index];
@ -108,7 +109,7 @@ INLINE void *fixed_dict_get(const struct fixed_dict *dict, struct string key)
{
__prof;
u64 hash = hash_fnv64(BUFFER_FROM_STRING(key));
u64 hash = hash_fnv64(HASH_FNV64_SEED, BUFFER_FROM_STRING(key));
u64 index = hash % dict->buckets_count;
struct fixed_dict_bucket *bucket = &dict->buckets[index];