[svn] r6363: nemerle/trunk/lib/hashtable.n
VladD2
svnadmin at nemerle.org
Sat Jun 3 04:15:17 CEST 2006
Log:
1.Performance improvement of Hashtable.Get() method. 2. Has added alternative methods for get value.
Author: VladD2
Date: Sat Jun 3 04:15:15 2006
New Revision: 6363
Modified:
nemerle/trunk/lib/hashtable.n
Modified: nemerle/trunk/lib/hashtable.n
==============================================================================
--- nemerle/trunk/lib/hashtable.n (original)
+++ nemerle/trunk/lib/hashtable.n Sat Jun 3 04:15:15 2006
@@ -97,12 +97,42 @@
*/
public Get (key : 'a) : option ['b]
{
- if (ContainsKey (key))
- Some (this [key])
+ mutable value;
+
+ if (TryGetValue (key, out value))
+ Some (value)
else
None ()
}
+ public TryGetValue (key : 'a) : 'b * bool
+ {
+ mutable value;
+
+ if (TryGetValue (key, out value))
+ (value, true)
+ else
+ (Nemerle.Extensions.DefaultValue ('b), false)
+ }
+
+ public GetValueOrDefault (key : 'a) : 'b
+ {
+ mutable value;
+
+ ignore (TryGetValue (key, out value));
+
+ value
+ }
+
+ public GetValueOrDefault (key : 'a, defaultValue : 'b) : 'b
+ {
+ mutable value;
+
+ if (TryGetValue (key, out value))
+ value
+ else
+ defaultValue
+ }
/**
* This is different from add, which can fail if the key is
More information about the svn
mailing list