[m-rev.] diff: additions to bimap.m

Zoltan Somogyi zs at cs.mu.OZ.AU
Thu Sep 9 08:59:22 AEST 2004


library/bimap.m:
	Add some predicates to move the functionality of this module closer
	to that of map.m:

		det_insert
		forward_search
		reverse_search
		from_corresponding_lists
		map_keys
		map_values
		det_insert_from_assoc_list
		det_insert_from_corresponding_lists
		set_from_assoc_list
		set_from_corresponding_lists
		delete_key
		delete_value
		delete_keys
		delete_values
		overlay
		apply_forward_map_to_list
		apply_reverse_map_to_list
		foldl

	Add function forms of all predicates in the module for which this makes
	sense, both the new ones and some old ones.

	Make the implementation of the bimap type private; add two functions,
	forward_map and reverse_map, to replace the explicit type definition.

	Fix the implementation of bimap__set: it wasn't ensuring the bijective
	property.

NEWS:
	Mention the new predicates and functions.

Zoltan.

cvs diff: Diffing .
Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.337
diff -u -r1.337 NEWS
--- NEWS	8 Jul 2004 06:00:50 -0000	1.337
+++ NEWS	6 Sep 2004 02:59:53 -0000
@@ -140,6 +140,26 @@
 	input_stream_foldl2_io_maybe_stop/{6,7},
 	binary_input_stream_foldl2_io_maybe_stop/{6,7}.
 
+* We've added several new predicates and functions to the bimap module:
+	det_insert,
+	forward_search,
+	reverse_search,
+	from_corresponding_lists,
+	map_keys,
+	map_values,
+	det_insert_from_assoc_list,
+	det_insert_from_corresponding_lists,
+	set_from_assoc_list,
+	set_from_corresponding_lists,
+	delete_key,
+	delete_value,
+	delete_keys,
+	delete_values,
+	overlay,
+	apply_forward_map_to_list,
+	apply_reverse_map_to_list,
+	foldl
+
 * We've added predicates relation__lookup_key_set_from/3 and
   relation__lookup_key_set_to/3.
 
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
Index: library/bimap.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/bimap.m,v
retrieving revision 1.14
diff -u -r1.14 bimap.m
--- library/bimap.m	12 Nov 2000 08:51:32 -0000	1.14
+++ library/bimap.m	12 Jul 2004 03:41:58 -0000
@@ -1,5 +1,5 @@
 %---------------------------------------------------------------------------%
-% Copyright (C) 1994-1995, 1997, 1999 The University of Melbourne.
+% Copyright (C) 1994-1995, 1997, 1999, 2004 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.
 %-----------------------------------------------------------------------------%
@@ -10,7 +10,7 @@
 %
 % This file provides a bijective map ADT.
 % A map (also known as a dictionary or an associative array) is a collection
-% of (Key,Data) pairs which allows you to look up any Data item given the
+% of (Key, Data) pairs which allows you to look up any Data item given the
 % Key.  A bimap also allows you to look up the Key given the Data.
 %
 % The implementation is a pair of maps.
@@ -20,7 +20,7 @@
 
 :- module bimap.
 :- interface.
-:- import_module list, assoc_list.
+:- import_module list, assoc_list, map.
 
 %-----------------------------------------------------------------------------%
 
@@ -29,123 +29,361 @@
 %-----------------------------------------------------------------------------%
 
 	% Initialize an empty bimap.
-:- pred bimap__init(bimap(_,_)).
-:- mode bimap__init(out) is det.
-
-:- func bimap__init = bimap(_,_).
+:- pred bimap__init(bimap(_, _)::out) is det.
+:- func bimap__init = bimap(_, _).
 
 	% Check whether a bimap is empty.
-:- pred bimap__is_empty(bimap(_,_)).
-:- mode bimap__is_empty(in) is semidet.
+:- pred bimap__is_empty(bimap(_, _)::in) is semidet.
 
-:- pred bimap__search(bimap(K,V), K, V).
+:- pred bimap__search(bimap(K, V), K, V).
 :- mode bimap__search(in, in, out) is semidet.
 :- mode bimap__search(in, out, in) is semidet.
 
