Method to determine if keys of a dictionary are in sequence or a range
I'm trying to determine when to remove entries in the sorteddictionary, when a sequence is found, i.e. where the key is a sequence of 1,2,3,4,5,6,7,8,9,10... etc.
I have:
SortedDictionary<int, string>
Its hard to explain. I'm adding pairs where the key can be any integer value, generally on a random'ish basis. So, the program may add
<2,"jim"> <15,"Jack"> <62,"jill"> and so on.
So when it executes, the dictionary is going to filled with a sorted list which is not necessary in sequence, but I want to check, if say key values 1..10 are present, in a proper sequence, i.e 1,2,3,4,5,6,7,8,9,10.
The background is i've got stuff coming in from a messaging pipe, which is not in order. So it goes into this dictionary, and then on another thread开发者_开发技巧 I check the dictionary, and if return's success for the range I provide, then removes it from the dictionary and enques it, in order onto a concurrentqueue. Fundamentally an inorder to ordered exchange.
Any help is appreciated. Bob.
If you get the highest and lowest keys, then the count would tell you if you've got a sequence.
精彩评论