diff options
author | Ruediger Klaehn <rklaehn@gmail.com> | 2012-08-09 03:41:08 +0200 |
---|---|---|
committer | Ruediger Klaehn <rklaehn@gmail.com> | 2012-08-09 03:41:08 +0200 |
commit | 90714e7d4a03a33aa26f757217972e306b96c9d0 (patch) | |
tree | c097dd172a0d0e270f2cdeb7726751a06af055e9 /src | |
parent | 6b3d36bc19cc82350c3754b0b91fb074a443d9bc (diff) | |
download | scala-90714e7d4a03a33aa26f757217972e306b96c9d0.tar.gz scala-90714e7d4a03a33aa26f757217972e306b96c9d0.tar.bz2 scala-90714e7d4a03a33aa26f757217972e306b96c9d0.zip |
Renamed elem to head and next to tail
both head and tail are now O(1) with very low overhead like you would expect for a list-like data structure
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/immutable/ListSet.scala | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/library/scala/collection/immutable/ListSet.scala b/src/library/scala/collection/immutable/ListSet.scala index ce3abaacb7..4dd0d62fc0 100644 --- a/src/library/scala/collection/immutable/ListSet.scala +++ b/src/library/scala/collection/immutable/ListSet.scala @@ -116,8 +116,8 @@ class ListSet[A] extends AbstractSet[A] def hasNext = that.nonEmpty def next: A = if (hasNext) { - val res = that.elem - that = that.next + val res = that.head + that = that.tail res } else Iterator.empty.next @@ -126,18 +126,18 @@ class ListSet[A] extends AbstractSet[A] /** * @throws Predef.NoSuchElementException */ - protected def elem: A = throw new NoSuchElementException("Set has no elements"); + override def head: A = throw new NoSuchElementException("Set has no elements"); /** * @throws Predef.NoSuchElementException */ - protected def next: ListSet[A] = throw new NoSuchElementException("Next of an empty set"); + override def tail: ListSet[A] = throw new NoSuchElementException("Next of an empty set"); override def stringPrefix = "ListSet" /** Represents an entry in the `ListSet`. */ - protected class Node(override protected val elem: A) extends ListSet[A] with Serializable { + protected class Node(override val head: A) extends ListSet[A] with Serializable { override private[ListSet] def unchecked_outer = self /** Returns the number of elements in this set. @@ -162,7 +162,7 @@ class ListSet[A] extends AbstractSet[A] */ override def contains(e: A) = containsInternal(this, e) @tailrec private def containsInternal(n: ListSet[A], e: A): Boolean = - !n.isEmpty && (n.elem == e || containsInternal(n.unchecked_outer, e)) + !n.isEmpty && (n.head == e || containsInternal(n.unchecked_outer, e)) /** This method creates a new set with an additional element. */ @@ -170,10 +170,10 @@ class ListSet[A] extends AbstractSet[A] /** `-` can be used to remove a single element from a set. */ - override def -(e: A): ListSet[A] = if (e == elem) self else { - val tail = self - e; new tail.Node(elem) + override def -(e: A): ListSet[A] = if (e == head) self else { + val tail = self - e; new tail.Node(head) } - override protected def next: ListSet[A] = self + override def tail: ListSet[A] = self } } |