in System.Collections:
authorJb Evain <jbevain@gmail.com>
Tue, 6 Nov 2007 16:48:36 +0000 (16:48 -0000)
committerJb Evain <jbevain@gmail.com>
Tue, 6 Nov 2007 16:48:36 +0000 (16:48 -0000)
2007-11-06  Jb Evain  <jbevain@novell.com>

* Hashtable.cs: Don't compare user keys against the special removed
key. Fix #324761.

in Test/System.Collections:
2007-11-06  Jb Evain  <jbevain@novell.com>

* HashtableTest.cs: Add test case for #324761.

svn path=/trunk/mcs/; revision=89004

mcs/class/corlib/System.Collections/ChangeLog
mcs/class/corlib/System.Collections/Hashtable.cs
mcs/class/corlib/Test/System.Collections/ChangeLog
mcs/class/corlib/Test/System.Collections/HashtableTest.cs

index bbfd9e1ffd9eaf2e5751a2ad1a18c43bf9955ed9..b8a78113be7c001edcbec4c676e804a5f31df1f2 100644 (file)
@@ -1,3 +1,8 @@
+2007-11-06  Jb Evain  <jbevain@novell.com>
+
+       * Hashtable.cs: Don't compare user keys against the special removed
+       key. Fix #324761.
+
 2007-11-05  Sebastien Pouliot  <sebastien@ximian.com>
 
        * Queue.cs: Avoid IndexOutOfRangeException after TrimToSize. Patch by
index 0c7d04a7ba064f28efd830e72195a5a2e84dbe10..339d9b700fd969152f14da6849222bd7caedcb1d 100644 (file)
@@ -646,6 +646,8 @@ namespace System.Collections {
                /// </summary>
                protected virtual bool KeyEquals (Object item, Object key)
                {
+                       if (key == KeyMarker.Removed)
+                               return false;
 #if NET_2_0
                        if (equalityComparer != null)
                                return equalityComparer.Equals (item, key);
index 4d400f5baf386a134b505b0df52ea20100e86716..f65e9743f6d592f6f9aead22254b07e6f975eefa 100644 (file)
@@ -1,3 +1,7 @@
+2007-11-06  Jb Evain  <jbevain@novell.com>
+
+       * HashtableTest.cs: Add test case for #324761.
+
 2007-11-05  Sebastien Pouliot  <sebastien@ximian.com>
 
        * QueueTest.cs: Test cases for #321657. Based on the test case 
index e8c364ae5004468cb9ffcdb9ce34a5a1376182af..dc4e817d2a3391b2926c5ff6221744b03f9c5b06 100644 (file)
@@ -824,6 +824,46 @@ public class HashtableTest : Assertion {
                Assert ("GetEnumerator.IsSerializable", ht.GetEnumerator ().GetType ().IsSerializable);\r
                Assert ("Synchronized.IsSerializable", Hashtable.Synchronized (ht).GetType ().IsSerializable);\r
        }\r
+\r
+       [Test]\r
+       public void TestHashtableWithCustomComparer ()\r
+       {\r
+               // see bug #324761\r
+               IDHashtable dd = new IDHashtable ();\r
+               Random r = new Random (1000);\r
+               for (int n = 0; n < 10000; n++) {\r
+                       int v = r.Next (0, 1000);\r
+                       dd [v] = v;\r
+                       v = r.Next (0, 1000);\r
+                       dd.Remove (v);\r
+               }\r
+       }\r
+}\r
+\r
+class IDHashtable : Hashtable {\r
+\r
+       class IDComparer : IComparer {\r
+               public int Compare (object x, object y)\r
+               {\r
+                       if ((int) x == (int) y)\r
+                               return 0;\r
+                       else\r
+                               return 1;\r
+               }\r
+       }\r
+\r
+       class IDHashCodeProvider : IHashCodeProvider {\r
+               public int GetHashCode (object o)\r
+               {\r
+                       return (int) o;\r
+               }\r
+       }\r
+\r
+       public IDHashtable ()\r
+               : base (new IDHashCodeProvider (),\r
+                               new IDComparer ())\r
+       {\r
+       }\r
 }\r
 \r
 [Serializable]\r