[m-rev.] diff: add map.det{min,max}_key/1

Julien Fischer jfischer at opturion.com
Thu Aug 8 01:53:17 AEST 2013


Add map.det_{min,max}_key/1.

library/map.m:
     As above.

NEWS:
     Announce the new functions.

Julien.

diff --git a/NEWS b/NEWS
index 89353cb..e964141 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,9 @@ Changes to the Mercury standard library:
  * We have added the following predicates to the array and version_array
    modules: is_empty/1, all_true/2 and all_false/2.

+* We have added the following functions the map module: det_min_key/1
+  and det_max_key/1.
+

  NEWS for Mercury 13.05.2
  ------------------------
diff --git a/library/map.m b/library/map.m
index 3eb8d02..addf248 100644
--- a/library/map.m
+++ b/library/map.m
@@ -93,12 +93,20 @@

      % Return the largest key in the map, if there is one.
      %
-:- func map.max_key(map(K,V)) = K is semidet.
+:- func map.max_key(map(K, V)) = K is semidet.
+
+    % As above, but abort if there is no largest key.
+    %
+:- func map.det_max_key(map(K, V)) = K.

      % Return the smallest key in the map, if there is one.
      %
  :- func map.min_key(map(K,V)) = K is semidet.

+    % As above, but abort if there is no smallest key.
+    %
+:- func map.det_min_key(map(K, V)) = K.
+
      % Search map for data.
      %
  :- pred map.inverse_search(map(K, V)::in, V::in, K::out) is nondet.
@@ -844,8 +852,22 @@ map.upper_bound_lookup(Map, SearchK, K, V) :-

  map.max_key(M) = tree234.max_key(M).

+map.det_max_key(M) = 
+    ( K = map.max_key(M) ->
+        K 
+    ;
+        func_error("map.det_max_key: map.max_key failed")
+    ).
+
  map.min_key(M) = tree234.min_key(M).

+map.det_min_key(M) = 
+    ( K = map.min_key(M) ->
+        K
+    ;
+        func_error("map.det_min_key: map.min_key failed")
+    ).
+
  map.insert(M1, K, V) = M2 :-
      map.insert(K, V, M1, M2).




More information about the reviews mailing list