Fix new filtering approach for TreeSearch

This commit is contained in:
Alexander Montag 2024-10-01 01:05:44 +02:00
parent 74cf9855a7
commit 4f7996b1ea
No known key found for this signature in database
GPG Key ID: 07FE50B35A2B7524
1 changed files with 15 additions and 6 deletions

View File

@ -62,6 +62,7 @@ void TreeSearch::_filter_tree(const String &p_search_mask) {
Vector<bool> item_visibilities;
item_visibilities.resize(ordered_tree_items.size());
item_visibilities.fill(false);
// Make all entries visible that have any matching descendents. O(n)
for (int i = 0; i < ordered_tree_items.size(); i++) {
@ -74,11 +75,19 @@ void TreeSearch::_filter_tree(const String &p_search_mask) {
// Make all descendents of matching entries visible. O(n) * log(|matching_entries|)
for (int i = 0; i < ordered_tree_items.size(); i++) {
TreeItem *entry = ordered_tree_items[i];
TreeItem *next_entry = entry->get_next();
if (!next_entry && i < ordered_tree_items.size() - 1) {
next_entry = ordered_tree_items[i + 1];
}
if (_vector_has_bsearch(matching_entries, entry)) {
// the [next_entry] at the same depth or depth above.
TreeItem *next_entry = entry->get_next();
// search above current depth if no [next_entry].
while (!next_entry && entry) {
entry = entry->get_parent();
}
if (entry) {
next_entry = entry->get_next();
}
// mark visible all successors upto next entry at the same depth or above
int j = i;
for (; j < ordered_tree_items.size() && ordered_tree_items[j] != next_entry; j++) {
item_visibilities.set(j, true);
@ -87,7 +96,7 @@ void TreeSearch::_filter_tree(const String &p_search_mask) {
}
}
// apply visibility. O(n)
// Apply visibility. O(n)
for (int i = 0; i < ordered_tree_items.size(); i++) {
if (!item_visibilities[i]) {
ordered_tree_items[i]->set_visible(false);
@ -95,7 +104,7 @@ void TreeSearch::_filter_tree(const String &p_search_mask) {
}
}
// makes all tree items visible.
// Makes all tree items visible.
void TreeSearch::_clear_filter() {
ERR_FAIL_COND(!tree_reference);
Vector<TreeItem *> items = { tree_reference->get_root() };