-:- func bimap__set(bimap(K,V), K, V) = bimap(K,V).
-
-:- pred bimap__lookup(bimap(K,V), K, V).
-:- mode bimap__lookup(in, in, out) is det.
-
-:- func bimap__lookup(bimap(K,V), K) = V.
+:- pred bimap__forward_search(bimap(K, V)::in, K::in, V::out) is semidet.
+:- func bimap__forward_search(bimap(K, V), K) = V is semidet.
 
-:- pred bimap__reverse_lookup(bimap(K,V), K, V).
-:- mode bimap__reverse_lookup(in, out, in) is det.
+:- pred bimap__reverse_search(bimap(K, V)::in, K::out, V::in) is semidet.
+:- func bimap__reverse_search(bimap(K, V), V) = K is semidet.
 
-:- pred bimap__insert(bimap(K,V), K, V, bimap(K,V)).
-:- mode bimap__insert(in, in, in, out) is semidet.
+:- pred bimap__lookup(bimap(K, V)::in, K::in, V::out) is det.
+:- func bimap__lookup(bimap(K, V), K) = V.
 
-:- pred bimap__set(bimap(K,V), K, V, bimap(K,V)).
-:- mode bimap__set(in, in, in, out) is det.
-
-	% Given a bimap, return a list of all the keys in the bimap
-:- pred bimap__ordinates(bimap(K, _V), list(K)).
-:- mode bimap__ordinates(in, out) is det.
+:- pred bimap__reverse_lookup(bimap(K, V)::in, K::out, V::in) is det.
+:- func bimap__reverse_lookup(bimap(K, V), V) = K.
 
+	% Given a bimap, return a list of all the keys in the bimap.
+:- pred bimap__ordinates(bimap(K, _V)::in, list(K)::out) is det.
 :- func bimap__ordinates(bimap(K, _V)) = list(K).
 
-	% Given a bimap, return a list of all the data values in the bimap
-:- pred bimap__coordinates(bimap(_K, V), list(V)).
-:- mode bimap__coordinates(in, out) is det.
-
+	% Given a bimap, return a list of all the data values in the bimap.
+:- pred bimap__coordinates(bimap(_K, V)::in, list(V)::out) is det.
 :- func bimap__coordinates(bimap(_K, V)) = list(V).
 
-	% convert a bimap to an association list
-:- pred bimap__to_assoc_list(bimap(K,V), assoc_list(K,V)).
-:- mode bimap__to_assoc_list(in, out) is det.
-
-:- func bimap__to_assoc_list(bimap(K,V)) = assoc_list(K,V).
+:- pred bimap__contains_key(bimap(K, V)::in, K::in) is semidet.
 
-	% convert an association list to a bimap
-:- pred bimap__from_assoc_list(assoc_list(K,V), bimap(K,V)).
-:- mode bimap__from_assoc_list(in, out) is det.
+:- pred bimap__contains_value(bimap(K, V)::in, V::in) is semidet.
 
