diff options
author | Erik Rozendaal <erik@deler.org> | 2011-12-17 22:42:21 +0100 |
---|---|---|
committer | Erik Rozendaal <erik@deler.org> | 2011-12-28 13:12:33 +0100 |
commit | 9cdede8f033f661cfa3840070089fadd1b17fede (patch) | |
tree | 311cd2cca4f3b40b0bab7547e017eef53c09398d | |
parent | edcec038ed11dde5ccda92463d705916c3b39a34 (diff) | |
download | scala-9cdede8f033f661cfa3840070089fadd1b17fede.tar.gz scala-9cdede8f033f661cfa3840070089fadd1b17fede.tar.bz2 scala-9cdede8f033f661cfa3840070089fadd1b17fede.zip |
Optimized implementation of init/tail for TreeSet/TreeMap.
-rw-r--r-- | src/library/scala/collection/immutable/TreeMap.scala | 3 | ||||
-rw-r--r-- | src/library/scala/collection/immutable/TreeSet.scala | 3 |
2 files changed, 6 insertions, 0 deletions
diff --git a/src/library/scala/collection/immutable/TreeMap.scala b/src/library/scala/collection/immutable/TreeMap.scala index be67a45b1e..0e160ca50e 100644 --- a/src/library/scala/collection/immutable/TreeMap.scala +++ b/src/library/scala/collection/immutable/TreeMap.scala @@ -82,6 +82,9 @@ class TreeMap[A, +B](override val size: Int, t: RedBlack[A]#Tree[B])(implicit va } override def lastOption = if (t.isEmpty) None else Some(last) + override def tail = new TreeMap(size - 1, tree.delete(firstKey)) + override def init = new TreeMap(size - 1, tree.delete(lastKey)) + /** A factory to create empty maps of the same type of keys. */ override def empty: TreeMap[A, B] = TreeMap.empty[A, B](ordering) diff --git a/src/library/scala/collection/immutable/TreeSet.scala b/src/library/scala/collection/immutable/TreeSet.scala index 85f4ae4b0e..b969ecc0e8 100644 --- a/src/library/scala/collection/immutable/TreeSet.scala +++ b/src/library/scala/collection/immutable/TreeSet.scala @@ -58,6 +58,9 @@ class TreeSet[A](override val size: Int, t: RedBlack[A]#Tree[Unit]) override def last = t.greatest.key override def lastOption = if (t.isEmpty) None else Some(last) + override def tail = new TreeSet(size - 1, tree.delete(firstKey)) + override def init = new TreeSet(size - 1, tree.delete(lastKey)) + def isSmaller(x: A, y: A) = compare(x,y) < 0 def this()(implicit ordering: Ordering[A]) = this(0, null)(ordering) |