1 package body Discrete_Set is
 2 
 3 ----------------------------------------------------------------------------
 4 Þfunction Is_Member (Set     : in Set_Type;  
 5                 Element : in Element_Type) return Boolean is  
 6 begin

	-- Returning Set(Element) will return either true or false, depending
	-- on if the element is there or not.

 7 return Set(Element);
 8 end Is_Member;
 9 
10 ----------------------------------------------------------------------------
11 function "+" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
12 begin

-- Returning Left or Right returns a set that is the union of the two 
-- sets, which is all elements in both sets.
13 return  Left or Right;
14 end "+";
15 
16 ----------------------------------------------------------------------------
17 function "+" (Left  : in Set_Type; 
18           Right : in Element_Type) return Set_Type is
19 Result : Set_Type;
20 begin

-- Result is set to the set type, and then the element, Right, that is
-- given to the function is set to true, which adds the element to the
-- set.
21 Result := Left;
22 Result(Right) := True;   -- Add the new element to the set
23 return Result;
24 end "+";
25 
26 ----------------------------------------------------------------------------
27 function "+" (Left  : in Element_Type;
28           Right : in Set_Type) return Set_Type is
29 Result : Set_Type;
30 begin

-- Result is set to the set type, and then the element, Left, that is 
-- given to the function is set to true, adding it to the set
31 Result := Right;
32 Result(Left) := True;   -- Add the new element to the set
33 return Result;
34 end "+";
35 
36 ----------------------------------------------------------------------------
37 function "*" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
38 begin

-- Returning Left and Right returns the intersection of the two sets
-- because the intersection is what elements are true in both Left
-- and in Right.  Only the elements that are true in both will be in 
-- the set that is returned
39 return  Left and Right;
40 end "*";
41 
42 ----------------------------------------------------------------------------
43 function "-" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
44 begin

-- Returning Left and not Right returns the difference of the two sets
-- because it will return the elements in Left that are true but are 
-- also false in Right.  
45 return Left and not Right;
46 end "-";
47 
48 ----------------------------------------------------------------------------

49 function "-" (Left  : in Set_Type;
50           Right : in Element_Type) return Set_Type is
51 Result : Set_Type;
52 begin
	
	-- This will remove the given element from the set, by changing the
	-- element, Right, in the set Result (which is equal to the given set)
	-- from true to false.
53 Result := Left;
54 Result(Right) := False;   -- Remove the element from the set
55 return Result;
56 end "-";
57 
58 ----------------------------------------------------------------------------
59 function "<=" (Left : in Set_Type; Right : in Set_Type) return Boolean is
60 Is_A_Subset : Boolean;
61 begin
	
	-- This will return true if Left is a subset of Right, because when the
	-- difference of the set Left and the set Right is equal to the Empty
	-- set (all false), Is_A_Subset is given the value true.  Otherwise,
	-- it is given false because it is not a subset.
62 Is_A_Subset := (Left - Right) = Empty_Set;
63 return Is_A_Subset;
64 end "<=";
65 
66 ----------------------------------------------------------------------------
67 function "<" (Left : in Set_Type; Right : in Set_Type) return Boolean is
68 Result : Boolean;
69 begin
	
	-- This checks whether the two sets are equal, because as described 
	-- below, if the elements in each set are equal, then it is not a 
	-- proper subset.
70 if Left = Right then  -- If the sets are equal, not a proper subset
71 Result := False;
	
	-- This calls the subset function from above to get a value of true or
	-- false to store in Result, which is returned.
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 ----------------------------------------------------------------------------
79 function ">=" (Left : in Set_Type; Right : in Set_Type) return Boolean is
80 begin

	-- This switches where Left and Right are, causing it to work the same 
	-- as the previous functions, but putting Right where Left is and Left
	-- where Right is.
81 return  Right <= Left;   -- Reverse the order of the 
82                          -- parameters and use the operation 
83                          -- we've already written
84 end ">=";
85 
86 ----------------------------------------------------------------------------
87 function ">" (Left : in Set_Type; Right : in Set_Type) return Boolean is
88 begin

	-- This switches where Left and Right are, causing it to work the same 
	-- as the previous functions, but putting Right where Left is and Left
	-- where Right is.
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