summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/immutable/ListMap.scala
diff options
context:
space:
mode:
authorRuediger Klaehn <rklaehn@gmail.com>2014-01-20 21:37:21 +0100
committerRuediger Klaehn <rklaehn@gmail.com>2014-01-20 23:42:16 +0100
commit7f65b37a30cb0162711e3889edd35b2608ffa729 (patch)
treea02c7fc1bad6ddb5e5f15b9435eb8bff8f51cc59 /src/library/scala/collection/immutable/ListMap.scala
parent8f6f4032b5c026fd9301cebe28dde5bb7c8e264c (diff)
downloadscala-7f65b37a30cb0162711e3889edd35b2608ffa729.tar.gz
scala-7f65b37a30cb0162711e3889edd35b2608ffa729.tar.bz2
scala-7f65b37a30cb0162711e3889edd35b2608ffa729.zip
SI-7445 ListMap.tail is returning wrong result
Reverted the commit that introduced the bug, and modified HashMap to no longer assume that tail is O(1). Review by @Ichoran, @soc
Diffstat (limited to 'src/library/scala/collection/immutable/ListMap.scala')
-rw-r--r--src/library/scala/collection/immutable/ListMap.scala16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/library/scala/collection/immutable/ListMap.scala b/src/library/scala/collection/immutable/ListMap.scala
index b2a1b1ce29..7c40e84280 100644
--- a/src/library/scala/collection/immutable/ListMap.scala
+++ b/src/library/scala/collection/immutable/ListMap.scala
@@ -123,12 +123,12 @@ extends AbstractMap[A, B]
def hasNext = !self.isEmpty
def next(): (A,B) =
if (!hasNext) throw new NoSuchElementException("next on empty iterator")
- else { val res = (self.key, self.value); self = self.tail; res }
+ else { val res = (self.key, self.value); self = self.next; res }
}.toList.reverseIterator
protected def key: A = throw new NoSuchElementException("empty map")
protected def value: B = throw new NoSuchElementException("empty map")
- override def tail: ListMap[A, B] = throw new NoSuchElementException("empty map")
+ protected def next: ListMap[A, B] = throw new NoSuchElementException("empty map")
/** This class represents an entry in the `ListMap`.
*/
@@ -142,7 +142,7 @@ extends AbstractMap[A, B]
override def size: Int = size0(this, 0)
// to allow tail recursion and prevent stack overflows
- @tailrec private def size0(cur: ListMap[A, B1], acc: Int): Int = if (cur.isEmpty) acc else size0(cur.tail, acc + 1)
+ @tailrec private def size0(cur: ListMap[A, B1], acc: Int): Int = if (cur.isEmpty) acc else size0(cur.next, acc + 1)
/** Is this an empty map?
*
@@ -163,7 +163,7 @@ extends AbstractMap[A, B]
@tailrec private def apply0(cur: ListMap[A, B1], k: A): B1 =
if (cur.isEmpty) throw new NoSuchElementException("key not found: "+k)
else if (k == cur.key) cur.value
- else apply0(cur.tail, k)
+ else apply0(cur.next, k)
/** Checks if this map maps `key` to a value and return the
* value if it exists.
@@ -175,7 +175,7 @@ extends AbstractMap[A, B]
@tailrec private def get0(cur: ListMap[A, B1], k: A): Option[B1] =
if (k == cur.key) Some(cur.value)
- else if (cur.tail.nonEmpty) get0(cur.tail, k) else None
+ else if (cur.next.nonEmpty) get0(cur.next, k) else None
/** This method allows one to create a new map with an additional mapping
* from `key` to `value`. If the map contains already a mapping for `key`,
@@ -196,12 +196,12 @@ extends AbstractMap[A, B]
if (cur.isEmpty)
acc.last
else if (k == cur.key)
- (cur.tail /: acc) {
+ (cur.next /: acc) {
case (t, h) => val tt = t; new tt.Node(h.key, h.value) // SI-7459
}
else
- remove0(k, cur.tail, cur::acc)
+ remove0(k, cur.next, cur::acc)
- override def tail: ListMap[A, B1] = ListMap.this
+ override protected def next: ListMap[A, B1] = ListMap.this
}
}