Reputation: 42
I would like to enumerate a sortedset starting from a given position. Say my set contains [1,2,10,23,30]. I would like to search for 10 and then enumerate from that position. I believe enumeration from a fixed position in a sorted set runs in O(n) where n is the number of elements you want to visit. But accessing by index is O(log n). So if I tried to say find 10 and got index 2 and then did a for loop of index 2 - N that would be runtime O(n log n) which is not acceptable.
Anyone have any experience here?
Upvotes: 0
Views: 391
Reputation: 171188
Use GetViewBetween. It is made for the purpose of range scans.
Whenever I use a new class I look at its members in Reflector to try to discover useful gems there.
Upvotes: 1
Reputation: 20620
s.SkipWhile(x => x < 10)
should be O(n)
, where n is the number of elements in the list.
Moving from one element to the next is quick; moving to the i th element from the start if you look up by index might not be.
Upvotes: 0