Say I have the following codes:
SortedDictionary<int,string> test = new SortedDictionary<int, string> ( );
test.Add ( 1, "one" );
test.Add ( 3, "three" );
test.Add ( 7, "seven" );
test.Add ( 8, "eight" );
int key = GetFirstKeyGreaterThan ( test, 3 ); // expects to get 7
int key2 = GetFirstKeyGreaterThan ( test, 6 ); // expects to get 7
Is there an easy way to implement GetFirstKeyGreaterThan method? I know we can use GetEnumerator method and call MoveNext after we reach the key of 3, but it would be an O(n) operation.
I do not want to use SortedList because I need an O(log n) for key insertion and removal.