Replaced immutable.Queue.apply, which should fix the build.

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@19407 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
phaller 2009-11-05 21:20:26 +00:00
parent ed29785397
commit 1a1f5c65b0
1 changed files with 7 additions and 11 deletions

View File

@ -40,17 +40,13 @@ class Queue[+A] protected(
* @throws Predef.NoSuchElementException if the queue is too short.
*/
def apply(n: Int): A = {
@tailrec
def walk(i: Int, inlist: List[A], outlist: List[A]): A =
(i == 0, inlist.isEmpty, outlist.isEmpty) match {
case (_, true, true) => throw new NoSuchElementException("index out of range")
case (true, _, false) => outlist.head
case (true, _, true) => inlist.last
case (false, _, false) => walk(i - 1, inlist, outlist.tail)
case (false, false, true) => walk(i - 1, Nil, inlist.reverse.tail)
val len = out.length
if (n < len) out.apply(n)
else {
val m = n - len
if (m < in.length) in.reverse.apply(m)
else throw new NoSuchElementException("index out of range")
}
walk(n, in, out)
}
/** Returns the elements in the list as an iterator