annotate gcc/ada/libgnat/a-coormu.ads @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT LIBRARY COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- A D A . C O N T A I N E R S . O R D E R E D _ M U L T I S E T S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 2004-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- This unit was originally developed by Matthew J Heaney. --
kono
parents:
diff changeset
28 ------------------------------------------------------------------------------
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 -- The ordered multiset container is similar to the ordered set, but with the
kono
parents:
diff changeset
31 -- difference that multiple equivalent elements are allowed. It also provides
kono
parents:
diff changeset
32 -- additional operations, to iterate over items that are equivalent.
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 private with Ada.Containers.Red_Black_Trees;
kono
parents:
diff changeset
35 private with Ada.Finalization;
kono
parents:
diff changeset
36 private with Ada.Streams;
kono
parents:
diff changeset
37 with Ada.Iterator_Interfaces;
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 generic
kono
parents:
diff changeset
40 type Element_Type is private;
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 with function "<" (Left, Right : Element_Type) return Boolean is <>;
kono
parents:
diff changeset
43 with function "=" (Left, Right : Element_Type) return Boolean is <>;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 package Ada.Containers.Ordered_Multisets is
kono
parents:
diff changeset
46 pragma Annotate (CodePeer, Skip_Analysis);
kono
parents:
diff changeset
47 pragma Preelaborate;
kono
parents:
diff changeset
48 pragma Remote_Types;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 function Equivalent_Elements (Left, Right : Element_Type) return Boolean;
kono
parents:
diff changeset
51 -- Returns False if Left is less than Right, or Right is less than Left;
kono
parents:
diff changeset
52 -- otherwise, it returns True.
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 type Set is tagged private
kono
parents:
diff changeset
55 with Constant_Indexing => Constant_Reference,
kono
parents:
diff changeset
56 Default_Iterator => Iterate,
kono
parents:
diff changeset
57 Iterator_Element => Element_Type;
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 pragma Preelaborable_Initialization (Set);
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 type Cursor is private;
kono
parents:
diff changeset
62 pragma Preelaborable_Initialization (Cursor);
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 Empty_Set : constant Set;
kono
parents:
diff changeset
65 -- The default value for set objects declared without an explicit
kono
parents:
diff changeset
66 -- initialization expression.
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 No_Element : constant Cursor;
kono
parents:
diff changeset
69 -- The default value for cursor objects declared without an explicit
kono
parents:
diff changeset
70 -- initialization expression.
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 function Has_Element (Position : Cursor) return Boolean;
kono
parents:
diff changeset
73 -- Equivalent to Position /= No_Element
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 package Set_Iterator_Interfaces is new
kono
parents:
diff changeset
76 Ada.Iterator_Interfaces (Cursor, Has_Element);
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 function "=" (Left, Right : Set) return Boolean;
kono
parents:
diff changeset
79 -- If Left denotes the same set object as Right, then equality returns
kono
parents:
diff changeset
80 -- True. If the length of Left is different from the length of Right, then
kono
parents:
diff changeset
81 -- it returns False. Otherwise, set equality iterates over Left and Right,
kono
parents:
diff changeset
82 -- comparing the element of Left to the element of Right using the equality
kono
parents:
diff changeset
83 -- operator for elements. If the elements compare False, then the iteration
kono
parents:
diff changeset
84 -- terminates and set equality returns False. Otherwise, if all elements
kono
parents:
diff changeset
85 -- compare True, then set equality returns True.
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 function Equivalent_Sets (Left, Right : Set) return Boolean;
kono
parents:
diff changeset
88 -- Similar to set equality, but with the difference that elements are
kono
parents:
diff changeset
89 -- compared for equivalence instead of equality.
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 function To_Set (New_Item : Element_Type) return Set;
kono
parents:
diff changeset
92 -- Constructs a set object with New_Item as its single element
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 function Length (Container : Set) return Count_Type;
kono
parents:
diff changeset
95 -- Returns the total number of elements in Container
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 function Is_Empty (Container : Set) return Boolean;
kono
parents:
diff changeset
98 -- Returns True if Container.Length is 0
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 procedure Clear (Container : in out Set);
kono
parents:
diff changeset
101 -- Deletes all elements from Container
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 function Element (Position : Cursor) return Element_Type;
kono
parents:
diff changeset
104 -- If Position equals No_Element, then Constraint_Error is raised.
kono
parents:
diff changeset
105 -- Otherwise, function Element returns the element designed by Position.
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 procedure Replace_Element
kono
parents:
diff changeset
108 (Container : in out Set;
kono
parents:
diff changeset
109 Position : Cursor;
kono
parents:
diff changeset
110 New_Item : Element_Type);
kono
parents:
diff changeset
111 -- If Position equals No_Element, then Constraint_Error is raised. If
kono
parents:
diff changeset
112 -- Position is associated with a set different from Container, then
kono
parents:
diff changeset
113 -- Program_Error is raised. If New_Item is equivalent to the element
kono
parents:
diff changeset
114 -- designated by Position, then if Container is locked (element tampering
kono
parents:
diff changeset
115 -- has been attempted), Program_Error is raised; otherwise, the element
kono
parents:
diff changeset
116 -- designated by Position is assigned the value of New_Item. If New_Item is
kono
parents:
diff changeset
117 -- not equivalent to the element designated by Position, then if the
kono
parents:
diff changeset
118 -- container is busy (cursor tampering has been attempted), Program_Error
kono
parents:
diff changeset
119 -- is raised; otherwise, the element designed by Position is assigned the
kono
parents:
diff changeset
120 -- value of New_Item, and the node is moved to its new position (in
kono
parents:
diff changeset
121 -- canonical insertion order).
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 procedure Query_Element
kono
parents:
diff changeset
124 (Position : Cursor;
kono
parents:
diff changeset
125 Process : not null access procedure (Element : Element_Type));
kono
parents:
diff changeset
126 -- If Position equals No_Element, then Constraint_Error is
kono
parents:
diff changeset
127 -- raised. Otherwise, it calls Process with the element designated by
kono
parents:
diff changeset
128 -- Position as the parameter. This call locks the container, so attempts to
kono
parents:
diff changeset
129 -- change the value of the element while Process is executing (to "tamper
kono
parents:
diff changeset
130 -- with elements") will raise Program_Error.
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 type Constant_Reference_Type
kono
parents:
diff changeset
133 (Element : not null access constant Element_Type) is private
kono
parents:
diff changeset
134 with Implicit_Dereference => Element;
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 function Constant_Reference
kono
parents:
diff changeset
137 (Container : aliased Set;
kono
parents:
diff changeset
138 Position : Cursor) return Constant_Reference_Type;
kono
parents:
diff changeset
139 pragma Inline (Constant_Reference);
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 procedure Assign (Target : in out Set; Source : Set);
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 function Copy (Source : Set) return Set;
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 procedure Move (Target : in out Set; Source : in out Set);
kono
parents:
diff changeset
146 -- If Target denotes the same object as Source, the operation does
kono
parents:
diff changeset
147 -- nothing. If either Target or Source is busy (cursor tampering is
kono
parents:
diff changeset
148 -- attempted), then it raises Program_Error. Otherwise, Target is cleared,
kono
parents:
diff changeset
149 -- and the nodes from Source are moved (not copied) to Target (so Source
kono
parents:
diff changeset
150 -- becomes empty).
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 procedure Insert
kono
parents:
diff changeset
153 (Container : in out Set;
kono
parents:
diff changeset
154 New_Item : Element_Type;
kono
parents:
diff changeset
155 Position : out Cursor);
kono
parents:
diff changeset
156 -- Insert adds New_Item to Container, and returns cursor Position
kono
parents:
diff changeset
157 -- designating the newly inserted node. The node is inserted after any
kono
parents:
diff changeset
158 -- existing elements less than or equivalent to New_Item (and before any
kono
parents:
diff changeset
159 -- elements greater than New_Item). Note that the issue of where the new
kono
parents:
diff changeset
160 -- node is inserted relative to equivalent elements does not arise for
kono
parents:
diff changeset
161 -- unique-key containers, since in that case the insertion would simply
kono
parents:
diff changeset
162 -- fail. For a multiple-key container (the case here), insertion always
kono
parents:
diff changeset
163 -- succeeds, and is defined such that the new item is positioned after any
kono
parents:
diff changeset
164 -- equivalent elements already in the container.
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 procedure Insert
kono
parents:
diff changeset
167 (Container : in out Set;
kono
parents:
diff changeset
168 New_Item : Element_Type);
kono
parents:
diff changeset
169 -- Inserts New_Item in Container, but does not return a cursor designating
kono
parents:
diff changeset
170 -- the newly-inserted node.
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 -- TODO: include Replace too???
kono
parents:
diff changeset
173 --
kono
parents:
diff changeset
174 -- procedure Replace
kono
parents:
diff changeset
175 -- (Container : in out Set;
kono
parents:
diff changeset
176 -- New_Item : Element_Type);
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 procedure Exclude
kono
parents:
diff changeset
179 (Container : in out Set;
kono
parents:
diff changeset
180 Item : Element_Type);
kono
parents:
diff changeset
181 -- Deletes from Container all of the elements equivalent to Item
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 procedure Delete
kono
parents:
diff changeset
184 (Container : in out Set;
kono
parents:
diff changeset
185 Item : Element_Type);
kono
parents:
diff changeset
186 -- Deletes from Container all of the elements equivalent to Item. If there
kono
parents:
diff changeset
187 -- are no elements equivalent to Item, then it raises Constraint_Error.
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 procedure Delete
kono
parents:
diff changeset
190 (Container : in out Set;
kono
parents:
diff changeset
191 Position : in out Cursor);
kono
parents:
diff changeset
192 -- If Position equals No_Element, then Constraint_Error is raised. If
kono
parents:
diff changeset
193 -- Position is associated with a set different from Container, then
kono
parents:
diff changeset
194 -- Program_Error is raised. Otherwise, the node designated by Position is
kono
parents:
diff changeset
195 -- removed from Container, and Position is set to No_Element.
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 procedure Delete_First (Container : in out Set);
kono
parents:
diff changeset
198 -- Removes the first node from Container
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 procedure Delete_Last (Container : in out Set);
kono
parents:
diff changeset
201 -- Removes the last node from Container
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 procedure Union (Target : in out Set; Source : Set);
kono
parents:
diff changeset
204 -- If Target is busy (cursor tampering is attempted), the Program_Error is
kono
parents:
diff changeset
205 -- raised. Otherwise, it inserts each element of Source into
kono
parents:
diff changeset
206 -- Target. Elements are inserted in the canonical order for multisets, such
kono
parents:
diff changeset
207 -- that the elements from Source are inserted after equivalent elements
kono
parents:
diff changeset
208 -- already in Target.
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 function Union (Left, Right : Set) return Set;
kono
parents:
diff changeset
211 -- Returns a set comprising the all elements from Left and all of the
kono
parents:
diff changeset
212 -- elements from Right. The elements from Right follow the equivalent
kono
parents:
diff changeset
213 -- elements from Left.
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 function "or" (Left, Right : Set) return Set renames Union;
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 procedure Intersection (Target : in out Set; Source : Set);
kono
parents:
diff changeset
218 -- If Target denotes the same object as Source, the operation does
kono
parents:
diff changeset
219 -- nothing. If Target is busy (cursor tampering is attempted),
kono
parents:
diff changeset
220 -- Program_Error is raised. Otherwise, the elements in Target having no
kono
parents:
diff changeset
221 -- equivalent element in Source are deleted from Target.
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 function Intersection (Left, Right : Set) return Set;
kono
parents:
diff changeset
224 -- If Left denotes the same object as Right, then the function returns a
kono
parents:
diff changeset
225 -- copy of Left. Otherwise, it returns a set comprising the equivalent
kono
parents:
diff changeset
226 -- elements from both Left and Right. Items are inserted in the result set
kono
parents:
diff changeset
227 -- in canonical order, such that the elements from Left precede the
kono
parents:
diff changeset
228 -- equivalent elements from Right.
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 function "and" (Left, Right : Set) return Set renames Intersection;
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 procedure Difference (Target : in out Set; Source : Set);
kono
parents:
diff changeset
233 -- If Target is busy (cursor tampering is attempted), then Program_Error is
kono
parents:
diff changeset
234 -- raised. Otherwise, the elements in Target that are equivalent to
kono
parents:
diff changeset
235 -- elements in Source are deleted from Target.
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 function Difference (Left, Right : Set) return Set;
kono
parents:
diff changeset
238 -- Returns a set comprising the elements from Left that have no equivalent
kono
parents:
diff changeset
239 -- element in Right.
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 function "-" (Left, Right : Set) return Set renames Difference;
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 procedure Symmetric_Difference (Target : in out Set; Source : Set);
kono
parents:
diff changeset
244 -- If Target is busy, then Program_Error is raised. Otherwise, the elements
kono
parents:
diff changeset
245 -- in Target equivalent to elements in Source are deleted from Target, and
kono
parents:
diff changeset
246 -- the elements in Source not equivalent to elements in Target are inserted
kono
parents:
diff changeset
247 -- into Target.
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 function Symmetric_Difference (Left, Right : Set) return Set;
kono
parents:
diff changeset
250 -- Returns a set comprising the union of the elements from Target having no
kono
parents:
diff changeset
251 -- equivalent in Source, and the elements of Source having no equivalent in
kono
parents:
diff changeset
252 -- Target.
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 function "xor" (Left, Right : Set) return Set renames Symmetric_Difference;
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 function Overlap (Left, Right : Set) return Boolean;
kono
parents:
diff changeset
257 -- Returns True if Left contains an element equivalent to an element of
kono
parents:
diff changeset
258 -- Right.
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 function Is_Subset (Subset : Set; Of_Set : Set) return Boolean;
kono
parents:
diff changeset
261 -- Returns True if every element in Subset has an equivalent element in
kono
parents:
diff changeset
262 -- Of_Set.
kono
parents:
diff changeset
263
kono
parents:
diff changeset
264 function First (Container : Set) return Cursor;
kono
parents:
diff changeset
265 -- If Container is empty, the function returns No_Element. Otherwise, it
kono
parents:
diff changeset
266 -- returns a cursor designating the smallest element.
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 function First_Element (Container : Set) return Element_Type;
kono
parents:
diff changeset
269 -- Equivalent to Element (First (Container))
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 function Last (Container : Set) return Cursor;
kono
parents:
diff changeset
272 -- If Container is empty, the function returns No_Element. Otherwise, it
kono
parents:
diff changeset
273 -- returns a cursor designating the largest element.
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275 function Last_Element (Container : Set) return Element_Type;
kono
parents:
diff changeset
276 -- Equivalent to Element (Last (Container))
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 function Next (Position : Cursor) return Cursor;
kono
parents:
diff changeset
279 -- If Position equals No_Element or Last (Container), the function returns
kono
parents:
diff changeset
280 -- No_Element. Otherwise, it returns a cursor designating the node that
kono
parents:
diff changeset
281 -- immediately follows (as per the insertion order) the node designated by
kono
parents:
diff changeset
282 -- Position.
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 procedure Next (Position : in out Cursor);
kono
parents:
diff changeset
285 -- Equivalent to Position := Next (Position)
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 function Previous (Position : Cursor) return Cursor;
kono
parents:
diff changeset
288 -- If Position equals No_Element or First (Container), the function returns
kono
parents:
diff changeset
289 -- No_Element. Otherwise, it returns a cursor designating the node that
kono
parents:
diff changeset
290 -- immediately precedes (as per the insertion order) the node designated by
kono
parents:
diff changeset
291 -- Position.
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 procedure Previous (Position : in out Cursor);
kono
parents:
diff changeset
294 -- Equivalent to Position := Previous (Position)
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 function Find (Container : Set; Item : Element_Type) return Cursor;
kono
parents:
diff changeset
297 -- Returns a cursor designating the first element in Container equivalent
kono
parents:
diff changeset
298 -- to Item. If there is no equivalent element, it returns No_Element.
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 function Floor (Container : Set; Item : Element_Type) return Cursor;
kono
parents:
diff changeset
301 -- If Container is empty, the function returns No_Element. If Item is
kono
parents:
diff changeset
302 -- equivalent to elements in Container, it returns a cursor designating the
kono
parents:
diff changeset
303 -- first equivalent element. Otherwise, it returns a cursor designating the
kono
parents:
diff changeset
304 -- largest element less than Item, or No_Element if all elements are
kono
parents:
diff changeset
305 -- greater than Item.
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 function Ceiling (Container : Set; Item : Element_Type) return Cursor;
kono
parents:
diff changeset
308 -- If Container is empty, the function returns No_Element. If Item is
kono
parents:
diff changeset
309 -- equivalent to elements of Container, it returns a cursor designating the
kono
parents:
diff changeset
310 -- last equivalent element. Otherwise, it returns a cursor designating the
kono
parents:
diff changeset
311 -- smallest element greater than Item, or No_Element if all elements are
kono
parents:
diff changeset
312 -- less than Item.
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 function Contains (Container : Set; Item : Element_Type) return Boolean;
kono
parents:
diff changeset
315 -- Equivalent to Container.Find (Item) /= No_Element
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 function "<" (Left, Right : Cursor) return Boolean;
kono
parents:
diff changeset
318 -- Equivalent to Element (Left) < Element (Right)
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 function ">" (Left, Right : Cursor) return Boolean;
kono
parents:
diff changeset
321 -- Equivalent to Element (Right) < Element (Left)
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 function "<" (Left : Cursor; Right : Element_Type) return Boolean;
kono
parents:
diff changeset
324 -- Equivalent to Element (Left) < Right
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 function ">" (Left : Cursor; Right : Element_Type) return Boolean;
kono
parents:
diff changeset
327 -- Equivalent to Right < Element (Left)
kono
parents:
diff changeset
328
kono
parents:
diff changeset
329 function "<" (Left : Element_Type; Right : Cursor) return Boolean;
kono
parents:
diff changeset
330 -- Equivalent to Left < Element (Right)
kono
parents:
diff changeset
331
kono
parents:
diff changeset
332 function ">" (Left : Element_Type; Right : Cursor) return Boolean;
kono
parents:
diff changeset
333 -- Equivalent to Element (Right) < Left
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 procedure Iterate
kono
parents:
diff changeset
336 (Container : Set;
kono
parents:
diff changeset
337 Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
338 -- Calls Process with a cursor designating each element of Container, in
kono
parents:
diff changeset
339 -- order from Container.First to Container.Last.
kono
parents:
diff changeset
340
kono
parents:
diff changeset
341 procedure Reverse_Iterate
kono
parents:
diff changeset
342 (Container : Set;
kono
parents:
diff changeset
343 Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
344 -- Calls Process with a cursor designating each element of Container, in
kono
parents:
diff changeset
345 -- order from Container.Last to Container.First.
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 procedure Iterate
kono
parents:
diff changeset
348 (Container : Set;
kono
parents:
diff changeset
349 Item : Element_Type;
kono
parents:
diff changeset
350 Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
351 -- Call Process with a cursor designating each element equivalent to Item,
kono
parents:
diff changeset
352 -- in order from Container.Floor (Item) to Container.Ceiling (Item).
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 procedure Reverse_Iterate
kono
parents:
diff changeset
355 (Container : Set;
kono
parents:
diff changeset
356 Item : Element_Type;
kono
parents:
diff changeset
357 Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
358 -- Call Process with a cursor designating each element equivalent to Item,
kono
parents:
diff changeset
359 -- in order from Container.Ceiling (Item) to Container.Floor (Item).
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 function Iterate
kono
parents:
diff changeset
362 (Container : Set)
kono
parents:
diff changeset
363 return Set_Iterator_Interfaces.Reversible_Iterator'class;
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365 function Iterate
kono
parents:
diff changeset
366 (Container : Set;
kono
parents:
diff changeset
367 Start : Cursor)
kono
parents:
diff changeset
368 return Set_Iterator_Interfaces.Reversible_Iterator'class;
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370 generic
kono
parents:
diff changeset
371 type Key_Type (<>) is private;
kono
parents:
diff changeset
372
kono
parents:
diff changeset
373 with function Key (Element : Element_Type) return Key_Type;
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 with function "<" (Left, Right : Key_Type) return Boolean is <>;
kono
parents:
diff changeset
376
kono
parents:
diff changeset
377 package Generic_Keys is
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
kono
parents:
diff changeset
380 -- Returns False if Left is less than Right, or Right is less than Left;
kono
parents:
diff changeset
381 -- otherwise, it returns True.
kono
parents:
diff changeset
382
kono
parents:
diff changeset
383 function Key (Position : Cursor) return Key_Type;
kono
parents:
diff changeset
384 -- Equivalent to Key (Element (Position))
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 function Element (Container : Set; Key : Key_Type) return Element_Type;
kono
parents:
diff changeset
387 -- Equivalent to Element (Find (Container, Key))
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 procedure Exclude (Container : in out Set; Key : Key_Type);
kono
parents:
diff changeset
390 -- Deletes from Container any elements whose key is equivalent to Key
kono
parents:
diff changeset
391
kono
parents:
diff changeset
392 procedure Delete (Container : in out Set; Key : Key_Type);
kono
parents:
diff changeset
393 -- Deletes from Container any elements whose key is equivalent to
kono
parents:
diff changeset
394 -- Key. If there are no such elements, then it raises Constraint_Error.
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 function Find (Container : Set; Key : Key_Type) return Cursor;
kono
parents:
diff changeset
397 -- Returns a cursor designating the first element in Container whose key
kono
parents:
diff changeset
398 -- is equivalent to Key. If there is no equivalent element, it returns
kono
parents:
diff changeset
399 -- No_Element.
kono
parents:
diff changeset
400
kono
parents:
diff changeset
401 function Floor (Container : Set; Key : Key_Type) return Cursor;
kono
parents:
diff changeset
402 -- If Container is empty, the function returns No_Element. If Item is
kono
parents:
diff changeset
403 -- equivalent to the keys of elements in Container, it returns a cursor
kono
parents:
diff changeset
404 -- designating the first such element. Otherwise, it returns a cursor
kono
parents:
diff changeset
405 -- designating the largest element whose key is less than Item, or
kono
parents:
diff changeset
406 -- No_Element if all keys are greater than Item.
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 function Ceiling (Container : Set; Key : Key_Type) return Cursor;
kono
parents:
diff changeset
409 -- If Container is empty, the function returns No_Element. If Item is
kono
parents:
diff changeset
410 -- equivalent to the keys of elements of Container, it returns a cursor
kono
parents:
diff changeset
411 -- designating the last such element. Otherwise, it returns a cursor
kono
parents:
diff changeset
412 -- designating the smallest element whose key is greater than Item, or
kono
parents:
diff changeset
413 -- No_Element if all keys are less than Item.
kono
parents:
diff changeset
414
kono
parents:
diff changeset
415 function Contains (Container : Set; Key : Key_Type) return Boolean;
kono
parents:
diff changeset
416 -- Equivalent to Find (Container, Key) /= No_Element
kono
parents:
diff changeset
417
kono
parents:
diff changeset
418 procedure Update_Element -- Update_Element_Preserving_Key ???
kono
parents:
diff changeset
419 (Container : in out Set;
kono
parents:
diff changeset
420 Position : Cursor;
kono
parents:
diff changeset
421 Process : not null access
kono
parents:
diff changeset
422 procedure (Element : in out Element_Type));
kono
parents:
diff changeset
423 -- If Position equals No_Element, then Constraint_Error is raised. If
kono
parents:
diff changeset
424 -- Position is associated with a set object different from Container,
kono
parents:
diff changeset
425 -- then Program_Error is raised. Otherwise, it makes a copy of the key
kono
parents:
diff changeset
426 -- of the element designated by Position, and then calls Process with
kono
parents:
diff changeset
427 -- the element as the parameter. Update_Element then compares the key
kono
parents:
diff changeset
428 -- value obtained before calling Process to the key value obtained from
kono
parents:
diff changeset
429 -- the element after calling Process. If the keys are equivalent then
kono
parents:
diff changeset
430 -- the operation terminates. If Container is busy (cursor tampering has
kono
parents:
diff changeset
431 -- been attempted), then Program_Error is raised. Otherwise, the node
kono
parents:
diff changeset
432 -- is moved to its new position (in canonical order).
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 procedure Iterate
kono
parents:
diff changeset
435 (Container : Set;
kono
parents:
diff changeset
436 Key : Key_Type;
kono
parents:
diff changeset
437 Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
438 -- Call Process with a cursor designating each element equivalent to
kono
parents:
diff changeset
439 -- Key, in order from Floor (Container, Key) to
kono
parents:
diff changeset
440 -- Ceiling (Container, Key).
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 procedure Reverse_Iterate
kono
parents:
diff changeset
443 (Container : Set;
kono
parents:
diff changeset
444 Key : Key_Type;
kono
parents:
diff changeset
445 Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
446 -- Call Process with a cursor designating each element equivalent to
kono
parents:
diff changeset
447 -- Key, in order from Ceiling (Container, Key) to
kono
parents:
diff changeset
448 -- Floor (Container, Key).
kono
parents:
diff changeset
449
kono
parents:
diff changeset
450 end Generic_Keys;
kono
parents:
diff changeset
451
kono
parents:
diff changeset
452 private
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 pragma Inline (Next);
kono
parents:
diff changeset
455 pragma Inline (Previous);
kono
parents:
diff changeset
456
kono
parents:
diff changeset
457 type Node_Type;
kono
parents:
diff changeset
458 type Node_Access is access Node_Type;
kono
parents:
diff changeset
459
kono
parents:
diff changeset
460 type Node_Type is limited record
kono
parents:
diff changeset
461 Parent : Node_Access;
kono
parents:
diff changeset
462 Left : Node_Access;
kono
parents:
diff changeset
463 Right : Node_Access;
kono
parents:
diff changeset
464 Color : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
kono
parents:
diff changeset
465 Element : Element_Type;
kono
parents:
diff changeset
466 end record;
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 package Tree_Types is
kono
parents:
diff changeset
469 new Red_Black_Trees.Generic_Tree_Types (Node_Type, Node_Access);
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 type Set is new Ada.Finalization.Controlled with record
kono
parents:
diff changeset
472 Tree : Tree_Types.Tree_Type;
kono
parents:
diff changeset
473 end record;
kono
parents:
diff changeset
474
kono
parents:
diff changeset
475 overriding procedure Adjust (Container : in out Set);
kono
parents:
diff changeset
476
kono
parents:
diff changeset
477 overriding procedure Finalize (Container : in out Set) renames Clear;
kono
parents:
diff changeset
478
kono
parents:
diff changeset
479 use Red_Black_Trees;
kono
parents:
diff changeset
480 use Tree_Types, Tree_Types.Implementation;
kono
parents:
diff changeset
481 use Ada.Finalization;
kono
parents:
diff changeset
482 use Ada.Streams;
kono
parents:
diff changeset
483
kono
parents:
diff changeset
484 type Set_Access is access all Set;
kono
parents:
diff changeset
485 for Set_Access'Storage_Size use 0;
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 -- In all predefined libraries the following type is controlled, for proper
kono
parents:
diff changeset
488 -- management of tampering checks. For performance reason we omit this
kono
parents:
diff changeset
489 -- machinery for multisets, which are used in a number of our tools.
kono
parents:
diff changeset
490
kono
parents:
diff changeset
491 type Reference_Control_Type is record
kono
parents:
diff changeset
492 Container : Set_Access;
kono
parents:
diff changeset
493 end record;
kono
parents:
diff changeset
494
kono
parents:
diff changeset
495 type Constant_Reference_Type
kono
parents:
diff changeset
496 (Element : not null access constant Element_Type) is record
kono
parents:
diff changeset
497 Control : Reference_Control_Type :=
kono
parents:
diff changeset
498 raise Program_Error with "uninitialized reference";
kono
parents:
diff changeset
499 -- The RM says, "The default initialization of an object of
kono
parents:
diff changeset
500 -- type Constant_Reference_Type or Reference_Type propagates
kono
parents:
diff changeset
501 -- Program_Error."
kono
parents:
diff changeset
502 end record;
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504 type Cursor is record
kono
parents:
diff changeset
505 Container : Set_Access;
kono
parents:
diff changeset
506 Node : Node_Access;
kono
parents:
diff changeset
507 end record;
kono
parents:
diff changeset
508
kono
parents:
diff changeset
509 procedure Write
kono
parents:
diff changeset
510 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
511 Item : Cursor);
kono
parents:
diff changeset
512
kono
parents:
diff changeset
513 for Cursor'Write use Write;
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 procedure Read
kono
parents:
diff changeset
516 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
517 Item : out Cursor);
kono
parents:
diff changeset
518
kono
parents:
diff changeset
519 for Cursor'Read use Read;
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 No_Element : constant Cursor := Cursor'(null, null);
kono
parents:
diff changeset
522
kono
parents:
diff changeset
523 procedure Write
kono
parents:
diff changeset
524 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
525 Container : Set);
kono
parents:
diff changeset
526
kono
parents:
diff changeset
527 for Set'Write use Write;
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529 procedure Read
kono
parents:
diff changeset
530 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
531 Container : out Set);
kono
parents:
diff changeset
532
kono
parents:
diff changeset
533 for Set'Read use Read;
kono
parents:
diff changeset
534
kono
parents:
diff changeset
535 procedure Read
kono
parents:
diff changeset
536 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
537 Item : out Constant_Reference_Type);
kono
parents:
diff changeset
538
kono
parents:
diff changeset
539 for Constant_Reference_Type'Read use Read;
kono
parents:
diff changeset
540
kono
parents:
diff changeset
541 procedure Write
kono
parents:
diff changeset
542 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
543 Item : Constant_Reference_Type);
kono
parents:
diff changeset
544
kono
parents:
diff changeset
545 for Constant_Reference_Type'Write use Write;
kono
parents:
diff changeset
546
kono
parents:
diff changeset
547 Empty_Set : constant Set := (Controlled with others => <>);
kono
parents:
diff changeset
548
kono
parents:
diff changeset
549 type Iterator is new Limited_Controlled and
kono
parents:
diff changeset
550 Set_Iterator_Interfaces.Reversible_Iterator with
kono
parents:
diff changeset
551 record
kono
parents:
diff changeset
552 Container : Set_Access;
kono
parents:
diff changeset
553 Node : Node_Access;
kono
parents:
diff changeset
554 end record
kono
parents:
diff changeset
555 with Disable_Controlled => not T_Check;
kono
parents:
diff changeset
556
kono
parents:
diff changeset
557 overriding procedure Finalize (Object : in out Iterator);
kono
parents:
diff changeset
558
kono
parents:
diff changeset
559 overriding function First (Object : Iterator) return Cursor;
kono
parents:
diff changeset
560 overriding function Last (Object : Iterator) return Cursor;
kono
parents:
diff changeset
561
kono
parents:
diff changeset
562 overriding function Next
kono
parents:
diff changeset
563 (Object : Iterator;
kono
parents:
diff changeset
564 Position : Cursor) return Cursor;
kono
parents:
diff changeset
565
kono
parents:
diff changeset
566 overriding function Previous
kono
parents:
diff changeset
567 (Object : Iterator;
kono
parents:
diff changeset
568 Position : Cursor) return Cursor;
kono
parents:
diff changeset
569
kono
parents:
diff changeset
570 end Ada.Containers.Ordered_Multisets;