summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library/scala/collection/immutable/IntMap.scala19
-rw-r--r--test/files/run/intmap.check0
-rw-r--r--test/files/run/intmap.scala8
3 files changed, 27 insertions, 0 deletions
diff --git a/src/library/scala/collection/immutable/IntMap.scala b/src/library/scala/collection/immutable/IntMap.scala
index c7ebab3f65..33bbccfb96 100644
--- a/src/library/scala/collection/immutable/IntMap.scala
+++ b/src/library/scala/collection/immutable/IntMap.scala
@@ -369,5 +369,24 @@ sealed abstract class IntMap[+T] extends scala.collection.immutable.Map[Int, T]{
case (that : IntMap[_]) => this.unionWith[S](that.asInstanceOf[IntMap[S]], (key, x, y) => y);
case that => that.foldLeft(this : IntMap[S])({case (m, (x, y)) => m.update(x, y)});
}
+
+
+ /**
+ * The entry with the lowest key value considered in unsigned order.
+ */
+ final def firstKey : Int = this match {
+ case Bin(_, _, l, r) => l.firstKey;
+ case Tip(k, v) => k;
+ case Nil => error("Empty set")
+ }
+
+ /**
+ * The entry with the highest key value considered in unsigned order.
+ */
+ final def lastKey : Int = this match {
+ case Bin(_, _, l, r) => r.lastKey;
+ case Tip(k, v) => k;
+ case Nil => error("Empty set")
+ }
}
diff --git a/test/files/run/intmap.check b/test/files/run/intmap.check
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/files/run/intmap.check
diff --git a/test/files/run/intmap.scala b/test/files/run/intmap.scala
new file mode 100644
index 0000000000..8c3e0b2ca3
--- /dev/null
+++ b/test/files/run/intmap.scala
@@ -0,0 +1,8 @@
+object Test extends Application{
+ import scala.collection.immutable.IntMap;
+
+ val it = IntMap(8 -> 2, 11 -> 3, 1 -> 2, 7 -> 13);
+
+ assert(it.firstKey == 1);
+ assert(it.lastKey == 11);
+}