Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLawrence Pit <lawrence@mono-cvs.ximian.com>2002-05-10 00:05:33 +0400
committerLawrence Pit <lawrence@mono-cvs.ximian.com>2002-05-10 00:05:33 +0400
commitf31d7f7c449272e1bf5f6f225438cbc4085a09ce (patch)
tree52f59c21ec5e15c07868cce0c62ec7cc812f4baf /mcs/class/System/System.Collections.Specialized
parent608ee73d25d6a9c46d29ba897c0a94b3ec786b3b (diff)
* HybridDictionary.cs: implemented
* CollectionsUtil.cs: implemented * BitVector32.cs: implemeneted * Modified signature of method ListDictionary.GetEnumerator svn path=/trunk/mcs/; revision=4458
Diffstat (limited to 'mcs/class/System/System.Collections.Specialized')
-rw-r--r--mcs/class/System/System.Collections.Specialized/BitVector32.cs144
-rwxr-xr-xmcs/class/System/System.Collections.Specialized/ChangeLog6
-rw-r--r--mcs/class/System/System.Collections.Specialized/CollectionsUtil.cs38
-rw-r--r--mcs/class/System/System.Collections.Specialized/HybridDictionary.cs183
4 files changed, 352 insertions, 19 deletions
diff --git a/mcs/class/System/System.Collections.Specialized/BitVector32.cs b/mcs/class/System/System.Collections.Specialized/BitVector32.cs
index e176a220f8c..078e6753270 100644
--- a/mcs/class/System/System.Collections.Specialized/BitVector32.cs
+++ b/mcs/class/System/System.Collections.Specialized/BitVector32.cs
@@ -3,29 +3,97 @@
//
// Author:
// Miguel de Icaza (miguel@ximian.com)
+// Lawrence Pit (loz@cable.a2000.nl)
//
// (C) Ximian, Inc. http://www.ximian.com
//
+using System;
+using System.Text;
+
namespace System.Collections.Specialized {
public struct BitVector32 {
int value;
public struct Section {
- public short maxval;
+ private short mask;
+ private short offset;
+
+ internal Section (short mask, short offset) {
+ this.mask = mask;
+ this.offset = offset;
+ }
+
+ public short Mask {
+ get { return mask; }
+ }
+
+ public short Offset {
+ get { return offset; }
+ }
+
+ public override bool Equals (object o)
+ {
+ if (! (o is Section))
+ return false;
+
+ Section section = (Section) o;
+ return this.mask == section.mask &&
+ this.offset == section.offset;
+ }
+
+ public override int GetHashCode ()
+ {
+ return (((Int16) mask).GetHashCode () << 16) +
+ ((Int16) offset).GetHashCode ();
+ }
+
+ public override string ToString ()
+ {
+ return "Section{0x" + Convert.ToString(mask, 16) +
+ ", 0x" + Convert.ToString(offset, 16) + "}";
+ }
}
-
- [MonoTODO]
- public static Section CreateSection (short maxval)
+
+ // Constructors
+
+ public BitVector32 (BitVector32 source)
{
- Section s = new Section();
-
- // FIXME: Imeplemtn me
+ value = source.value;
+ }
- return s;
+ public BitVector32 (int init)
+ {
+ value = init;
+ }
+
+ // Properties
+
+ public int Data {
+ get { return value; }
+ }
+
+ [MonoTODO]
+ public int this [BitVector32.Section section] {
+ get { return ((this.value >> section.Offset) & section.Mask); }
+ set {
+ throw new NotImplementedException ();
+ }
+ }
+
+ public bool this [int bit] {
+ get { return (value & bit) == bit; }
+ set {
+ if (value)
+ this.value |= bit;
+ else
+ this.value &= ~bit;
+ }
}
+ // Methods
+
public static int CreateMask ()
{
return 1;
@@ -33,19 +101,44 @@ namespace System.Collections.Specialized {
public static int CreateMask (int prev)
{
+ if (prev == 0)
+ return 1;
+ if (prev == Int32.MinValue)
+ throw new InvalidOperationException ("all bits set");
return prev << 1;
}
-
- public BitVector32 (BitVector32 source)
- {
- value = source.value;
- }
- public BitVector32 (int init)
+ public static Section CreateSection (short maxValue)
{
- value = init;
+ return CreateSection (maxValue, new Section (0, 0));
}
+
+ public static Section CreateSection (short maxValue, BitVector32.Section previous)
+ {
+ if (maxValue < 1)
+ throw new ArgumentException ("maxValue");
+
+ int newmask = (int) maxValue;
+ int mask = 0x8000;
+ while ((newmask & mask) == 0)
+ mask >>= 1;
+ while (mask > 0) {
+ newmask |= mask;
+ mask >>= 1;
+ }
+ short count = 0;
+ int prev = previous.Mask;
+ mask = 0x8000;
+ while (mask > 0) {
+ if ((prev & mask) != 0)
+ count++;
+ mask >>= 1;
+ }
+
+ return new Section ((short) newmask, (short) (previous.Offset + count));
+ }
+
public override bool Equals (object o)
{
if (!(o is BitVector32))
@@ -56,13 +149,26 @@ namespace System.Collections.Specialized {
public override int GetHashCode ()
{
- return 0;
+ return value.GetHashCode ();
}
- public int Data {
- get {
- return value;
+ public override string ToString ()
+ {
+ return ToString (this);
+ }
+
+ public static string ToString (BitVector32 value)
+ {
+ long val = (long) value.value;
+ StringBuilder b = new StringBuilder ();
+ b.Append ("BitVector32{");
+ long mask = (long) 0x80000000;
+ while (mask > 0) {
+ b.Append (((val & mask) == 0) ? '0' : '1');
+ mask >>= 1;
}
+ b.Append ('}');
+ return b.ToString ();
}
}
}
diff --git a/mcs/class/System/System.Collections.Specialized/ChangeLog b/mcs/class/System/System.Collections.Specialized/ChangeLog
index e582af13fa2..305d7ce9593 100755
--- a/mcs/class/System/System.Collections.Specialized/ChangeLog
+++ b/mcs/class/System/System.Collections.Specialized/ChangeLog
@@ -1,3 +1,9 @@
+2002-09-10 Lawrence Pit <loz@cable.a2000.nl>
+
+ * HybridDictionary.cs: implemented
+ * CollectionsUtil.cs: implemented
+ * BitVector32.cs: implemeneted
+ * Modified signature of method ListDictionary.GetEnumerator
Fri Feb 8 18:02:50 CET 2002 Paolo Molaro <lupus@ximian.com>
diff --git a/mcs/class/System/System.Collections.Specialized/CollectionsUtil.cs b/mcs/class/System/System.Collections.Specialized/CollectionsUtil.cs
new file mode 100644
index 00000000000..82d103134f1
--- /dev/null
+++ b/mcs/class/System/System.Collections.Specialized/CollectionsUtil.cs
@@ -0,0 +1,38 @@
+//
+// System.Collections.Specialized.CollectionsUtil.cs
+//
+// Author:
+// Lawrence Pit (loz@cable.a2000.nl)
+//
+
+using System.Collections;
+
+namespace System.Collections.Specialized {
+
+ public class CollectionsUtil {
+
+ public CollectionsUtil () {}
+
+ public static Hashtable CreateCaseInsensitiveHashtable ()
+ {
+ return new Hashtable (CaseInsensitiveHashCodeProvider.Default,
+ CaseInsensitiveComparer.Default);
+ }
+
+
+ public static Hashtable CreateCaseInsensitiveHashtable (IDictionary d) {
+ return new Hashtable (d, CaseInsensitiveHashCodeProvider.Default,
+ CaseInsensitiveComparer.Default);
+ }
+
+ public static Hashtable CreateCaseInsensitiveHashtable (int capacity) {
+ return new Hashtable (capacity, CaseInsensitiveHashCodeProvider.Default,
+ CaseInsensitiveComparer.Default);
+ }
+
+
+ public static SortedList CreateCaseInsensitiveSortedList () {
+ return new SortedList (CaseInsensitiveComparer.Default);
+ }
+ }
+} \ No newline at end of file
diff --git a/mcs/class/System/System.Collections.Specialized/HybridDictionary.cs b/mcs/class/System/System.Collections.Specialized/HybridDictionary.cs
new file mode 100644
index 00000000000..a8b313cbd91
--- /dev/null
+++ b/mcs/class/System/System.Collections.Specialized/HybridDictionary.cs
@@ -0,0 +1,183 @@
+//
+// System.Collections.Specialized.HybridDictionary.cs
+//
+// Author:
+// Lawrence Pit (loz@cable.a2000.nl)
+//
+
+using System;
+using System.Collections;
+
+namespace System.Collections.Specialized {
+
+ [Serializable]
+ public class HybridDictionary : IDictionary, ICollection, IEnumerable {
+
+ private const int switchAfter = 10;
+
+ private ListDictionary list;
+ private Hashtable hashtable;
+ private bool caseInsensitive = false;
+
+ // Constructors
+
+ public HybridDictionary() : this (0, false) { }
+
+ public HybridDictionary (bool caseInsensitive) : this (0, caseInsensitive) { }
+
+ public HybridDictionary (int initialSize) : this (initialSize, false) { }
+
+ public HybridDictionary(int initialSize, bool caseInsensitive)
+ {
+ this.caseInsensitive = caseInsensitive;
+
+ if (initialSize <= switchAfter)
+ if (caseInsensitive)
+ list = new ListDictionary (CaseInsensitiveComparer.Default);
+ else
+ list = new ListDictionary ();
+ else
+ if (caseInsensitive)
+ hashtable = new Hashtable (initialSize,
+ CaseInsensitiveHashCodeProvider.Default,
+ CaseInsensitiveComparer.Default);
+ else
+ hashtable = new Hashtable (initialSize);
+ }
+
+
+ // Properties
+
+ public int Count {
+ get {
+ if (list != null)
+ return list.Count;
+ return hashtable.Count;
+ }
+ }
+
+ public bool IsFixedSize {
+ get { return false; }
+ }
+
+ public bool IsReadOnly {
+ get { return false; }
+ }
+
+ public bool IsSynchronized {
+ get { return false; }
+ }
+
+ public object this [object key] {
+ get {
+ if (key == null)
+ throw new ArgumentNullException("key");
+ if (list != null)
+ return list [key];
+ return hashtable [key];
+ }
+ set {
+ if (list != null)
+ if (list.Count >= switchAfter)
+ Switch ();
+ else {
+ list [key] = value;
+ return;
+ }
+ hashtable [key] = value;
+ }
+ }
+
+ public ICollection Keys {
+ get {
+ if (list != null)
+ return list.Keys;
+ return hashtable.Keys;
+ }
+ }
+
+ public object SyncRoot {
+ get { return this; }
+ }
+
+ public ICollection Values {
+ get {
+ if (list != null)
+ return list.Values;
+ return hashtable.Values;
+ }
+ }
+
+
+ // Methods
+
+ public void Add (object key, object value)
+ {
+ if (list != null)
+ if (list.Count >= switchAfter)
+ Switch ();
+ else {
+ list.Add (key, value);
+ return;
+ }
+ hashtable.Add (key, value);
+ }
+
+ public void Clear ()
+ {
+ if (caseInsensitive)
+ list = new ListDictionary (CaseInsensitiveComparer.Default);
+ else
+ list = new ListDictionary ();
+ hashtable = null;
+ }
+
+ public bool Contains (object key)
+ {
+ if (list != null)
+ return list.Contains (key);
+ return hashtable.Contains (key);
+ }
+
+ public void CopyTo (Array array, int index)
+ {
+ if (list != null)
+ list.CopyTo (array, index);
+ else
+ hashtable.CopyTo (array, index);
+ }
+
+ public IDictionaryEnumerator GetEnumerator ()
+ {
+ if (list != null)
+ return list.GetEnumerator ();
+ return hashtable.GetEnumerator ();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator ()
+ {
+ return GetEnumerator ();
+ }
+
+ public void Remove (object key)
+ {
+ if (list != null)
+ list.Remove (key);
+ hashtable.Remove (key);
+ }
+
+ private void Switch ()
+ {
+ if (caseInsensitive)
+ hashtable = new Hashtable (switchAfter + 1,
+ CaseInsensitiveHashCodeProvider.Default,
+ CaseInsensitiveComparer.Default);
+ else
+ hashtable = new Hashtable (switchAfter + 1);
+ IDictionaryEnumerator e = list.GetEnumerator ();
+ while (e.MoveNext ())
+ hashtable.Add (e.Key, e.Value);
+ list = null;
+ }
+ }
+}