T
The One We Call 'Dave'
I have a list of DateTime objects stored in a collection:
SortedList<DateTime,Object> MyDates=new SortedList<DateTime,Object>();
The dates, which can be accessed via MyDates.Keys, are stored in ascending
order. What is the fastest way to find the MAXIMUM date within 'MyDates'
which is LESS THAN or EQUAL to 12/30/05?
MyDates.ContainsKey() will tell me if the 12/30/05 exists in the list. If,
however, 12/30/05 does NOT exist in the list but 12/29/05 DOES exist in the
list, I'd like 12/29/05 to be returned.
The brute force method of iterating through the entire MyDates.Keys
collection will work of course, but this method strikes me as inefficient
since it's not taking advantage of the fact that the items are in fact
ordered.
The other idea that I came up with is to start looking in the middle of the
list and gradually narrow my search area based upon each 'hit'.
What's the best way to approach this problem? Is there an instance method
that I'm overlooking ?
Dave
SortedList<DateTime,Object> MyDates=new SortedList<DateTime,Object>();
The dates, which can be accessed via MyDates.Keys, are stored in ascending
order. What is the fastest way to find the MAXIMUM date within 'MyDates'
which is LESS THAN or EQUAL to 12/30/05?
MyDates.ContainsKey() will tell me if the 12/30/05 exists in the list. If,
however, 12/30/05 does NOT exist in the list but 12/29/05 DOES exist in the
list, I'd like 12/29/05 to be returned.
The brute force method of iterating through the entire MyDates.Keys
collection will work of course, but this method strikes me as inefficient
since it's not taking advantage of the fact that the items are in fact
ordered.
The other idea that I came up with is to start looking in the middle of the
list and gradually narrow my search area based upon each 'hit'.
What's the best way to approach this problem? Is there an instance method
that I'm overlooking ?
Dave