eliminate content-layer-specific u128 hash

This commit is contained in:
Ryan Fleury
2025-10-07 16:24:54 -07:00
parent cd26bf1bcc
commit 166b84cf30
4 changed files with 15 additions and 25 deletions
+1 -16
View File
@@ -7,21 +7,6 @@
//////////////////////////////// ////////////////////////////////
//~ rjf: Basic Helpers //~ rjf: Basic Helpers
#if !defined(XXH_IMPLEMENTATION)
# define XXH_IMPLEMENTATION
# define XXH_STATIC_LINKING_ONLY
# include "third_party/xxHash/xxhash.h"
#endif
internal U128
c_hash_from_data(String8 data)
{
U128 u128 = {0};
XXH128_hash_t hash = XXH3_128bits(data.str, data.size);
MemoryCopy(&u128, &hash, sizeof(u128));
return u128;
}
internal C_ID internal C_ID
c_id_make(U64 u64_0, U64 u64_1) c_id_make(U64 u64_0, U64 u64_1)
{ {
@@ -181,7 +166,7 @@ c_submit_data(C_Key key, Arena **data_arena, String8 data)
C_Stripe *key_stripe = &c_shared->key_stripes[key_stripe_idx]; C_Stripe *key_stripe = &c_shared->key_stripes[key_stripe_idx];
//- rjf: hash data, unpack hash //- rjf: hash data, unpack hash
U128 hash = c_hash_from_data(data); U128 hash = u128_hash_from_str8(data);
U64 slot_idx = hash.u64[1]%c_shared->blob_slots_count; U64 slot_idx = hash.u64[1]%c_shared->blob_slots_count;
U64 stripe_idx = slot_idx%c_shared->blob_stripes_count; U64 stripe_idx = slot_idx%c_shared->blob_stripes_count;
C_BlobSlot *slot = &c_shared->blob_slots[slot_idx]; C_BlobSlot *slot = &c_shared->blob_slots[slot_idx];
-1
View File
@@ -197,7 +197,6 @@ global C_Shared *c_shared = 0;
//////////////////////////////// ////////////////////////////////
//~ rjf: Basic Helpers //~ rjf: Basic Helpers
internal U128 c_hash_from_data(String8 data);
internal C_ID c_id_make(U64 u64_0, U64 u64_1); internal C_ID c_id_make(U64 u64_0, U64 u64_1);
internal B32 c_id_match(C_ID a, C_ID b); internal B32 c_id_match(C_ID a, C_ID b);
internal C_Key c_key_make(C_Root root, C_ID id); internal C_Key c_key_make(C_Root root, C_ID id);
+11 -5
View File
@@ -6009,15 +6009,15 @@ ctrl_memory_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out)
B32 pre_run_state = ins_atomic_u64_eval(&ctrl_state->ctrl_thread_run_state); B32 pre_run_state = ins_atomic_u64_eval(&ctrl_state->ctrl_thread_run_state);
if(range_size != 0) if(range_size != 0)
{ {
// rjf: set up arena
U64 page_size = os_get_system_info()->page_size; // TODO(rjf): @page_size_from_process U64 page_size = os_get_system_info()->page_size; // TODO(rjf): @page_size_from_process
U64 arena_size = AlignPow2(range_size + ARENA_HEADER_SIZE, page_size); U64 arena_size = AlignPow2(range_size + ARENA_HEADER_SIZE, page_size);
range_arena = arena_alloc(.reserve_size = range_size+ARENA_HEADER_SIZE, .commit_size = range_size+ARENA_HEADER_SIZE); range_arena = arena_alloc(.reserve_size = range_size+ARENA_HEADER_SIZE, .commit_size = range_size+ARENA_HEADER_SIZE);
if(range_arena == 0)
{ // rjf: if we got an arena -> push buffer & read
range_size = 0; if(range_arena != 0)
}
else
{ {
// rjf: read as much as possible
range_base = push_array_no_zero(range_arena, U8, range_size); range_base = push_array_no_zero(range_arena, U8, range_size);
U64 bytes_read = 0; U64 bytes_read = 0;
U64 retry_count = 0; U64 retry_count = 0;
@@ -6042,16 +6042,22 @@ ctrl_memory_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out)
break; break;
} }
} }
// rjf: if we read nothing, release arena
if(bytes_read == 0) if(bytes_read == 0)
{ {
arena_release(range_arena); arena_release(range_arena);
range_base = 0; range_base = 0;
range_arena = 0; range_arena = 0;
} }
// rjf: if we only got a partial read, zero the rest
else if(bytes_read < range_size) else if(bytes_read < range_size)
{ {
MemoryZero((U8 *)range_base + bytes_read, range_size-bytes_read); MemoryZero((U8 *)range_base + bytes_read, range_size-bytes_read);
} }
// rjf: determine final size; zero terminate if needed; pop any unneeded bytes if zero-terminating
zero_terminated_size = bytes_read; zero_terminated_size = bytes_read;
if(zero_terminated && range_base != 0) if(zero_terminated && range_base != 0)
{ {
+2 -2
View File
@@ -148,7 +148,7 @@ for(Test *test = test_##name_identifier; test != 0; test = 0)
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
String8 path = n->string; String8 path = n->string;
String8 data = os_data_from_file_path(scratch.arena, path); String8 data = os_data_from_file_path(scratch.arena, path);
rdi_hashes[idx] = c_hash_from_data(data); rdi_hashes[idx] = u128_hash_from_str8(data);
rdi_paths_array[idx] = path; rdi_paths_array[idx] = path;
scratch_end(scratch); scratch_end(scratch);
} }
@@ -160,7 +160,7 @@ for(Test *test = test_##name_identifier; test != 0; test = 0)
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
String8 path = n->string; String8 path = n->string;
String8 data = os_data_from_file_path(scratch.arena, path); String8 data = os_data_from_file_path(scratch.arena, path);
dump_hashes[idx] = c_hash_from_data(data); dump_hashes[idx] = u128_hash_from_str8(data);
dump_paths_array[idx] = path; dump_paths_array[idx] = path;
scratch_end(scratch); scratch_end(scratch);
} }