[Mono-list] A small patch for SortedList

POUSSINEAU Hervé herve.poussineau@cegetel.fr
Fri, 13 Jun 2003 13:27:04 +0200


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_000_01C3319E.B75E24E0
Content-Type: multipart/alternative;
	boundary="----_=_NextPart_001_01C3319E.B75E24E0"


------_=_NextPart_001_01C3319E.B75E24E0
Content-Type: text/plain;
	charset="iso-8859-1"

ChangeLog
* SortedList.cs: Can enumerate on DictionaryEntries, not only on keys on
values. Enumerate by default on DictionaryEntries.


------_=_NextPart_001_01C3319E.B75E24E0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2653.12">
<TITLE>A small patch for SortedList</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>ChangeLog</FONT>
<BR><FONT SIZE=3D2>* SortedList.cs: Can enumerate on DictionaryEntries, =
not only on keys on values. Enumerate by default on =
DictionaryEntries.</FONT></P>

<P><FONT FACE=3D"Arial" SIZE=3D2 COLOR=3D"#000000"></FONT>&nbsp;

</BODY>
</HTML>
------_=_NextPart_001_01C3319E.B75E24E0--

------_=_NextPart_000_01C3319E.B75E24E0
Content-Type: application/octet-stream;
	name="SortedList.patch"
Content-Disposition: attachment;
	filename="SortedList.patch"

Index: class/corlib/System.Collections/SortedList.cs
===================================================================
RCS file: /mono/mcs/class/corlib/System.Collections/SortedList.cs,v
retrieving revision 1.11
diff -u -r1.11 SortedList.cs
--- class/corlib/System.Collections/SortedList.cs	9 Jun 2003 00:41:38 -0000	1.11
+++ class/corlib/System.Collections/SortedList.cs	12 Jun 2003 20:27:42 -0000
@@ -3,6 +3,7 @@
 // 
 // Author:
 //   Sergey Chaban (serge@wildwestsoftware.com)
+//   Herve Poussineau (hpoussineau@fr.st)
 // 
 
 
@@ -29,7 +30,7 @@
 
 		private readonly static int INITIAL_SIZE = 16;
 
-		public enum EnumeratorMode : int {KEY_MODE = 0, VALUE_MODE}
+		public enum EnumeratorMode : int {KEY_MODE = 0, VALUE_MODE, ENTRY_MODE}
 
 		private int inUse;
 		private int modificationCount;
@@ -219,7 +220,7 @@
 
 		public virtual IDictionaryEnumerator GetEnumerator ()
 		{
-			return new Enumerator (this, EnumeratorMode.KEY_MODE);
+			return new Enumerator (this, EnumeratorMode.ENTRY_MODE);
 		}
 
 		public virtual void Remove (object key)
@@ -591,7 +592,7 @@
 			}
 
 			public Enumerator (SortedList host)
-			: this (host, EnumeratorMode.KEY_MODE)
+			: this (host, EnumeratorMode.ENTRY_MODE)
 			{
 			}
 
@@ -657,9 +658,17 @@
 					if (invalid || pos >= size || pos == -1)
 						throw new InvalidOperationException (xstr);
 					
-					return (mode == EnumeratorMode.KEY_MODE)
-					        ? currentKey
-					        : currentValue;
+					switch (mode)
+					{
+						case EnumeratorMode.KEY_MODE:
+							return currentKey;
+						case EnumeratorMode.VALUE_MODE:
+							return currentValue;
+						case EnumeratorMode.ENTRY_MODE:
+							return this.Entry;
+					}
+					// Should never happen
+					throw new NotSupportedException("Not supported mode == " + mode);
 				}
 			}
 		}

------_=_NextPart_000_01C3319E.B75E24E0--