1 ÏÕÖ×package body Discrete_Set is
 2 ÏÏ§
 3 ÏÏ§----------------------------------------------------------------------------
     §    -- function that returns the value in Set(Element)
     §       -- true if the element is a member of the set
     §       -- false if the element is not a member of the set
 4 ÏÏ§ÏÞßàfunction Is_Member (Set     : in Set_Type;  
 5 ÏÏ§ÏÏ§Ï                Element : in Element_Type) return Boolean is  
 6 ÏÏ§ÏÏ§begin
 7 ÏÏ§Â¹Ä¹¹Ïreturn Set(Element);
 8 ÏÏ§ÏÏ©end Is_Member;
 9 ÏÏ§
10 ÏÏ§----------------------------------------------------------------------------
     §    -- function that returns the union of the two sets
11 ÏÏ§ÏÞßàfunction "+" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
12 ÏÏ§ÏÏ§begin
     §  §           -- OR statement allows any element that is true in
     §  §           -- sets Left or Right to be returned
13 ÏÏ§Â¹Ä¹¹Ïreturn  Left or Right;
14 ÏÏ§ÏÏ©end "+";
15 ÏÏ§
16 ÏÏ§----------------------------------------------------------------------------
     §    -- function that adds an element Right to the set Left
17 ÏÏ§ÏÞßàfunction "+" (Left  : in Set_Type; 
18 ÏÏ§ÏÏ§Ï          Right : in Element_Type) return Set_Type is
19 ÏÏ§ÏÏ§ÏíÏResult : Set_Type;
20 ÏÏ§ÏÏ§begin
21 ÏÏ§ÏÏ¨¹¹ÏResult := Left;          -- assign the parameter set to Result
22 ÏÏ§ÏÏ¨¹¹ÏResult(Right) := True;   -- Add the new element to the set
23 ÏÏ§Â¹Ä¹¹Ïreturn Result;           -- return the set with the added element
24 ÏÏ§ÏÏ©end "+";
25 ÏÏ§
26 ÏÏ§----------------------------------------------------------------------------
     §    -- function that adds an element Left to the set Left
     §       -- the overloaded “+” has two functions that perform this task
     §       -- the parameter order doesn’t matter because of the two methods
27 ÏÏ§ÏÞßàfunction "+" (Left  : in Element_Type;
28 ÏÏ§ÏÏ§Ï          Right : in Set_Type) return Set_Type is
29 ÏÏ§ÏÏ§ÏíÏResult : Set_Type;
30 ÏÏ§ÏÏ§begin
31 ÏÏ§ÏÏ¨¹¹ÏResult := Right;        -- assign the parameter set to Result
32 ÏÏ§ÏÏ¨¹¹ÏResult(Left) := True;   -- Add the new element to the set
33 ÏÏ§Â¹Ä¹¹Ïreturn Result;          -- return the set with the added element
34 ÏÏ§ÏÏ©end "+";
35 ÏÏ§
36 ÏÏ§----------------------------------------------------------------------------
     §    -- function that returns the intersection of sets Left and Right
37 ÏÏ§ÏÞßàfunction "*" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
38 ÏÏ§ÏÏ§begin
     §  §           -- AND statement allows only elements that are true in both
     §  §           -- sets Left and Right to be returned
39 ÏÏ§Â¹Ä¹¹Ïreturn  Left and Right;
40 ÏÏ§ÏÏ©end "*";
41 ÏÏ§
42 ÏÏ§----------------------------------------------------------------------------
     §    -- function that returns the difference of sets Left and Right
43 ÏÏ§ÏÞßàfunction "-" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
44 ÏÏ§ÏÏ§begin
     §  §          -- AND NOT statement allows only elements that appear in Left but
     §  §          -- not in Right to be returned
45 ÏÏ§Â¹Ä¹¹Ïreturn Left and not Right;
46 ÏÏ§ÏÏ©end "-";
47 ÏÏ§
48 ÏÏ§----------------------------------------------------------------------------
     §    -- function that removes an element from the set 
