dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Collections Hashtable


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Collections Hashtable.cs,1.7,1.8
Date: Fri, 04 Apr 2003 23:57:07 -0500

Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Collections
In directory subversions:/tmp/cvs-serv16039/runtime/System/Collections

Modified Files:
        Hashtable.cs 
Log Message:


Fix bug #3048 - "Keys" and "Values" properties of "Hashtable" should
return a live view of the collection, not a copy.


Index: Hashtable.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Collections/Hashtable.cs,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** Hashtable.cs        2 Mar 2003 08:34:39 -0000       1.7
--- Hashtable.cs        5 Apr 2003 04:57:05 -0000       1.8
***************
*** 535,539 ****
                                {
                                        int posn;
!                                       for(posn = 0; posn < num; ++posn)
                                        {
                                                if(table[posn].key != null)
--- 535,539 ----
                                {
                                        int posn;
!                                       for(posn = 0; posn < table.Length; 
++posn)
                                        {
                                                if(table[posn].key != null)
***************
*** 748,763 ****
                                get
                                {
!                                       Object[] array = new Object [num];
!                                       int posn, index;
!                                       Object key;
!                                       index = 0;
!                                       for(posn = 0; posn < capacity; ++posn)
!                                       {
!                                               if((key = table[posn].key) != 
null)
!                                               {
!                                                       array[index++] = key;
!                                               }
!                                       }
!                                       return array;
                                }
                        }
--- 748,752 ----
                                get
                                {
!                                       return new 
HashtableKeyValueCollection(this, true);
                                }
                        }
***************
*** 766,780 ****
                                get
                                {
!                                       Object[] array = new Object [num];
!                                       int posn, index;
!                                       index = 0;
!                                       for(posn = 0; posn < capacity; ++posn)
!                                       {
!                                               if(table[posn].key != null)
!                                               {
!                                                       array[index++] = 
table[posn].value;
!                                               }
!                                       }
!                                       return array;
                                }
                        }
--- 755,759 ----
                                get
                                {
!                                       return new 
HashtableKeyValueCollection(this, false);
                                }
                        }
***************
*** 1269,1273 ****
                                }
  
!       }; // HashtableEnum
  
  }; // class Hashtable
--- 1248,1373 ----
                                }
  
!       }; // class HashtableEnum
! 
!       // Key/value enumerator class.
!       private sealed class HashtableKeyValueEnumerator : IEnumerator
!       {
!               // Internal state.
!               private IDictionaryEnumerator e;
!               private bool keys;
! 
!               // Constructor.
!               public HashtableKeyValueEnumerator(IDictionaryEnumerator e, 
bool keys)
!                               {
!                                       this.e = e;
!                                       this.keys = keys;
!                               }
! 
!               // Implement the IEnumerator interface.
!               public bool MoveNext()
!                               {
!                                       return e.MoveNext();
!                               }
!               public void Reset()
!                               {
!                                       e.Reset();
!                               }
!               public Object Current
!                               {
!                                       get
!                                       {
!                                               if(keys)
!                                               {
!                                                       return e.Key;
!                                               }
!                                               else
!                                               {
!                                                       return e.Value;
!                                               }
!                                       }
!                               }
! 
!       }; // class HashtableKeyValueEnumerator
! 
!       // Collection access to the keys or values in a hash table.
!       private sealed class HashtableKeyValueCollection : ICollection
!       {
!               // Internal state.
!               private Hashtable table;
!               private bool keys;
! 
!               // Constructor.
!               public HashtableKeyValueCollection(Hashtable table, bool keys)
!                               {
!                                       this.table = table;
!                                       this.keys = keys;
!                               }
! 
!               // Implement the ICollection interface.
!               public void CopyTo(Array array, int index)
!                               {
!                                       if(array == null)
!                                       {
!                                               throw new 
ArgumentNullException("array");
!                                       }
!                                       else if(array.Rank != 1)
!                                       {
!                                               throw new 
ArgumentException(_("Arg_RankMustBe1"));
!                                       }
!                                       else if(index < array.GetLowerBound(0))
!                                       {
!                                               throw new 
ArgumentOutOfRangeException
!                                                       ("index", 
_("Arg_InvalidArrayIndex"));
!                                       }
!                                       else if(index > (array.GetLength(0) - 
table.Count))
!                                       {
!                                               throw new 
ArgumentException(_("Arg_InvalidArrayRange"));
!                                       }
!                                       else
!                                       {
!                                               IDictionaryEnumerator e = 
table.GetEnumerator();
!                                               while(e.MoveNext())
!                                               {
!                                                       if(keys)
!                                                       {
!                                                               
array.SetValue(e.Key, index++);
!                                                       }
!                                                       else
!                                                       {
!                                                               
array.SetValue(e.Value, index++);
!                                                       }
!                                               }
!                                       }
!                               }
!               public int Count
!                               {
!                                       get
!                                       {
!                                               return table.Count;
!                                       }
!                               }
!               public bool IsSynchronized
!                               {
!                                       get
!                                       {
!                                               return table.IsSynchronized;
!                                       }
!                               }
!               public Object SyncRoot
!                               {
!                                       get
!                                       {
!                                               return table.SyncRoot;
!                                       }
!                               }
! 
!               // Implement the IEnumerable interface.
!               public IEnumerator GetEnumerator()
!                               {
!                                       return new HashtableKeyValueEnumerator
!                                               (table.GetEnumerator(), keys);
!                               }
! 
!       }; // class HashtableKeyCollection
  
  }; // class Hashtable





reply via email to

[Prev in Thread] Current Thread [Next in Thread]