diff options
author | Matthias Zenger <mzenger@gmail.com> | 2004-05-03 20:17:00 +0000 |
---|---|---|
committer | Matthias Zenger <mzenger@gmail.com> | 2004-05-03 20:17:00 +0000 |
commit | 0c42b4a80bdd112f14925ef5d2e202575536e307 (patch) | |
tree | d3c40d6b0a35605c7fb38a706efc9570284478bb /sources/scala/collection/immutable/ListSet.scala | |
parent | c7ce40c3c7041bdc018e4054e634f061537b15e2 (diff) | |
download | scala-0c42b4a80bdd112f14925ef5d2e202575536e307.tar.gz scala-0c42b4a80bdd112f14925ef5d2e202575536e307.tar.bz2 scala-0c42b4a80bdd112f14925ef5d2e202575536e307.zip |
Refactored library.
Diffstat (limited to 'sources/scala/collection/immutable/ListSet.scala')
-rw-r--r-- | sources/scala/collection/immutable/ListSet.scala | 91 |
1 files changed, 47 insertions, 44 deletions
diff --git a/sources/scala/collection/immutable/ListSet.scala b/sources/scala/collection/immutable/ListSet.scala index 67bf86c1c2..fa87d40cd9 100644 --- a/sources/scala/collection/immutable/ListSet.scala +++ b/sources/scala/collection/immutable/ListSet.scala @@ -14,9 +14,9 @@ object ListSet { /** constructs an empty ListSet */ def Empty[A] = new ListSet[A]; - } + /** This class implements immutable sets using a list-based data * structure. Instances of <code>ListSet</code> represent * empty sets; they can be either created by calling the constructor @@ -28,16 +28,16 @@ object ListSet { class ListSet[A] with Set[A] { /** Returns the number of elements in this set. - * - * @return number of set elements. - */ + * + * @return number of set elements. + */ def size: Int = 0; /** Checks if this set contains element <code>elem</code>. - * - * @param elem the element to check for membership. - * @return true, iff <code>elem</code> is contained in this set. - */ + * + * @param elem the element to check for membership. + * @return true, iff <code>elem</code> is contained in this set. + */ def contains(elem: A): Boolean = false; /** This method creates a new set with an additional element. @@ -63,8 +63,8 @@ class ListSet[A] with Set[A] { override def toList: List[A] = Nil; /** Compares two sets for equality. - * Two set are equal iff they contain the same elements. - */ + * Two set are equal iff they contain the same elements. + */ override def equals(obj: Any): Boolean = if (obj.isInstanceOf[scala.collection.Set[A]]) { val that = obj.asInstanceOf[scala.collection.Set[A]]; @@ -75,39 +75,42 @@ class ListSet[A] with Set[A] { override def hashCode(): Int = 0; protected class Node(elem: A) extends ListSet[A] { - /** Returns the number of elements in this set. - * - * @return number of set elements. - */ - override def size = ListSet.this.size + 1; - /** Checks if this set is empty. - * - * @return true, iff there is no element in the set. - */ - override def isEmpty: Boolean = false; - - /** Checks if this set contains element <code>elem</code>. - * - * @param elem the element to check for membership. - * @return true, iff <code>elem</code> is contained in this set. - */ - override def contains(e: A) = (e == elem) || ListSet.this.contains(e); - - /** This method creates a new set with an additional element. - */ - override def +(e: A): ListSet[A] = if (contains(e)) this else new Node(e); - /** <code>-</code> can be used to remove a single element from - * a set. - */ - override def -(e: A): ListSet[A] = if (e == elem) ListSet.this else { - val tail = ListSet.this - e; new tail.Node(elem) - } - - /** Transform this set into a list of all elements. - * - * @return a list which enumerates all elements of this set. - */ - override def toList: List[A] = elem :: ListSet.this.toList; - override def hashCode(): Int = elem.hashCode() + ListSet.this.hashCode(); + /** Returns the number of elements in this set. + * + * @return number of set elements. + */ + override def size = ListSet.this.size + 1; + + /** Checks if this set is empty. + * + * @return true, iff there is no element in the set. + */ + override def isEmpty: Boolean = false; + + /** Checks if this set contains element <code>elem</code>. + * + * @param elem the element to check for membership. + * @return true, iff <code>elem</code> is contained in this set. + */ + override def contains(e: A) = (e == elem) || ListSet.this.contains(e); + + /** This method creates a new set with an additional element. + */ + override def +(e: A): ListSet[A] = if (contains(e)) this else new Node(e); + + /** <code>-</code> can be used to remove a single element from + * a set. + */ + override def -(e: A): ListSet[A] = if (e == elem) ListSet.this else { + val tail = ListSet.this - e; new tail.Node(elem) + } + + /** Transform this set into a list of all elements. + * + * @return a list which enumerates all elements of this set. + */ + override def toList: List[A] = elem :: ListSet.this.toList; + + override def hashCode(): Int = elem.hashCode() + ListSet.this.hashCode(); } } |