-:- func bimap__from_assoc_list(assoc_list(K,V)) = bimap(K,V).
+:- pred bimap__insert(bimap(K, V)::in, K::in, V::in, bimap(K, V)::out)
+	is semidet.
+:- func bimap__insert(bimap(K, V), K, V) = bimap(K, V) is semidet.
+
+:- pred bimap__det_insert(bimap(K, V)::in, K::in, V::in, bimap(K, V)::out)
+	is det.
+:- func bimap__det_insert(bimap(K, V), K, V) = bimap(K, V).
+
+:- pred bimap__set(bimap(K, V)::in, K::in, V::in, bimap(K, V)::out) is det.
+:- func bimap__set(bimap(K, V), K, V) = bimap(K, V).
+
+:- pred bimap__det_insert_from_assoc_list(assoc_list(K, V)::in,
+	bimap(K, V)::in, bimap(K, V)::out) is det.
+:- func bimap__det_insert_from_assoc_list(assoc_list(K, V), bimap(K, V))
+	= bimap(K, V).
+
+:- pred bimap__det_insert_from_corresponding_lists(list(K)::in, list(V)::in,
+	bimap(K, V)::in, bimap(K, V)::out) is det.
+:- func bimap__det_insert_from_corresponding_lists(list(K), list(V),
+	bimap(K, V)) = bimap(K, V).
+
+:- pred bimap__set_from_assoc_list(assoc_list(K, V)::in,
+	bimap(K, V)::in, bimap(K, V)::out) is det.
+:- func bimap__set_from_assoc_list(assoc_list(K, V), bimap(K, V))
+	= bimap(K, V).
+
+:- pred bimap__set_from_corresponding_lists(list(K)::in, list(V)::in,
+	bimap(K, V)::in, bimap(K, V)::out) is det.
+:- func bimap__set_from_corresponding_lists(list(K), list(V),
+	bimap(K, V)) = bimap(K, V).
+
+	% Delete a key-value pair from a bimap. If the key is not present,
+	% leave the bimap unchanged.
+:- pred bimap__delete_key(K::in, bimap(K, V)::in, bimap(K, V)::out) is det.
+:- func bimap__delete_key(bimap(K, V), K) = bimap(K, V).
+
+	% Delete a key-value pair from a bimap. If the value is not present,
+	% leave the bimap unchanged.
+:- pred bimap__delete_value(V::in, bimap(K, V)::in, bimap(K, V)::out) is det.
+:- func bimap__delete_value(bimap(K, V), V) = bimap(K, V).
+
+	% Apply bimap__delete_key to a list of keys.
+:- pred bimap__delete_keys(list(K)::in, bimap(K, V)::in, bimap(K, V)::out)
+	is det.
+:- func bimap__delete_keys(bimap(K, V), list(K)) = bimap(K, V).
+
+	% Apply bimap__delete_value to a list of values.
+:- pred bimap__delete_values(list(V)::in, bimap(K, V)::in, bimap(K, V)::out)
+	is det.
+:- func bimap__delete_values(bimap(K, V), list(V)) = bimap(K, V).
+
+	% bimap__overlay(BIMapA, BIMapB, BIMap):
+	% Apply map__overlay to the forward maps of BIMapA and BIMapB,
+	% and compute the reverse map from the resulting map.
+:- pred bimap__overlay(bimap(K, V)::in, bimap(K, V)::in, bimap(K, V)::out)
+	is det.
+:- func bimap__overlay(bimap(K, V), bimap(K, V)) = bimap(K, V).
 
-/****
-	% delete a key-value pair from a bimap
-:- pred bimap__delete(bimap(K,V), K, V, bimap(K,V)).
-:- mode bimap__delete(in, in, out, out) is det.
-:- mode bimap__delete(in, out, in, out) is det.
+	% convert a bimap to an association list
+:- pred bimap__to_assoc_list(bimap(K, V)::in, assoc_list(K, V)::out) is det.
+:- func bimap__to_assoc_list(bimap(K, V)) = assoc_list(K, V).
 
-:- pred bimap__from_corresponding_lists(list(K), list(V), bimap(K, V)).
-:- mode bimap__from_corresponding_lists(in, in, out) is det.
+	% convert an association list to a bimap
+:- pred bimap__from_assoc_list(assoc_list(K, V)::in, bimap(K, V)::out) is det.
+:- func bimap__from_assoc_list(assoc_list(K, V)) = bimap(K, V).
 
+:- pred bimap__from_corresponding_lists(list(K)::in, list(V)::in,
+	bimap(K, V)::out) is det.
 :- func bimap__from_corresponding_lists(list(K), list(V)) = bimap(K, V).
-****/
 
