Generics Findall vs BinarySearch

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

I am using a collection to store about 300 records that I will be searching
through about 400 times for various items. So it has to traverse the whole
collection (300 items) 400 times to get all the items I need.

The collection is sorted and works fine with findall but I assume that
binarySearch is faster but it only finds one item.

Is there an equivelant BinarySearchAll for faster searching of sorted
objects?

Thanks,

Tom
 
tshad said:
I am using a collection to store about 300 records that I will be
searching through about 400 times for various items. So it has to
traverse the whole collection (300 items) 400 times to get all the
items I need.
The collection is sorted and works fine with findall but I assume that
binarySearch is faster but it only finds one item.

Is there an equivelant BinarySearchAll for faster searching of sorted
objects?

Use BinarySearch to get the index of one matching item.

Move forward and backward from that index, all other matching items will be
adjacent.
 
400 times to get all the items I need.

If you are going to search 400 times it makes sense to have a

Dictionary<string, List<string, object>> (assuming the key value is a
string)

Go through the list once and put the objects into the relevant list. Then
the next 399 lookups will be much faster.



Pete
 
Back
Top