diff options
author | Matthias Zenger <mzenger@gmail.com> | 2003-07-10 01:15:45 +0000 |
---|---|---|
committer | Matthias Zenger <mzenger@gmail.com> | 2003-07-10 01:15:45 +0000 |
commit | 808974e3492160faea5a0e085b4bb709e1457b65 (patch) | |
tree | 6f1242087d6e9b63f77729a22df50c66a62e9727 | |
parent | 09ad15e15ab458c363f0ed6dc1c49786547fc988 (diff) | |
download | scala-808974e3492160faea5a0e085b4bb709e1457b65.tar.gz scala-808974e3492160faea5a0e085b4bb709e1457b65.tar.bz2 scala-808974e3492160faea5a0e085b4bb709e1457b65.zip |
Removed tabs.
-rw-r--r-- | sources/scala/collection/immutable/ListMap.scala | 66 | ||||
-rw-r--r-- | sources/scala/collection/immutable/ListSet.scala | 50 | ||||
-rw-r--r-- | sources/scala/collection/immutable/Map.scala | 2 | ||||
-rw-r--r-- | sources/scala/collection/immutable/Stack.scala | 140 |
4 files changed, 129 insertions, 129 deletions
diff --git a/sources/scala/collection/immutable/ListMap.scala b/sources/scala/collection/immutable/ListMap.scala index 1f4c854cfb..8d048506b0 100644 --- a/sources/scala/collection/immutable/ListMap.scala +++ b/sources/scala/collection/immutable/ListMap.scala @@ -11,7 +11,7 @@ package scala.collection.immutable; object ListMap { - def Empty[A, B] = new ListMap[A, B]; + def Empty[A, B] = new ListMap[A, B]; } /** This class implements immutable maps using a list-based data @@ -28,7 +28,7 @@ class ListMap[A, B] with Map[A, B, ListMap[A, B]] { def get(key: A): Option[B] = None; - def update(key: A, value: B): ListMap[A, B] = new Node(key, value); + def update(key: A, value: B): ListMap[A, B] = new Node(key, value); def -(key: A): ListMap[A, B] = this; @@ -36,40 +36,40 @@ class ListMap[A, B] with Map[A, B, ListMap[A, B]] { override def toList: List[Pair[A, B]] = Nil; - override def equals(obj: Any): Boolean = - if (obj is scala.collection.Map[A, B]) { - val that = obj as scala.collection.Map[A, B]; - if (size != that.size) false else toList.forall { - case Pair(key, value) => that.get(key) match { - case None => false; - case Some(v) => v == value; - } - }; - } else - false; + override def equals(obj: Any): Boolean = + if (obj is scala.collection.Map[A, B]) { + val that = obj as scala.collection.Map[A, B]; + if (size != that.size) false else toList.forall { + case Pair(key, value) => that.get(key) match { + case None => false; + case Some(v) => v == value; + } + }; + } else + false; - override def hashCode(): Int = 0; + override def hashCode(): Int = 0; protected class Node(key: A, value: B) extends ListMap[A, B] { override def size: Int = ListMap.this.size + 1; - override def isEmpty: Boolean = true; - override def apply(k: A): B = if (k == key) value else ListMap.this(k); - override def get(k: A): Option[B] = - if (k == key) Some(value) else ListMap.this.get(k); - override def update(k: A, v: B): ListMap[A, B] = - if (k == key) { - new ListMap.this.Node(k, v); - } else { - val tail = ListMap.this.update(k,v); new tail.Node(key, value) - } - override def -(k: A): ListMap[A, B] = - if (k == key) - ListMap.this - else { - val tail = ListMap.this - k; new tail.Node(key, value) - } - override def toList: List[Pair[A, B]] = Pair(key, value) :: ListMap.this.toList; - override def hashCode(): Int = - (key.hashCode() ^ value.hashCode()) + ListMap.this.hashCode(); + override def isEmpty: Boolean = true; + override def apply(k: A): B = if (k == key) value else ListMap.this(k); + override def get(k: A): Option[B] = + if (k == key) Some(value) else ListMap.this.get(k); + override def update(k: A, v: B): ListMap[A, B] = + if (k == key) { + new ListMap.this.Node(k, v); + } else { + val tail = ListMap.this.update(k,v); new tail.Node(key, value) + } + override def -(k: A): ListMap[A, B] = + if (k == key) + ListMap.this + else { + val tail = ListMap.this - k; new tail.Node(key, value) + } + override def toList: List[Pair[A, B]] = Pair(key, value) :: ListMap.this.toList; + override def hashCode(): Int = + (key.hashCode() ^ value.hashCode()) + ListMap.this.hashCode(); } } diff --git a/sources/scala/collection/immutable/ListSet.scala b/sources/scala/collection/immutable/ListSet.scala index a47d4b3d68..3dc637500d 100644 --- a/sources/scala/collection/immutable/ListSet.scala +++ b/sources/scala/collection/immutable/ListSet.scala @@ -11,7 +11,7 @@ package scala.collection.immutable; object ListSet { - def Empty[A] = new ListSet[A]; + def Empty[A] = new ListSet[A]; } /** This class implements immutable sets using a list-based data @@ -24,36 +24,36 @@ object ListSet { */ class ListSet[A] with Set[A, ListSet[A]] { - def size: Int = 0; + def size: Int = 0; - def contains(elem: A): Boolean = false; + def contains(elem: A): Boolean = false; - def +(elem: A): ListSet[A] = new Node(elem); + def +(elem: A): ListSet[A] = new Node(elem); - def -(elem: A): ListSet[A] = this; + def -(elem: A): ListSet[A] = this; - def elements: Iterator[A] = toList.elements; + def elements: Iterator[A] = toList.elements; - override def toList: List[A] = Nil; + override def toList: List[A] = Nil; - override def equals(obj: Any): Boolean = - if (obj is scala.collection.Set[A]) { - val that = obj as scala.collection.Set[A]; - if (size != that.size) false else toList.forall(that.contains); - } else - false; + override def equals(obj: Any): Boolean = + if (obj is scala.collection.Set[A]) { + val that = obj as scala.collection.Set[A]; + if (size != that.size) false else toList.forall(that.contains); + } else + false; - override def hashCode(): Int = 0; + override def hashCode(): Int = 0; - protected class Node(elem: A) extends ListSet[A] { - override def size = ListSet.this.size + 1; - override def isEmpty: Boolean = false; - override def contains(e: A) = (e == elem) || ListSet.this.contains(e); - override def +(e: A): ListSet[A] = if (contains(e)) this else new Node(e); - override def -(e: A): ListSet[A] = if (e == elem) ListSet.this else { - val tail = ListSet.this - e; new tail.Node(elem) - } - override def toList: List[A] = elem :: ListSet.this.toList; - override def hashCode(): Int = elem.hashCode() + ListSet.this.hashCode(); - } + protected class Node(elem: A) extends ListSet[A] { + override def size = ListSet.this.size + 1; + override def isEmpty: Boolean = false; + override def contains(e: A) = (e == elem) || ListSet.this.contains(e); + override def +(e: A): ListSet[A] = if (contains(e)) this else new Node(e); + override def -(e: A): ListSet[A] = if (e == elem) ListSet.this else { + val tail = ListSet.this - e; new tail.Node(elem) + } + override def toList: List[A] = elem :: ListSet.this.toList; + override def hashCode(): Int = elem.hashCode() + ListSet.this.hashCode(); + } } diff --git a/sources/scala/collection/immutable/Map.scala b/sources/scala/collection/immutable/Map.scala index 74e0eaa3a8..ae1488e919 100644 --- a/sources/scala/collection/immutable/Map.scala +++ b/sources/scala/collection/immutable/Map.scala @@ -33,7 +33,7 @@ trait Map[A, B, This <: Map[A, B, This]]: This with scala.collection.Map[A, B] { def excl(keys: A*): This = excl(keys); def excl(keys: Iterable[A]): This = { - val iter = keys.elements; + val iter = keys.elements; var res = this; while (iter.hasNext) { res = res - iter.next; diff --git a/sources/scala/collection/immutable/Stack.scala b/sources/scala/collection/immutable/Stack.scala index 5a8e7972d2..fdb9b03b37 100644 --- a/sources/scala/collection/immutable/Stack.scala +++ b/sources/scala/collection/immutable/Stack.scala @@ -11,7 +11,7 @@ package scala.collection.immutable; object Stack { - def Empty[A] = new Stack[A]; + def Empty[A] = new Stack[A]; } /** This class implements immutable stacks using a list-based data @@ -24,107 +24,107 @@ object Stack { */ class Stack[+A] with Seq[A] { - /** Checks if this stack is empty. - * - * @returns true, iff there is no element on the stack. - */ - def isEmpty: Boolean = true; + /** Checks if this stack is empty. + * + * @returns true, iff there is no element on the stack. + */ + def isEmpty: Boolean = true; - /** Returns the size of this stack. - * - * @returns the stack size. - */ - def length: Int = 0; + /** Returns the size of this stack. + * + * @returns the stack size. + */ + def length: Int = 0; /** Push an element on the stack. * - * @param elem the element to push on the stack. + * @param elem the element to push on the stack. * @returns the stack with the new element on top. */ - def +[B >: A](elem: B): Stack[B] = new Node(elem); + def +[B >: A](elem: B): Stack[B] = new Node(elem); /** Push all elements provided by the given iterable object onto * the stack. The last element returned by the iterable object * will be on top of the new stack. * - * @param elems the iterable object. + * @param elems the iterable object. * @returns the stack with the new elements on top. */ - def +[B >: A](elems: Iterable[B]): Stack[B] = { - var res: Stack[B] = this; - elems.elements.foreach { elem => res = res + elem; } - res; - } - - /** Push a sequence of elements onto the stack. The last element - * of the sequence will be on top of the new stack. + def +[B >: A](elems: Iterable[B]): Stack[B] = { + var res: Stack[B] = this; + elems.elements.foreach { elem => res = res + elem; } + res; + } + + /** Push a sequence of elements onto the stack. The last element + * of the sequence will be on top of the new stack. * - * @param elems the element sequence. + * @param elems the element sequence. * @returns the stack with the new elements on top. */ - def push[B >: A](elems: B*): Stack[B] = this + elems; + def push[B >: A](elems: B*): Stack[B] = this + elems; - /** Returns the top element of the stack. An error is signaled if - * there is no element on the stack. + /** Returns the top element of the stack. An error is signaled if + * there is no element on the stack. * * @returns the top element. */ - def top: A = error("no element on stack"); - - /** Removes the top element from the stack. - * - * @returns the new stack without the former top element. - */ - def pop: Stack[A] = error("no element on stack"); - - /** Returns the n-th element of this stack. The top element has index - * 0, elements below are indexed with increasing numbers. - * - * @param n the index number. - * @returns the n-th element on the stack. - */ - def apply(n: Int): A = error("no element on stack"); - - /** Returns an iterator over all elements on the stack. The iterator + def top: A = error("no element on stack"); + + /** Removes the top element from the stack. + * + * @returns the new stack without the former top element. + */ + def pop: Stack[A] = error("no element on stack"); + + /** Returns the n-th element of this stack. The top element has index + * 0, elements below are indexed with increasing numbers. + * + * @param n the index number. + * @returns the n-th element on the stack. + */ + def apply(n: Int): A = error("no element on stack"); + + /** Returns an iterator over all elements on the stack. The iterator * issues elements in the reversed order they were inserted into the * stack (LIFO order). * * @returns an iterator over all stack elements. */ - def elements: Iterator[A] = toList.elements; + def elements: Iterator[A] = toList.elements; - /** Creates a list of all stack elements in LIFO order. + /** Creates a list of all stack elements in LIFO order. * * @returns the created list. */ - def toList: List[A] = Nil; + def toList: List[A] = Nil; - /** Compares this stack with the given object. + /** Compares this stack with the given object. * * @returns true, iff the two stacks are equal; i.e. they contain the * same elements in the same order. */ - override def equals(obj: Any): Boolean = - if (obj is Stack[A]) toList.equals((obj as Stack[A]).toList); - else false; - - /** Returns the hash code for this stack. - * - * @returns the hash code of the stack. - */ - override def hashCode(): Int = 0; - - // Here comes true magic: covariant lists with implicit tail references - - protected class Node[+B >: A](elem: B) extends Stack[B] { - override def isEmpty: Boolean = false; - override def length: Int = Stack.this.length + 1; - override def +[C >: B](elem: C): Stack[C] = new Node(elem); - override def +[C >: B](elems: Iterable[C]): Stack[C] = super.+(elems); - override def top: B = elem; - override def pop: Stack[B] = Stack.this; - override def apply(n: Int): B = if (n > 0) Stack.this(n - 1) else elem; - override def toList: List[B] = elem :: Stack.this.toList; - override def hashCode(): Int = elem.hashCode() + Stack.this.hashCode(); - } + override def equals(obj: Any): Boolean = + if (obj is Stack[A]) toList.equals((obj as Stack[A]).toList); + else false; + + /** Returns the hash code for this stack. + * + * @returns the hash code of the stack. + */ + override def hashCode(): Int = 0; + + // Here comes true magic: covariant lists with implicit tail references + + protected class Node[+B >: A](elem: B) extends Stack[B] { + override def isEmpty: Boolean = false; + override def length: Int = Stack.this.length + 1; + override def +[C >: B](elem: C): Stack[C] = new Node(elem); + override def +[C >: B](elems: Iterable[C]): Stack[C] = super.+(elems); + override def top: B = elem; + override def pop: Stack[B] = Stack.this; + override def apply(n: Int): B = if (n > 0) Stack.this(n - 1) else elem; + override def toList: List[B] = elem :: Stack.this.toList; + override def hashCode(): Int = elem.hashCode() + Stack.this.hashCode(); + } } |