[m-rev.] diff/for review: more library improvements for caribou
Zoltan Somogyi
zs at cs.mu.OZ.AU
Thu Jan 6 13:08:21 AEDT 2005
Add some library functions I discovered I needed while working on my scanner
generator.
library/char.m:
Add char__int_to_char, a more expressive name for the reverse mode
of char__to_int, and a deterministic version, char__det_int_to_char.
library/list.m:
Add some more arities of the foldl and map_foldl predicates.
Use a consistent naming scheme for the type variables in signatures
of the various versions of the foldl and map_foldl predicates.
library/map.m:
Add a new predicate reverse_map, which turns a map(K, V) into
a map(V, set(K)).
library/svqueue.m:
library/svbimap.m:
New modules, which contain state-variable-friendly versions of the
relevant predicates from queue.m and bimap.m respectively.
library/library.m:
NEWS:
Mention the two new modules.
Zoltan.
cvs diff: Diffing .
Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.356
diff -u -r1.356 NEWS
--- NEWS 20 Dec 2004 05:26:04 -0000 1.356
+++ NEWS 5 Jan 2005 06:42:25 -0000
@@ -22,9 +22,9 @@
version_array2d, version_bitmap, version_hash_table, and version_store,
implementing non-unique versions of these types supporting O(1) access for
non-persistent use. A new module term_to_xml has been added for converting
- arbitrary terms to XML documents. Two new modules, svmap and svset, now
- provide more convenient ways to update maps and sets in code that uses
- state variables.
+ arbitrary terms to XML documents. Four new modules, svmap, svbimap, svset
+ and svqueue now provide more convenient ways to update maps, bimaps, sets
+ and queues 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
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/easyx
cvs diff: Diffing extras/graphics/easyx/samples
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 extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
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
cvs diff: Diffing library
Index: library/char.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/char.m,v
retrieving revision 1.46
diff -u -r1.46 char.m
--- library/char.m 15 Mar 2004 23:49:30 -0000 1.46
+++ library/char.m 4 Jan 2005 00:53:32 -0000
@@ -49,6 +49,14 @@
:- mode char__to_int(in, in) is semidet. % implied
:- mode char__to_int(out, in) is semidet.
+ % Converts an integer to its corresponding character, if any.
+ % A more expressive name for the reverse mode of char__to_int.
+:- pred char__int_to_char(int::in, char::out) is semidet.
+
+ % Converts an integer to its corresponding character. Aborts
+ % if there isn't one.
+:- pred char__det_int_to_char(int::in, char::out) is det.
+
% Returns the maximum numerical character code.
:- func char__max_char_value = int.
:- pred char__max_char_value(int::out) is det.
@@ -403,6 +411,16 @@
char__lower_upper('z', 'Z').
%-----------------------------------------------------------------------------%
+
+char__int_to_char(Int, Char) :-
+ char__to_int(Char, Int).
+
+char__det_int_to_char(Int, Char) :-
+ ( char__int_to_char(Int, CharPrime) ->
+ Char = CharPrime
+ ;
+ error("char__det_int_to_char: conversion failed")
+ ).
:- pragma foreign_proc("C",
char__to_int(Character::in, Int::out),
Index: library/library.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/library.m,v
retrieving revision 1.79
diff -u -r1.79 library.m
--- library/library.m 16 Dec 2004 03:17:27 -0000 1.79
+++ library/library.m 4 Jan 2005 00:42:50 -0000
@@ -97,7 +97,9 @@
:- import_module std_util.
:- import_module store.
:- import_module string.
+:- import_module svbimap.
:- import_module svmap.
+:- import_module svqueue.
:- import_module svset.
:- import_module term.
:- import_module term_io.
@@ -223,7 +225,9 @@
mercury_std_library_module("std_util").
mercury_std_library_module("store").
mercury_std_library_module("string").
+mercury_std_library_module("svbimap").
mercury_std_library_module("svmap").
+mercury_std_library_module("svqueue").
mercury_std_library_module("svset").
mercury_std_library_module("table_builtin").
mercury_std_library_module("term").
Index: library/list.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.128
diff -u -r1.128 list.m
--- library/list.m 14 Dec 2004 01:07:20 -0000 1.128
+++ library/list.m 27 Dec 2004 08:21:55 -0000
@@ -469,7 +469,7 @@
% element of List (working left-to-right) and an accumulator
% (with the initial value of Start), and returns the final
% value in End.
-:- pred list__foldl(pred(X, Y, Y), list(X), Y, Y).
+:- pred list__foldl(pred(L, A, A), list(L), A, A).
:- mode list__foldl(pred(in, di, uo) is det, in, di, uo) is det.
:- mode list__foldl(pred(in, in, out) is det, in, in, out) is det.
:- mode list__foldl(pred(in, in, out) is semidet, in, in, out) is semidet.
@@ -477,13 +477,13 @@
:- mode list__foldl(pred(in, di, uo) is cc_multi, in, di, uo) is cc_multi.
:- mode list__foldl(pred(in, in, out) is cc_multi, in, in, out) is cc_multi.
-:- func list__foldl(func(X, Y) = Y, list(X), Y) = Y.
+:- func list__foldl(func(L, A) = A, list(L), A) = A.
% list__foldr(Pred, List, Start, End) calls Pred with each
% element of List (working right-to-left) and an accumulator
% (with the initial value of Start), and returns the final
% value in End.
-:- pred list__foldr(pred(X, Y, Y), list(X), Y, Y).
+:- pred list__foldr(pred(L, A, A), list(L), A, A).
:- mode list__foldr(pred(in, di, uo) is det, in, di, uo) is det.
:- mode list__foldr(pred(in, in, out) is det, in, in, out) is det.
:- mode list__foldr(pred(in, in, out) is semidet, in, in, out) is semidet.
@@ -491,13 +491,13 @@
:- mode list__foldr(pred(in, di, uo) is cc_multi, in, di, uo) is cc_multi.
:- mode list__foldr(pred(in, in, out) is cc_multi, in, in, out) is cc_multi.
-:- func list__foldr(func(X, Y) = Y, list(X), Y) = Y.
+:- func list__foldr(func(L, A) = A, list(L), A) = A.
% list__foldl2(Pred, List, !Acc1, !Acc2)
% Does the same job as list__foldl, but with two accumulators.
% (Although no more expressive than list__foldl, this is often
% a more convenient format, and a little more efficient).
-:- pred list__foldl2(pred(X, Y, Y, Z, Z), list(X), Y, Y, Z, Z).
+:- pred list__foldl2(pred(L, A, A, Z, Z), list(L), A, A, Z, Z).
:- mode list__foldl2(pred(in, in, out, in, out) is det,
in, in, out, in, out) is det.
:- mode list__foldl2(pred(in, in, out, in, out) is cc_multi,
@@ -523,8 +523,8 @@
% Does the same job as list__foldl, but with three accumulators.
% (Although no more expressive than list__foldl, this is often
% a more convenient format, and a little more efficient).
-:- pred list__foldl3(pred(L, A1, A1, A2, A2, A3, A3), list(L),
- A1, A1, A2, A2, A3, A3).
+:- pred list__foldl3(pred(L, A, A, B, B, C, C), list(L),
+ A, A, B, B, C, C).
:- mode list__foldl3(pred(in, in, out, in, out, in, out) is det,
in, in, out, in, out, in, out) is det.
:- mode list__foldl3(pred(in, in, out, in, out, in, out) is cc_multi,
@@ -542,8 +542,8 @@
% Does the same job as list__foldl, but with four accumulators.
% (Although no more expressive than list__foldl, this is often
% a more convenient format, and a little more efficient).
-:- pred list__foldl4(pred(L, A1, A1, A2, A2, A3, A3, A4, A4), list(L),
- A1, A1, A2, A2, A3, A3, A4, A4).
+:- pred list__foldl4(pred(L, A, A, B, B, C, C, D, D), list(L),
+ A, A, B, B, C, C, D, D).
:- mode list__foldl4(pred(in, in, out, in, out, in, out, in, out) is det,
in, in, out, in, out, in, out, in, out) is det.
:- mode list__foldl4(pred(in, in, out, in, out, in, out, in, out) is cc_multi,
@@ -561,8 +561,8 @@
% Does the same job as list__foldl, but with five accumulators.
% (Although no more expressive than list__foldl, this is often
% a more convenient format, and a little more efficient).
-:- pred list__foldl5(pred(L, A1, A1, A2, A2, A3, A3, A4, A4, A5, A5), list(L),
- A1, A1, A2, A2, A3, A3, A4, A4, A5, A5).
+:- pred list__foldl5(pred(L, A, A, B, B, C, C, D, D, E, E), list(L),
+ A, A, B, B, C, C, D, D, E, E).
:- mode list__foldl5(pred(in, in, out, in, out, in, out, in, out, in, out)
is det,
in, in, out, in, out, in, out, in, out, in, out) is det.
@@ -582,12 +582,37 @@
is cc_multi,
in, in, out, in, out, in, out, in, out, di, uo) is cc_multi.
+ % list__foldl6(Pred, List, !Acc1, !Acc2, !Acc3, !Acc4, !Acc5, !Acc6)
+ % Does the same job as list__foldl, but with five accumulators.
+ % (Although no more expressive than list__foldl, this is often
+ % a more convenient format, and a little more efficient).
+:- pred list__foldl6(pred(L, A, A, B, B, C, C, D, D, E, E, F, F), list(L),
+ A, A, B, B, C, C, D, D, E, E, F, F).
+:- mode list__foldl6(pred(in, in, out, in, out, in, out, in, out, in, out,
+ in, out) is det,
+ in, in, out, in, out, in, out, in, out, in, out, in, out) is det.
+:- mode list__foldl6(pred(in, in, out, in, out, in, out, in, out, in, out,
+ in, out) is cc_multi,
+ in, in, out, in, out, in, out, in, out, in, out, in, out) is cc_multi.
+:- mode list__foldl6(pred(in, in, out, in, out, in, out, in, out, in, out,
+ in, out) is semidet,
+ in, in, out, in, out, in, out, in, out, in, out, in, out) is semidet.
+:- mode list__foldl6(pred(in, in, out, in, out, in, out, in, out, in, out,
+ in, out) is nondet,
+ in, in, out, in, out, in, out, in, out, in, out, in, out) is nondet.
+:- mode list__foldl6(pred(in, in, out, in, out, in, out, in, out, in, out,
+ di, uo) is det,
+ in, in, out, in, out, in, out, in, out, in, out, di, uo) is det.
+:- mode list__foldl6(pred(in, in, out, in, out, in, out, in, out, in, out,
+ di, uo) is cc_multi,
+ in, in, out, in, out, in, out, in, out, in, out, di, uo) is cc_multi.
+
% list__map_foldl(Pred, InList, OutList, Start, End) calls Pred
% with an accumulator (with the initial value of Start) on
% each element of InList (working left-to-right) to transform
% InList into OutList. The final value of the accumulator is
% returned in End.
-:- pred list__map_foldl(pred(X, Y, Z, Z), list(X), list(Y), Z, Z).
+:- pred list__map_foldl(pred(L, M, A, A), list(L), list(M), A, A).
:- mode list__map_foldl(pred(in, out, di, uo) is det, in, out, di, uo)
is det.
:- mode list__map_foldl(pred(in, out, in, out) is det, in, out, in, out)
@@ -602,8 +627,8 @@
is nondet.
% Same as list__map_foldl, but with two mapped outputs.
-:- pred list__map2_foldl(pred(X, Y1, Y2, Z, Z), list(X), list(Y1), list(Y2),
- Z, Z).
+:- pred list__map2_foldl(pred(L, M, N, A, A), list(L), list(M), list(N),
+ A, A).
:- mode list__map2_foldl(pred(in, out, out, di, uo) is det, in, out, out,
di, uo) is det.
:- mode list__map2_foldl(pred(in, out, out, in, out) is det, in, out, out,
@@ -618,7 +643,7 @@
in, out) is nondet.
% Same as list__map_foldl, but with two accumulators.
-:- pred list__map_foldl2(pred(X, Y, A, A, B, B), list(X), list(Y), A, A, B, B).
+:- pred list__map_foldl2(pred(L, M, A, A, B, B), list(L), list(M), A, A, B, B).
:- mode list__map_foldl2(pred(in, out, in, out, di, uo) is det,
in, out, in, out, di, uo) is det.
:- mode list__map_foldl2(pred(in, out, in, out, in, out) is det,
@@ -633,7 +658,7 @@
in, out, in, out, in, out) is nondet.
% Same as list__map_foldl, but with three accumulators.
-:- pred list__map_foldl3(pred(X, Y, A, A, B, B, C, C), list(X), list(Y),
+:- pred list__map_foldl3(pred(L, M, A, A, B, B, C, C), list(L), list(M),
A, A, B, B, C, C).
:- mode list__map_foldl3(pred(in, out, in, out, in, out, di, uo) is det,
in, out, in, out, in, out, di, uo) is det.
@@ -649,7 +674,7 @@
in, out, in, out, in, out, in, out) is nondet.
% Same as list__map_foldl, but with four accumulators.
-:- pred list__map_foldl4(pred(X, Y, A, A, B, B, C, C, D, D), list(X), list(Y),
+:- pred list__map_foldl4(pred(L, M, A, A, B, B, C, C, D, D), list(L), list(M),
A, A, B, B, C, C, D, D).
:- mode list__map_foldl4(pred(in, out, in, out, in, out, in, out, di, uo)
is det,
@@ -671,8 +696,8 @@
in, out, in, out, in, out, in, out, in, out) is nondet.
% Same as list__map_foldl, but with five accumulators.
-:- pred list__map_foldl5(pred(X, Y, A, A, B, B, C, C, D, D, E, E),
- list(X), list(Y), A, A, B, B, C, C, D, D, E, E).
+:- pred list__map_foldl5(pred(L, M, A, A, B, B, C, C, D, D, E, E),
+ list(L), list(M), A, A, B, B, C, C, D, D, E, E).
:- mode list__map_foldl5(pred(in, out, in, out, in, out, in, out, in, out,
di, uo) is det,
in, out, in, out, in, out, in, out, in, out, di, uo) is det.
@@ -692,6 +717,32 @@
in, out) is nondet,
in, out, in, out, in, out, in, out, in, out, in, out) is nondet.
+ % Same as list__map_foldl, but with six accumulators.
+:- pred list__map_foldl6(pred(L, M, A, A, B, B, C, C, D, D, E, E, F, F),
+ list(L), list(M), A, A, B, B, C, C, D, D, E, E, F, F).
+:- mode list__map_foldl6(pred(in, out, in, out, in, out, in, out, in, out,
+ in, out, di, uo) is det,
+ in, out, in, out, in, out, in, out, in, out, in, out, di, uo) is det.
+:- mode list__map_foldl6(pred(in, out, in, out, in, out, in, out, in, out,
+ in, out, in, out) is det,
+ in, out, in, out, in, out, in, out, in, out, in, out, in, out) is det.
+:- mode list__map_foldl6(pred(in, out, in, out, in, out, in, out, in, out,
+ in, out, di, uo) is cc_multi,
+ in, out, in, out, in, out, in, out, in, out, in, out, di, uo)
+ is cc_multi.
+:- mode list__map_foldl6(pred(in, out, in, out, in, out, in, out, in, out,
+ in, out, in, out) is cc_multi,
+ in, out, in, out, in, out, in, out, in, out, in, out, in, out)
+ is cc_multi.
+:- mode list__map_foldl6(pred(in, out, in, out, in, out, in, out, in, out,
+ in, out, in, out) is semidet,
+ in, out, in, out, in, out, in, out, in, out, in, out, in, out)
+ is semidet.
+:- mode list__map_foldl6(pred(in, out, in, out, in, out, in, out, in, out,
+ in, out, in, out) is nondet,
+ in, out, in, out, in, out, in, out, in, out, in, out, in, out)
+ is nondet.
+
% list__all_true(Pred, List) takes a closure with one input argument.
% If Pred succeeds for every member of List, all_true succeeds.
% If Pred fails for any member of List, all_true fails.
@@ -1423,6 +1474,11 @@
call(P, H, !A, !B, !C, !D, !E),
list__foldl5(P, T, !A, !B, !C, !D, !E).
+list__foldl6(_, [], !A, !B, !C, !D, !E, !F).
+list__foldl6(P, [H | T], !A, !B, !C, !D, !E, !F) :-
+ call(P, H, !A, !B, !C, !D, !E, !F),
+ list__foldl6(P, T, !A, !B, !C, !D, !E, !F).
+
list__map_foldl(_, [], [], !A).
list__map_foldl(P, [H0 | T0], [H | T], !A) :-
call(P, H0, H, !A),
@@ -1452,6 +1508,11 @@
list__map_foldl5(P, [H0 | T0], [H | T], !A, !B, !C, !D, !E) :-
call(P, H0, H, !A, !B, !C, !D, !E),
list__map_foldl5(P, T0, T, !A, !B, !C, !D, !E).
+
+list__map_foldl6(_, [], [], !A, !B, !C, !D, !E, !F).
+list__map_foldl6(P, [H0 | T0], [H | T], !A, !B, !C, !D, !E, !F) :-
+ call(P, H0, H, !A, !B, !C, !D, !E, !F),
+ list__map_foldl6(P, T0, T, !A, !B, !C, !D, !E, !F).
list__foldr(_, [], !A).
list__foldr(P, [H | T], !A) :-
Index: library/map.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/map.m,v
retrieving revision 1.91
diff -u -r1.91 map.m
--- library/map.m 16 Dec 2004 03:17:27 -0000 1.91
+++ library/map.m 5 Jan 2005 08:08:28 -0000
@@ -350,6 +350,11 @@
:- func map__det_union(func(V, V) = V, map(K, V), map(K, V)) = map(K, V).
:- mode map__det_union(func(in, in) = out is semidet, in, in) = out is det.
+ % Consider the original map a set of key-value pairs. This predicate
+ % returns a map that maps each value to the set of keys it is paired
+ % with in the original map.
+:- pred map__reverse_map(map(K, V)::in, map(V, set(K))::out) is det.
+
% Field selection for maps.
% Map ^ elem(Key) = map__search(Map, Key).
@@ -429,7 +434,7 @@
:- implementation.
-:- import_module std_util, require, string.
+:- import_module svmap, svset, std_util, require, string.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
@@ -965,6 +970,20 @@
map__det_union(F, M1, M2) = M3 :-
P = ( pred(X::in, Y::in, Z::out) is semidet :- Z = F(X, Y) ),
map__det_union(P, M1, M2, M3).
+
+map__reverse_map(Map, RevMap) :-
+ map__foldl(map__reverse_map_2, Map, map__init, RevMap).
+
+:- pred map__reverse_map_2(K::in, V::in,
+ map(V, set(K))::in, map(V, set(K))::out) is det.
+
+map__reverse_map_2(Key, Value, !RevMap) :-
+ ( map__search(!.RevMap, Value, Keys0) ->
+ svset__insert(Key, Keys0, Keys),
+ svmap__det_update(Value, Keys, !RevMap)
+ ;
+ svmap__det_insert(Value, set__make_singleton_set(Key), !RevMap)
+ ).
map__elem(Key, Map) = map__search(Map, Key).
Index: library/svbimap.m
===================================================================
RCS file: library/svbimap.m
diff -N library/svbimap.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ library/svbimap.m 4 Jan 2005 00:49:11 -0000
@@ -0,0 +1,47 @@
+%---------------------------------------------------------------------------%
+% 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.
+%-----------------------------------------------------------------------------%
+%
+% File: bimap.m.
+% Main author: conway.
+% Stability: medium.
+%
+% This file provides an interface to the 'bimap' ADT that is conducive to the
+% use of state variable notation. The predicates here do the same thing as
+% their counterparts in the bimap module; the only difference is the order
+% of the arguments.
+
+%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- module svbimap.
+
+:- interface.
+
+:- import_module bimap.
+
+%-----------------------------------------------------------------------------%
+
+:- pred svbimap__insert(K::in, V::in, bimap(K, V)::in, bimap(K, V)::out)
+ is semidet.
+
+:- pred svbimap__det_insert(K::in, V::in, bimap(K, V)::in, bimap(K, V)::out)
+ is det.
+
+:- pred svbimap__set(K::in, V::in, bimap(K, V)::in, bimap(K, V)::out) is det.
+
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+svbimap__insert(K, V, Bimap0, Bimap) :-
+ bimap__insert(Bimap0, K, V, Bimap).
+
+svbimap__det_insert(K, V, Bimap0, Bimap) :-
+ bimap__det_insert(Bimap0, K, V, Bimap).
+
+svbimap__set(K, V, Bimap0, Bimap) :-
+ bimap__set(Bimap0, K, V, Bimap).
Index: library/svqueue.m
===================================================================
RCS file: library/svqueue.m
diff -N library/svqueue.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ library/svqueue.m 4 Jan 2005 00:49:49 -0000
@@ -0,0 +1,62 @@
+%---------------------------------------------------------------------------%
+% Copyright (C) 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.
+%---------------------------------------------------------------------------%
+
+% File: svqueue.m.
+% Author: zs.
+% Stability: high.
+
+% This file provides an interface to the 'queue' ADT that is conducive to the
+% use of state variable notation. The predicates here do the same thing as
+% their counterparts in the queue module; the only difference is the order
+% of the arguments.
+
+%--------------------------------------------------------------------------%
+
+:- module svqueue.
+
+:- interface.
+
+:- import_module list, queue.
+
+ % `svqueue__put(Elem, Queue0, Queue)' is true iff `Queue' is
+ % the queue which results from appending `Elem' onto the end
+ % of `Queue0'.
+
+:- pred svqueue__put(T::in, queue(T)::in, queue(T)::out) is det.
+
+ % `svqueue__put_list(Elems, Queue0, Queue)' is true iff `Queue'
+ % is the queue which results from inserting the items in the
+ % list `Elems' into `Queue0'.
+
+:- pred svqueue__put_list(list(T)::in, queue(T)::in, queue(T)::out) is det.
+
+ % `svqueue__get(Elem, Queue0, Queue)' is true iff `Queue0' is
+ % a non-empty queue whose first element is `Elem', and `Queue'
+ % the queue which results from removing that element from
+ % the front of `Queue0'.
+
+:- pred svqueue__get(T::out, queue(T)::in, queue(T)::out) is semidet.
+
+ % `svqueue__delete_all(Elem, Queue0, Queue)' is true iff `Queue' is
+ % the same queue as `Queue0' with all occurences of `Elem' removed
+ % from it.
+:- pred svqueue__delete_all(T::in, queue(T)::in, queue(T)::out) is det.
+
+%--------------------------------------------------------------------------%
+
+:- implementation.
+
+svqueue__put(Elem, Queue0, Queue) :-
+ queue__put(Queue0, Elem, Queue).
+
+svqueue__put_list(List, Queue0, Queue) :-
+ queue__put_list(Queue0, List, Queue).
+
+svqueue__get(Elem, Queue0, Queue) :-
+ queue__get(Queue0, Elem, Queue).
+
+svqueue__delete_all(Elem, Queue0, Queue) :-
+ queue__delete_all(Queue0, Elem, Queue).
--------------------------------------------------------------------------
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