1 package body Discrete_Set is
 2 
 3 ----------------------------------------------------------------------------
   -- Is_Member takes in the Set a Set_type, and the Element a Element_type.  
   -- It returns the set type of the element.

 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 ----------------------------------------------------------------------------
   -- “+” takes in the Left Set_Type, and the Right Set_Type.  It returns the
   -- set type of either Left or Right, so returning the union of Left and Right.

11 function "+" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
12 begin
13 return  Left or Right;
14 end "+";
15 
16 ----------------------------------------------------------------------------
   -- “+” takes in Left a Set_Type and Right a Element_Type. Result is set
   -- to the set type of Left, Then of that set elemenent Right is set to
   -- True, adding it to the set.  “+“ Returns the Set_type Result.

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 
26 ----------------------------------------------------------------------------
   -- “+” takes in Left a Element_Type and Right a Set_Type. Result is set
   -- to the set type of Right, Then of that set elemenent Left is set to
   -- True, adding it to the set.  “+“ Returns the Set_type Result.

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 
36 ----------------------------------------------------------------------------
   -- “*”takes in Left a Set_Type and Right a Set_Type.  It Returns Left and
   -- Right as a Set_type. So if set was A union B this would return A and B.

37 function "*" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
38 begin
39 return  Left and Right;
40 end "*";
41 
42 ----------------------------------------------------------------------------
   -- “-“ takes in Left a Set_Type and Right a Set_Type.  It Returns Left a 
   -- set_Type and not Right.  So if set was A union B this would return just A.

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 
48 ----------------------------------------------------------------------------
   -- “-“ takes in Left a Set_Type and Right a Set_Element_Type.  Result is set
   -- to the set type of Left, Then of that set elemenent Right is set to
   -- False, removing it from the set.  “-“ Returns the Set_type Result.

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 
58 ----------------------------------------------------------------------------
   -- “<=” takes in Left a Set_Type and Right a Set_Type.  Sets Is_ A_Subset to
   -- The Boolean of Left – Right equaling the Empty set, it then Returns 
   -- Is_A_Subset.

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 
66 ----------------------------------------------------------------------------
   -- “<” takes in Left a Set_Type and Right a Set_Type.  If the two are equal
   -- then it returns False.  Else it uses the Function above to see if rights a
   -- subset of the left. Returns Result.

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 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 ----------------------------------------------------------------------------
   -- “>=” takes in Left a Set_Type and Right a Set_Type.  Uses “<=”
   -- to determine if Right is a subset of Left.  Returns the Boolean of this 
   -- operation.

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 ----------------------------------------------------------------------------
   -- “>” takes in Left a Set_Type and Right a Set_Type.  It then reverses the order
   -- putting Right where left should be and Left where right should be and use the <
   -- Function.  This will determine if Left is a proper subset of Right.

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