TODO optimize the performance for very large item lists#1
Open
Anda275 wants to merge 2 commits intoUPB-CS-OpenSourceUpstream:masterfrom
Open
TODO optimize the performance for very large item lists#1Anda275 wants to merge 2 commits intoUPB-CS-OpenSourceUpstream:masterfrom
Anda275 wants to merge 2 commits intoUPB-CS-OpenSourceUpstream:masterfrom
Conversation
alexandruradovici
requested changes
Jan 7, 2024
| /// | ||
| /// ```ignore | ||
| /// table.set_on_sort(|siv: &mut Cursive, column: BasicColumn, order: Ordering| { | ||
| /// ```rust |
There was a problem hiding this comment.
Any reason why these are modified?
Author
There was a problem hiding this comment.
I saw that one of the tests ignored from the beginning was solved and I modified it to solve this one as well
Comment on lines
+909
to
+914
| let reverse_mapping: HashMap<usize, usize> = self.rows_to_items.iter().enumerate().map(|(row, &item)| (item, row)).collect(); | ||
|
|
||
| // Use the reverse mapping to find the row corresponding to the item_index | ||
| if let Some(&row) = reverse_mapping.get(&item_index) { | ||
| self.focus = row; | ||
| self.scroll_core.scroll_to_y(row); |
There was a problem hiding this comment.
Unless you always keep the hasmap up to date when adding and deleting items, this is slower than the original code. It does one O(n) traversal to build the hashmap, and for each item an O(log n) to insert into the hasmap. It does another O(log n) to retrieve the item.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This approach uses a HashMap to create an inverse mapping between the index of an element and the corresponding row in a list. When you want to set a selected element by index, you can directly use the reverse map to find the corresponding row without traversing the entire list.