@@ -1349,7 +1349,7 @@ rdim_bake_string_chunk_list_sorted_from_unsorted(RDIM_Arena *arena, RDIM_BakeStr
13491349 {
13501350 // rjf: write each chunk node's array into original array, detect if there is size left to sort
13511351 RDI_U64 bucket_base_idx = write_idx ;
1352- RDI_U64 max_size_left_to_sort = 0 ;
1352+ RDI_U64 need_next_char_sort = 0 ;
13531353 for (RDIM_BakeStringChunkNode * n = buckets [bucket_idx ].first ; n != 0 ; n = n -> next )
13541354 {
13551355 rdim_memcpy (t -> v + write_idx , n -> v , sizeof (n -> v [0 ])* n -> count );
@@ -1358,14 +1358,14 @@ rdim_bake_string_chunk_list_sorted_from_unsorted(RDIM_Arena *arena, RDIM_BakeStr
13581358 {
13591359 if (n -> v [idx ].string .size > t -> string_off + 1 )
13601360 {
1361- max_size_left_to_sort = Max ( max_size_left_to_sort , ( n -> v [ idx ]. string . size - t -> string_off + 1 )) ;
1361+ need_next_char_sort = 1 ;
13621362 }
13631363 }
13641364 }
13651365
13661366 // rjf: if any bucket has >1 element & has some amount of size left to sort, push new task for this
13671367 // bucket's region in the array, and for remainder of keys
1368- if (buckets [bucket_idx ].total_count > 1 && max_size_left_to_sort > 0 )
1368+ if (buckets [bucket_idx ].total_count > 1 && need_next_char_sort )
13691369 {
13701370 SortTask * new_task = rdim_push_array (scratch .arena , SortTask , 1 );
13711371 RDIM_SLLQueuePush (first_task , last_task , new_task );
@@ -1376,12 +1376,11 @@ rdim_bake_string_chunk_list_sorted_from_unsorted(RDIM_Arena *arena, RDIM_BakeStr
13761376 }
13771377 }
13781378 }
1379- scratch_end (scratch );
1379+ rdim_scratch_end (scratch );
13801380 }
13811381
1382- //- rjf: iterate sorted chunk node, remove duplicates, count # to pop
1383- RDI_U64 num_to_pop = 0 ;
1384- RDI_U64 arena_pos_pre_pop = rdim_arena_pos (arena );
1382+ //- rjf: iterate sorted chunk node, remove duplicates, count # of duplicates
1383+ RDI_U64 num_duplicates = 0 ;
13851384 if (dst .first != 0 )
13861385 {
13871386 RDI_U64 last_idx = 0 ;
@@ -1390,7 +1389,7 @@ rdim_bake_string_chunk_list_sorted_from_unsorted(RDIM_Arena *arena, RDIM_BakeStr
13901389 if (rdim_str8_match (dst .first -> v [last_idx ].string , dst .first -> v [idx ].string , 0 ))
13911390 {
13921391 rdim_memzero_struct (& dst .first -> v [idx ]);
1393- num_to_pop += 1 ;
1392+ num_duplicates += 1 ;
13941393 }
13951394 else
13961395 {
@@ -1400,32 +1399,33 @@ rdim_bake_string_chunk_list_sorted_from_unsorted(RDIM_Arena *arena, RDIM_BakeStr
14001399 }
14011400
14021401 //- rjf: iterate sorted chunk node, make non-empty elements contiguous
1403- if (num_to_pop != 0 )
1402+ if (num_duplicates != 0 )
14041403 {
14051404 RDI_U64 last_idx = 0 ;
14061405 for (RDI_U64 idx = 1 ; idx < dst .first -> count ; idx += 1 )
14071406 {
1408- if (dst .first -> v [idx ].string .RDIM_String8_SizeMember == 0 &&
1407+ if (last_idx == 0 &&
1408+ dst .first -> v [idx ].string .RDIM_String8_SizeMember == 0 &&
14091409 dst .first -> v [idx ].hash == 0 )
14101410 {
14111411 last_idx = idx ;
14121412 }
1413- else if (last_idx != 0 && last_idx != idx )
1413+ if (last_idx != 0 && dst . first -> v [ idx ]. string . RDIM_String8_SizeMember != 0 )
14141414 {
14151415 rdim_memcpy_struct (& dst .first -> v [last_idx ], & dst .first -> v [idx ]);
14161416 rdim_memzero_struct (& dst .first -> v [idx ]);
1417- idx = last_idx ;
1418- last_idx = 0 ;
1417+ last_idx += 1 ;
14191418 }
14201419 }
14211420
14221421 //- rjf: pop extras
1423- if (num_to_pop != 0 )
1422+ if (num_duplicates != 0 )
14241423 {
1425- rdim_arena_pop_to (arena , arena_pos_pre_pop - num_to_pop * sizeof (dst .first -> v [0 ]));
1426- dst .first -> count -= num_to_pop ;
1427- dst .first -> cap -= num_to_pop ;
1428- dst .total_count -= num_to_pop ;
1424+ RDI_U64 arena_pos_pre_pop = rdim_arena_pos (arena );
1425+ rdim_arena_pop_to (arena , arena_pos_pre_pop - num_duplicates * sizeof (dst .first -> v [0 ]));
1426+ dst .first -> count -= num_duplicates ;
1427+ dst .first -> cap -= num_duplicates ;
1428+ dst .total_count -= num_duplicates ;
14291429 }
14301430 }
14311431
@@ -1446,31 +1446,34 @@ rdim_bake_string_map_loose_make(RDIM_Arena *arena, RDIM_BakeStringMapTopology *t
14461446RDI_PROC void
14471447rdim_bake_string_map_loose_insert (RDIM_Arena * arena , RDIM_BakeStringMapTopology * map_topology , RDIM_BakeStringMapLoose * map , RDI_U64 chunk_cap , RDIM_String8 string )
14481448{
1449- RDI_U64 hash = rdi_hash (string .RDIM_String8_BaseMember , string .RDIM_String8_SizeMember );
1450- RDI_U64 slot_idx = hash %map_topology -> slots_count ;
1451- RDIM_BakeStringChunkList * slot = map -> slots [slot_idx ];
1452- if (slot == 0 )
1453- {
1454- slot = map -> slots [slot_idx ] = rdim_push_array (arena , RDIM_BakeStringChunkList , 1 );
1455- }
1456- RDI_S32 is_duplicate = 0 ;
1457- for (RDIM_BakeStringChunkNode * n = slot -> first ; n != 0 ; n = n -> next )
1449+ if (string .RDIM_String8_SizeMember != 0 )
14581450 {
1459- for (RDI_U64 idx = 0 ; idx < n -> count ; idx += 1 )
1451+ RDI_U64 hash = rdi_hash (string .RDIM_String8_BaseMember , string .RDIM_String8_SizeMember );
1452+ RDI_U64 slot_idx = hash %map_topology -> slots_count ;
1453+ RDIM_BakeStringChunkList * slot = map -> slots [slot_idx ];
1454+ if (slot == 0 )
1455+ {
1456+ slot = map -> slots [slot_idx ] = rdim_push_array (arena , RDIM_BakeStringChunkList , 1 );
1457+ }
1458+ RDI_S32 is_duplicate = 0 ;
1459+ for (RDIM_BakeStringChunkNode * n = slot -> first ; n != 0 ; n = n -> next )
14601460 {
1461- if ( rdim_str8_match ( n -> v [ idx ]. string , string , 0 ) )
1461+ for ( RDI_U64 idx = 0 ; idx < n -> count ; idx += 1 )
14621462 {
1463- is_duplicate = 1 ;
1464- goto break_all ;
1463+ if (rdim_str8_match (n -> v [idx ].string , string , 0 ))
1464+ {
1465+ is_duplicate = 1 ;
1466+ goto break_all ;
1467+ }
14651468 }
14661469 }
1467- }
1468- break_all :;
1469- if (! is_duplicate )
1470- {
1471- RDIM_BakeString * bstr = rdim_bake_string_chunk_list_push ( arena , slot , chunk_cap ) ;
1472- bstr -> string = string ;
1473- bstr -> hash = hash ;
1470+ break_all :;
1471+ if (! is_duplicate )
1472+ {
1473+ RDIM_BakeString * bstr = rdim_bake_string_chunk_list_push ( arena , slot , chunk_cap );
1474+ bstr -> string = string ;
1475+ bstr -> hash = hash ;
1476+ }
14741477 }
14751478}
14761479
0 commit comments