mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-12 23:31:38 -07:00
eliminate content-layer-specific u128 hash
This commit is contained in:
+1
-16
@@ -7,21 +7,6 @@
|
||||
////////////////////////////////
|
||||
//~ 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
|
||||
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];
|
||||
|
||||
//- 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 stripe_idx = slot_idx%c_shared->blob_stripes_count;
|
||||
C_BlobSlot *slot = &c_shared->blob_slots[slot_idx];
|
||||
|
||||
@@ -197,7 +197,6 @@ global C_Shared *c_shared = 0;
|
||||
////////////////////////////////
|
||||
//~ rjf: Basic Helpers
|
||||
|
||||
internal U128 c_hash_from_data(String8 data);
|
||||
internal C_ID c_id_make(U64 u64_0, U64 u64_1);
|
||||
internal B32 c_id_match(C_ID a, C_ID b);
|
||||
internal C_Key c_key_make(C_Root root, C_ID id);
|
||||
|
||||
+12
-6
@@ -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);
|
||||
if(range_size != 0)
|
||||
{
|
||||
// rjf: set up arena
|
||||
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);
|
||||
range_arena = arena_alloc(.reserve_size = range_size+ARENA_HEADER_SIZE, .commit_size = range_size+ARENA_HEADER_SIZE);
|
||||
if(range_arena == 0)
|
||||
{
|
||||
range_size = 0;
|
||||
}
|
||||
else
|
||||
|
||||
// rjf: if we got an arena -> push buffer & read
|
||||
if(range_arena != 0)
|
||||
{
|
||||
// rjf: read as much as possible
|
||||
range_base = push_array_no_zero(range_arena, U8, range_size);
|
||||
U64 bytes_read = 0;
|
||||
U64 retry_count = 0;
|
||||
@@ -6042,16 +6042,22 @@ ctrl_memory_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// rjf: if we read nothing, release arena
|
||||
if(bytes_read == 0)
|
||||
{
|
||||
arena_release(range_arena);
|
||||
range_base = 0;
|
||||
range_arena = 0;
|
||||
}
|
||||
|
||||
// rjf: if we only got a partial read, zero the rest
|
||||
else if(bytes_read < range_size)
|
||||
{
|
||||
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;
|
||||
if(zero_terminated && range_base != 0)
|
||||
{
|
||||
@@ -6091,7 +6097,7 @@ ctrl_memory_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out)
|
||||
U128 hash = {0};
|
||||
if((zero_terminated_size > 0 || !key_has_history) && range_size != 0 && pre_read_mem_gen == post_read_mem_gen)
|
||||
{
|
||||
hash = c_submit_data(content_key, &range_arena, str8((U8*)range_base, zero_terminated_size));
|
||||
hash = c_submit_data(content_key, &range_arena, str8((U8 *)range_base, zero_terminated_size));
|
||||
}
|
||||
else if(range_arena != 0)
|
||||
{
|
||||
|
||||
@@ -148,7 +148,7 @@ for(Test *test = test_##name_identifier; test != 0; test = 0)
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
String8 path = n->string;
|
||||
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;
|
||||
scratch_end(scratch);
|
||||
}
|
||||
@@ -160,7 +160,7 @@ for(Test *test = test_##name_identifier; test != 0; test = 0)
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
String8 path = n->string;
|
||||
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;
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user