I have a data structure that consists of pairs of values, the first of which is an integer, and the second of them is an alphanumeric string (which can start with numbers):
+--------+-----------------+ | Number | Name | +--------+-----------------+ | 15 | APPLES | | 16 | APPLE COMPUTER | | 17 | ORANGE | | 21 | TWENTY-1 | | 291 | 156TH ELEMENT | +--------+-----------------+
A table of them will contain up to 100,000 rows.
I would like to provide a search function in which the user can search for either a number (as if it were a string) or fragments of a string. Ideally, the search will be “live” as the user enters; after each keystroke (or maybe after a short delay of ~ 250-500 ms), a new search will be performed to find the most likely candidates. So, for example, search by
1 will return 15 APPLES , 16 APPLE COMPUTER , 17 ORANGE and 291 156TH ELEMENT15 narrow your search to 15 APPLES , 291 156TH ELEMENTAP will return 15 APPLES and 16 APPLE COMPUTER- (ideally, but not required)
ELEM will return 291 156TH ELEMENT .
I was thinking about using two Dictionary<string, string> , since in the end int compared as string - one will be indexed by the integer part, and the other by the string.
But in fact, substring searching should not use a hash function, and it seems wasteful to use twice as much memory, which I think I need.
Ultimately, the question arises: is there any well-executed way to text search two large lists at once for substrings?
Otherwise, how about a SortedDictionary ? May improve performance, but still will not solve the hash problem.
The thought of creating a regex on the fly, but I think it will be terrible.
I'm new to C # (came from the Java world), so I haven't looked at LINQ yet; this is the answer?
EDIT 18:21 EST . None of the lines in the "Name" field will be more than 12-15 characters, if this affects your potential decision.