Jonathan Spiker

   -- This package contains functions used to manipulate Set_Types and Element_Types
   -- and to compare Sets to each other.

 1 ÏÕÖ×package body Discrete_Set is
 2 ÏÏ§
   -- This function returns the Boolean value in the Set associated with the Element
   -- passed in which tells whether the element is in the set.
 3 ÏÏ§----------------------------------------------------------------------------
 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 ÏÏ§
   -- This function returns a “union” of all the Elements with true Boolean values
   -- in EITHER Set in the form of another Set
10 ÏÏ§----------------------------------------------------------------------------
11 ÏÏ§ÏÞßàfunction "+" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
12 ÏÏ§ÏÏ§begin
13 ÏÏ§Â¹Ä¹¹Ïreturn  Left or Right;
14 ÏÏ§ÏÏ©end "+";
15 ÏÏ§
   -- This function sets the Element in the Set that is passed in to true which
   -- adds the Element to the Set, the Set is the first parameter and the Element
   -- is the second parameter.
16 ÏÏ§----------------------------------------------------------------------------
17 ÏÏ§ÏÞßàfunction "+" (Left  : in Set_Type; 
18 ÏÏ§ÏÏ§Ï          Right : in Element_Type) return Set_Type is
19 ÏÏ§ÏÏ§ÏíÏResult : Set_Type;
20 ÏÏ§ÏÏ§begin
21 ÏÏ§ÏÏ¨¹¹ÏResult := Left;
22 ÏÏ§ÏÏ¨¹¹ÏResult(Right) := True;   -- Add the new element to the set
23 ÏÏ§Â¹Ä¹¹Ïreturn Result;
24 ÏÏ§ÏÏ©end "+";
25 ÏÏ§
   -- This function sets the Element in the Set that is passed in to true which
   -- adds the Element to the Set, the Element is the first parameter and the Set
   -- is the second parameter.
26 ÏÏ§----------------------------------------------------------------------------
27 ÏÏ§ÏÞßàfunction "+" (Left  : in Element_Type;
28 ÏÏ§ÏÏ§Ï          Right : in Set_Type) return Set_Type is
29 ÏÏ§ÏÏ§ÏíÏResult : Set_Type;
30 ÏÏ§ÏÏ§begin
31 ÏÏ§ÏÏ¨¹¹ÏResult := Right;
32 ÏÏ§ÏÏ¨¹¹ÏResult(Left) := True;   -- Add the new element to the set
33 ÏÏ§Â¹Ä¹¹Ïreturn Result;
34 ÏÏ§ÏÏ©end "+";
35 ÏÏ§

   -- This function returns an “intersection” of all the Elements with true Boolean
   -- values in BOTH Sets in the form of another set.
36 ÏÏ§----------------------------------------------------------------------------
37 ÏÏ§ÏÞßàfunction "*" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
38 ÏÏ§ÏÏ§begin
39 ÏÏ§Â¹Ä¹¹Ïreturn  Left and Right;
40 ÏÏ§ÏÏ©end "*";
41 ÏÏ§
   -- This function returns a Set of Boolean values that is in the first Set
   -- parameter but not in the second Set parameter.
42 ÏÏ§----------------------------------------------------------------------------
43 ÏÏ§ÏÞßàfunction "-" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
44 ÏÏ§ÏÏ§begin
45 ÏÏ§Â¹Ä¹¹Ïreturn Left and not Right;
46 ÏÏ§ÏÏ©end "-";
47 ÏÏ§
   -- This function sets the Element in the Set that is passed in to false which
   -- subtracts the Element from the Set.
48 ÏÏ§----------------------------------------------------------------------------
49 ÏÏ§ÏÞßàfunction "-" (Left  : in Set_Type;
50 ÏÏ§ÏÏ§Ï          Right : in Element_Type) return Set_Type is
51 ÏÏ§ÏÏ§ÏíÏResult : Set_Type;
52 ÏÏ§ÏÏ§begin
53 ÏÏ§ÏÏ¨¹¹ÏResult := Left;
54 ÏÏ§ÏÏ¨¹¹ÏResult(Right) := False;   -- Remove the element from the set
55 ÏÏ§Â¹Ä¹¹Ïreturn Result;
56 ÏÏ§ÏÏ©end "-";
57 ÏÏ§
   -- This function returns a Boolean that signifies whether the subtraction of
   -- one Set from another Set is equal to the Empty_Set which tells whether
   -- the second parameter is a subset of the first parameter.
58 ÏÏ§----------------------------------------------------------------------------
59 ÏÏ§ÏÞßàfunction "<=" (Left : in Set_Type; Right : in Set_Type) return Boolean is
60 ÏÏ§ÏÏ§ÏíÏIs_A_Subset : Boolean;
61 ÏÏ§ÏÏ§begin
62 ÏÏ§ÏÏ¨¹¹ÏIs_A_Subset := (Left - Right) = Empty_Set;
63 ÏÏ§Â¹Ä¹¹Ïreturn Is_A_Subset;
64 ÏÏ§ÏÏ©end "<=";
65 ÏÏ§

   -- This function returns a Boolean that signifies whether the second parameter
   -- is a proper subset (the first parameter has one or more values that the
   -- second parameter does not) of the first parameter by testing for equality first
   -- which would signify an improper subset and if they are not equal using the “<=”
   -- function to test if the second parameter is indeed a subset of the first
   -- parameter.
66 ÏÏ§----------------------------------------------------------------------------
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 ÏÏ§
   -- This function simply reverses what the <= function does by switching the
   -- parameter order and calling the <= function to see if the first parameter is
   -- a subset of the second parameter.
78 ÏÏ§----------------------------------------------------------------------------
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 ÏÏ§
   -- This function simply reverses what the < function does by switching the
   -- parameter order and calling the < function to see if the first parameter is
   -- a proper subset of the second parameter.
86 ÏÏ§----------------------------------------------------------------------------
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