[m-rev.] for review: set*__intersect_list

Zoltan Somogyi zs at cs.mu.OZ.AU
Tue Feb 19 19:40:31 AEDT 2002


library/set*.m:
	Add predicates for computing the intersection of a list of sets.

NEWS:
	Mention the new predicate in set.

Zoltan.

Index: ../NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.242
diff -u -b -r1.242 NEWS
--- ../NEWS	2002/02/15 08:23:53	1.242
+++ ../NEWS	2002/02/19 08:42:14
@@ -144,6 +144,9 @@
   existing versions in that they do not abort when called upon to deconstruct
   non-canonical terms, such as values of types with user-defined equality.
 
+* We've added a new predicate `intersect_list' in each of the modules
+  implementing sets in the Mercury standard library.
+
 * We've added a predicate version of `set__fold'.
 
 * We've added function versions of `builtin__unsafe_promise_unique',
cvs diff: Diffing .
Index: set.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/set.m,v
retrieving revision 1.58
diff -u -b -r1.58 set.m
--- set.m	2001/06/27 05:04:39	1.58
+++ set.m	2001/11/18 09:38:48
@@ -221,6 +221,11 @@
 
 :- func set__power_intersect(set(set(T))) = set(T).
 
+	% `set__intersect_list(A, B)' is true iff `B' is the intersection of
+	% all the sets in `A'
+
+:- func set__intersect_list(list(set(T))) = set(T).
+
 	% `set__difference(SetA, SetB, Set)' is true iff `Set' is the
 	% set containing all the elements of `SetA' except those that
 	% occur in `SetB'
@@ -373,6 +378,8 @@
 
 set__power_intersect(Sets, Set) :-
 	set_ordlist__power_intersect(Sets, Set).
+
+set__intersect_list(Sets) = set_ordlist__intersect_list(Sets).
 
 set__difference(SetA, SetB, Set) :-
 	set_ordlist__difference(SetA, SetB, Set).
Index: set_bbbtree.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/set_bbbtree.m,v
retrieving revision 1.17
diff -u -b -r1.17 set_bbbtree.m
--- set_bbbtree.m	2001/04/24 03:59:12	1.17
+++ set_bbbtree.m	2001/12/18 04:38:48
@@ -314,10 +314,10 @@
 % integer as an additional last argument. This integer is a ratio that is
 % used to measure how much larger one tree is allowed to be compared to the
 % other before some rotations are performed to rebalance them. These predicates
-% are currently not exported but it maybe useful to do so so that users are
-% able to influence the rebalancing process by specifying ratios.
+% are currently not exported but it maybe useful to do so to allow users to
+% influence the rebalancing process.
 %
-% NOTE :
+% NOTE:
 % The size of trees are measured in terms of number of elements and not height.
 % Also the fact that ratio is an integer seems counter intuitive but it should
 % be realized that this property is true at all levels of the tree. Hence the
@@ -887,6 +887,21 @@
 							Intersection0, Ratio),
 	set_bbbtree__power_intersect_r2(L, Intersection0, Intersection1, Ratio),
 	set_bbbtree__power_intersect_r2(R, Intersection1, Set, Ratio).
+
+:- func set_bbbtree__intersect_list(list(set_bbbtree(T))) = set_bbbtree(T).
+
+set_bbbtree__intersect_list([]) = set_bbbtree__init.
+set_bbbtree__intersect_list([Set | Sets]) =
+		set_bbbtree__intersect_list_r(Set, Sets, Ratio) :-
+	set_bbbtree__def_ratio(Ratio).
+
+:- func set_bbbtree__intersect_list_r(set_bbbtree(T), list(set_bbbtree(T)),
+	int) = set_bbbtree(T).
+
+set_bbbtree__intersect_list_r(Intersect, [], _Ratio) = Intersect.
+set_bbbtree__intersect_list_r(Intersect0, [Set | Sets], Ratio) = 
+		set_bbbtree__intersect_list_r(Intersect1, Sets, Ratio) :-
+	set_bbbtree__intersect_r(Intersect0, Set, Intersect1, Ratio).
 
 %------------------------------------------------------------------------------%
 
Index: set_ordlist.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/set_ordlist.m,v
retrieving revision 1.14
diff -u -b -r1.14 set_ordlist.m
--- set_ordlist.m	2001/04/24 03:59:13	1.14
+++ set_ordlist.m	2001/12/18 03:40:30
@@ -206,6 +206,11 @@
 :- func set_ordlist__power_intersect(set_ordlist(set_ordlist(T)))
 		= set_ordlist(T).
 
+	% `set_ordlist__intersect_list(A, B)' is true iff `B' is the
+	% intersection of all the sets in `A'.
+
+:- func set_ordlist__intersect_list(list(set_ordlist(T))) = set_ordlist(T).
+
 	% `set_ordlist__difference(SetA, SetB, Set)' is true iff `Set' is the
 	% set containing all the elements of `SetA' except those that
 	% occur in `SetB'.
@@ -418,6 +423,9 @@
 		set_ordlist__power_intersect(Ss, S1),
 		set_ordlist__intersect(S1, S0, S)
 	).
+
+set_ordlist__intersect_list(Sets) =
+	set_ordlist__power_intersect(Sets).
 
 %--------------------------------------------------------------------------%
 
Index: set_unordlist.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/set_unordlist.m,v
retrieving revision 1.19
diff -u -b -r1.19 set_unordlist.m
--- set_unordlist.m	2001/04/24 03:59:13	1.19
+++ set_unordlist.m	2001/12/18 03:40:40
@@ -211,6 +211,12 @@
 :- func set_unordlist__power_intersect(set_unordlist(set_unordlist(T)))
 		= set_unordlist(T).
 
+	% `set_unordlist__intersect_list(A, B)' is true iff `B' is the
+	% intersection of all the sets in `A'
+
+:- func set_unordlist__intersect_list(list(set_unordlist(T)))
+		= set_unordlist(T).
+
 	% `set_unordlist__difference(SetA, SetB, Set)' is true iff `Set' is the
 	% set containing all the elements of `SetA' except those that
 	% occur in `SetB'
@@ -359,6 +365,9 @@
 		set_unordlist__power_intersect(Ss, S1),
 		set_unordlist__intersect(S1, S0, S)
 	).
+
+set_unordlist__intersect_list(Sets) = 
+	set_unordlist__power_intersect(Sets).
 
 %--------------------------------------------------------------------------%
--------------------------------------------------------------------------
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