View source with formatted comments or as raw
    1/*  Part of SWI-Prolog
    2
    3    Author:        Jon Jagger
    4    E-mail:        J.R.Jagger@shu.ac.uk
    5    Copyright (c)  1993-2011, Jon Jagger
    6    All rights reserved.
    7
    8    Redistribution and use in source and binary forms, with or without
    9    modification, are permitted provided that the following conditions
   10    are met:
   11
   12    1. Redistributions of source code must retain the above copyright
   13       notice, this list of conditions and the following disclaimer.
   14
   15    2. Redistributions in binary form must reproduce the above copyright
   16       notice, this list of conditions and the following disclaimer in
   17       the documentation and/or other materials provided with the
   18       distribution.
   19
   20    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   21    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   22    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   23    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   24    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   25    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   26    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   27    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   28    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   29    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   30    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   31    POSSIBILITY OF SUCH DAMAGE.
   32*/
   33
   34:- module(oset,
   35          [ oset_is/1,
   36            oset_union/3,
   37            oset_int/3,
   38            oset_diff/3,
   39            oset_dint/2,
   40            oset_dunion/2,
   41            oset_addel/3,
   42            oset_delel/3,
   43            oset_power/2
   44          ]).   45:- autoload(library(lists), [reverse/2]).   46:- autoload(library(ordsets),
   47            [ is_ordset/1,
   48              ord_union/3,
   49              ord_intersection/3,
   50              ord_subtract/3,
   51              ord_add_element/3,
   52              ord_del_element/3,
   53              ord_union/2,
   54              ord_intersection/2
   55            ]).   56
   57/** <module> Ordered set manipulation
   58
   59This library defines set  operations  on   sets  represented  as ordered
   60lists. This current library is a   thin wrapper around library(ordsets).
   61Many of the  implementations  of   library(ordsets)  originate  from the
   62library.
   63
   64@author Jon Jagger
   65@deprecated Use the de-facto library(ordsets)
   66*/
   67
   68%!  oset_is(@OSet)
   69%
   70%   check that OSet in correct format (standard order)
   71%
   72%   @deprecated Use is_ordset/1 from library(ordsets)
   73
   74oset_is(OSet) :-
   75    is_ordset(OSet).
   76
   77%! oset_union(+OSet1, +OSet2, -Union)
   78%
   79%  Union is the union of OSet1 and OSet2.
   80%
   81%  @deprecated Use ord_union/3 from library(ordsets)
   82
   83oset_union(OSet1, OSet2, Union) :-
   84    ord_union(OSet1, OSet2, Union).
   85
   86%!  oset_int(+OSet1, +OSet2, -Int)
   87%
   88%   ordered set intersection
   89
   90oset_int(Set1, Set2, Intersection) :-
   91    ord_intersection(Set1, Set2, Intersection).
   92
   93%!  oset_diff(+InOSet, +NotInOSet, -Diff)
   94%
   95%   Ordered set difference
   96%
   97%   @deprecated Use ord_subtract/3 from library(ordsets)
   98
   99oset_diff(InOSet, NotInOSet, Diff) :-
  100    ord_subtract(InOSet, NotInOSet, Diff).
  101
  102%!  oset_dunion(+SetofSets, -DUnion)
  103%
  104%   Distributed union.
  105%
  106%   @deprecated Use ord_union/2 from library(ordsets)
  107
  108oset_dunion(SetofSets, DUnion) :-
  109    ord_union(SetofSets, DUnion).
  110
  111%!  oset_dint(+SetofSets, -DInt)
  112%
  113%   Distributed intersection.
  114%
  115%   @deprecated Use ord_intersection/2 from library(ordsets)
  116
  117oset_dint(SetofSets, DInt) :-
  118    ord_intersection(SetofSets, DInt).
  119
  120%!  oset_power(+Set, -PSet)
  121%
  122%   True when PSet is the powerset of Set. That is, Pset is a set of
  123%   all subsets of Set, where each subset is a proper ordered set.
  124
  125oset_power(S, PSet) :-
  126    reverse(S, R),
  127    pset(R, [[]], PSet0),
  128    sort(PSet0, PSet).
  129
  130% The powerset of a set  is  the  powerset   of  a  set  of one smaller,
  131% together with the set of one  smaller   where  each subset is extended
  132% with the new element.  Note that this produces the elements of the set
  133% in reverse order.  Hence the reverse in oset_power/2.
  134
  135pset([], PSet, PSet).
  136pset([H|T], PSet0, PSet) :-
  137    happ(PSet0, H, PSet1),
  138    pset(T, PSet1, PSet).
  139
  140happ([], _, []).
  141happ([S|Ss], H, [[H|S],S|Rest]) :-
  142    happ(Ss, H, Rest).
  143
  144%!  oset_addel(+Set, +El, -Add)
  145%
  146%   Ordered set element addition.
  147%
  148%   @deprecated Use ord_add_element/3 from library(ordsets)
  149
  150oset_addel(Set1, Element, Set2) :-
  151    ord_add_element(Set1, Element, Set2).
  152
  153%!  oset_delel(+Set, +El, -Del)
  154%
  155%   Ordered set element deletion.
  156%
  157%   @deprecated Use ord_del_element/3 from library(ordsets)
  158
  159oset_delel(Set, Element, NewSet) :-
  160    ord_del_element(Set, Element, NewSet)