Collection Naming Conventions

  • Thread starter Thread starter J2EE Convert
  • Start date Start date
J

J2EE Convert

Hey All,

I was just curious as to why the SortedList collection in
System.Collections namespace was named as such. It seems strange to me
that it was not named a SortedDictionary. I noticed in the
System.Collection.Generic namespace they named a similar generic
collection a SortedDictionary. Not that it really matters but it
always throws me for a loop when I see it. My first instinct is that
it is a IList impl. I always end looking at the documentation and have
a Homer moment 'DOH!!!!'

PD
 
Hey All,

I was just curious as to why the SortedList collection in
System.Collections namespace was named as such. It seems strange to me
that it was not named a SortedDictionary. I noticed in the
System.Collection.Generic namespace they named a similar generic
collection a SortedDictionary. Not that it really matters but it
always throws me for a loop when I see it. My first instinct is that
it is a IList impl. I always end looking at the documentation and have
a Homer moment 'DOH!!!!'

Well, in generics there's both SortedList<TKey,TValue> and
SortedDictionary<TKey,TValue>. They're very similar, but have
different performance characteristics. Also, the Keys/Values
properties of SortedList<,> are IList<T> whereas
SortedDictionary<,>.Keys/Values are KeyCollection/ValueCollection,
which you can't access by numeric index.

But yes, I quite agree - the naming is very confusing.

Jon
 
In this case, it has to do with the performance profiles of each on
insertions. While they both do the same thing, and retrievals have O(log n)
retrieval time, the SortedList have an O(n) insertion time, while the
SortedDictionary has an O(log n) insertion time.
 
Back
Top