-%-----------------------------------------------------------------------------%
+:- pred bimap__apply_forward_map_to_list(bimap(K, V)::in, list(K)::in,
+	list(V)::out) is det.
+:- func bimap__apply_forward_map_to_list(bimap(K, V), list(K)) = list(V).
+
+:- pred bimap__apply_reverse_map_to_list(bimap(K, V)::in, list(V)::in,
+	list(K)::out) is det.
+:- func bimap__apply_reverse_map_to_list(bimap(K, V), list(V)) = list(K).
+
+	% Apply a transformation predicate to all the keys.
+:- pred bimap__map_keys(pred(V, K, L)::in(pred(in, in, out) is det),
+	bimap(K, V)::in, bimap(L, V)::out) is det.
+:- func bimap__map_keys(func(V, K) = L, bimap(K, V)) = bimap(L, V).
+
+	% Apply a transformation predicate to all the values.
+:- pred bimap__map_values(pred(K, V, W)::in(pred(in, in, out) is det),
+	bimap(K, V)::in, bimap(K, W)::out) is det.
+:- func bimap__map_values(func(K, V) = W, bimap(K, V)) = bimap(K, W).
+
+	% Apply a transformation predicate to all the values.
+:- pred bimap__foldl(pred(K, V, T, T), bimap(K, V), T, T).
+:- mode bimap__foldl(pred(in, in, di, uo) is det, in, di, uo) is det.
+:- mode bimap__foldl(pred(in, in, in, out) is det, in, in, out) is det.
+:- mode bimap__foldl(pred(in, in, in, out) is semidet, in, in, out) is semidet.
+:- func bimap__foldl(func(K, V, T) = T, bimap(K, V), T) = T.
 
-:- import_module map.
+:- func bimap__forward_map(bimap(K, V)) = map(K, V).
 
-:- type bimap(K,V)	--->	bimap(map(K,V), map(V, K)).
+:- func bimap__reverse_map(bimap(K, V)) = map(V, K).
 
 %-----------------------------------------------------------------------------%
-%-----------------------------------------------------------------------------%
 
 :- implementation.
 
+:- import_module std_util, require.
+
+:- type bimap(K, V)	--->	bimap(map(K, V), map(V, K)).
+
 %-----------------------------------------------------------------------------%
 
 bimap__init(B) :-
