diff options
author | Paul Phillips <paulp@improving.org> | 2013-02-08 07:36:07 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-02-08 07:36:07 -0800 |
commit | ce32c1af462de7d7c6b90efd56217e202a18d1e6 (patch) | |
tree | 165a33666c360c81190e11e4297a2061d682e49e /src | |
parent | 5545f35730e54841065cf142597b4e3db3334a1b (diff) | |
parent | 8bd03e063c412cefcd52f88fef68283290893708 (diff) | |
download | scala-ce32c1af462de7d7c6b90efd56217e202a18d1e6.tar.gz scala-ce32c1af462de7d7c6b90efd56217e202a18d1e6.tar.bz2 scala-ce32c1af462de7d7c6b90efd56217e202a18d1e6.zip |
Merge pull request #2042 from mt2309/SI-5151
SI-5151 - Add firstKey and lastKey to LongMap.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/immutable/LongMap.scala | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/library/scala/collection/immutable/LongMap.scala b/src/library/scala/collection/immutable/LongMap.scala index fab1b7f00b..60300c2a9e 100644 --- a/src/library/scala/collection/immutable/LongMap.scala +++ b/src/library/scala/collection/immutable/LongMap.scala @@ -12,6 +12,7 @@ package immutable import scala.collection.generic.{ CanBuildFrom, BitOperations } import scala.collection.mutable.{ Builder, MapBuilder } +import scala.annotation.tailrec /** Utility class for long maps. * @author David MacIver @@ -416,5 +417,20 @@ extends AbstractMap[Long, T] def ++[S >: T](that: LongMap[S]) = this.unionWith[S](that, (key, x, y) => y) + + @tailrec + final def firstKey: Long = this match { + case LongMap.Bin(_, _, l, r) => l.firstKey + case LongMap.Tip(k, v) => k + case LongMap.Nil => sys.error("Empty set") + } + + @tailrec + final def lastKey: Long = this match { + case LongMap.Bin(_, _, l, r) => r.lastKey + case LongMap.Tip(k , v) => k + case LongMap.Nil => sys.error("Empty set") + } + } |