[m-rev.] diff: reorder predicate arguments in set_{bbbtree,ordlist,unordlist} modules
Julien Fischer
juliensf at csse.unimelb.edu.au
Thu May 19 17:31:58 AEST 2011
Branches: main
Change the argument order of predicates in the set_bbbtree, set_ordlist, and
set_unordlist modules to (1) make them conducive to the use of state variable
notation and (2) make them consistent with the other modules that implement the
set ADT.
This change will break existing code that uses these modules, but such uses
should (and if Mercury and G12 are anything to go by, are) quite rare.
Group function clauses together with the clauses for the corresponding
predicates.
library/set_bbbtree.m:
library/set_ordlist.m:
library/set_unordlist.m:
As above.
Reorder the clauses in the set_ordlist module as the existing
order corresponds in no way to the order of declarations in
the module interface.
library/set.m:
tests/general/set_test.m:
Conform to the above changes.
library/dir.m:
Group predicate and function clauses together.
NEWS:
Announce the above changes.
Julien.
Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.572
diff -u -r1.572 NEWS
--- NEWS 18 May 2011 15:40:12 -0000 1.572
+++ NEWS 19 May 2011 07:23:59 -0000
@@ -55,6 +55,15 @@
rbtree.delete/3, rbtree.remove_smallest/4, rbtree.remove_largest/4,
set.insert/3, set.insert_list/3, set.delete/3, set.delete_list/3,
set.remove/3, set.remove_list/3, set.remove_least/3, tree234.insert/4,
+ set_bbbtree.insert/3, set_bbbtree.insert_list/3, set_bbbtree.delete/3,
+ set_bbbtree.delete_list/3, set_bbbtree.remove/3, set_bbbtree.remove_list/3,
+ set_bbbtree.remove_least/3, set_bbbtree.remove_largest/3,
+ set_ordlist.insert/3, set_ordlist.insert_list/3, set_ordlist.delete/3,
+ set_ordlist.delete_list/3, set_ordlist.remove/3, set_ordlist.remove_list/3,
+ set_ordlist.remove_least/3, set_unordlist.insert/3,
+ set_unordlist.insert_list/3, set_unordlist.delete/3,
+ set_unordlist.delete_list/3, set_unordlist.remove/3,
+ set.unordlist.remove_list/3, set_unordlist.remove_least/3,
tree234.set/4, tree234.remove/4, tree234.remove_smallest/4 and
tree234.update/4.
Index: library/dir.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/dir.m,v
retrieving revision 1.59
diff -u -r1.59 dir.m
--- library/dir.m 10 May 2011 04:12:27 -0000 1.59
+++ library/dir.m 19 May 2011 05:14:25 -0000
@@ -292,6 +292,8 @@
Sep = java.io.File.separatorChar;
").
+dir.directory_separator(dir.directory_separator).
+
:- func dir.alt_directory_separator = char.
dir.alt_directory_separator = (io.have_cygwin -> ('\\') ; ('/')).
@@ -330,8 +332,12 @@
dir.this_directory = ".".
+dir.this_directory(dir.this_directory).
+
dir.parent_directory = "..".
+dir.parent_directory(dir.parent_directory).
+
%-----------------------------------------------------------------------------%
dir.basename_det(FileName) = dir.det_basename(FileName).
@@ -362,6 +368,10 @@
BaseName = FileName
).
+dir.basename(S, dir.basename(S)).
+
+%-----------------------------------------------------------------------------%
+
dir.dirname(FileName) = DirName :-
FileNameChars = canonicalize_path_chars(string.to_char_list(FileName)),
(
@@ -388,6 +398,8 @@
DirName = dir.this_directory
).
+dir.dirname(S, dir.dirname(S)).
+
dir.split_name(FileName, DirName, BaseName) :-
FileNameChars = canonicalize_path_chars(string.to_char_list(FileName)),
\+ is_root_directory(FileNameChars),
@@ -2105,16 +2117,5 @@
).
%-----------------------------------------------------------------------------%
+:- end_module dir.
%-----------------------------------------------------------------------------%
-% Ralph Becket <rwab1 at cl.cam.ac.uk> 27/04/99
-% Functional forms added.
-
-dir.directory_separator(dir.directory_separator).
-
-dir.this_directory(dir.this_directory).
-
-dir.parent_directory(dir.parent_directory).
-
-dir.basename(S, dir.basename(S)).
-
-dir.dirname(S, dir.dirname(S)).
Index: library/set.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/set.m,v
retrieving revision 1.92
diff -u -r1.92 set.m
--- library/set.m 10 May 2011 05:26:51 -0000 1.92
+++ library/set.m 19 May 2011 04:16:07 -0000
@@ -453,14 +453,14 @@
set.insert_list(S1, Xs) = S2 :-
set.insert_list(Xs, S1, S2).
-set.insert_list(List, Set0, Set) :-
- set_ordlist.insert_list(Set0, List, Set).
+set.insert_list(List, !Set) :-
+ set_ordlist.insert_list(List, !Set).
set.insert(S1, T) = S2 :-
set.insert(T, S1, S2).
set.insert(X, !Set) :-
- set_ordlist.insert(!.Set, X, !:Set).
+ set_ordlist.insert(X, !Set).
set.equal(SetA, SetB) :-
set_ordlist.equal(SetA, SetB).
@@ -496,23 +496,23 @@
set.delete_list(S1, Xs) = S2 :-
set.delete_list(Xs, S1, S2).
-set.delete_list(List, Set0, Set) :-
- set_ordlist.delete_list(Set0, List, Set).
+set.delete_list(List, !Set) :-
+ set_ordlist.delete_list(List, !Set).
set.delete(S1, T) = S2 :-
set.delete(T, S1, S2).
-set.delete(X, Set0, Set) :-
- set_ordlist.delete(Set0, X, Set).
+set.delete(X, !Set) :-
+ set_ordlist.delete(X, !Set).
-set.remove_list(List, Set0, Set) :-
- set_ordlist.remove_list(Set0, List, Set).
+set.remove_list(List, !Set) :-
+ set_ordlist.remove_list(List, !Set).
-set.remove(X, Set0, Set) :-
- set_ordlist.remove(Set0, X, Set).
+set.remove(X, !Set) :-
+ set_ordlist.remove(X, !Set).
-set.remove_least(X, Set0, Set) :-
- set_ordlist.remove_least(Set0, X, Set).
+set.remove_least(X, !Set) :-
+ set_ordlist.remove_least(X, !Set).
set.union(S1, S2) = S3 :-
set.union(S1, S2, S3).
Index: library/set_bbbtree.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/set_bbbtree.m,v
retrieving revision 1.37
diff -u -r1.37 set_bbbtree.m
--- library/set_bbbtree.m 10 May 2011 05:26:51 -0000 1.37
+++ library/set_bbbtree.m 19 May 2011 05:11:33 -0000
@@ -93,72 +93,72 @@
%
:- pred set_bbbtree.equal(set_bbbtree(T)::in, set_bbbtree(T)::in) is semidet.
- % `set_bbbtree.insert(Set0, X, Set)' is true iff `Set' is the union of
+ % `set_bbbtree.insert(X, Set0, Set)' is true iff `Set' is the union of
% `Set0' and the set containing only `X'.
%
-:- pred set_bbbtree.insert(set_bbbtree(T), T, set_bbbtree(T)).
+:- pred set_bbbtree.insert(T, set_bbbtree(T), set_bbbtree(T)).
:- mode set_bbbtree.insert(di, di, uo) is det.
:- mode set_bbbtree.insert(in, in, out) is det.
:- func set_bbbtree.insert(set_bbbtree(T), T) = set_bbbtree(T).
- % `set_bbbtree.insert_list(Set0, Xs, Set)' is true iff `Set' is
+ % `set_bbbtree.insert_list(Xs, Set0, Set)' is true iff `Set' is
% the union of `Set0' and the set containing only the members of `Xs'.
%
-:- pred set_bbbtree.insert_list(set_bbbtree(T)::in, list(T)::in,
- set_bbbtree(T)::out) is det.
+:- pred set_bbbtree.insert_list(list(T)::in,
+ set_bbbtree(T)::in, set_bbbtree(T)::out) is det.
:- func set_bbbtree.insert_list(set_bbbtree(T), list(T)) = set_bbbtree(T).
- % `set_bbbtree.delete(Set0, X, Set)' is true iff `Set' is the relative
+ % `set_bbbtree.delete(X, Set0, Set)' is true iff `Set' is the relative
% complement of `Set0' and the set containing only `X', i.e.
% if `Set' is the set which contains all the elements of `Set0'
% except `X'.
%
-:- pred set_bbbtree.delete(set_bbbtree(T), T, set_bbbtree(T)).
-:- mode set_bbbtree.delete(di, in, uo) is det.
+:- pred set_bbbtree.delete(T, set_bbbtree(T), set_bbbtree(T)).
+:- mode set_bbbtree.delete(in, di, uo) is det.
:- mode set_bbbtree.delete(in, in, out) is det.
:- func set_bbbtree.delete(set_bbbtree(T), T) = set_bbbtree(T).
- % `set_bbbtree.delete_list(Set0, Xs, Set)' is true iff `Set' is the
+ % `set_bbbtree.delete_list(Xs, Set0, Set)' is true iff `Set' is the
% relative complement of `Set0' and the set containing only the members
% of `Xs'.
%
-:- pred set_bbbtree.delete_list(set_bbbtree(T)::in, list(T)::in,
- set_bbbtree(T)::out) is det.
+:- pred set_bbbtree.delete_list(list(T)::in,
+ set_bbbtree(T)::in, set_bbbtree(T)::out) is det.
:- func set_bbbtree.delete_list(set_bbbtree(T), list(T)) = set_bbbtree(T).
- % `set_bbbtree.remove(Set0, X, Set)' is true iff `Set0' contains `X',
+ % `set_bbbtree.remove(X, Set0, Set)' is true iff `Set0' contains `X',
% and `Set' is the relative complement of `Set0' and the set
% containing only `X', i.e. if `Set' is the set which contains
% all the elements of `Set0' except `X'.
%
-:- pred set_bbbtree.remove(set_bbbtree(T)::in, T::in, set_bbbtree(T)::out)
+:- pred set_bbbtree.remove(T::in, set_bbbtree(T)::in, set_bbbtree(T)::out)
is semidet.
- % `set_bbbtree.remove_list(Set0, Xs, Set)' is true iff Xs does not
+ % `set_bbbtree.remove_list(Xs, Set0, Set)' is true iff Xs does not
% contain any duplicates, `Set0' contains every member of `Xs',
% and `Set' is the relative complement of `Set0' and the set
% containing only the members of `Xs'.
%
-:- pred set_bbbtree.remove_list(set_bbbtree(T)::in, list(T)::in,
- set_bbbtree(T)::out) is semidet.
+:- pred set_bbbtree.remove_list(list(T)::in,
+ set_bbbtree(T)::in, set_bbbtree(T)::out) is semidet.
- % `set_bbbtree.remove_least(Set0, X, Set)' is true iff the union if
+ % `set_bbbtree.remove_least(X, Set0, Set)' is true iff the union if
% `X' and `Set' is `Set0' and `X' is smaller than all the elements of
% `Set'.
%
-:- pred set_bbbtree.remove_least(set_bbbtree(T)::in, T::out,
- set_bbbtree(T)::out) is semidet.
+:- pred set_bbbtree.remove_least(T::out,
+ set_bbbtree(T)::in, set_bbbtree(T)::out) is semidet.
- % `set_bbbtree.remove_largest(Set0, X, Set)' is true iff the union if
+ % `set_bbbtree.remove_largest(X, Set0, Set)' is true iff the union if
% `X' and `Set' is `Set0' and `X' is larger than all the elements of
% `Set'.
%
-:- pred set_bbbtree.remove_largest(set_bbbtree(T)::in, T::out,
- set_bbbtree(T)::out) is semidet.
+:- pred set_bbbtree.remove_largest(T::out,
+ set_bbbtree(T)::in, set_bbbtree(T)::out) is semidet.
% `set_bbbtree.list_to_set(List, Set)' is true iff `Set' is the set
% containing only the members of `List'. O(n lg n)
@@ -442,6 +442,9 @@
%------------------------------------------------------------------------------%
+set_bbbtree.init = S :-
+ set_bbbtree.init(S).
+
set_bbbtree.init(empty).
%------------------------------------------------------------------------------%
@@ -518,6 +521,9 @@
%------------------------------------------------------------------------------%
+set_bbbtree.make_singleton_set(T) = S :-
+ set_bbbtree.singleton_set(S, T).
+
set_bbbtree.singleton_set(tree(V, 1, empty, empty), V).
%------------------------------------------------------------------------------%
@@ -528,11 +534,14 @@
%------------------------------------------------------------------------------%
+set_bbbtree.insert(!.S, T) = !:S :-
+ set_bbbtree.insert(T, !S).
+
% This is a hack to handle the bugs with unique and destructive input modes.
-set_bbbtree.insert(Set0, X, Set) :-
+set_bbbtree.insert(X, !Set) :-
set_bbbtree.def_ratio(Ratio),
- set_bbbtree.insert_r(Set0, X, Set1, Ratio),
- unsafe_promise_unique(Set1, Set).
+ set_bbbtree.insert_r(!.Set, X, !:Set, Ratio),
+ unsafe_promise_unique(!Set).
% Uncomment this once destructive input and unique modes are fixed and delete
% the one above.
@@ -565,17 +574,20 @@
%------------------------------------------------------------------------------%
-set_bbbtree.insert_list(Set0, List, Set) :-
+set_bbbtree.insert_list(!.S, Xs) = !:S :-
+ set_bbbtree.insert_list(Xs, !S).
+
+set_bbbtree.insert_list(List, !Set) :-
set_bbbtree.def_ratio(Ratio),
- set_bbbtree.insert_list_r(Set0, List, Set, Ratio).
+ set_bbbtree.insert_list_r(!.Set, List, !:Set, Ratio).
:- pred set_bbbtree.insert_list_r(set_bbbtree(T)::in, list(T)::in,
set_bbbtree(T)::out, int::in) is det.
set_bbbtree.insert_list_r(Set, [], Set, _Ratio).
-set_bbbtree.insert_list_r(Set0, [X | Xs], Set, Ratio) :-
- set_bbbtree.insert_r(Set0, X, Set1, Ratio),
- set_bbbtree.insert_list_r(Set1, Xs, Set, Ratio).
+set_bbbtree.insert_list_r(!.Set, [X | Xs], !:Set, Ratio) :-
+ set_bbbtree.insert_r(!.Set, X, !:Set, Ratio),
+ set_bbbtree.insert_list_r(!.Set, Xs, !:Set, Ratio).
%------------------------------------------------------------------------------%
@@ -607,36 +619,42 @@
% Set = Set0
% ).
-set_bbbtree.delete(Set0, X, Set) :-
- ( set_bbbtree.remove(Set0, X, Set1) ->
- Set2 = Set1
+set_bbbtree.delete(!.S, T) = !:S :-
+ set_bbbtree.delete(T, !S).
+
+set_bbbtree.delete(X, !Set) :-
+ ( set_bbbtree.remove(X, !.Set, NewSet) ->
+ !:Set = NewSet
;
- Set2 = Set0
+ true
),
- unsafe_promise_unique(Set2, Set).
+ unsafe_promise_unique(!Set).
%------------------------------------------------------------------------------%
-set_bbbtree.delete_list(Set, [], Set).
-set_bbbtree.delete_list(Set0, [X | Xs], Set) :-
- set_bbbtree.delete(Set0, X, Set1),
- set_bbbtree.delete_list(Set1, Xs, Set).
+set_bbbtree.delete_list(!.S, Xs) = !:S :-
+ set_bbbtree.delete_list(Xs, !S).
+
+set_bbbtree.delete_list([], !Set).
+set_bbbtree.delete_list([X | Xs], !Set) :-
+ set_bbbtree.delete(X, !Set),
+ set_bbbtree.delete_list(Xs, !Set).
%------------------------------------------------------------------------------%
-% set_bbbtree.remove(empty, X, _):- fail.
-set_bbbtree.remove(tree(V, N, L, R), X, Set) :-
+% set_bbbtree.remove(X, empty, _):- fail.
+set_bbbtree.remove(X, tree(V, N, L, R), Set) :-
compare(Result, X, V),
(
% Remove X from left subtree.
Result = (<),
- set_bbbtree.remove(L, X, NewL), % X in left tree
+ set_bbbtree.remove(X, L, NewL), % X in left tree
NewN = N - 1,
Set = tree(V, NewN, NewL, R)
;
% Remove X from right subtree.
Result = (>),
- set_bbbtree.remove(R, X, NewR), % X in right tree
+ set_bbbtree.remove(X, R, NewR), % X in right tree
NewN = N - 1,
Set = tree(V, NewN, L, NewR)
;
@@ -647,18 +665,18 @@
%------------------------------------------------------------------------------%
-set_bbbtree.remove_list(Set, [], Set).
-set_bbbtree.remove_list(Set0, [X | Xs], Set) :-
- set_bbbtree.remove(Set0, X, Set1),
- set_bbbtree.remove_list(Set1, Xs, Set).
+set_bbbtree.remove_list([], !Set).
+set_bbbtree.remove_list([X | Xs], !Set) :-
+ set_bbbtree.remove(X, !Set),
+ set_bbbtree.remove_list(Xs, !Set).
%------------------------------------------------------------------------------%
% The tree is not rebalanced as the removal of one element will not cause the
% tree to become much more unbalanced.
-% set_bbbtree.remove_least(empty, X, _) :- fail.
-set_bbbtree.remove_least(tree(V, N, L, R), X, Set) :-
+% set_bbbtree.remove_least(X, empty, _) :- fail.
+set_bbbtree.remove_least(X, tree(V, N, L, R), Set) :-
(
% Found the least element.
L = empty,
@@ -667,7 +685,7 @@
;
% Search further in the left subtree.
L = tree(_V, _N, _L, _R),
- set_bbbtree.remove_least(L, X, NewL),
+ set_bbbtree.remove_least(X, L, NewL),
NewN = N - 1,
Set = tree(V, NewN, NewL, R)
).
@@ -677,8 +695,8 @@
% The tree is not rebalanced as the removal of one element will not cause the
% tree to become much more unbalanced.
-% set_bbbtree.remove_largest(empty, X, _) :- fail.
-set_bbbtree.remove_largest(tree(V, N, L, R), X, Set) :-
+% set_bbbtree.remove_largest(X, empty, _) :- fail.
+set_bbbtree.remove_largest(X, tree(V, N, L, R), Set) :-
(
% Found the largest element.
R = empty,
@@ -687,13 +705,16 @@
;
% Search further in the right subtree.
R = tree(_V, _N, _L, _R),
- set_bbbtree.remove_largest(R, X, NewR),
+ set_bbbtree.remove_largest(X, R, NewR),
NewN = N - 1,
Set = tree(V, NewN, L, NewR)
).
%------------------------------------------------------------------------------%
+set_bbbtree.list_to_set(Xs) = S :-
+ set_bbbtree.list_to_set(Xs, S).
+
set_bbbtree.list_to_set(List, Set) :-
set_bbbtree.def_ratio(Ratio),
set_bbbtree.list_to_set_r(List, Set, Ratio).
@@ -725,6 +746,9 @@
% Cases N = 3, N = 2 and N = 1 could safely be removed without change to
% computed results as long as the 3 in N > 3 is adjusted appropriately.
+set_bbbtree.sorted_list_to_set(Xs) = S :-
+ set_bbbtree.sorted_list_to_set(Xs, S).
+
set_bbbtree.sorted_list_to_set(List, Set) :-
list.length(List, N),
set_bbbtree.sorted_list_to_set_len(List, Set, N).
@@ -796,6 +820,9 @@
%------------------------------------------------------------------------------%
+set_bbbtree.to_sorted_list(S) = Xs :-
+ set_bbbtree.to_sorted_list(S, Xs).
+
% Flatten the tree by an accumulator based tree traversal
% traversing the tree in a right-to-left post order manner. O(n).
@@ -839,6 +866,9 @@
%------------------------------------------------------------------------------%
+set_bbbtree.union(S1, S2) = S3 :-
+ set_bbbtree.union(S1, S2, S3).
+
set_bbbtree.union_list(ListofSets) =
list.foldl(set_bbbtree.union, ListofSets, set_bbbtree.init).
@@ -854,6 +884,9 @@
% increasing dwarf the tree that is the root node and hence this cost will
% increase, but this cannot be avoided.
+set_bbbtree.power_union(SS) = S :-
+ set_bbbtree.power_union(SS, S).
+
set_bbbtree.power_union(Sets, Set) :-
set_bbbtree.def_ratio(Ratio),
set_bbbtree.power_union_r(Sets, Set, Ratio).
@@ -877,6 +910,9 @@
% union ( { a } )
% union ( { elem(x, A) | x > a } intersect { elem(x, B) | x > a } )
+set_bbbtree.intersect(S1, S2) = S3 :-
+ set_bbbtree.intersect(S1, S2, S3).
+
set_bbbtree.intersect(SetA, SetB, Set) :-
set_bbbtree.def_ratio(Ratio),
set_bbbtree.intersect_r(SetA, SetB, Set, Ratio).
@@ -905,6 +941,9 @@
% the accumulator, possibly of the empty set in which case the call immediately
% returns.
+set_bbbtree.power_intersect(SS) = S :-
+ set_bbbtree.power_intersect(SS, S).
+
set_bbbtree.power_intersect(Sets, Set) :-
set_bbbtree.def_ratio(Ratio),
set_bbbtree.power_intersect_r(Sets, Set, Ratio).
@@ -953,6 +992,9 @@
% union ( { a } )
% union ( { elem(x, A) | x > a } difference { elem(x, B) | x > a } )
+set_bbbtree.difference(S1, S2) = S3 :-
+ set_bbbtree.difference(S1, S2, S3).
+
set_bbbtree.difference(SetA, SetB, Set) :-
set_bbbtree.def_ratio(Ratio),
set_bbbtree.difference_r(SetA, SetB, Set, Ratio).
@@ -1168,13 +1210,13 @@
% right tree and make it the root of the left and
% the new right trees.
( LSize > RSize ->
- ( set_bbbtree.remove_largest(L, X, NewL) ->
+ ( set_bbbtree.remove_largest(X, L, NewL) ->
set_bbbtree.build_node(X, NewL, R, Set)
;
error("set_bbbtree.concat3.1")
)
;
- ( set_bbbtree.remove_least(R, X, NewR) ->
+ ( set_bbbtree.remove_least(X, R, NewR) ->
set_bbbtree.build_node(X, L, NewR, Set)
;
error("set_bbbtree.concat3.2")
@@ -1290,51 +1332,6 @@
list.foldl6(P, set_bbbtree.to_sorted_list(S), !A, !B, !C, !D, !E, !F).
%--------------------------------------------------------------------------%
-%--------------------------------------------------------------------------%
-% Ralph Becket <rwab1 at cam.sri.com> 24/04/99
-% Function forms added.
-
-set_bbbtree.list_to_set(Xs) = S :-
- set_bbbtree.list_to_set(Xs, S).
-
-set_bbbtree.sorted_list_to_set(Xs) = S :-
- set_bbbtree.sorted_list_to_set(Xs, S).
-
-set_bbbtree.to_sorted_list(S) = Xs :-
- set_bbbtree.to_sorted_list(S, Xs).
-
-set_bbbtree.init = S :-
- set_bbbtree.init(S).
-
-set_bbbtree.make_singleton_set(T) = S :-
- set_bbbtree.singleton_set(S, T).
-
-set_bbbtree.insert(S1, T) = S2 :-
- set_bbbtree.insert(S1, T, S2).
-
-set_bbbtree.insert_list(S1, Xs) = S2 :-
- set_bbbtree.insert_list(S1, Xs, S2).
-
-set_bbbtree.delete(S1, T) = S2 :-
- set_bbbtree.delete(S1, T, S2).
-
-set_bbbtree.delete_list(S1, Xs) = S2 :-
- set_bbbtree.delete_list(S1, Xs, S2).
-
-set_bbbtree.union(S1, S2) = S3 :-
- set_bbbtree.union(S1, S2, S3).
-
-set_bbbtree.power_union(SS) = S :-
- set_bbbtree.power_union(SS, S).
-
-set_bbbtree.intersect(S1, S2) = S3 :-
- set_bbbtree.intersect(S1, S2, S3).
-
-set_bbbtree.power_intersect(SS) = S :-
- set_bbbtree.power_intersect(SS, S).
-
-set_bbbtree.difference(S1, S2) = S3 :-
- set_bbbtree.difference(S1, S2, S3).
set_bbbtree.map(F, S1) = S2 :-
S2 = set_bbbtree.list_to_set(list.map(F,
Index: library/set_ordlist.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/set_ordlist.m,v
retrieving revision 1.37
diff -u -r1.37 set_ordlist.m
--- library/set_ordlist.m 10 May 2011 05:26:51 -0000 1.37
+++ library/set_ordlist.m 19 May 2011 05:23:14 -0000
@@ -106,19 +106,19 @@
%
:- pred set_ordlist.contains(set_ordlist(T)::in, T::in) is semidet.
- % `set_ordlist.insert(Set0, X, Set)' is true iff `Set' is the union
+ % `set_ordlist.insert(X, Set0, Set)' is true iff `Set' is the union
% of `Set0' and the set containing only `X'.
%
-:- pred set_ordlist.insert(set_ordlist(T)::in, T::in, set_ordlist(T)::out)
+:- pred set_ordlist.insert(T::in, set_ordlist(T)::in, set_ordlist(T)::out)
is det.
:- func set_ordlist.insert(set_ordlist(T), T) = set_ordlist(T).
- % `set_ordlist.insert_list(Set0, Xs, Set)' is true iff `Set' is the
+ % `set_ordlist.insert_list(Xs, Set0, Set)' is true iff `Set' is the
% union of `Set0' and the set containing only the members of `Xs'.
%
-:- pred set_ordlist.insert_list(set_ordlist(T)::in, list(T)::in,
- set_ordlist(T)::out) is det.
+:- pred set_ordlist.insert_list(list(T)::in,
+ set_ordlist(T)::in, set_ordlist(T)::out) is det.
:- func set_ordlist.insert_list(set_ordlist(T), list(T)) = set_ordlist(T).
% `set_ordlist.delete(Set0, X, Set)' is true iff `Set' is the
@@ -126,40 +126,40 @@
% if `Set' is the set which contains all the elements of `Set0'
% except `X'.
%
-:- pred set_ordlist.delete(set_ordlist(T)::in, T::in, set_ordlist(T)::out)
+:- pred set_ordlist.delete(T::in, set_ordlist(T)::in, set_ordlist(T)::out)
is det.
:- func set_ordlist.delete(set_ordlist(T), T) = set_ordlist(T).
- % `set_ordlist.delete_list(Set0, Xs, Set)' is true iff `Set' is the
+ % `set_ordlist.delete_list(Xs, Set0, Set)' is true iff `Set' is the
% relative complement of `Set0' and the set containing only the members
% of `Xs'.
%
-:- pred set_ordlist.delete_list(set_ordlist(T)::in, list(T)::in,
- set_ordlist(T)::out) is det.
+:- pred set_ordlist.delete_list(list(T)::in,
+ set_ordlist(T)::in, set_ordlist(T)::out) is det.
:- func set_ordlist.delete_list(set_ordlist(T), list(T)) = set_ordlist(T).
- % `set_ordlist.remove(Set0, X, Set)' is true iff `Set0' contains `X',
+ % `set_ordlist.remove(X, Set0, Set)' is true iff `Set0' contains `X',
% and `Set' is the relative complement of `Set0' and the set
% containing only `X', i.e. if `Set' is the set which contains
% all the elements of `Set0' except `X'.
%
-:- pred set_ordlist.remove(set_ordlist(T)::in, T::in, set_ordlist(T)::out)
+:- pred set_ordlist.remove(T::in, set_ordlist(T)::in, set_ordlist(T)::out)
is semidet.
- % `set_ordlist.remove_list(Set0, Xs, Set)' is true iff Xs does not
+ % `set_ordlist.remove_list(Xs, Set0, Set)' is true iff Xs does not
% contain any duplicates, `Set0' contains every member of `Xs',
% and `Set' is the relative complement of `Set0' and the set
% containing only the members of `Xs'.
%
-:- pred set_ordlist.remove_list(set_ordlist(T)::in, list(T)::in,
- set_ordlist(T)::out) is semidet.
+:- pred set_ordlist.remove_list(list(T)::in,
+ set_ordlist(T)::in, set_ordlist(T)::out) is semidet.
- % `set_ordlist.remove_least(Set0, X, Set)' is true iff `X' is the
+ % `set_ordlist.remove_least(X, Set0, Set)' is true iff `X' is the
% least element in `Set0', and `Set' is the set which contains all the
% elements of `Set0' except `X'.
-:- pred set_ordlist.remove_least(set_ordlist(T)::in, T::out,
- set_ordlist(T)::out) is semidet.
+:- pred set_ordlist.remove_least(T::out,
+ set_ordlist(T)::in, set_ordlist(T)::out) is semidet.
% `set_ordlist.union(SetA, SetB, Set)' is true iff `Set' is the union
% of `SetA' and `SetB'. The efficiency of the union operation is
@@ -391,25 +391,55 @@
:- type set_ordlist(T)
---> sol(list(T)).
+%-----------------------------------------------------------------------------%
+
+set_ordlist.init = S :-
+ set_ordlist.init(S).
+
+set_ordlist.init(sol([])).
+
+set_ordlist.make_singleton_set(T) = S :-
+ set_ordlist.singleton_set(S, T).
+
+set_ordlist.singleton_set(sol([X]), X).
+
+set_ordlist.equal(Set, Set).
+
+set_ordlist.empty(sol([])).
+
+set_ordlist.non_empty(sol([_ | _])).
+
+set_ordlist.is_empty(sol([])).
+
+set_ordlist.list_to_set(Xs) = S :-
+ set_ordlist.list_to_set(Xs, S).
+
set_ordlist.list_to_set(List0, sol(List)) :-
list.sort_and_remove_dups(List0, List).
set_ordlist.from_list(List) = Set :-
set_ordlist.list_to_set(List, Set).
+set_ordlist.sorted_list_to_set(Xs) = S :-
+ set_ordlist.sorted_list_to_set(Xs, S).
+
set_ordlist.sorted_list_to_set(List0, sol(List)) :-
list.remove_adjacent_dups(List0, List).
set_ordlist.from_sorted_list(List) = Set :-
set_ordlist.sorted_list_to_set(List, Set).
+set_ordlist.to_sorted_list(S) = Xs :-
+ set_ordlist.to_sorted_list(S, Xs).
+
set_ordlist.to_sorted_list(sol(List), List).
-set_ordlist.insert_list(Set0, List0, Set) :-
- list.sort_and_remove_dups(List0, List),
- set_ordlist.union(sol(List), Set0, Set).
+%-----------------------------------------------------------------------------%
-set_ordlist.insert(sol(List0), E, sol(List)) :-
+set_ordlist.insert(!.S, T) = !:S :-
+ set_ordlist.insert(T, !S).
+
+set_ordlist.insert(E, sol(List0), sol(List)) :-
set_ordlist.insert_2(List0, E, List).
:- pred set_ordlist.insert_2(list(T)::in, T::in, list(T)::out)
@@ -430,23 +460,66 @@
Js = [E, I | Is]
).
-set_ordlist.init(sol([])).
+set_ordlist.insert_list(!.S, Xs) = !:S :-
+ set_ordlist.insert_list(Xs, !S).
-set_ordlist.singleton_set(sol([X]), X).
+set_ordlist.insert_list(List0, !Set) :-
+ list.sort_and_remove_dups(List0, List),
+ set_ordlist.union(sol(List), !Set).
-set_ordlist.equal(Set, Set).
+%-----------------------------------------------------------------------------%
-set_ordlist.empty(sol([])).
+set_ordlist.delete(!.S, T) = !:S :-
+ set_ordlist.delete(T, !S).
-set_ordlist.non_empty(sol([_ | _])).
+set_ordlist.delete(Elem, !Set) :-
+ set_ordlist.difference(!.Set, sol([Elem]), !:Set).
-set_ordlist.is_empty(sol([])).
+set_ordlist.delete_list(!.S, Xs) = !:S :-
+ set_ordlist.delete_list(Xs, !S).
-set_ordlist.subset(Subset, Set) :-
- set_ordlist.intersect(Set, Subset, Subset).
+set_ordlist.delete_list(D, !Set) :-
+ list.sort_and_remove_dups(D, DS),
+ set_ordlist.difference(!.Set, sol(DS), !:Set).
-set_ordlist.superset(Superset, Set) :-
- set_ordlist.subset(Set, Superset).
+%-----------------------------------------------------------------------------%
+
+set_ordlist.remove_list(Elems, !Set) :-
+ set_ordlist.sort_no_dups(Elems, ElemSet),
+ set_ordlist.subset(ElemSet, !.Set),
+ set_ordlist.difference(!.Set, ElemSet, !:Set).
+
+ % set_ordlist.sort_no_dups(List, Set) is true iff
+ % List is a list with the same elements as Set and
+ % List contains no duplicates.
+ %
+:- pred set_ordlist.sort_no_dups(list(T)::in, set_ordlist(T)::out) is semidet.
+
+set_ordlist.sort_no_dups(List, sol(Set)) :-
+ list.sort(List, Set),
+ (
+ Set = []
+ ;
+ Set = [Elem | Elems],
+ set_ordlist.no_dups(Elem, Elems)
+ ).
+
+ % set_ordlist.no_dups(Elem, Set) is true iff Set does not contain Elem,
+ % and Set does not contains duplicates.
+ %
+:- pred set_ordlist.no_dups(T::in, list(T)::in) is semidet.
+
+set_ordlist.no_dups(_, []).
+set_ordlist.no_dups(Elem, [Elem0 | Elems]) :-
+ Elem \= Elem0,
+ set_ordlist.no_dups(Elem0, Elems).
+
+set_ordlist.remove(Elem, sol(Set0), sol(Set)) :-
+ list.delete_first(Set0, Elem, Set).
+
+set_ordlist.remove_least(Elem, sol([Elem | Set]), sol(Set)).
+
+%-----------------------------------------------------------------------------%
:- pragma promise_equivalent_clauses(set_ordlist.member/2).
@@ -477,47 +550,16 @@
set_ordlist.contains(S, E) :-
set_ordlist.member(E, S).
-set_ordlist.delete_list(S0, D, S) :-
- list.sort_and_remove_dups(D, DS),
- set_ordlist.difference(S0, sol(DS), S).
-
-set_ordlist.delete(Set0, Elem, Set) :-
- set_ordlist.difference(Set0, sol([Elem]), Set).
-
-set_ordlist.remove_list(Set0, Elems, Set) :-
- set_ordlist.sort_no_dups(Elems, ElemSet),
- set_ordlist.subset(ElemSet, Set0),
- set_ordlist.difference(Set0, ElemSet, Set).
-
- % set_ordlist.sort_no_dups(List, Set) is true iff
- % List is a list with the same elements as Set and
- % List contains no duplicates.
- %
-:- pred set_ordlist.sort_no_dups(list(T)::in, set_ordlist(T)::out) is semidet.
-
-set_ordlist.sort_no_dups(List, sol(Set)) :-
- list.sort(List, Set),
- (
- Set = []
- ;
- Set = [Elem | Elems],
- set_ordlist.no_dups(Elem, Elems)
- ).
-
- % set_ordlist.no_dups(Elem, Set) is true iff Set does not contain Elem,
- % and Set does not contains duplicates.
- %
-:- pred set_ordlist.no_dups(T::in, list(T)::in) is semidet.
+%-----------------------------------------------------------------------------%
-set_ordlist.no_dups(_, []).
-set_ordlist.no_dups(Elem, [Elem0 | Elems]) :-
- Elem \= Elem0,
- set_ordlist.no_dups(Elem0, Elems).
+set_ordlist.subset(Subset, Set) :-
+ set_ordlist.intersect(Set, Subset, Subset).
-set_ordlist.remove(sol(Set0), Elem, sol(Set)) :-
- list.delete_first(Set0, Elem, Set).
+set_ordlist.superset(Superset, Set) :-
+ set_ordlist.subset(Set, Superset).
-set_ordlist.remove_least(sol([Elem | Set]), Elem, sol(Set)).
+set_ordlist.union(S1, S2) = S3 :-
+ set_ordlist.union(S1, S2, S3).
set_ordlist.union(sol(Set0), sol(Set1), sol(Set)) :-
list.merge_and_remove_dups(Set0, Set1, Set).
@@ -526,6 +568,9 @@
set_ordlist.init(Set0),
set_ordlist.power_union_2(ListofSets, Set0, Set).
+set_ordlist.power_union(SS) = S :-
+ set_ordlist.power_union(SS, S).
+
set_ordlist.power_union(sol(ListofSets), Set) :-
Set = set_ordlist.union_list(ListofSets).
@@ -537,6 +582,11 @@
set_ordlist.union(Set0, NextSet, Set1),
set_ordlist.power_union_2(SetofSets, Set1, Set).
+%--------------------------------------------------------------------------%
+
+set_ordlist.intersect(S1, S2) = S3 :-
+ set_ordlist.intersect(S1, S2, S3).
+
set_ordlist.intersect(sol(Xs), sol(Ys), sol(Set)) :-
set_ordlist.intersect_2(Xs, Ys, Set).
@@ -560,6 +610,9 @@
set_ordlist.intersect_2([X | Xs], Ys, Set)
).
+set_ordlist.power_intersect(SS) = S :-
+ set_ordlist.power_intersect(SS, S).
+
set_ordlist.power_intersect(sol(S0), S) :-
set_ordlist.intersect_list(S0) = S.
@@ -576,6 +629,9 @@
%--------------------------------------------------------------------------%
+set_ordlist.difference(S1, S2) = S3 :-
+ set_ordlist.difference(S1, S2, S3).
+
set_ordlist.difference(sol(Xs), sol(Ys), sol(Set)) :-
set_ordlist.difference_2(Xs, Ys, Set).
@@ -600,6 +656,9 @@
%--------------------------------------------------------------------------%
+set_ordlist.count(S) = N :-
+ set_ordlist.count(S, N).
+
set_ordlist.count(sol(Set), Count) :-
list.length(Set, Count).
@@ -627,54 +686,6 @@
list.foldl6(P, set_ordlist.to_sorted_list(S), !A, !B, !C, !D, !E, !F).
%-----------------------------------------------------------------------------%
-%-----------------------------------------------------------------------------%
-% Ralph Becket <rwab1 at cam.sri.com> 24/04/99
-% Function forms added.
-
-set_ordlist.list_to_set(Xs) = S :-
- set_ordlist.list_to_set(Xs, S).
-
-set_ordlist.sorted_list_to_set(Xs) = S :-
- set_ordlist.sorted_list_to_set(Xs, S).
-
-set_ordlist.to_sorted_list(S) = Xs :-
- set_ordlist.to_sorted_list(S, Xs).
-
-set_ordlist.init = S :-
- set_ordlist.init(S).
-
-set_ordlist.make_singleton_set(T) = S :-
- set_ordlist.singleton_set(S, T).
-
-set_ordlist.insert(S1, T) = S2 :-
- set_ordlist.insert(S1, T, S2).
-
-set_ordlist.insert_list(S1, Xs) = S2 :-
- set_ordlist.insert_list(S1, Xs, S2).
-
-set_ordlist.delete(S1, T) = S2 :-
- set_ordlist.delete(S1, T, S2).
-
-set_ordlist.delete_list(S1, Xs) = S2 :-
- set_ordlist.delete_list(S1, Xs, S2).
-
-set_ordlist.union(S1, S2) = S3 :-
- set_ordlist.union(S1, S2, S3).
-
-set_ordlist.power_union(SS) = S :-
- set_ordlist.power_union(SS, S).
-
-set_ordlist.intersect(S1, S2) = S3 :-
- set_ordlist.intersect(S1, S2, S3).
-
-set_ordlist.power_intersect(SS) = S :-
- set_ordlist.power_intersect(SS, S).
-
-set_ordlist.difference(S1, S2) = S3 :-
- set_ordlist.difference(S1, S2, S3).
-
-set_ordlist.count(S) = N :-
- set_ordlist.count(S, N).
set_ordlist.map(F, S1) = S2 :-
S2 = set_ordlist.list_to_set(list.map(F, set_ordlist.to_sorted_list(S1))).
@@ -683,6 +694,8 @@
S2 = set_ordlist.list_to_set(list.filter_map(PF,
set_ordlist.to_sorted_list(S1))).
+%-----------------------------------------------------------------------------%
+
set_ordlist.divide(Pred, sol(Set), sol(TruePart), sol(FalsePart)) :-
% The calls to reverse allow us to make divide_2 tail recursive.
% This costs us a higher constant factor, but allows divide to work
@@ -736,4 +749,5 @@
).
%-----------------------------------------------------------------------------%
+:- end_module set_ordlist.
%-----------------------------------------------------------------------------%
Index: library/set_unordlist.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/set_unordlist.m,v
retrieving revision 1.34
diff -u -r1.34 set_unordlist.m
--- library/set_unordlist.m 10 May 2011 05:26:52 -0000 1.34
+++ library/set_unordlist.m 19 May 2011 04:31:24 -0000
@@ -111,67 +111,67 @@
%
:- pred set_unordlist.contains(set_unordlist(T)::in, T::in) is semidet.
- % `set_unordlist.insert(Set0, X, Set)' is true iff `Set' is the union
+ % `set_unordlist.insert(X, Set0, Set)' is true iff `Set' is the union
% of `Set0' and the set containing only `X'.
%
-:- pred set_unordlist.insert(set_unordlist(T), T, set_unordlist(T)).
+:- pred set_unordlist.insert(T, set_unordlist(T), set_unordlist(T)).
:- mode set_unordlist.insert(di, di, uo) is det.
:- mode set_unordlist.insert(in, in, out) is det.
:- func set_unordlist.insert(set_unordlist(T), T) = set_unordlist(T).
- % `set_unordlist.insert_list(Set0, Xs, Set)' is true iff `Set' is the
+ % `set_unordlist.insert_list(Xs, Set0, Set)' is true iff `Set' is the
% union of `Set0' and the set containing only the members of `Xs'.
%
-:- pred set_unordlist.insert_list(set_unordlist(T)::in, list(T)::in,
- set_unordlist(T)::out) is det.
+:- pred set_unordlist.insert_list(list(T)::in,
+ set_unordlist(T)::in, set_unordlist(T)::out) is det.
:- func set_unordlist.insert_list(set_unordlist(T), list(T))
= set_unordlist(T).
- % `set_unordlist.delete(Set0, X, Set)' is true iff `Set' is the
+ % `set_unordlist.delete(X, Set0, Set)' is true iff `Set' is the
% relative complement of `Set0' and the set containing only `X', i.e.
% if `Set' is the set which contains all the elements of `Set0'
% except `X'.
%
-:- pred set_unordlist.delete(set_unordlist(T), T, set_unordlist(T)).
-:- mode set_unordlist.delete(di, in, uo) is det.
+:- pred set_unordlist.delete(T, set_unordlist(T), set_unordlist(T)).
+:- mode set_unordlist.delete(in, di, uo) is det.
:- mode set_unordlist.delete(in, in, out) is det.
:- func set_unordlist.delete(set_unordlist(T), T) = set_unordlist(T).
- % `set_unordlist.delete_list(Set0, Xs, Set)' is true iff `Set' is the
+ % `set_unordlist.delete_list(Xs, Set0, Set)' is true iff `Set' is the
% relative complement of `Set0' and the set containing only the members
% of `Xs'.
%
-:- pred set_unordlist.delete_list(set_unordlist(T)::in, list(T)::in,
- set_unordlist(T)::out) is det.
+:- pred set_unordlist.delete_list(list(T)::in,
+ set_unordlist(T)::in, set_unordlist(T)::out) is det.
:- func set_unordlist.delete_list(set_unordlist(T), list(T))
= set_unordlist(T).
- % `set_unordlist.remove(Set0, X, Set)' is true iff `Set0' contains `X',
+ % `set_unordlist.remove(X, Set0, Set)' is true iff `Set0' contains `X',
% and `Set' is the relative complement of `Set0' and the set
% containing only `X', i.e. if `Set' is the set which contains
% all the elements of `Set0' except `X'.
%
-:- pred set_unordlist.remove(set_unordlist(T)::in, T::in,
- set_unordlist(T)::out) is semidet.
+:- pred set_unordlist.remove(T::in,
+ set_unordlist(T)::in, set_unordlist(T)::out) is semidet.
- % `set_unordlist.remove_list(Set0, Xs, Set)' is true iff Xs does not
+ % `set_unordlist.remove_list(Xs, Set0, Set)' is true iff Xs does not
% contain any duplicates, `Set0' contains every member of `Xs',
% and `Set' is the relative complement of `Set0' and the set
% containing only the members of `Xs'.
%
-:- pred set_unordlist.remove_list(set_unordlist(T)::in, list(T)::in,
- set_unordlist(T)::out) is semidet.
+:- pred set_unordlist.remove_list(list(T)::in,
+ set_unordlist(T)::in, set_unordlist(T)::out) is semidet.
- % `set_unordlist.remove_least(Set0, X, Set)' is true iff `X' is the
+ % `set_unordlist.remove_least(X, Set0, Set)' is true iff `X' is the
% least element in `Set0', and `Set' is the set which contains all the
% elements of `Set0' except `X'.
%
-:- pred set_unordlist.remove_least(set_unordlist(T)::in, T::out,
- set_unordlist(T)::out) is semidet.
+:- pred set_unordlist.remove_least(T::out,
+ set_unordlist(T)::in, set_unordlist(T)::out) is semidet.
% `set_unordlist.union(SetA, SetB, Set)' is true iff `Set' is the union
% of `SetA' and `SetB'. If the sets are known to be of different
@@ -377,10 +377,10 @@
set_unordlist.to_sorted_list(sul(Set), List) :-
list.sort_and_remove_dups(Set, List).
-set_unordlist.insert_list(sul(Set0), List, sul(Set)) :-
- list.append(List, Set0, Set).
+set_unordlist.insert_list(List, sul(!.Set), sul(!:Set)) :-
+ list.append(List, !Set).
-set_unordlist.insert(sul(S0), E, sul([E | S0])).
+set_unordlist.insert(E, sul(S0), sul([E | S0])).
set_unordlist.init(sul([])).
@@ -417,25 +417,25 @@
set_unordlist.contains(S, E) :-
set_unordlist.member(E, S).
-set_unordlist.delete_list(S, [], S).
-set_unordlist.delete_list(S0, [X | Xs], S) :-
- set_unordlist.delete(S0, X, S1),
- set_unordlist.delete_list(S1, Xs, S).
-
-set_unordlist.delete(sul(S0), E, sul(S)) :-
- list.delete_all(S0, E, S).
-
-set_unordlist.remove_list(S, [], S).
-set_unordlist.remove_list(S0, [X | Xs], S) :-
- set_unordlist.remove(S0, X, S1),
- set_unordlist.remove_list(S1, Xs, S).
+set_unordlist.delete_list([], !S).
+set_unordlist.delete_list([X | Xs], !S) :-
+ set_unordlist.delete(X, !S),
+ set_unordlist.delete_list(Xs, !S).
+
+set_unordlist.delete(E, sul(!.S), sul(!:S)) :-
+ list.delete_all(!.S, E, !:S).
+
+set_unordlist.remove_list([], !S).
+set_unordlist.remove_list([X | Xs], !S) :-
+ set_unordlist.remove(X, !S),
+ set_unordlist.remove_list(Xs, !S).
-set_unordlist.remove(sul(S0), E, sul(S)) :-
+set_unordlist.remove(E, sul(S0), sul(S)) :-
list.member(E, S0),
- set_unordlist.delete(sul(S0), E, sul(S)).
+ set_unordlist.delete(E, sul(S0), sul(S)).
-set_unordlist.remove_least(Set0, E, sul(Set)) :-
- Set0 = sul([_ | _]), % fail early on an empty set
+set_unordlist.remove_least(E, Set0, sul(Set)) :-
+ Set0 = sul([_ | _]), % Fail early on an empty set.
set_unordlist.to_sorted_list(Set0, [E | Set]).
set_unordlist.union(sul(Set0), sul(Set1), sul(Set)) :-
@@ -496,7 +496,7 @@
set_unordlist.difference_2(sul([]), C, C).
set_unordlist.difference_2(sul([E | Es]), A, C) :-
- set_unordlist.delete(A, E, B),
+ set_unordlist.delete(E, A, B),
set_unordlist.difference_2(sul(Es), B, C).
%-----------------------------------------------------------------------------%
@@ -551,17 +551,17 @@
set_unordlist.make_singleton_set(T) = S :-
set_unordlist.singleton_set(S, T).
-set_unordlist.insert(S1, T) = S2 :-
- set_unordlist.insert(S1, T, S2).
+set_unordlist.insert(!.S, T) = !:S :-
+ set_unordlist.insert(T, !S).
-set_unordlist.insert_list(S1, Xs) = S2 :-
- set_unordlist.insert_list(S1, Xs, S2).
+set_unordlist.insert_list(!.S, Xs) = !:S :-
+ set_unordlist.insert_list(Xs, !S).
-set_unordlist.delete(S1, T) = S2 :-
- set_unordlist.delete(S1, T, S2).
+set_unordlist.delete(!.S, T) = !:S :-
+ set_unordlist.delete(T, !S).
-set_unordlist.delete_list(S1, Xs) = S2 :-
- set_unordlist.delete_list(S1, Xs, S2).
+set_unordlist.delete_list(!.S, Xs) = !:S :-
+ set_unordlist.delete_list(Xs, !S).
set_unordlist.union(S1, S2) = S3 :-
set_unordlist.union(S1, S2, S3).
Index: tests/general/set_test.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/general/set_test.m,v
retrieving revision 1.4
diff -u -r1.4 set_test.m
--- tests/general/set_test.m 6 May 2011 15:19:34 -0000 1.4
+++ tests/general/set_test.m 19 May 2011 07:18:45 -0000
@@ -10,7 +10,6 @@
:- pred main(io__state :: di, io__state :: uo) is det.
-
:- implementation.
:- import_module bool, list, string, set_bbbtree.
@@ -33,7 +32,7 @@
;
io__write_string("set_bbbtree__is_member should have failed on empty set\n")
),
- { set_bbbtree__insert(Set0, 5, Set10) },
+ { set_bbbtree__insert(5, Set0, Set10) },
(
{ set_bbbtree__is_member(5, Set10, yes) },
{ set_bbbtree__is_member(6, Set10, no) },
@@ -45,7 +44,7 @@
;
io__write_string("set_bbbtree__is_member/set_bbbtree__singleton_set/set_bbbtree__least/set_bbbtree__largest failed\n")
),
- { set_bbbtree__delete(Set10, 5, Set20) },
+ { set_bbbtree__delete(5, Set10, Set20) },
(
{ set_bbbtree__empty(Set20) }
->
@@ -53,7 +52,7 @@
;
io__write_string("set_bbbtree__empty failed as set was not empty\n")
),
- { set_bbbtree__delete(Set20, 5, Set30) },
+ { set_bbbtree__delete(5, Set20, Set30) },
(
{ set_bbbtree__empty(Set30) }
->
@@ -62,7 +61,7 @@
io__write_string("set_bbbtree__empty failed as set was not empty\n")
),
- { set_bbbtree__delete_list(Set10,[0, 1, 2, 3, 4, 5, 6, 100000], Set40)},
+ { set_bbbtree__delete_list([0, 1, 2, 3, 4, 5, 6, 100000], Set10, Set40) },
(
{ set_bbbtree__empty(Set40) }
->
@@ -73,7 +72,7 @@
{ set_bbbtree__list_to_set([-2, 10, 0, -1, 2, -2, -2, 0], Set50) },
(
{ set_bbbtree__count(Set50, 5) },
- { set_bbbtree__remove_least(Set50, -2, TempSet) }
+ { set_bbbtree__remove_least(-2, Set50, TempSet) }
->
{ Set60 = TempSet },
(
@@ -83,7 +82,7 @@
;
io__write_string("set_bbbtree__is_member failed\n")
),
- { set_bbbtree__delete_list(Set60, [-2, -2, -2, 10], Set70) },
+ { set_bbbtree__delete_list([-2, -2, -2, 10], Set60, Set70) },
(
{ set_bbbtree__is_member(-2, Set70, no) },
{ set_bbbtree__is_member(10, Set70, no) },
@@ -150,10 +149,10 @@
),
{ set_bbbtree__init(Set110) },
- { set_bbbtree__insert(Set110, Set90, Set120) },
- { set_bbbtree__insert(Set120, Set100, Set130) },
- { set_bbbtree__insert(Set130, SetIntersection, Set140) },
- { set_bbbtree__insert(Set140, SetDifference, Set150) },
+ { set_bbbtree__insert(Set90, Set110, Set120) },
+ { set_bbbtree__insert(Set100, Set120, Set130) },
+ { set_bbbtree__insert(SetIntersection, Set130, Set140) },
+ { set_bbbtree__insert(SetDifference, Set140, Set150) },
{ set_bbbtree__power_union(Set150, SetUnion10) },
(
{ set_bbbtree__equal(SetUnion10, SetUnion) }
--------------------------------------------------------------------------
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