-	map__init(O),
-	map__init(C),
-	B = bimap(O, C).
-
-bimap__is_empty(bimap(O,_C)) :-
-	map__is_empty(O). % by inference == map__is_empty(C).
-
-bimap__search(bimap(O, C), K, V) :-
-	map__search(O, K, V),
-	map__search(C, V, K).
-
-bimap__lookup(bimap(O, _C), K, V) :-
-	map__lookup(O, K, V).
-
-bimap__reverse_lookup(bimap(_O, C), K, V) :-
-	map__lookup(C, V, K).
-
-bimap__insert(bimap(O0, C0), K, V, bimap(O, C)) :-
-	map__insert(O0, K, V, O),
-	map__insert(C0, V, K, C).
- 
-bimap__set(bimap(O0, C0), K, V, bimap(O, C)) :-
-	map__set(O0, K, V, O),
-	map__set(C0, V, K, C).
- 
-bimap__ordinates(bimap(O, _C), Os) :-
-	map__keys(O, Os).
-
-bimap__coordinates(bimap(_O, C), Cs) :-
-	map__keys(C, Cs).
+	map__init(Forward),
+	map__init(Reverse),
+	B = bimap(Forward, Reverse).
+
+bimap__is_empty(bimap(Forward, _)) :-
+	map__is_empty(Forward). % by inference == map__is_empty(Reverse).
+
+bimap__search(bimap(Forward, Reverse), K, V) :-
+	map__search(Forward, K, V),
+	map__search(Reverse, V, K).
+
+bimap__forward_search(bimap(Forward, _), K, V) :-
+	map__search(Forward, K, V).
+
+bimap__reverse_search(bimap(_, Reverse), K, V) :-
+	map__search(Reverse, V, K).
+
+bimap__contains_key(bimap(Forward, _), K) :-
+	map__contains(Forward, K).
+
+bimap__contains_value(bimap(_, Reverse), V) :-
+	map__contains(Reverse, V).
+
+bimap__lookup(bimap(Forward, _), K, V) :-
+	map__lookup(Forward, K, V).
+
+bimap__reverse_lookup(bimap(_, Reverse), K, V) :-
+	map__lookup(Reverse, V, K).
+
+bimap__ordinates(bimap(Forward, _), Os) :-
+	map__keys(Forward, Os).
+
+bimap__coordinates(bimap(_, Reverse), Cs) :-
+	map__keys(Reverse, Cs).
+
+bimap__insert(bimap(Forward0, Reverse0), K, V, bimap(Forward, Reverse)) :-
+	map__insert(Forward0, K, V, Forward),
+	map__insert(Reverse0, V, K, Reverse).
+
+bimap__det_insert(bimap(Forward0, Reverse0), K, V, bimap(Forward, Reverse)) :-
+	map__det_insert(Forward0, K, V, Forward),
+	map__det_insert(Reverse0, V, K, Reverse).
+
+bimap__set(bimap(Forward0, Reverse0), K, V, bimap(Forward, Reverse)) :-
+	( map__search(Forward0, K, KVal) ->
+		map__det_update(Forward0, K, V, Forward1),
+		map__delete(Reverse0, KVal, Reverse1)
+	;
+		map__det_insert(Forward0, K, V, Forward1),
+		Reverse1 = Reverse0
+	),
+	( map__search(Reverse0, V, VKey) ->
+		map__det_update(Reverse1, V, K, Reverse),
+		map__delete(Forward1, VKey, Forward)
+	;
+		map__det_insert(Reverse1, V, K, Reverse),
+		Forward = Forward1
+	).
+
+bimap__det_insert_from_assoc_list([], !BM).
+bimap__det_insert_from_assoc_list([Key - Value | KeysValues], !BM) :-
+	bimap__det_insert(!.BM, Key, Value, !:BM),
+	bimap__det_insert_from_assoc_list(KeysValues, !BM).
+
+bimap__det_insert_from_corresponding_lists([], [], !BM).
+bimap__det_insert_from_corresponding_lists([], [_ | _], !BM) :-
+	error("bimap__det_insert_from_corresponding_lists: length mismatch").
+bimap__det_insert_from_corresponding_lists([_ | _], [], !BM) :-
+	error("bimap__det_insert_from_corresponding_lists: length mismatch").
+bimap__det_insert_from_corresponding_lists([Key | Keys], [Value | Values],
+		!BM) :-
+	bimap__det_insert(!.BM, Key, Value, !:BM),
+	bimap__det_insert_from_corresponding_lists(Keys, Values, !BM).
+
+bimap__set_from_assoc_list([], !BM).
+bimap__set_from_assoc_list([Key - Value | KeysValues], !BM) :-
+	bimap__set(!.BM, Key, Value, !:BM),
+	bimap__set_from_assoc_list(KeysValues, !BM).
+
+bimap__set_from_corresponding_lists([], [], !BM).
+bimap__set_from_corresponding_lists([], [_ | _], !BM) :-
+	error("bimap__set_from_corresponding_lists: length mismatch").
+bimap__set_from_corresponding_lists([_ | _], [], !BM) :-
+	error("bimap__set_from_corresponding_lists: length mismatch").
+bimap__set_from_corresponding_lists([Key | Keys], [Value | Values],
+		!BM) :-
+	bimap__set(!.BM, Key, Value, !:BM),
+	bimap__set_from_corresponding_lists(Keys, Values, !BM).
+
+bimap__delete_key(K, BM0, BM) :-
+	BM0 = bimap(Forward0, Reverse0),
+	( map__search(Forward0, K, V) ->
+		map__delete(Forward0, K, Forward),
+		map__delete(Reverse0, V, Reverse),
+		BM = bimap(Forward, Reverse)
+	;
+		BM = BM0
+	).
+
+bimap__delete_value(V, BM0, BM) :-
+	BM0 = bimap(Forward0, Reverse0),
+	( map__search(Reverse0, V, K) ->
+		map__delete(Forward0, K, Forward),
+		map__delete(Reverse0, V, Reverse),
+		BM = bimap(Forward, Reverse)
+	;
+		BM = BM0
+	).
+
+bimap__delete_keys([], !BM).
+bimap__delete_keys([Key | Keys], !BM) :-
+	bimap__delete_key(Key, !BM),
+	bimap__delete_keys(Keys, !BM).
+
+bimap__delete_values([], !BM).
+bimap__delete_values([Value | Values], !BM) :-
+	bimap__delete_value(Value, !BM),
+	bimap__delete_values(Values, !BM).
+
+bimap__overlay(BMA, BMB, BM) :-
+	bimap__to_assoc_list(BMB, KVBs),
+	bimap__overlay_2(KVBs, BMA, BM).
+
+:- pred bimap__overlay_2(assoc_list(K, V)::in, bimap(K, V)::in,
+	bimap(K, V)::out) is det.
+
+bimap__overlay_2([], !BM).
+bimap__overlay_2([Key - Value | KeysValues], !BM) :-
+	bimap__set(!.BM, Key, Value, !:BM),
+	bimap__overlay_2(KeysValues, !BM).
 
