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
 7 ÏÏ§Â¹Ä¹¹Ïreturn Set(Element);   -- True if Element is in Set, False if it is not. Set is indexed by 
 8 ÏÏ§ÏÏ©end Is_Member;		     -- element names, and the value true is in each filled position.
 9 ÏÏ§
10 ÏÏ§----------------------------------------------------------------------------
11 ÏÏ§ÏÞßàfunction "+" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
12 ÏÏ§ÏÏ§begin
13 ÏÏ§Â¹Ä¹¹Ïreturn  Left or Right; -- Returns a set that holds all elements of both sets. Each element in
14 ÏÏ§ÏÏ©end "+";			     -- the sets will hold the value true.
15 ÏÏ§
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 at the index of the name of the
23 ÏÏ§Â¹Ä¹¹Ïreturn Result;	     -- element, setting that element to true. If the element is already
24 ÏÏ§ÏÏ©end "+";			     -- in the set, it will not be changed as it will already be set to true.
25 ÏÏ§
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;		-- Same as above, but the variable names are switched.
34 ÏÏ§ÏÏ©end "+";
35 ÏÏ§
36 ÏÏ§----------------------------------------------------------------------------
37 ÏÏ§ÏÞßàfunction "*" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
38 ÏÏ§ÏÏ§begin
39 ÏÏ§Â¹Ä¹¹Ïreturn  Left and Right;  -- Returns the intersection of the two sets, as if an element is in 
40 ÏÏ§ÏÏ©end "*";				 -- both sets, the ‘and’ will return true.
41 ÏÏ§
42 ÏÏ§----------------------------------------------------------------------------
43 ÏÏ§ÏÞßàfunction "-" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
44 ÏÏ§ÏÏ§begin
45 ÏÏ§Â¹Ä¹¹Ïreturn Left and not Right;  -- Returns the difference of the two sets. If an element is in one, 
46 ÏÏ§ÏÏ©end "-";			-- and not the other, the Boolean will be true and not false, returning true
47 ÏÏ§
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;		  -- Sets the index of the element to false, thus removing it.
56 ÏÏ§ÏÏ©end "-";
57 ÏÏ§
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;  -- If the difference of the two sets is the empty
63 ÏÏ§Â¹Ä¹¹Ïreturn Is_A_Subset;				  -- set, it must be a subset.
64 ÏÏ§ÏÏ©end "<=";
65 ÏÏ§
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 ÏÏ§
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 ÏÏ§
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