7fd59977 |
1 | -- File: TCollection_Set.cdl |
2 | -- Created: Tue Mar 2 11:06:03 1993 |
3 | -- Author: Remi LEQUETTE |
4 | -- <rle@phylox> |
5 | ---Copyright: Matra Datavision 1993 |
6 | |
7 | |
8 | generic class Set from TCollection (Item as any) |
9 | |
10 | ---Purpose: A set is an unordered collection of items without |
11 | -- duplications. To test for duplications the operators == and != |
12 | -- are used on the items. |
13 | -- Use a SetIterator to explore a Set. |
14 | -- Warning |
15 | -- A set generates the same result as a map. A map is |
16 | -- more effective; therefore it is advisable to use maps instead of sets. |
17 | -- Set is a generic class which consists of Items, types of elements in a set. |
18 | raises |
19 | NoSuchObject from Standard |
20 | |
21 | private class SetList instantiates List from TCollection(Item); |
22 | |
23 | class SetIterator from TCollection |
24 | ---Purpose: Functions used for iterating the contents of a Set. |
25 | -- Note: an iterator class is automatically instantiated from |
26 | -- this generic class at the time of instantiation of a Set. |
27 | -- Warning |
28 | -- - A set is a non-ordered data structure. The order in |
29 | -- which entries of a set are explored by the iterator |
30 | -- depends on its contents, and changes when the set is edited. |
31 | -- - It is not recommended to modify the contents of a set |
32 | -- during iteration: the result is unpredictable. |
33 | |
34 | |
35 | raises NoSuchObject from Standard |
36 | is |
37 | Create returns SetIterator from TCollection; |
38 | ---Purpose: Creates an empty iterator for a Set; |
39 | -- use the function Initialize to define the set to explore;. |
40 | |
41 | Create(S : Set from TCollection) returns SetIterator from TCollection; |
42 | ---Purpose: Creates an iterator on the set <S>. |
43 | |
44 | Initialize(me : in out; S : Set from TCollection) |
45 | ---Purpose: Sets or resets the iterator on the set <S>. |
46 | is static; |
47 | |
48 | More(me) returns Boolean from Standard |
49 | ---Purpose: Returns True if there are other items. |
50 | ---C++: inline |
51 | is static; |
52 | |
53 | Next(me: in out) |
54 | ---Purpose: Positions the iterator to the next item. |
55 | ---C++: inline |
56 | is static; |
57 | |
58 | Value(me) returns any Item |
59 | raises NoSuchObject from Standard |
60 | ---Purpose: Returns the item value corresponding to the |
61 | -- current position of the iterator. |
62 | ---C++: return const & |
63 | ---C++: inline |
64 | is static; |
65 | |
66 | fields |
67 | myIterator : ListIteratorOfSetList; |
68 | |
69 | end SetIterator from TCollection; |
70 | |
71 | |
72 | is |
73 | |
74 | Create returns Set from TCollection; |
75 | ---Purpose: Creation of an empty set. |
76 | |
77 | Create(Other : Set from TCollection) |
78 | returns Set from TCollection |
79 | is private; |
80 | ---Purpose: Creates by copying an existing Set. |
81 | -- Warning: Prints a message when other is not empty. It is |
82 | -- recommanded to use Assign (operator =). |
83 | |
84 | Extent(me) returns Integer from Standard |
85 | ---Level: Public |
86 | ---Purpose: Returns the number of items in the set. |
87 | ---C++: inline |
88 | is static; |
89 | |
90 | IsEmpty(me) returns Boolean from Standard |
91 | ---Level: Public |
92 | ---Purpose: Returns True if the set is empty. i.e. |
93 | -- Extent() == 0. |
94 | ---C++: inline |
95 | is static; |
96 | |
97 | Clear(me : in out) |
98 | ---Level: Public |
99 | ---Purpose: Removes all items from the set. |
100 | ---C++: inline |
101 | is static; |
102 | |
103 | Add(me : in out; T : Item) returns Boolean from Standard |
104 | ---Level: Public |
105 | ---Purpose: Adds the item <T> in the set if it does not |
106 | -- already exist.Returns False if the item T already exists. |
107 | -- Example: |
108 | -- before |
109 | -- me = {a,b,c,d}, T = y |
110 | -- after |
111 | -- me = {a,b,c,d,y} returns True |
112 | is static; |
113 | |
114 | Remove(me : in out; T : Item) returns Boolean from Standard |
115 | ---Level: Public |
116 | ---Purpose: Removes the item <T> from the set. Returns True if |
117 | -- the item was in the set. |
118 | -- Example: |
119 | -- before |
120 | -- me = {a,b,c,d}, T = a |
121 | -- after |
122 | -- me = {b,c,d} returns True |
123 | is static; |
124 | |
125 | Union(me : in out; B : Set from TCollection) |
126 | ---Level: Public |
127 | ---Purpose: Add to <me> all the items of the set <B> |
128 | -- which are not in <me>. |
129 | -- Example: |
130 | -- before |
131 | -- me = {a,b,c}, B = {d,a,f} |
132 | -- after |
133 | -- me = {a,b,c,d,f}, B = {d,a,f} |
134 | is static; |
135 | |
136 | Intersection(me : in out; B : Set from TCollection) |
137 | ---Level: Public |
138 | ---Purpose: Removes from <me> all the items which are not in <B>. |
139 | -- Example: |
140 | -- before |
141 | -- me = {a,b,c}, B = {d,a,f} |
142 | -- after |
143 | -- me = {a}, B = {d,a,f} |
144 | is static; |
145 | |
146 | Difference(me : in out; B: Set from TCollection) |
147 | ---Level: Public |
148 | ---Purpose: Removes from <me> all the items which are in <B>. |
149 | -- Example: |
150 | -- before |
151 | -- me = {a,b,c}, B = {d,a,f} |
152 | -- after |
153 | -- me = {b,c}, B = {d,a,f} |
154 | is static; |
155 | |
156 | Contains(me; T : Item) returns Boolean from Standard |
157 | ---Level: Public |
158 | ---Purpose: Returns True if the item <T> is in the set. |
159 | is static; |
160 | |
161 | IsASubset(me; S : Set from TCollection) returns Boolean from Standard |
162 | ---Level: Public |
163 | ---Purpose: returns True if <S> is a subset of <me>. i.e. all |
164 | -- elements of <S> are in <me>. |
165 | is static; |
166 | |
167 | IsAProperSubset(me; S : Set from TCollection) |
168 | returns Boolean from Standard |
169 | ---Level: Public |
170 | ---Purpose: returns True if <S> is strictly contained in <me>. |
171 | -- i.e <S> is a subset and its extent is not equal to |
172 | -- the extent of <me>. |
173 | is static; |
174 | |
175 | fields |
176 | myItems : SetList; |
177 | |
178 | friends |
179 | class SetIterator from TCollection |
180 | |
181 | end Set from TCollection; |