-bimap__to_assoc_list(bimap(O, _C), L) :-
-	map__to_assoc_list(O, L).
+bimap__to_assoc_list(bimap(Forward, _), L) :-
+	map__to_assoc_list(Forward, L).
 
-bimap__from_assoc_list(L, bimap(O, C)) :-
-	map__from_assoc_list(L, O),
+bimap__from_assoc_list(L, bimap(Forward, Reverse)) :-
+	map__from_assoc_list(L, Forward),
 	assoc_list__reverse_members(L, L1),
-	map__from_assoc_list(L1, C).
+	map__from_assoc_list(L1, Reverse).
+
+bimap__from_corresponding_lists(Ks, Vs, BM) :-
+	assoc_list__from_corresponding_lists(Ks, Vs, L),
+	bimap__from_assoc_list(L, BM).
+
+bimap__apply_forward_map_to_list(bimap(Forward, _), Ks, Vs) :-
+	map__apply_to_list(Ks, Forward, Vs).
+
+bimap__apply_reverse_map_to_list(bimap(_, Reverse), Vs, Ks) :-
+	map__apply_to_list(Vs, Reverse, Ks).
+
+bimap__map_keys(KeyMap, BM0, BM) :-
+	bimap__to_assoc_list(BM0, L0),
+	bimap__map_keys_2(KeyMap, L0, [], L),
+	bimap__from_assoc_list(L, BM).
+
+bimap__map_keys(KeyMap, BM0) = BM :-
+	bimap__to_assoc_list(BM0, L0),
+	bimap__map_keys_func_2(KeyMap, L0, [], L),
+	bimap__from_assoc_list(L, BM).
+
+bimap__map_values(ValueMap, BM0, BM) :-
+	bimap__to_assoc_list(BM0, L0),
+	bimap__map_values_2(ValueMap, L0, [], L),
+	bimap__from_assoc_list(L, BM).
+
+bimap__map_values(ValueMap, BM0) = BM :-
+	bimap__to_assoc_list(BM0, L0),
+	bimap__map_values_func_2(ValueMap, L0, [], L),
+	bimap__from_assoc_list(L, BM).
+
+:- pred bimap__map_keys_2(pred(V, K, L)::in(pred(in, in, out) is det),
+	assoc_list(K, V)::in, assoc_list(L, V)::in, assoc_list(L, V)::out)
+	is det.
+
+bimap__map_keys_2(_KeyMap, [], !List).
+bimap__map_keys_2(KeyMap, [Key0 - Value | Tail0], !List) :-
+	KeyMap(Value, Key0, Key),
+	!:List = [Key - Value | !.List],
+	bimap__map_keys_2(KeyMap, Tail0, !List).
+
+:- pred bimap__map_keys_func_2(func(V, K) = L::in(func(in, in) = out is det),
+	assoc_list(K, V)::in, assoc_list(L, V)::in, assoc_list(L, V)::out)
+	is det.
+
+bimap__map_keys_func_2(_KeyMap, [], !List).
+bimap__map_keys_func_2(KeyMap, [Key0 - Value | Tail0], !List) :-
+	Key = KeyMap(Value, Key0),
+	!:List = [Key - Value | !.List],
+	bimap__map_keys_func_2(KeyMap, Tail0, !List).
+
+:- pred bimap__map_values_2(pred(K, V, W)::in(pred(in, in, out) is det),
+	assoc_list(K, V)::in, assoc_list(K, W)::in, assoc_list(K, W)::out)
+	is det.
+
+bimap__map_values_2(_ValueMap, [], !List).
+bimap__map_values_2(ValueMap, [Key - Value0 | Tail0], !List) :-
+	ValueMap(Key, Value0, Value),
+	!:List = [Key - Value | !.List],
+	bimap__map_values_2(ValueMap, Tail0, !List).
+
+:- pred bimap__map_values_func_2(func(K, V) = W::in(func(in, in) = out is det),
+	assoc_list(K, V)::in, assoc_list(K, W)::in, assoc_list(K, W)::out)
+	is det.
+
+bimap__map_values_func_2(_ValueMap, [], !List).
+bimap__map_values_func_2(ValueMap, [Key - Value0 | Tail0], !List) :-
+	Value = ValueMap(Key, Value0),
+	!:List = [Key - Value | !.List],
+	bimap__map_values_func_2(ValueMap, Tail0, !List).
+
+bimap__foldl(Pred, bimap(Forward, _), List0, List) :-
+	map__foldl(Pred, Forward, List0, List).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -155,11 +393,17 @@
 bimap__init = BM :-
 	bimap__init(BM).
 
