--
-- Version: @(#)sets.ada 1.3  Date: 10/19/84
--
--
-- Author:  Bryce Bardin
--          Ada Projects Section
--          Software Engineering Division
--          Ground Systems Group
--          Hughes Aircraft Company
--          Fullerton, CA
--
-- This is a highly portable implementation of sets in Ada.
--
-- N. B.:  Vendors are invited to supply listings which demonstrate
-- the quality of the code generated.
--
generic
    type Element is (<>);
    with function Image (E : Element) return String is Element'Image;
package Sets is

    type Set is private;
    -- A set of elements.

    Empty_Set : constant Set;
    -- The set of no elements.

    Full_Set : constant Set;
    -- The set of all elements.

    function "and" (Left, Right : Set) return Set;
    -- Returns the conjunction (intersection) of two sets.
    -- Usage:  S1 and S2

    function "or" (Left, Right : Set) return Set;
    -- Returns the inclusive disjunction (union) of two sets.
    -- Usage:  S1 or S2

    function "xor" (Left, Right : Set) return Set;
    -- Returns the exclusive disjunction of two sets.
    -- Usage:  S1 xor S2

    function "not" (Right : Set) return Set;
    -- Returns the negation (complement) of a set, i.e., the set of
    -- all elements not in Right.
    -- Usage:  not S

    function "-" (Left, Right : Set) return Set;
    -- Returns the difference of two sets, i.e., the set of elements
    -- in Left which are not in Right.
    -- Usage:  S1 - S2

    function "+" (Left : Element; Right : Set) return Set;
    -- Adds an element to a set.
    -- Returns the union (or) of an element with a set.
    -- Usage:  E + S

    function "+" (Left : Set; Right : Element) return Set;
    -- Adds an element to a set.
    -- Returns the union (or) of an element with a set.
    -- Usage:  S + E

    function "+" (Right : Element) return Set;
    -- Makes an element into a Set.
    -- Returns the union of the element with the Empty_Set.
    -- Usage:  + E

    function "+" (Left, Right : Element) return Set;
    -- Combines two elements into a Set.
    -- Returns the union (or) of two elements with the Empty_Set.
    -- Usage:  E1 + E2

    function "-" (Left : Set; Right : Element) return Set;
    -- Deletes an element from a set, i.e., removes it from the set
    -- if it is currently a member of the set, otherwise it returns
    -- the original set.
    -- Usage:  S - E

    -- This function is predefined:
    -- function "=" (Left, Right : Set) return Boolean;
    -- Tests whether Left is identical to Right.
    -- Usage: S1 = S2

    function "<=" (Left, Right : Set) return Boolean;
    -- Tests whether Left is contained in Right, i.e., whether Left
    -- is a subset of Right.
    -- Usage:  S1 <= S2

    function Is_Member (S : Set; E : Element) return Boolean;
    -- Tests an element for membership in a set.
    -- Returns true if an element is in a set.
    -- Usage:  Is_Member (S, E)

    procedure Put (S : Set);
    -- Prints a set.
    -- Usage:  Put (S)

private

    type Set is array (Element) of Boolean;
    -- A set of elements.

    Empty_Set : constant Set := (Element => False);
    -- The set of no elements.

    Full_Set : constant Set := (Element => True);
    -- The set of all elements.

    pragma Inline ("and");
    pragma Inline ("or");
    pragma Inline ("xor");
    pragma Inline ("not");
    pragma Inline ("-");
    pragma Inline ("+");
    pragma Inline ("<=");
    pragma Inline (Is_Member);

end Sets;