Indexing Items in a Generics List

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using a generics List<MyStructure> object of a structure of information
I need in my application. Initially I created a predicate to retrieve the
correct struct of data, but I am finding that this approach is very CPU
intensive ~15% for just the look up. I did a test where I created a list
that contained just the index values I needed so that I could use a
BinarySearch to give me an index value that I could use to pull the item out
of the list of structures. This is very fast but because the List has to be
sorted to to use the BinarySearch the ordinal positions of my lists no longer
match. It seems like I need to create an index list that contains the value
I want to lookup and the position of the data in the original list so that I
can pull it out. It seems like I need to implement a Comparer to be able to
sort and search my index. The on-line help does not provide any examples of
how to do this. If I create a Comparer will I still get the efficiency of
the BinarySearch or will it need to look through the entire list to find my
value like the Predicate does?

Does this seem like the correct approach? It seems like wanting to have an
index on a list would be something that a number of applications would need.
Any ideas would be appreciated.
 
I found the SortedDictionary object that is doing the job for me. I use my
first index value as the key and my structure as the value. I then create
additional SortedDictionaries for each of the other indexes with the value
containing the key in the first SortedDictionary. Isn't it always the case,
once you post a message for help you find the answer?
 
Back
Top