Reputation: 1156
I need a efficient data structure for searching. Currently I am using a simple List from System.Collections.Generic until I find a good solution.
The user can add/remove strings at runtime by clicking on them in a list. But the main operation is searching because every time the user want's to see the list I need to check for every entry if the user already clicked on it before. The list may contain about 100-1000 entries of which the user can choose about 100. The list with the chosen strings will also be saved as a string array to disk and needs to be loaded again. So the data structure should be fast to rebuild from a string array if the array was saved in the correct order.
I thought about using an AVL tree. Is it a good solution? Or would hashing be possible (I don't know the strings that can be chosen at compile time)?
Upvotes: 1
Views: 2783
Reputation: 447
Since you are using C# I would recommend using: Dictionary
. It will allow you to store strings in a Hash Map (which is a related to Java's Map
). The benefit of storing strings in a Dictionary
is similar to that of a hash table which will allow constant time of searching, inserting, and deleting. Should you want to check if there are duplicate values you can check here for more information: Finding duplicate values in dictionary and print Key of the duplicate element.
Upvotes: 1