[m-rev.] diff: more set_of_var interoperability improvements
Zoltan Somogyi
zs at csse.unimelb.edu.au
Tue Aug 23 13:48:45 AEST 2011
compiler/set_of_var.m:
Minor changes to allow set.m and set_ordlist.m to implement this
interface.
library/set_tree234.m:
library/tree_bitset.m:
Add the functions and predicates needed to allow this module to
implement the functionality required by set_of_var.m.
Zoltan.
cvs diff: Diffing .
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/extra
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/extra
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/libatomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops/doc
cvs diff: Diffing boehm_gc/libatomic_ops/src
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/armcc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/gcc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/hpc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/ibmc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/icc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/msftc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/sunc
cvs diff: Diffing boehm_gc/libatomic_ops/tests
cvs diff: Diffing boehm_gc/libatomic_ops-1.2
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/doc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/tests
cvs diff: Diffing boehm_gc/m4
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/set_of_var.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/set_of_var.m,v
retrieving revision 1.4
diff -u -b -r1.4 set_of_var.m
--- compiler/set_of_var.m 16 Aug 2011 03:26:33 -0000 1.4
+++ compiler/set_of_var.m 23 Aug 2011 03:47:19 -0000
@@ -164,7 +164,7 @@
% representation and on set_ordlist, aborting on any discrepancy),
%
% - change every occurrence of tree_bitset in this file that is on a line
-% containing MODULE to tree_bitset.
+% containing MODULE to test_bitset.
%
% Once the representation has been proven, you can change all those occurrences
% of test_bitset to the name of the module implementing the new representation.
@@ -233,9 +233,15 @@
to_sorted_list(Set, List) :-
List = set_of_var.to_sorted_list(Set).
-set_to_bitset(OrdSet) = tree_bitset.from_set(OrdSet). % MODULE
-
-bitset_to_set(Set) = tree_bitset.to_set(Set). % MODULE
+set_to_bitset(OrdSet) = BitSet :-
+ % We don't use from_set, since set.m itself doesn't have that.
+ set.to_sorted_list(OrdSet, List),
+ tree_bitset.sorted_list_to_set(List, BitSet). % MODULE
+
+bitset_to_set(BitSet) = OrdSet :-
+ % We don't use to_set, since set.m itself doesn't have that.
+ tree_bitset.to_sorted_list(BitSet, List), % MODULE
+ set.sorted_list_to_set(List, OrdSet).
%---------------
% Updates.
cvs diff: Diffing compiler/notes
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/base64
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/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/fixed
cvs diff: Diffing extras/gator
cvs diff: Diffing extras/gator/generations
cvs diff: Diffing extras/gator/generations/1
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_allegro
cvs diff: Diffing extras/graphics/mercury_allegro/examples
cvs diff: Diffing extras/graphics/mercury_allegro/samples
cvs diff: Diffing extras/graphics/mercury_allegro/samples/demo
cvs diff: Diffing extras/graphics/mercury_allegro/samples/mandel
cvs diff: Diffing extras/graphics/mercury_allegro/samples/pendulum2
cvs diff: Diffing extras/graphics/mercury_allegro/samples/speed
cvs diff: Diffing extras/graphics/mercury_cairo
cvs diff: Diffing extras/graphics/mercury_cairo/samples
cvs diff: Diffing extras/graphics/mercury_cairo/samples/data
cvs diff: Diffing extras/graphics/mercury_cairo/tutorial
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/log4m
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/monte
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/mopenssl
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/net
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/posix/samples
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/solver_types
cvs diff: Diffing extras/solver_types/library
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/windows_installer_generator
cvs diff: Diffing extras/windows_installer_generator/sample
cvs diff: Diffing extras/windows_installer_generator/sample/images
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 library
Index: library/set_tree234.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/set_tree234.m,v
retrieving revision 1.18
diff -u -b -r1.18 set_tree234.m
--- library/set_tree234.m 26 May 2011 06:20:09 -0000 1.18
+++ library/set_tree234.m 22 Aug 2011 14:25:56 -0000
@@ -20,6 +20,7 @@
:- import_module bool.
:- import_module list.
+:- import_module set.
%--------------------------------------------------------------------------%
@@ -38,6 +39,8 @@
:- func set_tree234.make_singleton_set(T) = set_tree234(T).
+:- pred set_tree234.is_singleton(set_tree234(T)::in, T::out) is semidet.
+
% `set_tree234.empty(Set)' is true iff `Set' is an empty set.
%
:- pred set_tree234.empty(set_tree234(_T)::in) is semidet.
@@ -47,6 +50,7 @@
:- pred set_tree234.is_empty(set_tree234(_T)::in) is semidet.
:- pred set_tree234.non_empty(set_tree234(T)::in) is semidet.
+:- pred set_tree234.is_non_empty(set_tree234(T)::in) is semidet.
% `set_tree234.member(X, Set)' is true iff `X' is a member of `Set'.
%
@@ -68,18 +72,32 @@
% containing only the members of `List'.
%
:- func set_tree234.list_to_set(list(T)) = set_tree234(T).
+:- pred set_tree234.list_to_set(list(T)::in, set_tree234(T)::out) is det.
:- func set_tree234.from_list(list(T)) = set_tree234(T).
+:- pred set_tree234.from_list(list(T)::in, set_tree234(T)::out) is det.
% `set_tree234.sorted_list_to_set(List) = Set' is true iff `Set' is
% the set containing only the members of `List'. `List' must be sorted.
%
:- func set_tree234.sorted_list_to_set(list(T)) = set_tree234(T).
+:- pred set_tree234.sorted_list_to_set(list(T)::in, set_tree234(T)::out) is det.
+
+ % `from_set(Set)' returns a set_tree234 containing only the members of
+ % `Set'. Takes O(card(Set)) time and space.
+ %
+:- func from_set(set.set(T)) = set_tree234(T).
% `set_tree234.to_sorted_list(Set) = List' is true iff `List' is the
% list of all the members of `Set', in sorted order.
%
:- func set_tree234.to_sorted_list(set_tree234(T)) = list(T).
+:- pred set_tree234.to_sorted_list(set_tree234(T)::in, list(T)::out) is det.
+
+ % `to_sorted_list(Set)' returns a set.set containing all the members
+ % of `Set', in sorted order. Takes O(card(Set)) time and space.
+ %
+:- func to_set(set_tree234(T)) = set.set(T).
% `set_tree234.equal(SetA, SetB)' is true iff
% `SetA' and `SetB' contain the same elements.
@@ -184,11 +202,15 @@
%
:- func set_tree234.power_intersect(set_tree234(set_tree234(T)))
= set_tree234(T).
+:- pred set_tree234.power_intersect(set_tree234(set_tree234(T))::in,
+ set_tree234(T)::out) is det.
% `set_tree234.intersect_list(A, B)' is true iff `B' is the
% intersection of all the sets in `A'.
%
:- func set_tree234.intersect_list(list(set_tree234(T))) = set_tree234(T).
+:- pred set_tree234.intersect_list(list(set_tree234(T))::in,
+ set_tree234(T)::out) is det.
% `set_tree234.difference(SetA, SetB, Set)' is true iff `Set' is the
% set containing all the elements of `SetA' except those that
@@ -323,6 +345,8 @@
% Return the set of items for which the predicate succeeds.
%
+:- func set_tree234.filter(pred(T)::in(pred(in) is semidet),
+ set_tree234(T)::in) = (set_tree234(T)::out) is det.
:- pred set_tree234.filter(pred(T)::in(pred(in) is semidet),
set_tree234(T)::in, set_tree234(T)::out) is det.
@@ -415,6 +439,8 @@
set_tree234.make_singleton_set(X) = two(X, empty, empty).
+set_tree234.is_singleton(two(X, empty, empty), X).
+
set_tree234.empty(empty).
set_tree234.is_empty(empty).
@@ -423,6 +449,10 @@
set_tree234.non_empty(three(_, _, _, _, _)).
set_tree234.non_empty(four(_, _, _, _, _, _, _)).
+set_tree234.is_non_empty(two(_, _, _)).
+set_tree234.is_non_empty(three(_, _, _, _, _)).
+set_tree234.is_non_empty(four(_, _, _, _, _, _, _)).
+
:- pragma promise_equivalent_clauses(set_tree234.member/2).
set_tree234.member(Element::out, Set::in) :-
@@ -556,12 +586,22 @@
set_tree234.list_to_set(List) = Tree :-
set_tree234.list_to_set_2(List, empty, Tree).
+set_tree234.list_to_set(List, Tree) :-
+ set_tree234.list_to_set_2(List, empty, Tree).
+
set_tree234.from_list(List) = set_tree234.list_to_set(List).
+set_tree234.from_list(List, Tree) :-
+ Tree = set_tree234.list_to_set(List).
+
set_tree234.sorted_list_to_set(List) = Tree :-
% XXX We should exploit the sortedness of List.
set_tree234.list_to_set_2(List, empty, Tree).
+set_tree234.sorted_list_to_set(List, Tree) :-
+ % XXX We should exploit the sortedness of List.
+ set_tree234.list_to_set_2(List, empty, Tree).
+
:- pred set_tree234.list_to_set_2(list(E)::in, set_tree234(E)::in,
set_tree234(E)::out) is det.
@@ -570,11 +610,17 @@
set_tree234.insert(E, !Tree),
set_tree234.list_to_set_2(Es, !Tree).
+set_tree234.to_set(Tree) =
+ set.sorted_list_to_set(set_tree234.to_sorted_list(Tree)).
+
%------------------------------------------------------------------------------%
set_tree234.to_sorted_list(Tree) = List :-
set_tree234.to_sorted_list_2(Tree, [], List).
+set_tree234.to_sorted_list(Tree, List) :-
+ set_tree234.to_sorted_list_2(Tree, [], List).
+
:- pred set_tree234.to_sorted_list_2(set_tree234(T)::in,
list(T)::in, list(T)::out) is det.
@@ -592,11 +638,14 @@
set_tree234.to_sorted_list_2(T1, [E1 | L2], L3),
set_tree234.to_sorted_list_2(T0, [E0 | L3], L).
+set_tree234.from_set(Set) =
+ set_tree234.sorted_list_to_set(set.to_sorted_list(Set)).
+
%------------------------------------------------------------------------------%
set_tree234.equal(SetA, SetB) :-
- ListA = set_tree234.to_sorted_list(SetA),
- ListB = set_tree234.to_sorted_list(SetB),
+ set_tree234.to_sorted_list(SetA, ListA),
+ set_tree234.to_sorted_list(SetB, ListB),
ListA = ListB.
set_tree234.subset(empty, _Set).
@@ -1937,9 +1986,12 @@
),
set_tree234.intersect_2(T3, SetB, !Intersect).
-set_tree234.intersect_list([]) = empty.
-set_tree234.intersect_list([Set | Sets]) =
- set_tree234.intersect_list_2(Set, Sets).
+set_tree234.intersect_list(Sets) = Intersect :-
+ set_tree234.intersect_list(Sets, Intersect).
+
+set_tree234.intersect_list([], empty).
+set_tree234.intersect_list([Set | Sets], Intersect) :-
+ Intersect = set_tree234.intersect_list_2(Set, Sets).
:- func set_tree234.intersect_list_2(set_tree234(T), list(set_tree234(T)))
= set_tree234(T).
@@ -1952,8 +2004,11 @@
set_tree234.intersect_list_2(set_tree234.intersect(Set, Head), Tail)
).
-set_tree234.power_intersect(Sets) =
- set_tree234.intersect_list(set_tree234.to_sorted_list(Sets)).
+set_tree234.power_intersect(Sets) = Intersect :-
+ set_tree234.power_intersect(Sets, Intersect).
+
+set_tree234.power_intersect(Sets, Intersect) :-
+ Intersect = set_tree234.intersect_list(set_tree234.to_sorted_list(Sets)).
%------------------------------------------------------------------------------%
@@ -2344,6 +2399,10 @@
%------------------------------------------------------------------------------%
+set_tree234.filter(Pred, Set) = TrueSet :-
+ % XXX This should be more efficient.
+ set_tree234.divide(Pred, Set, TrueSet, _FalseSet).
+
set_tree234.filter(Pred, Set, TrueSet) :-
% XXX This should be more efficient.
set_tree234.divide(Pred, Set, TrueSet, _FalseSet).
Index: library/tree_bitset.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/tree_bitset.m,v
retrieving revision 1.14
diff -u -b -r1.14 tree_bitset.m
--- library/tree_bitset.m 4 Aug 2011 02:01:36 -0000 1.14
+++ library/tree_bitset.m 23 Aug 2011 03:17:12 -0000
@@ -67,11 +67,13 @@
% Takes O(length(List)) time and space.
%
:- func list_to_set(list(T)) = tree_bitset(T) <= enum(T).
+:- pred list_to_set(list(T)::in, tree_bitset(T)::out) is det <= enum(T).
% `sorted_list_to_set(List)' returns a set containing only the members
% of `List'. `List' must be sorted. Takes O(length(List)) time and space.
%
:- func sorted_list_to_set(list(T)) = tree_bitset(T) <= enum(T).
+:- pred sorted_list_to_set(list(T)::in, tree_bitset(T)::out) is det <= enum(T).
% `from_set(Set)' returns a bitset containing only the members of `Set'.
% Takes O(card(Set)) time and space.
@@ -82,6 +84,7 @@
% in sorted order. Takes O(card(Set)) time and space.
%
:- func to_sorted_list(tree_bitset(T)) = list(T) <= enum(T).
+:- pred to_sorted_list(tree_bitset(T)::in, list(T)::out) is det <= enum(T).
% `to_sorted_list(Set)' returns a set.set containing all the members
% of `Set', in sorted order. Takes O(card(Set)) time and space.
@@ -339,15 +342,21 @@
:- pragma type_spec(list_to_set/1, T = var(_)).
:- pragma type_spec(list_to_set/1, T = int).
+:- pragma type_spec(list_to_set/2, T = var(_)).
+:- pragma type_spec(list_to_set/2, T = int).
:- pragma type_spec(sorted_list_to_set/1, T = var(_)).
:- pragma type_spec(sorted_list_to_set/1, T = int).
+:- pragma type_spec(sorted_list_to_set/2, T = var(_)).
+:- pragma type_spec(sorted_list_to_set/2, T = int).
:- pragma type_spec(from_set/1, T = var(_)).
:- pragma type_spec(from_set/1, T = int).
:- pragma type_spec(to_sorted_list/1, T = var(_)).
:- pragma type_spec(to_sorted_list/1, T = int).
+:- pragma type_spec(to_sorted_list/2, T = var(_)).
+:- pragma type_spec(to_sorted_list/2, T = int).
:- pragma type_spec(to_set/1, T = var(_)).
:- pragma type_spec(to_set/1, T = int).
@@ -898,8 +907,8 @@
equal(SetA, SetB) :-
trace [compile_time(flag("tree-bitset-integrity"))] (
(
- ListA = to_sorted_list(SetA),
- ListB = to_sorted_list(SetB),
+ to_sorted_list(SetA, ListA),
+ to_sorted_list(SetB, ListB),
(
SetA = SetB
<=>
@@ -917,6 +926,9 @@
to_sorted_list(Set) = foldr(list.cons, Set, []).
+to_sorted_list(Set, List) :-
+ List = to_sorted_list(Set).
+
to_set(Set) = set.sorted_list_to_set(to_sorted_list(Set)).
from_set(Set) = sorted_list_to_set(set.to_sorted_list(Set)).
@@ -1374,6 +1386,9 @@
list_to_set(List) = sorted_list_to_set(list.sort(List)).
+list_to_set(List, Set) :-
+ Set = list_to_set(List).
+
%-----------------------------------------------------------------------------%
sorted_list_to_set(Elems) = Set :-
@@ -1402,6 +1417,9 @@
Set = wrap_tree_bitset(List)
).
+sorted_list_to_set(List, Set) :-
+ Set = sorted_list_to_set(List).
+
:- pred items_to_index(list(T)::in, list(int)::out) is det <= enum(T).
:- pragma type_spec(items_to_index/2, T = var(_)).
:- pragma type_spec(items_to_index/2, T = int).
cvs diff: Diffing mdbcomp
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/appengine
cvs diff: Diffing samples/appengine/war
cvs diff: Diffing samples/appengine/war/WEB-INF
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/c_interface/standalone_c
cvs diff: Diffing samples/concurrency
cvs diff: Diffing samples/concurrency/dining_philosophers
cvs diff: Diffing samples/concurrency/midimon
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/java_interface
cvs diff: Diffing samples/java_interface/java_calls_mercury
cvs diff: Diffing samples/java_interface/mercury_calls_java
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/solver_types
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 slice
cvs diff: Diffing ssdb
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 messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list