[svn] r6091: nemerle/trunk/lib/rlist.n
d
svnadmin at nemerle.org
Sun Jan 29 12:58:34 CET 2006
Log:
Fix Length, add the simplest version of FromList.
Author: d
Date: Sun Jan 29 12:58:34 2006
New Revision: 6091
Modified:
nemerle/trunk/lib/rlist.n
Modified: nemerle/trunk/lib/rlist.n
==============================================================================
--- nemerle/trunk/lib/rlist.n (original)
+++ nemerle/trunk/lib/rlist.n Sun Jan 29 12:58:34 2006
@@ -300,7 +300,7 @@
static _Length (xs : RList ['a], tmp = 1, count = 0) : int {
match (xs) {
| Zero (ps) => RList [Pair ['a]]._Length (ps, tmp * 2, count)
- | One (_, ps) => _Length (Zero (ps), tmp, count + tmp)
+ | One (_, ps) => RList [Pair ['a]]._Length (ps, tmp * 2, count + tmp)
| Nil => count
}
}
@@ -509,6 +509,19 @@
Rev (this)
}
+ /** Returns an RList composed of the elements of list [xs].
+ Time complexity: O (|xs| * log |xs|).
+ <param name="xs">
+ The list used when composing the return value.
+ </param>
+ <returns>
+ An RList composed of the elements of [xs].
+ </returns>
+ */
+ public static FromList (xs : list ['a]) : RList ['a] {
+ List.FoldLeft (List.Rev (xs), Nil (), Cons)
+ }
+
/** Returns a list of elements of the RList [xs] in the same order.
Time complexity: O (|xs|).
<param name="xs">
@@ -519,7 +532,7 @@
</returns>
*/
public static ToList (xs : RList ['a]) : list ['a] {
- Nemerle.Collections.List.Rev (FoldLeft (xs, [], _ :: _))
+ List.Rev (FoldLeft (xs, [], _ :: _))
}
/** Returns a list of elements of the RList [this] in the same order.
@@ -559,7 +572,6 @@
}
}
- /* The enumerator for rlists */
public GetEnumerator () : SCG.IEnumerator ['a] {
match (this) {
| Zero (ps) =>
More information about the svn
mailing list