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
      --loop through all elements of Set
      --check each element to see if it matches the Element
      --if at any point there is a matching element
        --set the return value to true
        --leave the loop
      --if nothing matches return false
 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
      --create a new set_Type to store all the accumulated elements
      --set the new set_type to left
      --loop through right
         --if the element does not match any of the elements in the new set_type
           --add the element to the new set
         --if there is a match ignore it and move to the next element in right
13 ÏÏ§Â¹Ä¹¹Ïreturn  Left or Right; --return the new set
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
21 ÏÏ§ÏÏ¨¹¹ÏResult := Left;
            --loop through result
        --if any element in result matches right
          --leave the loop
        --else add the element to result
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
31 ÏÏ§ÏÏ¨¹¹ÏResult := Right;
      --loop through result
        --if any element in result matches left
          --leave the loop
        --else add the element to result
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
      --create a new set
      --loop through the larger of the sets
        --loop through the other set
          --if the current element of the larger set matches any element of the smaller set
            --check the elements of the new set
            --if any of them do not match the newly found match
              --add the element to the new set
39 ÏÏ§Â¹Ä¹¹Ïreturn  newSet;
40 ÏÏ§ÏÏ©end "*";
41 ÏÏ§
42 ÏÏ§----------------------------------------------------------------------------
43 ÏÏ§ÏÞßàfunction "-" (Left : in Set_Type;  Right : in Set_Type) return Set_Type is
44 ÏÏ§ÏÏ§begin
      --loop through left
        --loop through right
          --if the element in left matches the element in right
            --remove that element
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
53 ÏÏ§ÏÏ¨¹¹ÏResult := Left;
            --loop through result
              --if at any element of result matches right
                --remove that element
                --leave the loop
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
            --loop through left
              --loop through right
                --check to see if the element in left is also in right
                --if the element is not in right
                  --set Is_A_Subset to false
                  --leave the loop 
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
            --loop through all possible combinations of elements in left
        --loop through right
          --if at any point the combination in left cannot be found in right
            --set result to false
            --leave the loop
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
            --call “<=”(Right, Left);
            --return the result
84 ÏÏ§ÏÏ©end ">=";
85 ÏÏ§
86 ÏÏ§----------------------------------------------------------------------------
87 ÏÏ§ÏÞßàfunction ">" (Left : in Set_Type; Right : in Set_Type) return Boolean is
88 ÏÏ§ÏÏ§begin
            --call “<”(Right, Left);
      --return the result
92 ÏÏ§ÏÏ©end ">";
93 ÏÏ§
94 ÏÏ©end Discrete_Set;
95