From eec124c53bc2a0fbecaaa95d97f46b60f7fae53a Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Fri, 29 Mar 2024 11:28:45 -0700 Subject: [PATCH] eliminate old text searching thread code --- src/df/gfx/df_gfx.c | 299 ------------------------------------------ src/df/gfx/df_gfx.h | 76 ----------- src/df/gfx/df_views.c | 56 -------- 3 files changed, 431 deletions(-) diff --git a/src/df/gfx/df_gfx.c b/src/df/gfx/df_gfx.c index 02a9ba04..a4bc8282 100644 --- a/src/df/gfx/df_gfx.c +++ b/src/df/gfx/df_gfx.c @@ -7643,305 +7643,6 @@ df_push_search_string(Arena *arena) return result; } -//////////////////////////////// -//~ rjf: Background Text Searching Thread - -internal void -df_text_search_match_chunk_list_push(Arena *arena, DF_TextSearchMatchChunkList *list, U64 cap, DF_TextSearchMatch *match) -{ - DF_TextSearchMatchChunkNode *node = list->last; - if(node == 0 || node->count >= node->cap) - { - node = push_array(arena, DF_TextSearchMatchChunkNode, 1); - node->cap = cap; - node->v = push_array_no_zero(arena, DF_TextSearchMatch, node->cap); - SLLQueuePush(list->first, list->last, node); - list->node_count += 1; - } - node->v[node->count] = *match; - node->count += 1; - list->total_count += 1; -} - -internal DF_TextSearchMatchArray -df_text_search_match_array_from_chunk_list(Arena *arena, DF_TextSearchMatchChunkList *chunks) -{ - DF_TextSearchMatchArray array = {0}; - array.count = chunks->total_count; - array.v = push_array_no_zero(arena, DF_TextSearchMatch, array.count); - U64 idx = 0; - for(DF_TextSearchMatchChunkNode *node = chunks->first; node != 0; node = node->next) - { - MemoryCopy(array.v+idx, node->v, node->count * sizeof(DF_TextSearchMatch)); - idx += node->count; - } - return array; -} - -internal U64 -df_text_search_little_hash_from_hash(U128 hash) -{ - // TODO(rjf): [ ] @de2ctrl df_text_search_little_hash_from_hash - U64 little_hash = 0; - MemoryCopy(&little_hash, &hash, sizeof(little_hash)); - return little_hash; -} - -internal void -df_text_search_thread_entry_point(void *p) -{ -#if 0 - // TODO(rjf): [ ] @de2ctrl text searcher -- wound up in DE_Hash - - //- rjf: types - typedef enum WorkKind - { - WorkKind_Search, - WorkKind_GarbageCollect, - WorkKind_COUNT - } - WorkKind; - typedef struct WorkNode WorkNode; - struct WorkNode - { - WorkNode *next; - WorkKind kind; - U128 hash; - String8 needle; - DF_TextSliceFlags flags; - TxtPt start_pt; - }; - - //- rjf: set up local debug engine map - Arena *local_map_arena = arena_alloc(); - DE_ContentMap local_map = {0}; - DE_PipelineHint hint = zero_struct; - - //- rjf: loop over work - for(;;) - { - //- rjf: begin - Temp scratch = scratch_begin(0, 0); - DE_Session *session = de_session_begin(); - - //- rjf: wait for changes - os_mutex_take(df_gfx_state->tsrch_wakeup_mutex); - os_condition_variable_wait(df_gfx_state->tsrch_wakeup_cv, df_gfx_state->tsrch_wakeup_mutex, os_now_microseconds()+1000000); - os_mutex_drop(df_gfx_state->tsrch_wakeup_mutex); - - //- rjf: gather all searches to complete - WorkNode *first_work_node = 0; - WorkNode *last_work_node = 0; - for(U64 slot_idx = 0; slot_idx < df_gfx_state->tsrch_slot_count; slot_idx += 1) - { - //- rjf: slot idx -> slot * stripe - DF_TextSearchCacheSlot *slot = &df_gfx_state->tsrch_slots[slot_idx]; - U64 stripe_idx = slot_idx%df_gfx_state->tsrch_stripe_count; - OS_Handle stripe_rw_mutex = df_gfx_state->tsrch_stripe_rw_mutexes[stripe_idx]; - - //- rjf: gather nodes in this slot - os_rw_mutex_take_r(stripe_rw_mutex); - { - for(DF_TextSearchCacheNode *n = slot->first; n != 0; n = n->next) - { - B32 not_done = (n->good == 0); - B32 expired = (os_now_microseconds() >= n->last_time_touched_us + 10000000); - if(not_done || expired) - { - WorkNode *work = push_array(scratch.arena, WorkNode, 1); - work->kind = not_done ? WorkKind_Search : WorkKind_GarbageCollect; - work->hash = n->hash; - work->needle = push_str8_copy(scratch.arena, n->needle); - work->flags = n->flags; - work->start_pt = n->start_pt; - SLLQueuePush(first_work_node, last_work_node, work); - } - } - } - os_rw_mutex_drop_r(stripe_rw_mutex); - } - - //- rjf: perform all searches - for(WorkNode *work_node = first_work_node; work_node != 0; work_node = work_node->next) - { - //- rjf: unpack work node - WorkKind kind = work_node->kind; - DE_Hash hash = work_node->hash; - String8 needle = work_node->needle; - DF_TextSliceFlags flags = work_node->flags; - TxtPt start_pt = work_node->start_pt; - - //- rjf: work params -> slot/stripe info - U64 little_hash = df_text_search_little_hash_from_hash(hash); - U64 slot_idx = little_hash%df_gfx_state->tsrch_slot_count; - DF_TextSearchCacheSlot *slot = &df_gfx_state->tsrch_slots[slot_idx]; - U64 stripe_idx = slot_idx%df_gfx_state->tsrch_stripe_count; - OS_Handle stripe_rw_mutex = df_gfx_state->tsrch_stripe_rw_mutexes[stripe_idx]; - - //- rjf: do work - switch(kind) - { - //- rjf: search - default: - case WorkKind_Search: - { - //- rjf: hash -> artifacts - DE_Key hash2data_key = de_key_hash(DE_KeyFunc_DataFromHash, &hash); - DE_Val *hash2data_val = de_shared_chained_lookup(local_map_arena, &local_map, de_shared, &hint, &hash2data_key); - DE_ContentBlock *hash2data_block = de_session_node_access_via_val(session, hash2data_val); - String8 data = hash2data_block->data; - DE_Key hash2txti_key = de_key_hash(DE_KeyFunc_TxtiFromHash, &hash); - DE_Val *hash2txti_val = de_shared_chained_lookup(local_map_arena, &local_map, de_shared, &hint, &hash2txti_key); - DE_ContentBlock *hash2txti_block = de_session_node_access_via_val(session, hash2txti_val); - DE_InfoTxt *txt = hash2txti_block->txt; - - //- rjf: start pt -> search start offset - U64 start_off = 0; - if(1 <= start_pt.line && start_pt.line <= txt->line_count) - { - start_off = txt->line_ranges[start_pt.line-1].min; - if(1 <= start_pt.column && start_pt.column <= dim_1u64(txt->line_ranges[start_pt.line-1])) - { - start_off += (start_pt.column-1); - } - } - - //- rjf: search for all needle occurrences - U8 *byte_first = data.str; - U8 *byte_opl = data.str+data.size; - U8 *byte_start = byte_first + start_off; - U64 num_bytes_traversed = 0; - for(U8 *byte = byte_start; num_bytes_traversed < data.size;) - { - String8 rest_of_data = str8(byte, byte_opl-byte); - String8 next_needle_size = str8_prefix(rest_of_data, needle.size); - B32 found_match = str8_match(next_needle_size, needle, StringMatchFlag_CaseInsensitive); - - // rjf: record match - if(found_match) - { - U64 match_off = (U64)(byte-byte_first); - TxtPt match_pt = de_txt_pt_from_txti_off(txt, match_off); - DF_TextSearchMatch match = {match_pt}; - os_rw_mutex_take_w(stripe_rw_mutex); - { - DF_TextSearchCacheNode *node = 0; - for(DF_TextSearchCacheNode *n = slot->first; n != 0; n = n->next) - { - if(MemoryMatchStruct(&hash, &n->hash) && - str8_match(needle, n->needle, 0) && - flags == n->flags) - { - node = n; - } - } - df_text_search_match_chunk_list_push(node->arena, &node->search_matches, 256, &match); - node->good = 1; - } - os_rw_mutex_drop_w(stripe_rw_mutex); - } - - // rjf: increment - byte += 1; - num_bytes_traversed += 1; - if(byte >= byte_opl) - { - byte = byte_first; - } - } - - }break; - - //- rjf: garbage collect - case WorkKind_GarbageCollect: - { - os_rw_mutex_take_w(stripe_rw_mutex); - { - DF_TextSearchCacheNode *node = 0; - for(DF_TextSearchCacheNode *n = slot->first; n != 0; n = n->next) - { - if(MemoryMatchStruct(&hash, &n->hash) && - str8_match(needle, n->needle, 0) && - flags == n->flags) - { - node = n; - } - } - if(node != 0) - { - DLLRemove(slot->first, slot->last, node); - arena_release(node->arena); - } - } - os_rw_mutex_drop_w(stripe_rw_mutex); - }break; - } - } - - //- rjf: end - de_session_end(session); - scratch_end(scratch); - } -#endif -} - -internal int -df_text_search_match_array_qsort_compare(TxtPt *a, TxtPt *b) -{ - int result = 0; - if(txt_pt_less_than(*a, *b)) - { - result = -1; - } - else if(txt_pt_less_than(*b, *a)) - { - result = +1; - } - return result; -} - -internal void -df_text_search_match_array_sort_in_place(DF_TextSearchMatchArray *array) -{ - qsort(array->v, array->count, sizeof(DF_TextSearchMatch), (int (*)(const void *, const void *))df_text_search_match_array_qsort_compare); -} - -internal DF_TextSearchMatch -df_text_search_match_array_find_nearest__linear_scan(DF_TextSearchMatchArray *array, TxtPt pt, Side side) -{ - ProfBeginFunction(); - DF_TextSearchMatch result = {0}; - if(array->count != 0) - { - S64 best_line_distance = max_S64; - S64 best_column_distance = max_S64; - B32 best_matches_side = 0; - for(U64 idx = 0; idx < array->count; idx += 1) - { - S64 line_distance = abs_s64(array->v[idx].pt.line - pt.line); - S64 column_distance = abs_s64(array->v[idx].pt.column - pt.column); - B32 matches_side = (side == Side_Max ? txt_pt_less_than(pt, array->v[idx].pt) : - side == Side_Min ? txt_pt_less_than(array->v[idx].pt, pt) : - 1); - if(matches_side >= best_matches_side && line_distance == 0 && column_distance < best_column_distance) - { - best_matches_side = matches_side; - best_line_distance = 0; - best_column_distance = column_distance; - result = array->v[idx]; - } - else if(matches_side >= best_matches_side && line_distance < best_line_distance) - { - best_matches_side = matches_side; - best_line_distance = line_distance; - result = array->v[idx]; - } - } - } - ProfEnd(); - return result; -} - //////////////////////////////// //~ rjf: Colors, Fonts, Config diff --git a/src/df/gfx/df_gfx.h b/src/df/gfx/df_gfx.h index ae1d455f..c20510f2 100644 --- a/src/df/gfx/df_gfx.h +++ b/src/df/gfx/df_gfx.h @@ -47,71 +47,6 @@ struct DF_StringBindingPair DF_Binding binding; }; -//////////////////////////////// -//~ rjf: Text Searching Types - -typedef struct DF_TextSearchMatch DF_TextSearchMatch; -struct DF_TextSearchMatch -{ - TxtPt pt; -}; - -typedef struct DF_TextSearchMatchChunkNode DF_TextSearchMatchChunkNode; -struct DF_TextSearchMatchChunkNode -{ - DF_TextSearchMatchChunkNode *next; - DF_TextSearchMatch *v; - U64 count; - U64 cap; -}; - -typedef struct DF_TextSearchMatchChunkList DF_TextSearchMatchChunkList; -struct DF_TextSearchMatchChunkList -{ - DF_TextSearchMatchChunkNode *first; - DF_TextSearchMatchChunkNode *last; - U64 node_count; - U64 total_count; -}; - -typedef struct DF_TextSearchMatchArray DF_TextSearchMatchArray; -struct DF_TextSearchMatchArray -{ - DF_TextSearchMatch *v; - U64 count; -}; - -typedef struct DF_TextSearchCacheNode DF_TextSearchCacheNode; -struct DF_TextSearchCacheNode -{ - // rjf: links - DF_TextSearchCacheNode *next; - DF_TextSearchCacheNode *prev; - - // rjf: allocation - Arena *arena; - - // rjf: search parameters - U128 hash; - String8 needle; - DF_TextSliceFlags flags; - TxtPt start_pt; - - // rjf: search results - B32 good; - DF_TextSearchMatchChunkList search_matches; - - // rjf: last time touched - U64 last_time_touched_us; -}; - -typedef struct DF_TextSearchCacheSlot DF_TextSearchCacheSlot; -struct DF_TextSearchCacheSlot -{ - DF_TextSearchCacheNode *first; - DF_TextSearchCacheNode *last; -}; - //////////////////////////////// //~ rjf: Key Map Types @@ -985,17 +920,6 @@ internal void df_set_autocomp_lister_query(DF_Window *ws, UI_Key root_key, DF_Ct internal void df_set_search_string(String8 string); internal String8 df_push_search_string(Arena *arena); -//////////////////////////////// -//~ rjf: Text Searching - -internal void df_text_search_match_chunk_list_push(Arena *arena, DF_TextSearchMatchChunkList *list, U64 cap, DF_TextSearchMatch *match); -internal DF_TextSearchMatchArray df_text_search_match_array_from_chunk_list(Arena *arena, DF_TextSearchMatchChunkList *chunks); -internal U64 df_text_search_little_hash_from_hash(U128 hash); -internal void df_text_search_thread_entry_point(void *p); -internal int df_text_search_match_array_qsort_compare(TxtPt *a, TxtPt *b); -internal void df_text_search_match_array_sort_in_place(DF_TextSearchMatchArray *array); -internal DF_TextSearchMatch df_text_search_match_array_find_nearest__linear_scan(DF_TextSearchMatchArray *array, TxtPt pt, Side side); - //////////////////////////////// //~ rjf: Colors, Fonts, Config diff --git a/src/df/gfx/df_views.c b/src/df/gfx/df_views.c index 65286173..b168524b 100644 --- a/src/df/gfx/df_views.c +++ b/src/df/gfx/df_views.c @@ -5172,17 +5172,6 @@ DF_VIEW_UI_FUNCTION_DEF(Code) tv->center_cursor = 1; } - ////////////////////////////// - //- rjf: search query -> matches - // - DF_TextSearchMatchArray search_query_matches = {0}; -#if 0 - { - search_query_matches = df_text_search_match_array_from_entity_needle(scratch.arena, entity, search_query, entity_line_string_flags, tv->cursor); - df_text_search_match_array_sort_in_place(&search_query_matches); - } -#endif - ////////////////////////////// //- rjf: do searching operations // @@ -5525,23 +5514,6 @@ DF_VIEW_UI_FUNCTION_DEF(Code) // if(text_info_is_ready) { - // rjf: center first match - TxtPt next_match = df_text_search_match_array_find_nearest__linear_scan(&search_query_matches, tv->cursor, search_query_side).pt; - if(search_query.size != 0 && next_match.line != 0) - { - // TODO(rjf): [ ] @de2ctrl -#if 0 - DF_TextSlice match_line_slice = df_text_slice_from_entity(scratch.arena, entity, r1s64(next_match.line, next_match.line), entity_line_string_flags); - String8 match_line = match_line_slice.visible_range_text; - F32 match_advance = f_dim_from_tag_size_string(code_font, code_font_size, str8_prefix(match_line, next_match.column-1)).x; - container_box->view_off_target.x = match_advance - code_area_dim.x/2; - container_box->view_off_target.y = next_match.line*code_line_height - code_area_dim.y/2 + code_line_height*1.5f; - container_box->view_off_target.x = ClampBot(container_box->view_off_target.x, 0); - container_box->view_off_target.y = ClampBot(container_box->view_off_target.y, 0); - tv->drifted_for_search = 1; -#endif - } - // rjf: contain => snap if(tv->contain_cursor) { @@ -6983,17 +6955,6 @@ DF_VIEW_UI_FUNCTION_DEF(Output) tv->center_cursor = 1; } - ////////////////////////////// - //- rjf: search query -> matches - // - DF_TextSearchMatchArray search_query_matches = {0}; -#if 0 - { - search_query_matches = df_text_search_match_array_from_entity_needle(scratch.arena, entity, search_query, entity_line_string_flags, tv->cursor); - df_text_search_match_array_sort_in_place(&search_query_matches); - } -#endif - ////////////////////////////// //- rjf: do searching operations // @@ -7212,23 +7173,6 @@ DF_VIEW_UI_FUNCTION_DEF(Output) // if(txti_buffer_is_ready) { - // rjf: center first match - TxtPt next_match = df_text_search_match_array_find_nearest__linear_scan(&search_query_matches, tv->cursor, search_query_side).pt; - if(search_query.size != 0 && next_match.line != 0) - { - // TODO(rjf): [ ] @de2ctrl -#if 0 - DF_TextSlice match_line_slice = df_text_slice_from_entity(scratch.arena, entity, r1s64(next_match.line, next_match.line), entity_line_string_flags); - String8 match_line = match_line_slice.visible_range_text; - F32 match_advance = f_dim_from_tag_size_string(code_font, code_font_size, str8_prefix(match_line, next_match.column-1)).x; - container_box->view_off_target.x = match_advance - code_area_dim.x/2; - container_box->view_off_target.y = next_match.line*code_line_height - code_area_dim.y/2 + code_line_height*1.5f; - container_box->view_off_target.x = ClampBot(container_box->view_off_target.x, 0); - container_box->view_off_target.y = ClampBot(container_box->view_off_target.y, 0); - tv->drifted_for_search = 1; -#endif - } - // rjf: contain => snap if(tv->contain_cursor) {