[m-rev.] for review: set__intersect_list

Ralph Becket rafe at cs.mu.OZ.AU
Tue Dec 18 14:33:04 AEDT 2001


Zoltan Somogyi, Tuesday, 18 December 2001:
> 
> For review by anyone.
> 
> Estimated hours taken: 0.5
> Branches: main
> 
> library/set.m:
> library/set_ordlist.m:
> library/set_unordlist.m:
> 	Add a function for computing the intersection of a list of sets.
> 
> 	There is already code to compute the intersection of a set of sets,
> 	but there should be no need to convert a list to a set, which can
> 	involve an expensive sorting process, unless you want the set of sets
> 	for some other reason.
> 
> Zoltan.
> 
> cvs diff: Diffing library
> Index: library/set.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/library/set.m,v
> retrieving revision 1.58
> diff -u -b -r1.58 set.m
> --- library/set.m	2001/06/27 05:04:39	1.58
> +++ library/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: library/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
> --- library/set_ordlist.m	2001/04/24 03:59:13	1.14
> +++ library/set_ordlist.m	2001/11/18 09:36:17
> @@ -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) = S :-
> +	set_ordlist__power_intersect(Sets, S).
>  
>  %--------------------------------------------------------------------------%
>  
> Index: library/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
> --- library/set_unordlist.m	2001/04/24 03:59:13	1.19
> +++ library/set_unordlist.m	2001/11/18 09:37:15
> @@ -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) = S :-
> +	set_unordlist__power_intersect(Sets, S).

I think it's better to use the func versions when implementing funcs:

set_unordlist__intersect_list(Sets) =
	set_unordlist__power_intersect(Sets, S).

Otherwise that looks fine to me.

- Ralph
--------------------------------------------------------------------------
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