49 ÏÏ§ÏÞßàfunction "-" (Left  : in Set_Type;
50 ÏÏ§ÏÏ§Ï          Right : in Element_Type) return Set_Type is
51 ÏÏ§ÏÏ§ÏíÏResult : Set_Type;
52 ÏÏ§ÏÏ§begin
53 ÏÏ§ÏÏ¨¹¹ÏResult := Left;           -- assign the parameter set to Result
54 ÏÏ§ÏÏ¨¹¹ÏResult(Right) := False;   -- Remove the element from the set
55 ÏÏ§Â¹Ä¹¹Ïreturn Result;            -- return the set with the element removed
56 ÏÏ§ÏÏ©end "-";
57 ÏÏ§
58 ÏÏ§----------------------------------------------------------------------------
     §    -- function that returns true if Left is a subset of Right
59 ÏÏ§ÏÞßàfunction "<=" (Left : in Set_Type; Right : in Set_Type) return Boolean is
60 ÏÏ§ÏÏ§ÏíÏIs_A_Subset : Boolean;
61 ÏÏ§ÏÏ§begin
     §  §   -- if Left is a subset of Right, the difference of Left and Right will
     §  §   -- be the empty set (meaning every element of Left will be in Right)
62 ÏÏ§ÏÏ¨¹¹ÏIs_A_Subset := (Left - Right) = Empty_Set;
63 ÏÏ§Â¹Ä¹¹Ïreturn Is_A_Subset;
64 ÏÏ§ÏÏ©end "<=";
65 ÏÏ§
66 ÏÏ§----------------------------------------------------------------------------
     §    -- function that returns True if Left is a proper subset of Right
     §    -- (a proper subset is subset of another set but not equal to the other set)
67 ÏÏ§ÏÞßàfunction "<" (Left : in Set_Type; Right : in Set_Type) return Boolean is
68 ÏÏ§ÏÏ§ÏíÏResult : Boolean;
69 ÏÏ§ÏÏ§begin
70 ÏÏ§ÏÏ¨¹³´if Left = Right then  -- If the sets are equal, not a proper subset
71 ÏÏ§ÏÏ§Ï6¾¹¹ÏResult := False;
72 ÏÏ§ÏÏ§Ïö´else
73 ÏÏ§ÏÏ§Ï¸¾¹¹ÏResult := Left <= Right;  -- If not equal, test for subset
74 ÏÏ§ÏÏ§ÏÈÏend if;                      -- using the function above
75 ÏÏ§Â¹Ä¹¹Ïreturn Result;
76 ÏÏ§ÏÏ©end "<";
77 ÏÏ§
78 ÏÏ§----------------------------------------------------------------------------
     §    -- function that returns True if Right is a subset of Left
79 ÏÏ§ÏÞßàfunction ">=" (Left : in Set_Type; Right : in Set_Type) return Boolean is
80 ÏÏ§ÏÏ§begin
81 ÏÏ§Â¹Ä¹¹Ïreturn  Right <= Left;   -- Reverse the order of the 
82 ÏÏ§ÏÏ§                         -- parameters and use the operation 
83 ÏÏ§ÏÏ§                         -- we've already written
84 ÏÏ§ÏÏ©end ">=";
85 ÏÏ§
86 ÏÏ§----------------------------------------------------------------------------
          -- function that returns True if Right is a proper subset of Left
87 ÏÏ§ÏÞßàfunction ">" (Left : in Set_Type; Right : in Set_Type) return Boolean is
88 ÏÏ§ÏÏ§begin
89 ÏÏ§Â¹Ä¹¹Ïreturn  Right < Left;     -- Reverse the order of the 
90 ÏÏ§ÏÏ§                          -- parameters and use the operation 
91 ÏÏ§ÏÏ§                          -- we've already written
92 ÏÏ§ÏÏ©end ">";
93 ÏÏ§
94 ÏÏ©end Discrete_Set;
95