[Mono-devel-list] Implemented Dictionary<K,V>
Ben Maurer
bmaurer at ximian.com
Sun Feb 27 11:35:02 EST 2005
On Sun, 2005-02-27 at 10:14 +0100, Matthijs ter Woord (meddochat) wrote:
> Hi Everybody,
>
> I implemented Dictionary<K,V>, can someone take a look at it?
+ public V this[K Index]{
+ get{
+ if (Index == null){
+ throw new ArgumentNullException("Index");
+ }
+ if (!ContainsKey(Index)){
+ throw new KeyNotFoundException();
+ }
+ foreach(KeyValuePair<K,V> kvp in underlyingList){
+ if (kvp.Key.Equals(Index)){
+ return kvp.Value;
+ }
+ }
+ return default(V);
+ }
+ set{
+ if (Index == null){
+ throw new ArgumentNullException("Index");
+ }
+ if (!ContainsKey(Index)){
+ throw new KeyNotFoundException();
+ }
+ foreach(KeyValuePair<K,V> kvp in underlyingList){
+ if (kvp.Key.Equals(Index)){
+ KeyValuePair<K,V> Temp = kvp;
+ int TempInt = underlyingList.IndexOf(Temp);
+ underlyingList.RemoveAt(TempInt);
+ Temp.Value = value;
+ underlyingList.Insert(TempInt, Temp);
+ }
+ }
+ }
+ }
This is a linear search. The Dictionary needs to be implemented like Hashtable.
-- Ben
More information about the Mono-devel-list
mailing list