Wednesday, July 28, 2004 1:38 AM
pgolde
A couple changes to OrderedDictionary
Based on various feedback, I updated some parts of OrderedDictionary:
1. The View nested class, returned by Range, RangeTo, RangeFrom, and Reversed, now implements IDictionary and IDictionary<KeyType,ValueType>. You can add and delete entries through a view, which affects the underlying OrderedDictionary (views never copy or snapshot data). This has a couple nice effects:
a. You can pass the results of a Range call to any method that takes an IDictionary. For example, you can do:
dict1.Merge(dict2.Range(from, to));
to merge part of one dictionary into another.
b. You can use Clear to clear part of an OrderedDictionary. For example:
dict1.Range(”A”, “B”).Clear();
removes all the keys that begin with “A” from the dictionary.
2. I renamed RemoveCollection, which removes a set of keys, to RemoveAll.
I'm tempted to rename Merge to AddAll to be similar. However, I'm hesitating become the semantics are subtly different from the “Add” method -- Add throws an exception if the key already exists, while Merge/AddAll replaces keys that already exists. Is AddAll too confusing a name given this difference?
Comments?