[m-rev.] diff: add svmulti_map to standard library

Julien Fischer juliensf at cs.mu.OZ.AU
Fri Feb 25 01:06:33 AEDT 2005


Estimated hours taken: 0.5
Branches: main, release

library/svmulti_map.m:
	Add a module with versions of the multi_map predicates
	that are conducive to the use of state variables.

library/multi_map.m:
	Fix up some minor problems with the documentation.

library/library.m:
NEWS:
	Mention the above addition.

Julien.

Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.374
diff -u -r1.374 NEWS
--- NEWS	21 Feb 2005 05:34:33 -0000	1.374
+++ NEWS	24 Feb 2005 07:36:37 -0000
@@ -25,10 +25,11 @@
   arbitrary terms to XML documents. Two new modules, set_tree234 and
   set_ctree234, have been added to provide operations on sets with better
   worst-case behavior (but worse constant factors) than the current
-  implementation. Nine new modules, svarray, sveqvclass, svmap, svbimap,
-  svset, svbag, svqueue, svrelation and svvarset now provide more convenient
-  ways to update arrays, equivalence classes, maps, bimaps, sets, bags,
-  queues, relations and varsets in code that uses state variables.
+  implementation. Ten new modules, svarray, sveqvclass, svmap, svmulti_map,
+  svbimap, svset, svbag, svqueue, svrelation and svvarset now provide more
+  convenient ways to update arrays, equivalence classes, maps, multi_maps,
+  bimaps, sets, bags, queues, relations and varsets in code that uses state
+  variables.
 * New procedures have been added to many of the existing standard library
   modules.  Most notably, these include procedures for creating
   directories and symbolic links, for checking file types and file
Index: library/library.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/library.m,v
retrieving revision 1.86
diff -u -r1.86 library.m
--- library/library.m	21 Feb 2005 05:34:41 -0000	1.86
+++ library/library.m	24 Feb 2005 06:52:00 -0000
@@ -105,6 +105,7 @@
 :- import_module svbimap.
 :- import_module sveqvclass.
 :- import_module svmap.
+:- import_module svmulti_map.
 :- import_module svqueue.
 :- import_module svrelation.
 :- import_module svset.
@@ -241,6 +242,7 @@
 mercury_std_library_module("svbimap").
 mercury_std_library_module("sveqvclass").
 mercury_std_library_module("svmap").
+mercury_std_library_module("svmulti_map").
 mercury_std_library_module("svqueue").
 mercury_std_library_module("svrelation").
 mercury_std_library_module("svset").
Index: library/multi_map.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/multi_map.m,v
retrieving revision 1.16
diff -u -r1.16 multi_map.m
--- library/multi_map.m	2 Feb 2005 04:28:47 -0000	1.16
+++ library/multi_map.m	24 Feb 2005 12:24:55 -0000
@@ -78,28 +78,28 @@
 :- pred multi_map__det_insert(multi_map(K, V)::in, K::in, V::in,
 	multi_map(K, V)::out) is det.

-	% Update (add) the value corresponding to a given key
-	% Fail if the key doesn't already exist.
+	% Update (add) the value corresponding to a given key.
+	% Fail if the key does not already exist.
 	%
 :- pred multi_map__update(multi_map(K, V)::in, K::in, V::in,
 	multi_map(K, V)::out) is semidet.

-	% Update (add) the value corresponding to a given key
-	% Abort if the key doesn't already exist.
+	% Update (add) the value corresponding to a given key.
+	% Abort if the key does not already exist.
 	%
 :- func multi_map__det_update(multi_map(K, V), K, V) = multi_map(K, V).
 :- pred multi_map__det_update(multi_map(K, V)::in, K::in, V::in,
 	multi_map(K, V)::out) is det.

-	% Update (replace) the value corresponding to a given key
-	% Abort if the key doesn't already exist.
+	% Update (replace) the value corresponding to a given key.
+	% Abort if the key does not already exist.
 	%
 :- func multi_map__det_replace(multi_map(K, V), K, list(V)) = multi_map(K, V).
 :- pred multi_map__det_replace(multi_map(K, V)::in, K::in, list(V)::in,
 	multi_map(K, V)::out) is det.

 	% Update (add) value if the key is already present, otherwise
-	% insert new key and value.
+	% insert the new key and value.
 	%
 :- func multi_map__set(multi_map(K, V), K, V) = multi_map(K, V).
 :- pred multi_map__set(multi_map(K, V)::in, K::in, V::in, multi_map(K, V)::out)
@@ -109,7 +109,7 @@
 :- pred multi_map__add(multi_map(K, V)::in, K::in, V::in, multi_map(K, V)::out)
 	is det.

-	% Given a multi_map, return a list of all the keys in the multi_map
+	% Given a multi_map, return a list of all the keys in the multi_map.
 	%
 :- func multi_map__keys(multi_map(K, _V)) = list(K).
 :- pred multi_map__keys(multi_map(K, _V)::in, list(K)::out) is det.
@@ -174,7 +174,7 @@
 	multi_map(K, V)::out) is semidet.

 	% Delete a key-value pair from a multi_map and return the value.
-	% abort if the key is not present.
+	% Abort if the key is not present.
 	%
 :- pred multi_map__det_remove(multi_map(K, V)::in, K::in, list(V)::out,
 	multi_map(K, V)::out) is det.
