Generics Findall vs BinarySearch

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
 
B

Ben Voigt [C++ MVP]

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.
 
P

Peter Morris

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top