+bimap__forward_search(BM, K) = V :-
+	bimap__forward_search(BM, K, V).
+
+bimap__reverse_search(BM, V) = K :-
+	bimap__reverse_search(BM, K, V).
+
 bimap__lookup(BM, K) = V :-
 	bimap__lookup(BM, K, V).
 
-bimap__set(BM1, K, V) = BM2 :-
-	bimap__set(BM1, K, V, BM2).
+bimap__reverse_lookup(BM, V) = K :-
+	bimap__reverse_lookup(BM, K, V).
 
 bimap__ordinates(BM) = Ks :-
 	bimap__ordinates(BM, Ks).
@@ -167,13 +411,60 @@
 bimap__coordinates(BM) = Vs :-
 	bimap__coordinates(BM, Vs).
 
+bimap__insert(BM1, K, V) = BM2 :-
+	bimap__insert(BM1, K, V, BM2).
+
+bimap__det_insert(BM1, K, V) = BM2 :-
+	bimap__det_insert(BM1, K, V, BM2).
+
+bimap__det_insert_from_assoc_list(KVs, BM0) = BM :-
+	bimap__det_insert_from_assoc_list(KVs, BM0, BM).
+
+bimap__det_insert_from_corresponding_lists(Ks, Vs, BM0) = BM :-
+	bimap__det_insert_from_corresponding_lists(Ks, Vs, BM0, BM).
+
+bimap__set_from_assoc_list(KVs, BM0) = BM :-
+	bimap__set_from_assoc_list(KVs, BM0, BM).
+
+bimap__set_from_corresponding_lists(Ks, Vs, BM0) = BM :-
+	bimap__set_from_corresponding_lists(Ks, Vs, BM0, BM).
+
+bimap__set(BM1, K, V) = BM2 :-
+	bimap__set(BM1, K, V, BM2).
+
+bimap__delete_key(BM0, K) = BM :-
+	bimap__delete_key(K, BM0, BM).
+
+bimap__delete_value(BM0, V) = BM :-
+	bimap__delete_value(V, BM0, BM).
+
+bimap__delete_keys(BM0, Ks) = BM :-
+	bimap__delete_keys(Ks, BM0, BM).
+
+bimap__delete_values(BM0, Vs) = BM :-
+	bimap__delete_values(Vs, BM0, BM).
+
+bimap__overlay(BMA, BMB) = BM :-
+	bimap__overlay(BMA, BMB, BM).
+
 bimap__to_assoc_list(BM) = AL :-
 	bimap__to_assoc_list(BM, AL).
 
 bimap__from_assoc_list(AL) = BM :-
 	bimap__from_assoc_list(AL, BM).
 
-%%% bimap__from_corresponding_lists(Ks, Vs) = BM :-
-%%% 	bimap__from_corresponding_lists(Ks, Vs, BM).
+bimap__from_corresponding_lists(Ks, Vs) = BM :-
+	bimap__from_corresponding_lists(Ks, Vs, BM).
+
+bimap__apply_forward_map_to_list(BM, Ks) = Vs :-
+	bimap__apply_forward_map_to_list(BM, Ks, Vs).
+
+bimap__apply_reverse_map_to_list(BM, Vs) = Ks :-
+	bimap__apply_reverse_map_to_list(BM, Vs, Ks).
+
+bimap__foldl(Func, bimap(Forward, _), List0) =
+	map__foldl(Func, Forward, List0).
 
+bimap__forward_map(bimap(Forward, _)) = Forward.
 
+bimap__reverse_map(bimap(_, Reverse)) = Reverse.
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
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