[m-dev.] For review: small change to map.m and tree234.m
Ralph Becket
rbeck at microsoft.com
Tue Sep 12 22:05:33 AEDT 2000
Estimated hours taken: 1.1
tree234__keys/2 returns its keys in sorted order. This is a very
handy property, but not documented. This change rectifies the
situation.
library/map.m:
Added map__sorted_keys.
library/tree234.m:
Renamed tree234__keys as tree234__sorted_keys.
Added tree234__keys as a synonym.
Index: map.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/map.m,v
retrieving revision 1.75
diff -u -r1.75 map.m
--- map.m 2000/08/04 02:01:27 1.75
+++ map.m 2000/09/12 11:02:05
@@ -109,7 +109,7 @@
:- pred map__keys(map(K, _V), list(K)).
:- mode map__keys(in, out) is det.
- % Given a map, return a list of all the keys in the map,
+ % Given a map, return a list of all the keys in the map
% in sorted order.
:- pred map__sorted_keys(map(K, _V), list(K)).
:- mode map__sorted_keys(in, out) is det.
@@ -354,8 +354,7 @@
tree234__keys(Map, KeyList).
map__sorted_keys(Map, KeyList) :-
- % Guaranteed to yield sorted lists.
- tree234__keys(Map, KeyList).
+ tree234__sorted_keys(Map, KeyList).
map__values(Map, KeyList) :-
tree234__values(Map, KeyList).
Index: tree234.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/tree234.m,v
retrieving revision 1.30
diff -u -r1.30 tree234.m
--- tree234.m 2000/07/24 00:52:34 1.30
+++ tree234.m 2000/09/12 11:02:11
@@ -76,6 +76,9 @@
:- pred tree234__keys(tree234(K, V), list(K)).
:- mode tree234__keys(in, out) is det.
+:- pred tree234__sorted_keys(tree234(K, V), list(K)).
+:- mode tree234__sorted_keys(in, out) is det.
+
:- pred tree234__values(tree234(K, V), list(V)).
:- mode tree234__values(in, out) is det.
@@ -2334,24 +2337,29 @@
%---------------------------------------------------------------------------
---%
tree234__keys(Tree, Keys) :-
- tree234__keys_2(Tree, [], Keys).
+ tree234__sorted_keys(Tree, Keys).
+
+%--------------------------------------------------------------------------
----%
+
+tree234__sorted_keys(Tree, Keys) :-
+ tree234__sorted_keys_2(Tree, [], Keys).
-:- pred tree234__keys_2(tree234(K, V), list(K), list(K)).
-:- mode tree234__keys_2(in, in, out) is det.
+:- pred tree234__sorted_keys_2(tree234(K, V), list(K), list(K)).
+:- mode tree234__sorted_keys_2(in, in, out) is det.
-tree234__keys_2(empty, List, List).
-tree234__keys_2(two(K0, _V0, T0, T1), L0, L) :-
- tree234__keys_2(T1, L0, L1),
- tree234__keys_2(T0, [K0 | L1], L).
-tree234__keys_2(three(K0, _V0, K1, _V1, T0, T1, T2), L0, L) :-
- tree234__keys_2(T2, L0, L1),
- tree234__keys_2(T1, [K1 | L1], L2),
- tree234__keys_2(T0, [K0 | L2], L).
-tree234__keys_2(four(K0, _V0, K1, _V1, K2, _V2, T0, T1, T2, T3), L0, L) :-
- tree234__keys_2(T3, L0, L1),
- tree234__keys_2(T2, [K2 | L1], L2),
- tree234__keys_2(T1, [K1 | L2], L3),
- tree234__keys_2(T0, [K0 | L3], L).
+tree234__sorted_keys_2(empty, List, List).
+tree234__sorted_keys_2(two(K0, _V0, T0, T1), L0, L) :-
+ tree234__sorted_keys_2(T1, L0, L1),
+ tree234__sorted_keys_2(T0, [K0 | L1], L).
+tree234__sorted_keys_2(three(K0, _V0, K1, _V1, T0, T1, T2), L0, L) :-
+ tree234__sorted_keys_2(T2, L0, L1),
+ tree234__sorted_keys_2(T1, [K1 | L1], L2),
+ tree234__sorted_keys_2(T0, [K0 | L2], L).
+tree234__sorted_keys_2(four(K0, _V0, K1, _V1, K2, _V2, T0, T1, T2, T3), L0,
L):-
+ tree234__sorted_keys_2(T3, L0, L1),
+ tree234__sorted_keys_2(T2, [K2 | L1], L2),
+ tree234__sorted_keys_2(T1, [K1 | L2], L3),
+ tree234__sorted_keys_2(T0, [K0 | L3], L).
%---------------------------------------------------------------------------
---%
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list