[m-rev.] diff: change argument ordering in sparse_bitset module
Julien Fischer
juliensf at csse.unimelb.edu.au
Thu May 19 23:09:28 AEST 2011
Branches: main
Change the argument order of predicates in the sparse_bitset modules to make
it more conducive to the use of state variable notation.
Group function clauses together with the clauses for the corresponding
predicates.
library/sparse_bitset.m:
As above.
library/digraph.m:
compiler/make.dependencies.m:
compiler/mode_robdd.equiv_vars.m:
compiler/mode_robdd.implications.m:
compiler/mode_robdd.tfeirn.m:
tests/hard_coded/bitset_tester.m:
tests/hard_coded/pprint_test.m:
tests/valid/loop_inv_bug.m:
Conform to the above change.
library/digraph.m:
library/getopt.m:
library/getopt_io.m:
library/map.m:
Remove dependencies on the svset module.
NEWS:
Announce the above change.
Julien.
Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.573
diff -u -r1.573 NEWS
--- NEWS 19 May 2011 07:33:22 -0000 1.573
+++ NEWS 19 May 2011 12:33:03 -0000
@@ -64,6 +64,10 @@
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,
+ sparse_bitset.insert/3, sparse_bitset.insert_list/3, sparse_bitset.delete/3,
+ sparse_bitset.delete_list/3, sparse_bitset.remove/3,
+ sparse_bitset.remove_list/3, sparse_bitset.remove_leq/3,
+ sparse_bitset.remove_gt/3, sparse_bitset.remove_least/3,
tree234.set/4, tree234.remove/4, tree234.remove_smallest/4 and
tree234.update/4.
Index: compiler/make.dependencies.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.dependencies.m,v
retrieving revision 1.60
diff -u -r1.60 make.dependencies.m
--- compiler/make.dependencies.m 6 May 2011 05:03:21 -0000 1.60
+++ compiler/make.dependencies.m 19 May 2011 07:52:08 -0000
@@ -243,7 +243,7 @@
module_names_to_index_set_2([], !IndexSet, !Info).
module_names_to_index_set_2([ModuleName | ModuleNames], !Set, !Info) :-
module_name_to_index(ModuleName, ModuleIndex, !Info),
- insert(!.Set, ModuleIndex, !:Set),
+ insert(ModuleIndex, !Set),
module_names_to_index_set_2(ModuleNames, !Set, !Info).
module_index_set_to_plain_set(Info, ModuleIndices, Modules) :-
@@ -312,9 +312,9 @@
deps_set(dependency_file_index)::in, deps_set(dependency_file_index)::out,
make_info::in, make_info::out) is det.
-dependency_files_to_index_set_2(DepFiles, Set0, Set, !Info) :-
+dependency_files_to_index_set_2(DepFiles, !Set, !Info) :-
dependency_file_to_index(DepFiles, DepIndex, !Info),
- insert(Set0, DepIndex, Set).
+ insert(DepIndex, !Set).
%-----------------------------------------------------------------------------%
@@ -615,11 +615,11 @@
deps_set(dependency_file_index)::in, deps_set(dependency_file_index)::out,
make_info::in, make_info::out) is det.
-of_3(FileType, ModuleIndex, Set0, Set, !Info) :-
+of_3(FileType, ModuleIndex, !Set, !Info) :-
module_index_to_name(!.Info, ModuleIndex, ModuleName),
TargetFile = dep_target(target_file(ModuleName, FileType)),
dependency_file_to_index(TargetFile, TargetFileIndex, !Info),
- insert(Set0, TargetFileIndex, Set).
+ insert(TargetFileIndex, !Set).
:- func files_of(find_module_deps_plain_set(dependency_file),
find_module_deps(module_index)) = find_module_deps(dependency_file_index).
@@ -1150,7 +1150,7 @@
!Info, !IO) :-
find_transitive_module_dependencies(Globals, interface_imports, any_module,
ModuleIndex, Success, Modules0, !Info, !IO),
- delete(Modules0, ModuleIndex, Modules).
+ delete(ModuleIndex, Modules0, Modules).
:- pred find_transitive_module_dependencies(globals::in,
transitive_dependencies_type::in, module_locn::in, module_index::in,
Index: compiler/mode_robdd.equiv_vars.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mode_robdd.equiv_vars.m,v
retrieving revision 1.9
diff -u -r1.9 mode_robdd.equiv_vars.m
--- compiler/mode_robdd.equiv_vars.m 3 May 2011 04:34:56 -0000 1.9
+++ compiler/mode_robdd.equiv_vars.m 19 May 2011 07:52:36 -0000
@@ -147,7 +147,7 @@
normalise_leader_map((EQVars ^ leader(B) := A) ^ leader_map).
add_equalities(Vars0, EQVars) =
- ( remove_least(Vars0, Var, Vars) ->
+ ( remove_least(Var, Vars0, Vars) ->
foldl(add_equality(Var), Vars, EQVars)
;
EQVars
Index: compiler/mode_robdd.implications.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mode_robdd.implications.m,v
retrieving revision 1.8
diff -u -r1.8 mode_robdd.implications.m
--- compiler/mode_robdd.implications.m 20 Dec 2010 07:47:35 -0000 1.8
+++ compiler/mode_robdd.implications.m 19 May 2011 07:53:05 -0000
@@ -133,7 +133,7 @@
ImpVars ^ add_clause({neg(A), pos(B)}).
at_most_one_of(Vars0, ImpVars) =
- ( remove_least(Vars0, Var, Vars) ->
+ ( remove_least(Var, Vars0, Vars) ->
ImpVars ^ foldl(not_both(Var), Vars) ^ at_most_one_of(Vars)
;
ImpVars
Index: compiler/mode_robdd.tfeirn.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mode_robdd.tfeirn.m,v
retrieving revision 1.6
diff -u -r1.6 mode_robdd.tfeirn.m
--- compiler/mode_robdd.tfeirn.m 8 Aug 2008 05:02:21 -0000 1.6
+++ compiler/mode_robdd.tfeirn.m 19 May 2011 07:55:23 -0000
@@ -436,8 +436,8 @@
X = zero
;
VarsNF = Vars `difference` F,
- ( remove_least(VarsNF, Var1, VarsNF1) ->
- ( remove_least(VarsNF1, Var2, VarsNF2) ->
+ ( remove_least(Var1, VarsNF, VarsNF1) ->
+ ( remove_least(Var2, VarsNF1, VarsNF2) ->
( empty(VarsNF2) ->
X = mode_robdd(T, F, E,
I ^ either(Var1, Var2),
@@ -498,7 +498,7 @@
X ^ var(Var)
; Vars `subset` F ->
X ^ not_var(Var)
- ; remove_least(Vars, Var1, Vars1) ->
+ ; remove_least(Var1, Vars, Vars1) ->
( empty(Vars1) ->
X ^ eq_vars(Var, Var1)
;
@@ -562,7 +562,7 @@
is nondet.
labelling_2(Vars0, X0, TrueVars, FalseVars) :-
- ( remove_least(Vars0, V, Vars) ->
+ ( remove_least(V, Vars0, Vars) ->
(
X = var_restrict_false(V, X0),
X ^ robdd \= zero,
@@ -598,7 +598,7 @@
is semidet.
minimal_model_2(Vars0, X0, TrueVars, FalseVars) :-
- ( remove_least(Vars0, V, Vars) ->
+ ( remove_least(V, Vars0, Vars) ->
X1 = var_restrict_false(V, X0),
( X1 ^ robdd \= zero ->
minimal_model_2(Vars, X1, TrueVars, FalseVars0),
Index: library/digraph.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/digraph.m,v
retrieving revision 1.4
diff -u -r1.4 digraph.m
--- library/digraph.m 6 May 2011 06:04:56 -0000 1.4
+++ library/digraph.m 19 May 2011 07:41:38 -0000
@@ -337,7 +337,6 @@
:- import_module bimap.
:- import_module int.
:- import_module require.
-:- import_module svset.
%-----------------------------------------------------------------------------%
@@ -379,12 +378,12 @@
( contains(SuccXs0, Y) ->
Map = Map0
;
- insert(SuccXs0, Y, SuccXs),
+ insert(Y, SuccXs0, SuccXs),
Map = map.det_update(Map0, XI, SuccXs)
)
;
init(SuccXs0),
- insert(SuccXs0, Y, SuccXs),
+ insert(Y, SuccXs0, SuccXs),
Map = map.det_insert(Map0, XI, SuccXs)
).
@@ -393,7 +392,7 @@
key_set_map_delete(Map0, XI, Y) = Map :-
( map.search(Map0, XI, SuccXs0) ->
- delete(SuccXs0, Y, SuccXs),
+ delete(Y, SuccXs0, SuccXs),
Map = map.det_update(Map0, XI, SuccXs)
;
Map = Map0
@@ -654,7 +653,7 @@
true
;
digraph.lookup_key_set_from(G, X, SuccXs),
- insert(!.Visited, X, !:Visited),
+ insert(X, !Visited),
% Go and visit all of the node's children first.
sparse_bitset.foldl2(digraph.dfs_2(G), SuccXs, !Visited, !DfsRev),
@@ -809,11 +808,11 @@
set(set(digraph_key(T)))::in, set(set(digraph_key(T)))::out) is det.
digraph.components_2(G, Xs0, !Components) :-
- ( remove_least(Xs0, X, Xs1) ->
+ ( remove_least(X, Xs0, Xs1) ->
init(Comp0),
Keys0 = make_singleton_set(X),
digraph.reachable_from(G, Keys0, Comp0, Comp),
- svset.insert(to_set(Comp), !Components),
+ set.insert(to_set(Comp), !Components),
difference(Xs1, Comp, Xs2),
digraph.components_2(G, Xs2, !Components)
;
@@ -825,8 +824,8 @@
digraph.reachable_from(G, Keys0, !Comp) :-
% Invariant: Keys0 and !.Comp are disjoint.
- ( remove_least(Keys0, X, Keys1) ->
- insert(!.Comp, X, !:Comp),
+ ( remove_least(X, Keys0, Keys1) ->
+ insert(X, !Comp),
digraph.lookup_key_set_from(G, X, FwdSet),
digraph.lookup_key_set_to(G, X, BwdSet),
union(FwdSet, BwdSet, NextSet0),
@@ -871,7 +870,7 @@
% Insert the cycle into the clique set.
list_to_set(CliqueList, Clique),
- svset.insert(Clique, !Cliques),
+ set.insert(Clique, !Cliques),
% Delete all the visited vertices, so head of the list is the next
% highest non-visited vertex.
@@ -944,7 +943,7 @@
digraph.check_tsort(_, _, []).
digraph.check_tsort(G, Vis0, [X | Xs]) :-
- insert(Vis0, X, Vis),
+ insert(X, Vis0, Vis),
digraph.lookup_key_set_from(G, X, SuccXs),
intersect(Vis, SuccXs, BackPointers),
empty(BackPointers),
Index: library/getopt.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/getopt.m,v
retrieving revision 1.45
diff -u -r1.45 getopt.m
--- library/getopt.m 3 May 2011 04:35:01 -0000 1.45
+++ library/getopt.m 19 May 2011 07:50:32 -0000
@@ -295,7 +295,6 @@
:- import_module require.
:- import_module solutions.
:- import_module string.
-:- import_module svset.
%-----------------------------------------------------------------------------%
@@ -657,7 +656,7 @@
getopt.process_option(bool(_), _Option, Flag, MaybeArg, _OptionOps,
OptionTable0, Result, !OptionsSet) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(_Arg),
map.set(Flag, bool(no), OptionTable0, OptionTable),
@@ -669,7 +668,7 @@
).
getopt.process_option(int(_), Option, Flag, MaybeArg, _OptionOps,
!.OptionTable, Result, !OptionsSet) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(Arg),
( string.to_int(Arg, IntArg) ->
@@ -684,7 +683,7 @@
).
getopt.process_option(string(_), _Option, Flag, MaybeArg, _OptionOps,
!.OptionTable, Result, !OptionsSet) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(Arg),
map.set(Flag, string(Arg), !OptionTable),
@@ -695,7 +694,7 @@
).
getopt.process_option(maybe_int(_), Option, Flag, MaybeArg, _OptionOps,
!.OptionTable, Result, !OptionsSet) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(Arg),
( string.to_int(Arg, IntArg) ->
@@ -710,7 +709,7 @@
).
getopt.process_option(maybe_string(_), _Option, Flag, MaybeArg, _OptionOps,
!.OptionTable, Result, !OptionsSet) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(Arg),
map.set(Flag, maybe_string(yes(Arg)), !OptionTable),
@@ -721,7 +720,7 @@
).
getopt.process_option(accumulating(List0), _Option, Flag, MaybeArg, _OptionOps,
!.OptionTable, Result, !OptionsSet) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(Arg),
list.append(List0, [Arg], List),
@@ -733,7 +732,7 @@
).
getopt.process_option(special, Option, Flag, MaybeArg, OptionOps,
OptionTable0, Result, !OptionsSet) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(_Arg),
error("no special argument expected in getopt.process_option")
@@ -744,7 +743,7 @@
).
getopt.process_option(bool_special, Option, Flag, MaybeArg, OptionOps,
OptionTable0, Result, !OptionsSet) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(_Arg),
getopt.process_special(Option, Flag, bool(no),
@@ -756,7 +755,7 @@
).
getopt.process_option(int_special, Option, Flag, MaybeArg, OptionOps,
OptionTable0, Result, !OptionsSet) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(Arg),
( string.to_int(Arg, IntArg) ->
@@ -771,7 +770,7 @@
).
getopt.process_option(string_special, Option, Flag, MaybeArg, OptionOps,
OptionTable0, Result, !OptionsSet) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(Arg),
getopt.process_special(Option, Flag, string(Arg),
@@ -802,32 +801,32 @@
( map.search(OptionTable0, Flag, OptionData) ->
(
OptionData = bool(_),
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
map.set(Flag, bool(no), OptionTable0, OptionTable),
Result = ok(OptionTable)
;
OptionData = maybe_int(_),
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
map.set(Flag, maybe_int(no), OptionTable0, OptionTable),
Result = ok(OptionTable)
;
OptionData = maybe_string(_),
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
map.set(Flag, maybe_string(no), OptionTable0, OptionTable),
Result = ok(OptionTable)
;
OptionData = accumulating(_),
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
map.set(Flag, accumulating([]), OptionTable0, OptionTable),
Result = ok(OptionTable)
;
OptionData = bool_special,
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
getopt.process_special(Option, Flag, bool(no),
OptionOps, OptionTable0, Result, !OptionsSet)
;
OptionData = maybe_string_special,
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
getopt.process_special(Option, Flag, maybe_string(no),
OptionOps, OptionTable0, Result, !OptionsSet)
;
Index: library/getopt_io.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/getopt_io.m,v
retrieving revision 1.14
diff -u -r1.14 getopt_io.m
--- library/getopt_io.m 3 May 2011 04:35:01 -0000 1.14
+++ library/getopt_io.m 19 May 2011 07:50:47 -0000
@@ -301,7 +301,6 @@
:- import_module require.
:- import_module solutions.
:- import_module string.
-:- import_module svset.
%-----------------------------------------------------------------------------%
@@ -664,7 +663,7 @@
getopt_io.process_option(bool(_), _Option, Flag, MaybeArg, _OptionOps,
!.OptionTable, Result, !OptionsSet, !IO) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(_Arg),
map.set(Flag, bool(no), !OptionTable),
@@ -676,7 +675,7 @@
).
getopt_io.process_option(int(_), Option, Flag, MaybeArg, _OptionOps,
!.OptionTable, Result, !OptionsSet, !IO) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(Arg),
( string.to_int(Arg, IntArg) ->
@@ -691,7 +690,7 @@
).
getopt_io.process_option(string(_), _Option, Flag, MaybeArg, _OptionOps,
!.OptionTable, Result, !OptionsSet, !IO) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(Arg),
map.set(Flag, string(Arg), !OptionTable),
@@ -702,7 +701,7 @@
).
getopt_io.process_option(maybe_int(_), Option, Flag, MaybeArg, _OptionOps,
!.OptionTable, Result, !OptionsSet, !IO) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(Arg),
( string.to_int(Arg, IntArg) ->
@@ -717,7 +716,7 @@
).
getopt_io.process_option(maybe_string(_), _Option, Flag, MaybeArg, _OptionOps,
!.OptionTable, Result, !OptionsSet, !IO) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(Arg),
map.set(Flag, maybe_string(yes(Arg)), !OptionTable),
@@ -728,7 +727,7 @@
).
getopt_io.process_option(accumulating(List0), _Option, Flag, MaybeArg, _OptionOps,
!.OptionTable, Result, !OptionsSet, !IO) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(Arg),
list.append(List0, [Arg], List),
@@ -740,7 +739,7 @@
).
getopt_io.process_option(special, Option, Flag, MaybeArg, OptionOps,
OptionTable0, Result, !OptionsSet, !IO) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(_Arg),
error("no special argument expected in getopt_io.process_option")
@@ -751,7 +750,7 @@
).
getopt_io.process_option(bool_special, Option, Flag, MaybeArg, OptionOps,
OptionTable0, Result, !OptionsSet, !IO) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(_Arg),
getopt_io.process_special(Option, Flag, bool(no),
@@ -763,7 +762,7 @@
).
getopt_io.process_option(int_special, Option, Flag, MaybeArg, OptionOps,
OptionTable0, Result, !OptionsSet, !IO) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(Arg),
( string.to_int(Arg, IntArg) ->
@@ -778,7 +777,7 @@
).
getopt_io.process_option(string_special, Option, Flag, MaybeArg, OptionOps,
OptionTable0, Result, !OptionsSet, !IO) :-
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
(
MaybeArg = yes(Arg),
getopt_io.process_special(Option, Flag, string(Arg),
@@ -845,32 +844,32 @@
( map.search(OptionTable0, Flag, OptionData) ->
(
OptionData = bool(_),
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
map.set(Flag, bool(no), OptionTable0, OptionTable),
Result = ok(OptionTable)
;
OptionData = maybe_int(_),
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
map.set(Flag, maybe_int(no), OptionTable0, OptionTable),
Result = ok(OptionTable)
;
OptionData = maybe_string(_),
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
map.set(Flag, maybe_string(no), OptionTable0, OptionTable),
Result = ok(OptionTable)
;
OptionData = accumulating(_),
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
map.set(Flag, accumulating([]), OptionTable0, OptionTable),
Result = ok(OptionTable)
;
OptionData = bool_special,
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
getopt_io.process_special(Option, Flag, bool(no),
OptionOps, OptionTable0, Result, !OptionsSet)
;
OptionData = maybe_string_special,
- svset.insert(Flag, !OptionsSet),
+ set.insert(Flag, !OptionsSet),
getopt_io.process_special(Option, Flag, maybe_string(no),
OptionOps, OptionTable0, Result, !OptionsSet)
;
Index: library/map.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/map.m,v
retrieving revision 1.125
diff -u -r1.125 map.m
--- library/map.m 18 May 2011 15:40:19 -0000 1.125
+++ library/map.m 19 May 2011 07:49:49 -0000
@@ -710,7 +710,6 @@
:- import_module pair.
:- import_module require.
-:- import_module svset.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
@@ -1307,7 +1306,7 @@
map.reverse_map_2(Key, Value, !RevMap) :-
( map.search(!.RevMap, Value, Keys0) ->
- svset.insert(Key, Keys0, Keys),
+ set.insert(Key, Keys0, Keys),
map.det_update(Value, Keys, !RevMap)
;
map.det_insert(Value, set.make_singleton_set(Key), !RevMap)
Index: library/sparse_bitset.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/sparse_bitset.m,v
retrieving revision 1.37
diff -u -r1.37 sparse_bitset.m
--- library/sparse_bitset.m 10 May 2011 05:26:52 -0000 1.37
+++ library/sparse_bitset.m 19 May 2011 12:58:20 -0000
@@ -137,7 +137,7 @@
% only `X'. Takes O(rep_size(Set)) time and space.
%
:- func insert(sparse_bitset(T), T) = sparse_bitset(T) <= enum(T).
-:- pred insert(sparse_bitset(T)::in, T::in, sparse_bitset(T)::out)
+:- pred insert(T::in, sparse_bitset(T)::in, sparse_bitset(T)::out)
is det <= enum(T).
% `insert_list(Set, X)' returns the union of `Set' and the set containing
@@ -145,14 +145,14 @@
% more efficient.
%
:- func insert_list(sparse_bitset(T), list(T)) = sparse_bitset(T) <= enum(T).
-:- pred insert_list(sparse_bitset(T)::in, list(T)::in, sparse_bitset(T)::out)
+:- pred insert_list(list(T)::in, sparse_bitset(T)::in, sparse_bitset(T)::out)
is det <= enum(T).
% `delete(Set, X)' returns the difference of `Set' and the set containing
% only `X'. Takes O(rep_size(Set)) time and space.
%
:- func delete(sparse_bitset(T), T) = sparse_bitset(T) <= enum(T).
-:- pred delete(sparse_bitset(T)::in, T::in, sparse_bitset(T)::out)
+:- pred delete(T::in, sparse_bitset(T)::in, sparse_bitset(T)::out)
is det <= enum(T).
% `delete_list(Set, X)' returns the difference of `Set' and the set
@@ -160,22 +160,22 @@
% `difference(Set, list_to_set(X))', but may be more efficient.
%
:- func delete_list(sparse_bitset(T), list(T)) = sparse_bitset(T) <= enum(T).
-:- pred delete_list(sparse_bitset(T)::in, list(T)::in, sparse_bitset(T)::out)
+:- pred delete_list(list(T)::in, sparse_bitset(T)::in, sparse_bitset(T)::out)
is det <= enum(T).
- % `remove(Set0, X, Set)' returns in `Set' the difference of `Set0'
+ % `remove(X, Set0, Set)' returns in `Set' the difference of `Set0'
% and the set containing only `X', failing if `Set0' does not contain `X'.
% Takes O(rep_size(Set)) time and space.
%
-:- pred remove(sparse_bitset(T)::in, T::in, sparse_bitset(T)::out)
+:- pred remove(T::in, sparse_bitset(T)::in, sparse_bitset(T)::out)
is semidet <= enum(T).
- % `remove_list(Set0, X, Set)' returns in `Set' the difference of `Set0'
+ % `remove_list(X, Set0, Set)' returns in `Set' the difference of `Set0'
% and the set containing all the elements of `X', failing if any element
% of `X' is not in `Set0'. Same as `subset(list_to_set(X), Set0),
% difference(Set0, list_to_set(X), Set)', but may be more efficient.
%
-:- pred remove_list(sparse_bitset(T)::in, list(T)::in, sparse_bitset(T)::out)
+:- pred remove_list(list(T)::in, sparse_bitset(T)::in, sparse_bitset(T)::out)
is semidet <= enum(T).
% `remove_leq(Set, X)' returns `Set' with all elements less than or equal
@@ -183,7 +183,7 @@
% elements of `Set' which are greater than `X'.
%
:- func remove_leq(sparse_bitset(T), T) = sparse_bitset(T) <= enum(T).
-:- pred remove_leq(sparse_bitset(T)::in, T::in, sparse_bitset(T)::out)
+:- pred remove_leq(T::in, sparse_bitset(T)::in, sparse_bitset(T)::out)
is det <= enum(T).
% `remove_gt(Set, X)' returns `Set' with all elements greater than `X'
@@ -191,14 +191,14 @@
% of `Set' which are less than or equal to `X'.
%
:- func remove_gt(sparse_bitset(T), T) = sparse_bitset(T) <= enum(T).
-:- pred remove_gt(sparse_bitset(T)::in, T::in, sparse_bitset(T)::out)
+:- pred remove_gt(T::in, sparse_bitset(T)::in, sparse_bitset(T)::out)
is det <= enum(T).
% `remove_least(Set0, X, 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'. Takes O(1) time and space.
%
-:- pred remove_least(sparse_bitset(T)::in, T::out, sparse_bitset(T)::out)
+:- pred remove_least(T::out, sparse_bitset(T)::in, sparse_bitset(T)::out)
is semidet <= enum(T).
% `union(SetA, SetB)' returns the union of `SetA' and `SetB'. The
@@ -409,6 +409,8 @@
init = sparse_bitset([]).
+init(init).
+
empty(init).
equal(X, X).
@@ -417,6 +419,8 @@
%-----------------------------------------------------------------------------%
+to_sorted_list(A, to_sorted_list(A)).
+
to_sorted_list(Set) = foldr(func(Elem, Acc0) = [Elem | Acc0], Set, []).
to_set(Set) = set.sorted_list_to_set(to_sorted_list(Set)).
@@ -666,6 +670,13 @@
make_singleton_set(A) = insert(init, A).
+singleton_set(make_singleton_set(A), A).
+
+%-----------------------------------------------------------------------------%
+
+insert(E, !Set) :-
+ !:Set = insert(!.Set, E).
+
insert(sparse_bitset(Set), Elem) =
sparse_bitset(insert_2(Set, enum.to_int(Elem))).
@@ -691,24 +702,39 @@
Set = [Data0 | insert_2(Rest, Index)]
).
+insert_list(List, !Set) :-
+ !:Set = insert_list(!.Set, List).
+
insert_list(Set, List) = union(list_to_set(List), Set).
%-----------------------------------------------------------------------------%
+delete(E, !Set) :-
+ !:Set = delete(!.Set, E).
+
delete(Set, Elem) = difference(Set, insert(init, Elem)).
+
+delete_list(List, !Set) :-
+ !:Set = delete_list(!.Set, List).
+
delete_list(Set, List) = difference(Set, list_to_set(List)).
-remove(Set0, Elem, Set) :-
- contains(Set0, Elem),
- Set = delete(Set0, Elem).
+%-----------------------------------------------------------------------------%
+
+remove(Elem, !Set) :-
+ contains(!.Set, Elem),
+ !:Set = delete(!.Set, Elem).
-remove_list(Set0, Elems, Set) :-
+remove_list(Elems, !Set) :-
list_to_set(Elems, ElemsSet),
- subset(ElemsSet, Set0),
- Set = difference(Set0, ElemsSet).
+ subset(ElemsSet, !.Set),
+ !:Set = difference(!.Set, ElemsSet).
%-----------------------------------------------------------------------------%
+remove_leq(E, !Set) :-
+ !:Set = remove_leq(!.Set, E).
+
remove_leq(sparse_bitset(Set), Elem) =
sparse_bitset(remove_leq_2(Set, enum.to_int(Elem))).
@@ -736,6 +762,9 @@
%-----------------------------------------------------------------------------%
+remove_gt(E, !Set) :-
+ !:Set = remove_gt(!.Set, E).
+
remove_gt(sparse_bitset(Set), Elem) =
sparse_bitset(remove_gt_2(Set, enum.to_int(Elem))).
@@ -763,7 +792,7 @@
%-----------------------------------------------------------------------------%
-remove_least(sparse_bitset(Set0), Elem, sparse_bitset(Set)) :-
+remove_least(Elem, sparse_bitset(Set0), sparse_bitset(Set)) :-
Set0 = [First | Rest],
Bits0 = First ^ bits,
Offset = First ^ offset,
@@ -810,6 +839,8 @@
%-----------------------------------------------------------------------------%
+list_to_set(A, list_to_set(A)).
+
list_to_set(List) =
sparse_bitset(list_to_set_2(List, [])).
@@ -862,6 +893,8 @@
%-----------------------------------------------------------------------------%
+sorted_list_to_set(A, sorted_list_to_set(A)).
+
sorted_list_to_set(L) = sparse_bitset(sorted_list_to_set_2(L)).
:- func sorted_list_to_set_2(list(T)) = bitset_impl <= enum(T).
@@ -973,6 +1006,8 @@
rest([_ | Rest]) = Rest.
+union(A, B, union(A, B)).
+
union(sparse_bitset(Set1), sparse_bitset(Set2)) =
sparse_bitset(union_2(Set1, Set2)).
@@ -999,6 +1034,8 @@
%-----------------------------------------------------------------------------%
+intersect(A, B, intersect(A, B)).
+
intersect(sparse_bitset(Set1), sparse_bitset(Set2)) =
sparse_bitset(intersect_2(Set1, Set2)).
@@ -1030,6 +1067,8 @@
%-----------------------------------------------------------------------------%
+difference(A, B, difference(A, B)).
+
difference(sparse_bitset(Set1), sparse_bitset(Set2)) =
sparse_bitset(difference_2(Set1, Set2)).
@@ -1101,33 +1140,5 @@
make_bitset_elem(Offset, Bits) = bitset_elem(Offset, Bits).
%-----------------------------------------------------------------------------%
-
-init(init).
-
-singleton_set(make_singleton_set(A), A).
-
-insert(A, B, insert(A, B)).
-
-insert_list(A, B, insert_list(A, B)).
-
-delete(A, B, delete(A, B)).
-
-delete_list(A, B, delete_list(A, B)).
-
-remove_leq(A, B, remove_leq(A, B)).
-
-remove_gt(A, B, remove_gt(A, B)).
-
-list_to_set(A, list_to_set(A)).
-
-to_sorted_list(A, to_sorted_list(A)).
-
-sorted_list_to_set(A, sorted_list_to_set(A)).
-
-union(A, B, union(A, B)).
-
-intersect(A, B, intersect(A, B)).
-
-difference(A, B, difference(A, B)).
-
+:- end_module sparse_bitset.
%-----------------------------------------------------------------------------%
Index: tests/hard_coded/bitset_tester.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/bitset_tester.m,v
retrieving revision 1.6
diff -u -r1.6 bitset_tester.m
--- tests/hard_coded/bitset_tester.m 6 May 2011 05:03:29 -0000 1.6
+++ tests/hard_coded/bitset_tester.m 19 May 2011 12:28:49 -0000
@@ -135,7 +135,7 @@
delete_list(SetA, List) - set__delete_list(SetB, List)).
remove(SetA0 - SetB0, Elem) = Result :-
- ( remove(SetA0, Elem, SetA1) ->
+ ( remove(Elem, SetA0, SetA1) ->
( remove(Elem, SetB0, SetB1) ->
SetA = SetA1,
SetB = SetB1
@@ -150,7 +150,7 @@
Result = check("remove", SetA0 - SetB0, SetA - SetB).
remove_list(SetA0 - SetB0, List) = Result :-
- ( remove_list(SetA0, List, SetA1) ->
+ ( remove_list(List, SetA0, SetA1) ->
( set__remove_list(List, SetB0, SetB1) ->
SetA = SetA1,
SetB = SetB1
@@ -263,7 +263,7 @@
%-----------------------------------------------------------------------------%
remove_least(SetA0 - SetB0, Least, SetA - SetB) :-
- ( remove_least(SetA0, LeastA, SetA1) ->
+ ( remove_least(LeastA, SetA0, SetA1) ->
( remove_least(LeastB, SetB0, SetB1) ->
( LeastA = LeastB ->
SetA = SetA1,
Index: tests/hard_coded/pprint_test.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/pprint_test.m,v
retrieving revision 1.3
diff -u -r1.3 pprint_test.m
--- tests/hard_coded/pprint_test.m 5 May 2011 03:59:00 -0000 1.3
+++ tests/hard_coded/pprint_test.m 19 May 2011 12:29:22 -0000
@@ -36,8 +36,8 @@
io__nl,
{ Set0 = sparse_bitset__init },
- { sparse_bitset__insert(Set0, 42, Set1) },
- { sparse_bitset__insert(Set1, 84, Set2) },
+ { sparse_bitset__insert(42, Set0, Set1) },
+ { sparse_bitset__insert(84, Set1, Set2) },
pprint__write(line_length, to_doc(Set1)),
io__nl,
pprint__write(line_length, to_doc(Set2)),
Index: tests/valid/loop_inv_bug.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/valid/loop_inv_bug.m,v
retrieving revision 1.1
diff -u -r1.1 loop_inv_bug.m
--- tests/valid/loop_inv_bug.m 7 Feb 2005 07:56:54 -0000 1.1
+++ tests/valid/loop_inv_bug.m 19 May 2011 12:27:30 -0000
@@ -22,6 +22,6 @@
:- implementation.
foo(Var, TrueVars0, FalseVars0) :-
- sparse_bitset.remove_leq(TrueVars0, Var, TrueVars),
- sparse_bitset.remove_leq(FalseVars0, Var, FalseVars),
+ sparse_bitset.remove_leq(Var, TrueVars0, TrueVars),
+ sparse_bitset.remove_leq(Var, FalseVars0, FalseVars),
foo(Var, TrueVars, FalseVars).
--------------------------------------------------------------------------
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