Index: library/svmulti_map.m
===================================================================
RCS file: library/svmulti_map.m
diff -N library/svmulti_map.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ library/svmulti_map.m	24 Feb 2005 12:27:16 -0000
@@ -0,0 +1,140 @@
+%-----------------------------------------------------------------------------%
+% Copyright (C) 2005 The University of Melbourne.
+% This file may only be copied under the terms of the GNU Library General
+% Public License - see the file COPYING.LIB in the Mercury distribution.
+%-----------------------------------------------------------------------------%
+%
+% File: svmulti_map.m.
+% Author: dylan.
+% Stability: low.
+%
+% This file provides an interface to the 'multi_map' ADT that is conducive to
+% the use of state variable notation. The predicates here do the same thing as
+% their counterparts in the multi_map module; the only difference is the order
+% of the arguments.
+%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- module svmulti_map.
+
+:- interface.
+
+:- import_module list.
+:- import_module multi_map.
+
+%-----------------------------------------------------------------------------%
+
+	% Insert a new key and corresponding value into a multi_map.
+	% Fail if the key already exists.
+	%
+:- pred svmulti_map__insert(K::in, V::in,
+	multi_map(K, V)::in, multi_map(K, V)::out) is semidet.
+
+	% Insert a new key and corresponding value into a multi_map.
+	% Abort if the key already exists.
+	%
+:- pred svmulti_map__det_insert(K::in, V::in,
+	multi_map(K, V)::in, multi_map(K, V)::out) is det.
+
+	% Update (add) the value corresponding to a given key.
+	% Fail if the key does not already exist.
+	%
+:- pred svmulti_map__update(K::in, V::in,
+	multi_map(K, V)::in, multi_map(K, V)::out) is semidet.
+
+	% Update (add) the value corresponding to a given key.
+	% Abort if the key doesn't already exist.
+	%
+:- pred svmulti_map__det_update(K::in, V::in,
+	multi_map(K, V)::in, multi_map(K, V)::out) is det.
+
+	% Update (replace) the value corresponding to a given key.
+	% Abort if the key does not already exist.
+	%
+:- pred svmulti_map__det_replace(K::in, list(V)::in,
+	multi_map(K, V)::in, multi_map(K, V)::out) is det.
+
+	% Update (add) value if the key is already present, otherwise
+	% insert the new key and value.
+	%
+:- pred svmulti_map__set(K::in, V::in,
+	multi_map(K, V)::in, multi_map(K, V)::out) is det.
+
+:- pred svmulti_map__add(K::in, V::in,
+	multi_map(K, V)::in, multi_map(K, V)::out) is det.
+
+	% Delete a key and data from a multi_map
+	% If the key is not present, leave the multi_map unchanged.
+	%
+:- pred svmulti_map__delete(K::in, multi_map(K, V)::in, multi_map(K, V)::out)
+	is det.
+
+	% Delete a data value from a key in a multi_map
+	% If the key is not present, leave the multi_map unchanged.
+	%
+:- pred svmulti_map__delete(K::in, V::in,
+	multi_map(K, V)::in, multi_map(K, V)::out) is det.
+
+	% Delete a key-value pair from a multi_map and return the value.
+	% Fail if the key is not present.
+	%
+:- pred svmulti_map__remove(K::in, list(V)::out,
+	multi_map(K, V)::in, multi_map(K, V)::out) is semidet.
+
+	% Delete a key-value pair from a multi_map and return the value.
+	% Abort if the key is not present.
+	%
+:- pred svmulti_map__det_remove(K::in, list(V)::out,
+	multi_map(K, V)::in, multi_map(K, V)::out) is det.
+
+	% Remove the smallest item from the multi_map, fail if
+	% the multi_map is empty.
+	%
+:- pred svmulti_map__remove_smallest(K::out, list(V)::out,
+	multi_map(K, V)::in, multi_map(K, V)::out) is semidet.
+
+%----------------------------------------------------------------------------%
+%----------------------------------------------------------------------------%
+
+:- implementation.
+
+svmulti_map__insert(K, V, MultiMap0, MultiMap) :-
+	multi_map__insert(MultiMap0, K, V, MultiMap).
+
+svmulti_map__det_insert(K, V, MultiMap0, MultiMap) :-
+	multi_map__det_insert(MultiMap0, K, V, MultiMap).
+
+svmulti_map__update(K, V, MultiMap0, MultiMap) :-
+	multi_map__update(MultiMap0, K, V, MultiMap).
+
+svmulti_map__det_update(K, V, MultiMap0, MultiMap) :-
+	multi_map__det_update(MultiMap0, K, V, MultiMap).
+
+svmulti_map__det_replace(K, V, MultiMap0, MultiMap) :-
+	multi_map__det_replace(MultiMap0, K, V, MultiMap).
+
+svmulti_map__set(K, V, MultiMap0, MultiMap) :-
+	multi_map__set(MultiMap0, K, V, MultiMap).
+
+svmulti_map__add(K, V, MultiMap0, MultiMap) :-
+	multi_map__add(MultiMap0, K, V, MultiMap).
+
+svmulti_map__delete(K, MultiMap0, MultiMap) :-
+	multi_map__delete(MultiMap0, K, MultiMap).
+
+svmulti_map__delete(K, V, MultiMap0, MultiMap) :-
+	multi_map__delete(MultiMap0, K, V, MultiMap).
+
+svmulti_map__remove(K, V, MultiMap0, MultiMap) :-
+	multi_map__remove(MultiMap0, K, V, MultiMap).
+
+svmulti_map__det_remove(K, V, MultiMap0, MultiMap) :-
+	multi_map__det_remove(MultiMap0, K, V, MultiMap).
+
+svmulti_map__remove_smallest(K, V, MultiMap0, MultiMap) :-
+	multi_map__remove_smallest(MultiMap0, K, V, MultiMap).
+
+%----------------------------------------------------------------------------%
+:- end_module svmulti_map.
+%----------------------------------------------------------------------------%

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list