P
Paul Delhanty
Hi,
I am converting an existing native C++ program making heavy use of STL
to C#2.0 with STL usage replaced by the new generic collections. The
conversion has gone well to the point where I am replacing an STL map
instance by a System.Collections.Generic.SortedDictionary instance. In
need the collection to be ordered, and to have o(log(n)) look up - that
is fine so far SortedDictionary.TryGetValue does the job. I also need
the ability after a lookup to iterate to the next and previous values in
o(log(n)) time or better. In STL this is easy because map::find returns
an iterator. However, I can't see how to perform the equivalent
operation for a SortedDictionary in o(log(n)) time. (Enumerating the
whole SortedDictionary is o(n) for both average and worst case.)
Have I missed anything obvious? SortedDictionary seems to be based on a
red-black tree - System.Collections.Generic.TreeSet - so the
data-structure appears to be rich enough, but the public methods of
SortedDictionary do not appear to allow access to the functionality I need.
Thanks in advance for any replies.
Paul Delhanty
Cadcambridge Limited
http://www.cadcambridge.net
I am converting an existing native C++ program making heavy use of STL
to C#2.0 with STL usage replaced by the new generic collections. The
conversion has gone well to the point where I am replacing an STL map
instance by a System.Collections.Generic.SortedDictionary instance. In
need the collection to be ordered, and to have o(log(n)) look up - that
is fine so far SortedDictionary.TryGetValue does the job. I also need
the ability after a lookup to iterate to the next and previous values in
o(log(n)) time or better. In STL this is easy because map::find returns
an iterator. However, I can't see how to perform the equivalent
operation for a SortedDictionary in o(log(n)) time. (Enumerating the
whole SortedDictionary is o(n) for both average and worst case.)
Have I missed anything obvious? SortedDictionary seems to be based on a
red-black tree - System.Collections.Generic.TreeSet - so the
data-structure appears to be rich enough, but the public methods of
SortedDictionary do not appear to allow access to the functionality I need.
Thanks in advance for any replies.
Paul Delhanty
Cadcambridge Limited
http://www.cadcambridge.net