[svn] r7507: nemerle/trunk: lib/hashtable.n macros ncc/hierarchy/NamespaceTree.n

VladD2 svnadmin at nemerle.org
Fri Mar 2 06:07:43 CET 2007


Log:
Add standard ctors into Hashtable[,]

Author: VladD2
Date: Fri Mar  2 06:07:39 2007
New Revision: 7507

Modified:
   nemerle/trunk/lib/hashtable.n
   nemerle/trunk/macros/   (props changed)
   nemerle/trunk/ncc/hierarchy/NamespaceTree.n

Modified: nemerle/trunk/lib/hashtable.n
==============================================================================
--- nemerle/trunk/lib/hashtable.n	(original)
+++ nemerle/trunk/lib/hashtable.n	Fri Mar  2 06:07:39 2007
@@ -31,6 +31,7 @@
 using System.Runtime.Serialization;
   
 using SC = System.Collections;
+using SCG = System.Collections.Generic;
 
 namespace Nemerle.Collections
 {
@@ -42,61 +43,63 @@
   [System.Runtime.InteropServices.ComVisible(false)]
   [DebuggerDisplay("Count = {Count}: {ToString()}")]
   [DebuggerNonUserCode]
-  public class Hashtable ['a,'b] 
-             : SC.Generic.Dictionary ['a, 'b]
-    //           , IDictionary ['a,'b]
+  public class Hashtable [TKey, TValue] : SCG.Dictionary [TKey, TValue]
+    //           , IDictionary [TKey,TValue]
   {
     /* -- PUBLIC CONSTRUCTORS ---------------------------------------------- */
 
-    /**
-     * Creates an empty hashtable
-     */
-    public this ()
-    {
-    }
-
-    
-    /**
-     * Creates an empty hashtable and sets its default capacity
-     */
-//    [Requires (capacity > 0)]
-    public this (capacity : int)
-    {
-      base (capacity);
-    }
-
-    
-    /**
-     * Creates an empty hashtable and sets its default capacity
-     * and the load factor.
-     */
-    public this (capacity : int, loadFactor : float)
-    requires capacity > 0 && loadFactor >= 0.1f && loadFactor <= 1.0f
-    {
-      // S.C.G.Dictinary doesn't seem to support that
-      base (capacity);
-    }
-
+    /// <summary>Initializes a new instance of the <see cref="T:Nemerle.Collections.Hashtable`2"></see> class that is empty, has the default initial capacity, and uses the default equality comparer for the key type.</summary>
+    public this () { }
     
-    /* -- COPYING CONSTRUCTOR ---------------------------------------------- */
-
-    /**
-     * Creates a shallow copy of this hashtable
-     */
-    public this ([NotNull] ht : Hashtable ['a, 'b])
-    {
-      base (ht);
-    }
-
-    public this (generator : SC.Generic.IEnumerable ['a * 'b])
+    /// <summary>Initializes a new instance of the <see cref="T:Nemerle.Collections.Hashtable`2"></see> class that contains elements copied from the specified <see cref="T:System.Collections.Generic.IDictionary`2"></see> and uses the default equality comparer for the key type.</summary>
+    /// <param name="dictionary">The <see cref="T:System.Collections.Generic.IDictionary`2"></see> whose elements are copied to the new <see cref="T:Nemerle.Collections.Hashtable`2"></see>.</param>
+    /// <exception cref="T:System.ArgumentException">dictionary contains one or more duplicate keys.</exception>
+    /// <exception cref="T:System.ArgumentNullException">dictionary is null.</exception>
+    public this(dictionary : SCG.IDictionary[TKey, TValue]) { base (dictionary) }
+
+    /// <summary>Initializes a new instance of the <see cref="T:Nemerle.Collections.Hashtable`2"></see> class that contains elements copied from the specified <see cref="T:System.Collections.Generic.IEnumerable`1"></see> and uses the default equality comparer for the key type.</summary>
+    /// <param name="dictionary">The <see cref="T:System.Collections.Generic.IEnumerable`1"></see> whose elements are copied to the new <see cref="T:Nemerle.Collections.Hashtable`2"></see>.</param>
+    public this (generator : SC.Generic.IEnumerable [TKey * TValue])
     {
       base ();
       foreach ((key, val) in generator)
         Add (key, val)
     }
     
+    /// <summary>Initializes a new instance of the Hashtable[,] class that is empty, has the default 
+    /// initial capacity, and uses the specified <see cref="T:System.Collections.Generic.IEqualityComparer`1"></see>.</summary>
+    /// <param name="comparer">The <see cref="T:System.Collections.Generic.IEqualityComparer`1"></see> implementation to use when comparing keys, or null to use the default <see cref="T:System.Collections.Generic.EqualityComparer`1"></see> for the type of the key.</param>
+    public this(comparer : SCG.IEqualityComparer[TKey]) { base (comparer) }
+
+    /// <summary>Initializes a new instance of the <see cref="T:Nemerle.Collections.Hashtable`2"></see> class that is empty, has the specified initial capacity, and uses the default equality comparer for the key type.</summary>
+    /// <param name="capacity">The initial number of elements that the <see cref="T:Nemerle.Collections.Hashtable`2"></see> can contain.</param>
+    /// <exception cref="T:System.ArgumentOutOfRangeException">capacity is less than 0.</exception>
+    public this (capacity : int) { base (capacity); }
+
+    /// <summary>Initializes a new instance of the <see cref="T:Nemerle.Collections.Hashtable`2"></see> class that contains elements copied from the specified <see cref="T:System.Collections.Generic.IDictionary`2"></see> and uses the specified <see cref="T:System.Collections.Generic.IEqualityComparer`1"></see>.</summary>
+    /// <param name="dictionary">The <see cref="T:System.Collections.Generic.IDictionary`2"></see> whose elements are copied to the new <see cref="T:Nemerle.Collections.Hashtable`2"></see>.</param>
+    /// <param name="comparer">The <see cref="T:System.Collections.Generic.IEqualityComparer`1"></see> implementation to use when comparing keys, or null to use the default <see cref="T:System.Collections.Generic.EqualityComparer`1"></see> for the type of the key.</param>
+    /// <exception cref="T:System.ArgumentException">dictionary contains one or more duplicate keys.</exception>
+    /// <exception cref="T:System.ArgumentNullException">dictionary is null.</exception>
+    public this(dictionary : SCG.IDictionary[TKey, TValue], comparer : SCG.IEqualityComparer[TKey])
+    {
+      base (dictionary, comparer)
+    }
+
+    /// <summary>Initializes a new instance of the <see cref="T:Nemerle.Collections.Hashtable`2"></see> class that is empty, has the specified initial capacity, and uses the specified <see cref="T:System.Collections.Generic.IEqualityComparer`1"></see>.</summary>
+    /// <param name="capacity">The initial number of elements that the <see cref="T:Nemerle.Collections.Hashtable`2"></see> can contain.</param>
+    /// <param name="comparer">The <see cref="T:System.Collections.Generic.IEqualityComparer`1"></see> implementation to use when comparing keys, or null to use the default <see cref="T:System.Collections.Generic.EqualityComparer`1"></see> for the type of the key.</param>
+    /// <exception cref="T:System.ArgumentOutOfRangeException">capacity is less than 0.</exception>
+    public this(capacity : int, comparer : SCG.IEqualityComparer[TKey])
+    {
+      base (capacity, comparer)
+    }
+
     /* -- SERIALIZATION CONSTRUCTOR ---------------------------------------------- */
 
+    /// <summary>Initializes a new instance of the <see cref="T:System.Collections.Generic.Dictionary`2"></see> class with serialized data.</summary>
+    /// <param name="context">A <see cref="T:System.Runtime.Serialization.StreamingContext"></see> structure containing the source and destination of the serialized stream associated with the <see cref="T:System.Collections.Generic.Dictionary`2"></see>.</param>
+    /// <param name="info">A <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> object containing the information required to serialize the <see cref="T:System.Collections.Generic.Dictionary`2"></see>.</param>
     protected this (info : SerializationInfo, context :  StreamingContext)
     {
       base(info, context);
@@ -107,7 +110,7 @@
     /**
      * Returns an optional value associated with the specified key.
      */
-    public Get (key : 'a) : option ['b]
+    public Get (key : TKey) : option [TValue]
     {
       mutable value;
       
@@ -117,7 +120,7 @@
         None ()
     }
         
-    public TryGetValue (key : 'a) : 'b * bool
+    public TryGetValue (key : TKey) : TValue * bool
     {
       mutable value;
       
@@ -131,7 +134,7 @@
      * Returns value associated with the specified key or default value (null for 
      * referece type and result of parameterless constractor for value type).
      */
-    public GetValueOrDefault (key : 'a) : 'b
+    public GetValueOrDefault (key : TKey) : TValue
     {
       mutable value;
       
@@ -143,7 +146,7 @@
     /**
      * Returns value associated with the specified key or defaultValue.
      */
-    public GetValueOrDefault (key : 'a, defaultValue : 'b) : 'b
+    public GetValueOrDefault (key : TKey, defaultValue : TValue) : TValue
     {
       mutable value;
       
@@ -157,7 +160,7 @@
      * Returns value associated with the specified key or result of call getDefaultValue().
      * The getDefaultValue() called only if key not exists in collection.
      */
-    public GetValueOrGetDefault (key : 'a, getDefaultValue : void -> 'b) : 'b
+    public GetValueOrGetDefault (key : TKey, getDefaultValue : void -> TValue) : TValue
     {
       mutable value;
       
@@ -178,7 +181,7 @@
      * Console.WriteLine(map.GetValue("1", () => 2)); // Write "1"
      * Console.WriteLine(map["1"]);                   // Write "1"
      */
-    public GetValue (key : 'a, getNewValue : void -> 'b) : 'b
+    public GetValue (key : TKey, getNewValue : void -> TValue) : TValue
     {
       mutable value;
       
@@ -196,7 +199,7 @@
      * This is different from add, which can fail if the key is
      * already in the underlying Framework hashtable.
      */
-    public Set (key : 'a, val : 'b) : void
+    public Set (key : TKey, val : TValue) : void
     {
       this [key] = val;
     }
@@ -205,7 +208,7 @@
     /**
      * Clones this hashtable.
      */
-    public Clone () : Hashtable ['a,'b]
+    public Clone () : Hashtable [TKey,TValue]
     {
       Hashtable (this)
     }
@@ -217,7 +220,7 @@
      *
      * NOTE: this is the same as ContainsKey.
      */
-    public Contains (key : 'a) : bool
+    public Contains (key : TKey) : bool
     {
       ContainsKey (key)
     }
@@ -226,7 +229,7 @@
     /**
      * Folds a function over the key/value pairs.
      */
-    public Fold ['c] (s : 'c, f : ('a * 'b * 'c) -> 'c) : 'c 
+    public Fold ['c] (s : 'c, f : (TKey * TValue * 'c) -> 'c) : 'c 
     {
       mutable acc = s;
       
@@ -240,7 +243,7 @@
     /**
      * Iterates a function over the key/value pairs in the hashtable.
      */
-    public Iter (f : 'a * 'b -> void) : void
+    public Iter (f : TKey * TValue -> void) : void
     {
       foreach (x in this)
         f (x.Key, x.Value)
@@ -252,7 +255,7 @@
      * of this hashtable. A new hashtable object is created, containing
      * the results of the application.
      */
-    public Map ['c, 'd] (f : 'a * 'b -> 'c * 'd) : Hashtable ['c,'d]
+    public Map ['c, 'd] (f : TKey * TValue -> 'c * 'd) : Hashtable ['c,'d]
     {
       def ht = Hashtable (Count);
 
@@ -266,7 +269,7 @@
       ht
     }
 
-    public new Remove (key : 'a) : void
+    public new Remove (key : TKey) : void
     {
       _ = base.Remove (key)
     }
@@ -276,7 +279,7 @@
      * Returns a collection of the key/value pairs from this hashtable
      */
     [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
-    public KeyValuePairs : array ['a * 'b]
+    public KeyValuePairs : array [TKey * TValue]
     {
       get
       {
@@ -317,6 +320,6 @@
       _ = sb.Append ('}');
       sb.ToString ()
     }
-  } /* end of class Hashtable ('a,'b) */
+  } /* end of class Hashtable (TKey,TValue) */
 } /* end of namespace */
 

Modified: nemerle/trunk/ncc/hierarchy/NamespaceTree.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/NamespaceTree.n	(original)
+++ nemerle/trunk/ncc/hierarchy/NamespaceTree.n	Fri Mar  2 06:07:39 2007
@@ -238,7 +238,7 @@
           match (l) {
             | [x] =>
               when (cur_node.children == null)
-                cur_node.children = Hashtable (10, 1.0f);
+                cur_node.children = Hashtable (10);
                 
               match (cur_node.children.Get (x)) {
                 | Some (nd) => nd.Value
@@ -281,7 +281,7 @@
 
             | x :: xs =>
               when (cur_node.children == null)
-                cur_node.children = Hashtable (10, 1.0f);
+                cur_node.children = Hashtable (10);
                 
               match (cur_node.children.Get (x)) {
                 | Some (nd) => loop (xs, nd)



More information about the svn mailing list