Files
mercury/library/set.m
Fergus Henderson 23b3e9d352 Undo dylan's changes in the names of some library entities,
Estimated hours taken: 1.5

Undo dylan's changes in the names of some library entities,
by applying the following sed script

	s/term_atom/term__atom/g
	s/term_string/term__string/g
	s/term_integer/term__integer/g
	s/term_float/term__float/g
	s/term_context/term__context/g
	s/term_functor/term__functor/g
	s/term_variable/term__variable/g
	s/_term__/_term_/g
	s/std_util__bool_/bool__/g

to all the `.m' and `.pp' files in the compiler and library directories.
The reason for undoing these changes was to minimize incompatibilities
with 0.4 (and besides, the changes were not a really good idea in the first
place).

I also moved `bool' from std_util.m to a separate module.
The main reason for that change is to ensure that the `__' prefix is
only used when it genuinely represents a module qualifier.
(That's what dylan's changes were trying to acheive, but `term__'
does genuinely represent a module qualifier.)

library/bool.m:
	New file, containing stuff previously in std_util.m.
library/*.m:
	Apply sed script above;
	where appropriate, add `bool' to the list of imported modules.
1996-02-03 17:37:07 +00:00

244 lines
7.3 KiB
Mathematica

%---------------------------------------------------------------------------%
% Copyright (C) 1995 University of Melbourne.
% This file may only be copied under the terms of the GNU Library General
% Public License - see the file COPYING.LIB in the Mercury distribution.
%---------------------------------------------------------------------------%
% File: set.m.
% Main authors: conway, fjh, benyi.
% Stability: high.
% This module provides a set ADT.
% The implementation represents sets using unordered lists.
% This file just calls the equivalent predicates in set_unordlist.
%--------------------------------------------------------------------------%
:- module set.
:- interface.
:- import_module bool, list, std_util.
:- type set(T).
% `set__list_to_set(List, Set)' is true iff `Set' is the set
% containing only the members of `List'.
:- pred set__list_to_set(list(T), set(T)).
:- mode set__list_to_set(in, out) is det.
% `set__sorted_list_to_set(List, Set)' is true iff `Set' is the set
% containing only the members of `List'. `List' must be sorted.
:- pred set__sorted_list_to_set(list(T), set(T)).
:- mode set__sorted_list_to_set(in, out) is det.
% `set__to_sorted_list(Set, List)' is true iff `List' is the list
% of all the members of `Set', in sorted order.
:- pred set__to_sorted_list(set(T), list(T)).
:- mode set__to_sorted_list(in, out) is det.
% `set__init(Set)' is true iff `Set' is an empty set.
:- pred set__init(set(T)).
:- mode set__init(uo) is det.
% `set__singleton_set(Set, Elem)' is true iff `Set' is the set
% containing just the single element `Elem'.
:- pred set__singleton_set(set(T), T).
:- mode set__singleton_set(in, out) is semidet.
:- mode set__singleton_set(out, in) is det.
% `set__equal(SetA, SetB)' is true iff
% `SetA' and `SetB' contain the same elements.
:- pred set__equal(set(T), set(T)).
:- mode set__equal(in, in) is semidet.
:- pred set__empty(set(T)).
:- mode set__empty(in) is semidet.
% `set__subset(SetA, SetB)' is true iff `SetA' is a subset of `SetB'.
:- pred set__subset(set(T), set(T)).
:- mode set__subset(in, in) is semidet.
% `set__superset(SetA, SetB)' is true iff `SetA' is a
% superset of `SetB'.
:- pred set__superset(set(T), set(T)).
:- mode set__superset(in, in) is semidet.
% `set__member(X, Set)' is true iff `X' is a member of `Set'.
:- pred set__member(T, set(T)).
:- mode set__member(in, in) is semidet.
:- mode set__member(out, in) is nondet.
% `set_is_member(X, Set, Result)' returns
% `Result = yes' iff `X' is a member of `Set'.
:- pred set__is_member(T, set(T), bool).
:- mode set__is_member(in, in, out) is det.
% `set__insert(Set0, X, Set)' is true iff `Set' is the union of
% `Set0' and the set containing only `X'.
:- pred set__insert(set(T), T, set(T)).
:- mode set__insert(di, di, uo) is det.
:- mode set__insert(in, in, out) is det.
% `set__insert_list(Set0, Xs, Set)' is true iff `Set' is the union of
% `Set0' and the set containing only the members of `Xs'.
:- pred set__insert_list(set(T), list(T), set(T)).
:- mode set__insert_list(in, in, out) is det.
% `set__delete(Set0, X, 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__delete(set(T), T, set(T)).
:- mode set__delete(di, in, uo) is det.
:- mode set__delete(in, in, out) is det.
% `set__delete_list(Set0, Xs, Set)' is true iff `Set' is the relative
% complement of `Set0' and the set containing only the members of
% `Xs'.
:- pred set__delete_list(set(T), list(T), set(T)).
:- mode set__delete_list(in, in, out) is det.
% `set__remove(Set0, X, 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__remove(set(T), T, set(T)).
:- mode set__remove(in, in, out) is semidet.
% `set__remove_list(Set0, Xs, 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__remove_list(set(T), list(T), set(T)).
:- mode set__remove_list(in, in, out) is semidet.
:- pred set__remove_least(set(T), T, set(T)).
:- mode set__remove_least(in, out, out) is semidet.
% `set_union(SetA, SetB, Set)' is true iff `Set' is the union of
% `SetA' and `SetB'. If the sets are known to be of different
% sizes, then for efficiency make `SetA' the larger of the two.
:- pred set__union(set(T), set(T), set(T)).
:- mode set__union(in, in, out) is det.
% `set__power_union(A, B)' is true iff `B' is the union of
% all the sets in `A'
:- pred set__power_union(set(set(T)), set(T)).
:- mode set__power_union(in, out) is det.
% `set_intersect(SetA, SetB, Set)' is true iff `Set' is the
% intersection of `SetA' and `SetB'.
:- pred set__intersect(set(T), set(T), set(T)).
:- mode set__intersect(in, in, out) is det.
% `set__power_union(A, B)' is true iff `B' is the union of
% all the sets in `A'
:- pred set__power_intersect(set(set(T)), set(T)).
:- mode set__power_intersect(in, out) is det.
% `set__difference(SetA, SetB, Set)' is true iff `Set' is the
% set containing all the elements of `SetA' except those that
% occur in `SetB'
:- pred set__difference(set(T), set(T), set(T)).
:- mode set__difference(in, in, out) is det.
%--------------------------------------------------------------------------%
:- implementation.
:- import_module set_unordlist.
:- type set(T) == set_unordlist(T).
set__list_to_set(List, Set) :-
set_unordlist__list_to_set(List, Set).
set__sorted_list_to_set(List, Set) :-
set_unordlist__sorted_list_to_set(List, Set).
set__to_sorted_list(Set, List) :-
set_unordlist__to_sorted_list(Set, List).
set__insert_list(Set0, List, Set) :-
set_unordlist__insert_list(Set0, List, Set).
set__insert(Set0, X, Set) :-
set_unordlist__insert(Set0, X, Set).
set__init(Set) :-
set_unordlist__init(Set).
set__singleton_set(Set, X) :-
set_unordlist__singleton_set(Set, X).
set__equal(SetA, SetB) :-
set_unordlist__equal(SetA, SetB).
set__empty(Set) :-
set_unordlist__empty(Set).
set__subset(SetA, SetB) :-
set_unordlist__subset(SetA, SetB).
set__superset(SetA, SetB) :-
set_unordlist__superset(SetA, SetB).
set__member(X, Set) :-
set_unordlist__member(X, Set).
set__is_member(X, Set, Result) :-
set_unordlist__is_member(X, Set, Result).
set__delete_list(Set0, List, Set) :-
set_unordlist__delete_list(Set0, List, Set).
set__delete(Set0, X, Set) :-
set_unordlist__delete(Set0, X, Set).
set__remove_list(Set0, List, Set) :-
set_unordlist__remove_list(Set0, List, Set).
set__remove(Set0, X, Set) :-
set_unordlist__remove(Set0, X, Set).
set__remove_least(Set0, X, Set) :-
set_unordlist__remove_least(Set0, X, Set).
set__union(SetA, SetB, Set) :-
set_unordlist__union(SetA, SetB, Set).
set__power_union(Sets, Set) :-
set_unordlist__power_union(Sets, Set).
set__intersect(SetA, SetB, Set) :-
set_unordlist__intersect(SetA, SetB, Set).
set__power_intersect(Sets, Set) :-
set_unordlist__power_intersect(Sets, Set).
set__difference(SetA, SetB, Set) :-
set_unordlist__difference(SetA, SetB, Set).
%--------------------------------------------------------------------------%
%--------------------------------------------------------------------------%