summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2007-02-26 15:02:26 +0000
committermichelou <michelou@epfl.ch>2007-02-26 15:02:26 +0000
commit02e108bcf24f5c02cef221b995b60ca86aece287 (patch)
tree3403093d98ceab4331c57ea86bbd0d0cc01398aa /src
parent853b9424e5dbbcfccecc8b027dabbb460f1618c2 (diff)
downloadscala-02e108bcf24f5c02cef221b995b60ca86aece287.tar.gz
scala-02e108bcf24f5c02cef221b995b60ca86aece287.tar.bz2
scala-02e108bcf24f5c02cef221b995b60ca86aece287.zip
added svn keywords, improved comments
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/collection/Ranged.scala50
-rw-r--r--src/library/scala/collection/Sorted.scala2
-rw-r--r--src/library/scala/collection/SortedMap.scala2
-rw-r--r--src/library/scala/collection/SortedSet.scala47
-rw-r--r--src/library/scala/collection/TreeWalker.scala81
5 files changed, 114 insertions, 68 deletions
diff --git a/src/library/scala/collection/Ranged.scala b/src/library/scala/collection/Ranged.scala
index efcaaf5ba1..50d01f3ff3 100644
--- a/src/library/scala/collection/Ranged.scala
+++ b/src/library/scala/collection/Ranged.scala
@@ -1,27 +1,31 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
-// $Id: Sorted.scala 9621 2007-01-17 14:29:25Z michelou $
+// $Id$
-package scala.collection;
+package scala.collection
/** Any collection (including maps) whose keys (or elements) are ordered.
*
* @author Sean McDirmid
*/
-trait Ranged[K,+A] extends Iterable[A] {
+trait Ranged[K, +A] extends Iterable[A] {
//protected type SortedSelf <: Ranged[K,A];
+
/** Returns the first key of the collection. */
- def first: K;
+ def first: K
+
/** Returns the last key of the collection. */
- def last: K;
+ def last: K
+
/** Comparison function that orders keys. */
- def compare(k0: K, k1: K): Int;
+ def compare(k0: K, k1: K): Int
+
/** Creates a ranged projection of this collection. Any mutations in the
* ranged projection will update this collection and vice versa. Note: keys
* are not garuanteed to be consistent between this collection and the projection.
@@ -32,18 +36,26 @@ trait Ranged[K,+A] extends Iterable[A] {
* @param until The upper-bound (exclusive) of the ranged projection.
* <code>None</code> if there is no upper bound.
*/
- def rangeImpl(from: Option[K], until: Option[K]) : Ranged[K,A];
+ def rangeImpl(from: Option[K], until: Option[K]): Ranged[K, A]
+
/** Creates a ranged projection of this collection with no upper-bound.
- ** @param from The lower-bound (inclusive) of the ranged projection.
- **/
- def from(from: K) = rangeImpl(Some(from), None);
+ *
+ * @param from The lower-bound (inclusive) of the ranged projection.
+ */
+ def from(from: K) = rangeImpl(Some(from), None)
+
/** Creates a ranged projection of this collection with no lower-bound.
- ** @param until The upper-bound (exclusive) of the ranged projection.
- **/
- def until(until: K) = rangeImpl(None, Some(until));
-
- /** Creates a ranged projection of this collection with both a lower-bound and an upper-bound.
- ** @param from The upper-bound (exclusive) of the ranged projection.
- **/
- def range(from: K, until: K) = rangeImpl(Some(from),Some(until));
+ *
+ * @param until The upper-bound (exclusive) of the ranged projection.
+ */
+ def until(until: K) = rangeImpl(None, Some(until))
+
+ /** Creates a ranged projection of this collection with both a lower-bound
+ * and an upper-bound.
+ *
+ * @param from The upper-bound (exclusive) of the ranged projection.
+ * @param until ...
+ * @return ...
+ */
+ def range(from: K, until: K) = rangeImpl(Some(from), Some(until))
}
diff --git a/src/library/scala/collection/Sorted.scala b/src/library/scala/collection/Sorted.scala
index 8e7e2f0c6d..5040246a91 100644
--- a/src/library/scala/collection/Sorted.scala
+++ b/src/library/scala/collection/Sorted.scala
@@ -6,7 +6,7 @@
** |/ **
\* */
-// $Id: Sorted.scala 9621 2007-01-17 14:29:25Z michelou $
+// $Id$
package scala.collection;
diff --git a/src/library/scala/collection/SortedMap.scala b/src/library/scala/collection/SortedMap.scala
index 06411050c4..57649a84e2 100644
--- a/src/library/scala/collection/SortedMap.scala
+++ b/src/library/scala/collection/SortedMap.scala
@@ -6,7 +6,7 @@
** |/ **
\* */
-// $Id: SortedMap.scala 9621 2007-01-17 14:29:25Z michelou $
+// $Id$
package scala.collection;
diff --git a/src/library/scala/collection/SortedSet.scala b/src/library/scala/collection/SortedSet.scala
index 2200b761fd..8e605a61ce 100644
--- a/src/library/scala/collection/SortedSet.scala
+++ b/src/library/scala/collection/SortedSet.scala
@@ -1,41 +1,48 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
-// $Id: SortedSet.scala 9621 2007-01-17 14:29:25Z michelou $
+// $Id$
-package scala.collection;
+package scala.collection
/** Analogous to a Java sorted set.
*
* @author Sean McDirmid
*/
-trait SortedSet[A] extends Set[A] with Sorted[A,A] {
- override def keySet = this;
- override def first : A = {
- val i = elements;
- if (i.hasNext) i.next;
- else throw new NoSuchElementException;
+trait SortedSet[A] extends Set[A] with Sorted[A, A] {
+
+ override def keySet = this
+
+ override def first: A = {
+ val i = elements
+ if (i.hasNext) i.next
+ else throw new NoSuchElementException
}
- override def last : A = {
- var last : A = null.asInstanceOf[A];
- val i = elements;
+
+ override def last: A = {
+ var last: A = null.asInstanceOf[A]
+ val i = elements
while (i.hasNext) last = i.next;
- if (last == null) throw new NoSuchElementException;
- else last;
+ if (last == null) throw new NoSuchElementException
+ else last
}
- override def rangeImpl(from : Option[A], until : Option[A]) : SortedSet[A];
- override def from(from: A) = rangeImpl(Some(from), None);
- override def until(until: A) = rangeImpl(None, Some(until));
- override def range(from: A, until: A) = rangeImpl(Some(from),Some(until));
+
+ override def rangeImpl(from: Option[A], until: Option[A]): SortedSet[A]
+
+ override def from(from: A) = rangeImpl(Some(from), None)
+
+ override def until(until: A) = rangeImpl(None, Some(until))
+
+ override def range(from: A, until: A) = rangeImpl(Some(from),Some(until))
override def subsetOf(that: Set[A]): Boolean = that match {
- case that : SortedSet[A] => that.hasAll(elements);
- case that => super.subsetOf(that);
+ case that: SortedSet[A] => that.hasAll(elements)
+ case that => super.subsetOf(that)
}
}
diff --git a/src/library/scala/collection/TreeWalker.scala b/src/library/scala/collection/TreeWalker.scala
index 64200a4288..e6be41ad66 100644
--- a/src/library/scala/collection/TreeWalker.scala
+++ b/src/library/scala/collection/TreeWalker.scala
@@ -1,37 +1,64 @@
-package scala.collection;
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2007, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+// $Id$
+
+package scala.collection
+
+/**
+ * @author Sean McDirmid
+ */
object TreeWalker {
+
object Empty extends TreeWalker[Nothing] {
- def hasNext = None;
- def next = throw new NoSuchElementException;
+ def hasNext = None
+ def next = throw new NoSuchElementException
}
- private case class NonEmpty[+A](item : A, right : () => TreeWalker[A]) extends TreeWalker[A] {
- private var spent = false;
- def hasNext = if (spent) right().hasNext else Some(this);
+
+ private case class NonEmpty[+A](item: A, right: () => TreeWalker[A]) extends TreeWalker[A] {
+ private var spent = false
+ def hasNext = if (spent) right().hasNext else Some(this)
def next = if (spent) right().next else {
- spent = true;
- item;
+ spent = true
+ item
}
}
- def apply[A]( item : A ) : TreeWalker[A] = NonEmpty(item, () => Empty);
- def apply[A]( item : A, right : () => TreeWalker[A]) : () => TreeWalker[A] = () => NonEmpty(item, right);
- def apply[A](left : TreeWalker[A], item : A, right : () => TreeWalker[A]) : TreeWalker[A] = left match {
- case Empty => NonEmpty(item, right);
- case NonEmpty(first, middle) =>
- val rest = NonEmpty(item,right);
- NonEmpty(first, apply(middle, () => rest));
- }
- def apply[A](left : () => TreeWalker[A], right : () => TreeWalker[A]) : () => TreeWalker[A] = () => (left() match {
- case Empty => right();
- case NonEmpty(item, middle) => NonEmpty(item, apply(middle, right));
- });
+
+ def apply[A](item: A): TreeWalker[A] = NonEmpty(item, () => Empty)
+
+ def apply[A](item: A, right: () => TreeWalker[A]): () => TreeWalker[A] =
+ () => NonEmpty(item, right)
+
+ def apply[A](left: TreeWalker[A], item: A, right: () => TreeWalker[A]): TreeWalker[A] =
+ left match {
+ case Empty =>
+ NonEmpty(item, right)
+ case NonEmpty(first, middle) =>
+ val rest = NonEmpty(item,right)
+ NonEmpty(first, apply(middle, () => rest))
+ }
+
+ def apply[A](left: () => TreeWalker[A], right: () => TreeWalker[A]): () => TreeWalker[A] =
+ () => (left() match {
+ case Empty => right()
+ case NonEmpty(item, middle) =>
+ NonEmpty(item, apply(middle, right))
+ })
}
+/**
+ * @author Sean McDirmid
+ */
sealed abstract class TreeWalker[+A] {
- def hasNext : Option[TreeWalker[A]];
- def next : A;
- def append[B >: A](item : B) : TreeWalker[B] = append(item, () => TreeWalker.Empty);
- def append[B >: A](item : B, right : () => TreeWalker[B]) : TreeWalker[B] = TreeWalker[B](this, item, right);
+ def hasNext : Option[TreeWalker[A]]
+ def next: A
+ def append[B >: A](item: B): TreeWalker[B] = append(item, () => TreeWalker.Empty);
+ def append[B >: A](item: B, right: () => TreeWalker[B]): TreeWalker[B] = TreeWalker[B](this, item, right);
def append[B >: A](right : () => TreeWalker[B]) = TreeWalker(() => this,right)();
class Elements extends Iterator[A] {
private var cursor : TreeWalker[Any] = TreeWalker.this;
@@ -46,11 +73,11 @@ sealed abstract class TreeWalker[+A] {
}
def hasNext = !(check eq null);
def next = check match {
- case null => throw new NoSuchElementException;
- case cursor => cursor.next.asInstanceOf[A];
+ case null => throw new NoSuchElementException
+ case cursor => cursor.next.asInstanceOf[A]
}
}
- def elements = new Elements;
+ def elements = new Elements
}