[svn] r6302: nemerle/trunk/lib/rlist.n
d
svnadmin at nemerle.org
Wed May 17 22:49:29 CEST 2006
Log:
Add Last, @+ and Item.
Author: d
Date: Wed May 17 22:49:29 2006
New Revision: 6302
Modified:
nemerle/trunk/lib/rlist.n
Modified: nemerle/trunk/lib/rlist.n
==============================================================================
--- nemerle/trunk/lib/rlist.n (original)
+++ nemerle/trunk/lib/rlist.n Wed May 17 22:49:29 2006
@@ -301,6 +301,32 @@
Tail (this)
}
+ /** Returns the last element of the RList [xs].
+ Time complexity: O (log (|xs|)).
+ <param name="xs">
+ The RList, which last element is going to be returned.
+ </param>
+ <returns>
+ The last element of [xs].
+ </returns>
+ */
+ public static Last (xs : RList ['a]) : 'a {
+ | Zero (ps) => RList [Pair ['a]].Last (ps).snd;
+ | One (x, Nil) => x
+ | One (_, ps) => RList [Pair ['a]].Last (ps).snd;
+ | Nil => throw System.ArgumentException ("RList.Last called for empty RList")
+ }
+
+ /** Returns the last element of the RList [this].
+ Time complexity: O (log (|this|)).
+ <returns>
+ The last element of [this].
+ </returns>
+ */
+ public Last () : 'a {
+ Last (this)
+ }
+
/* An auxillary function used by the Length property.
Time complexity: O (log (|xs|)).
*/
@@ -562,6 +588,24 @@
Append (this, ys)
}
+ /** Returns an a new RList composed by appending [ys]
+ at the end of [xs].
+ Time complexity: roughly O (|xs| * log (|ys| + |xs|)).
+ An alias for Append.
+ <param name="xs">
+ The RList, which elements come first in the resulting RList.
+ </param>
+ <param name="ys">
+ The RList, which elements come second in the resulting RList.
+ </param>
+ <returns>
+ An RList composed by appending [ys] at the end of [xs].
+ </returns>
+ */
+ public static @+ (xs : RList ['a], ys : RList ['a]) : RList ['a] {
+ Append (xs, ys)
+ }
+
/** Returns an RList composed of the elements of list [xs].
Use RList (xs, |xs|) if |xs| is known.
Time complexity: O (|xs|).
@@ -679,6 +723,10 @@
| Nil => {}
}
}
+
+ public Item [index : int] : 'a {
+ get { Nth (this, index) }
+ }
}
}
More information about the svn
mailing list