Rebase.
[official-gcc.git] / gcc / ada / a-ciorse.ads
blob830f98866249d732f91393f0a04c782d8978d90c
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- ADA.CONTAINERS.INDEFINITE_ORDERED_SETS --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2004-2014, Free Software Foundation, Inc. --
10 -- --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the contents of the part following the private keyword. --
14 -- --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
21 -- --
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
23 -- additional permissions described in the GCC Runtime Library Exception, --
24 -- version 3.1, as published by the Free Software Foundation. --
25 -- --
26 -- You should have received a copy of the GNU General Public License and --
27 -- a copy of the GCC Runtime Library Exception along with this program; --
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
29 -- <http://www.gnu.org/licenses/>. --
30 -- --
31 -- This unit was originally developed by Matthew J Heaney. --
32 ------------------------------------------------------------------------------
34 with Ada.Iterator_Interfaces;
36 private with Ada.Containers.Red_Black_Trees;
37 private with Ada.Finalization;
38 private with Ada.Streams;
40 generic
41 type Element_Type (<>) is private;
43 with function "<" (Left, Right : Element_Type) return Boolean is <>;
44 with function "=" (Left, Right : Element_Type) return Boolean is <>;
46 package Ada.Containers.Indefinite_Ordered_Sets is
47 pragma Preelaborate;
48 pragma Remote_Types;
50 function Equivalent_Elements (Left, Right : Element_Type) return Boolean;
52 type Set is tagged private with
53 Constant_Indexing => Constant_Reference,
54 Default_Iterator => Iterate,
55 Iterator_Element => Element_Type;
57 pragma Preelaborable_Initialization (Set);
59 type Cursor is private;
60 pragma Preelaborable_Initialization (Cursor);
62 Empty_Set : constant Set;
64 No_Element : constant Cursor;
66 function Has_Element (Position : Cursor) return Boolean;
68 package Set_Iterator_Interfaces is new
69 Ada.Iterator_Interfaces (Cursor, Has_Element);
71 function "=" (Left, Right : Set) return Boolean;
73 function Equivalent_Sets (Left, Right : Set) return Boolean;
75 function To_Set (New_Item : Element_Type) return Set;
77 function Length (Container : Set) return Count_Type;
79 function Is_Empty (Container : Set) return Boolean;
81 procedure Clear (Container : in out Set);
83 function Element (Position : Cursor) return Element_Type;
85 procedure Replace_Element
86 (Container : in out Set;
87 Position : Cursor;
88 New_Item : Element_Type);
90 procedure Query_Element
91 (Position : Cursor;
92 Process : not null access procedure (Element : Element_Type));
94 type Constant_Reference_Type
95 (Element : not null access constant Element_Type) is
96 private with
97 Implicit_Dereference => Element;
99 function Constant_Reference
100 (Container : aliased Set;
101 Position : Cursor) return Constant_Reference_Type;
102 pragma Inline (Constant_Reference);
104 procedure Assign (Target : in out Set; Source : Set);
106 function Copy (Source : Set) return Set;
108 procedure Move (Target : in out Set; Source : in out Set);
110 procedure Insert
111 (Container : in out Set;
112 New_Item : Element_Type;
113 Position : out Cursor;
114 Inserted : out Boolean);
116 procedure Insert
117 (Container : in out Set;
118 New_Item : Element_Type);
120 procedure Include
121 (Container : in out Set;
122 New_Item : Element_Type);
124 procedure Replace
125 (Container : in out Set;
126 New_Item : Element_Type);
128 procedure Exclude
129 (Container : in out Set;
130 Item : Element_Type);
132 procedure Delete
133 (Container : in out Set;
134 Item : Element_Type);
136 procedure Delete
137 (Container : in out Set;
138 Position : in out Cursor);
140 procedure Delete_First (Container : in out Set);
142 procedure Delete_Last (Container : in out Set);
144 procedure Union (Target : in out Set; Source : Set);
146 function Union (Left, Right : Set) return Set;
148 function "or" (Left, Right : Set) return Set renames Union;
150 procedure Intersection (Target : in out Set; Source : Set);
152 function Intersection (Left, Right : Set) return Set;
154 function "and" (Left, Right : Set) return Set renames Intersection;
156 procedure Difference (Target : in out Set; Source : Set);
158 function Difference (Left, Right : Set) return Set;
160 function "-" (Left, Right : Set) return Set renames Difference;
162 procedure Symmetric_Difference (Target : in out Set; Source : Set);
164 function Symmetric_Difference (Left, Right : Set) return Set;
166 function "xor" (Left, Right : Set) return Set renames Symmetric_Difference;
168 function Overlap (Left, Right : Set) return Boolean;
170 function Is_Subset (Subset : Set; Of_Set : Set) return Boolean;
172 function First (Container : Set) return Cursor;
174 function First_Element (Container : Set) return Element_Type;
176 function Last (Container : Set) return Cursor;
178 function Last_Element (Container : Set) return Element_Type;
180 function Next (Position : Cursor) return Cursor;
182 procedure Next (Position : in out Cursor);
184 function Previous (Position : Cursor) return Cursor;
186 procedure Previous (Position : in out Cursor);
188 function Find
189 (Container : Set;
190 Item : Element_Type) return Cursor;
192 function Floor
193 (Container : Set;
194 Item : Element_Type) return Cursor;
196 function Ceiling
197 (Container : Set;
198 Item : Element_Type) return Cursor;
200 function Contains
201 (Container : Set;
202 Item : Element_Type) return Boolean;
204 function "<" (Left, Right : Cursor) return Boolean;
206 function ">" (Left, Right : Cursor) return Boolean;
208 function "<" (Left : Cursor; Right : Element_Type) return Boolean;
210 function ">" (Left : Cursor; Right : Element_Type) return Boolean;
212 function "<" (Left : Element_Type; Right : Cursor) return Boolean;
214 function ">" (Left : Element_Type; Right : Cursor) return Boolean;
216 procedure Iterate
217 (Container : Set;
218 Process : not null access procedure (Position : Cursor));
220 procedure Reverse_Iterate
221 (Container : Set;
222 Process : not null access procedure (Position : Cursor));
224 function Iterate
225 (Container : Set)
226 return Set_Iterator_Interfaces.Reversible_Iterator'class;
228 function Iterate
229 (Container : Set;
230 Start : Cursor)
231 return Set_Iterator_Interfaces.Reversible_Iterator'class;
233 generic
234 type Key_Type (<>) is private;
236 with function Key (Element : Element_Type) return Key_Type;
238 with function "<" (Left, Right : Key_Type) return Boolean is <>;
240 package Generic_Keys is
242 function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
244 function Key (Position : Cursor) return Key_Type;
246 function Element (Container : Set; Key : Key_Type) return Element_Type;
248 procedure Replace
249 (Container : in out Set;
250 Key : Key_Type;
251 New_Item : Element_Type);
253 procedure Exclude (Container : in out Set; Key : Key_Type);
255 procedure Delete (Container : in out Set; Key : Key_Type);
257 function Find
258 (Container : Set;
259 Key : Key_Type) return Cursor;
261 function Floor
262 (Container : Set;
263 Key : Key_Type) return Cursor;
265 function Ceiling
266 (Container : Set;
267 Key : Key_Type) return Cursor;
269 function Contains
270 (Container : Set;
271 Key : Key_Type) return Boolean;
273 procedure Update_Element_Preserving_Key
274 (Container : in out Set;
275 Position : Cursor;
276 Process : not null access
277 procedure (Element : in out Element_Type));
279 type Reference_Type (Element : not null access Element_Type) is private
280 with
281 Implicit_Dereference => Element;
283 function Reference_Preserving_Key
284 (Container : aliased in out Set;
285 Position : Cursor) return Reference_Type;
287 function Constant_Reference
288 (Container : aliased Set;
289 Key : Key_Type) return Constant_Reference_Type;
291 function Reference_Preserving_Key
292 (Container : aliased in out Set;
293 Key : Key_Type) return Reference_Type;
295 private
296 type Set_Access is access all Set;
297 for Set_Access'Storage_Size use 0;
299 type Key_Access is access all Key_Type;
301 type Reference_Control_Type is
302 new Ada.Finalization.Controlled with
303 record
304 Container : Set_Access;
305 Pos : Cursor;
306 Old_Key : Key_Access;
307 end record;
309 overriding procedure Adjust (Control : in out Reference_Control_Type);
310 pragma Inline (Adjust);
312 overriding procedure Finalize (Control : in out Reference_Control_Type);
313 pragma Inline (Finalize);
315 type Reference_Type (Element : not null access Element_Type) is record
316 Control : Reference_Control_Type;
317 end record;
319 use Ada.Streams;
321 procedure Write
322 (Stream : not null access Root_Stream_Type'Class;
323 Item : Reference_Type);
325 for Reference_Type'Write use Write;
327 procedure Read
328 (Stream : not null access Root_Stream_Type'Class;
329 Item : out Reference_Type);
331 for Reference_Type'Read use Read;
332 end Generic_Keys;
334 private
335 pragma Inline (Next);
336 pragma Inline (Previous);
338 type Node_Type;
339 type Node_Access is access Node_Type;
341 type Element_Access is access Element_Type;
343 type Node_Type is limited record
344 Parent : Node_Access;
345 Left : Node_Access;
346 Right : Node_Access;
347 Color : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
348 Element : Element_Access;
349 end record;
351 package Tree_Types is new Red_Black_Trees.Generic_Tree_Types
352 (Node_Type,
353 Node_Access);
355 type Set is new Ada.Finalization.Controlled with record
356 Tree : Tree_Types.Tree_Type;
357 end record;
359 overriding procedure Adjust (Container : in out Set);
361 overriding procedure Finalize (Container : in out Set) renames Clear;
363 use Red_Black_Trees;
364 use Tree_Types;
365 use Ada.Finalization;
366 use Ada.Streams;
368 procedure Write
369 (Stream : not null access Root_Stream_Type'Class;
370 Container : Set);
372 for Set'Write use Write;
374 procedure Read
375 (Stream : not null access Root_Stream_Type'Class;
376 Container : out Set);
378 for Set'Read use Read;
380 type Set_Access is access all Set;
381 for Set_Access'Storage_Size use 0;
383 type Cursor is record
384 Container : Set_Access;
385 Node : Node_Access;
386 end record;
388 procedure Write
389 (Stream : not null access Root_Stream_Type'Class;
390 Item : Cursor);
392 for Cursor'Write use Write;
394 procedure Read
395 (Stream : not null access Root_Stream_Type'Class;
396 Item : out Cursor);
398 for Cursor'Read use Read;
400 type Reference_Control_Type is
401 new Controlled with record
402 Container : Set_Access;
403 end record;
405 overriding procedure Adjust (Control : in out Reference_Control_Type);
406 pragma Inline (Adjust);
408 overriding procedure Finalize (Control : in out Reference_Control_Type);
409 pragma Inline (Finalize);
411 type Constant_Reference_Type
412 (Element : not null access constant Element_Type) is
413 record
414 Control : Reference_Control_Type;
415 end record;
417 procedure Read
418 (Stream : not null access Root_Stream_Type'Class;
419 Item : out Constant_Reference_Type);
421 for Constant_Reference_Type'Read use Read;
423 procedure Write
424 (Stream : not null access Root_Stream_Type'Class;
425 Item : Constant_Reference_Type);
427 for Constant_Reference_Type'Write use Write;
429 Empty_Set : constant Set :=
430 (Controlled with Tree => (First => null,
431 Last => null,
432 Root => null,
433 Length => 0,
434 Busy => 0,
435 Lock => 0));
437 No_Element : constant Cursor := Cursor'(null, null);
439 type Iterator is new Limited_Controlled and
440 Set_Iterator_Interfaces.Reversible_Iterator with
441 record
442 Container : Set_Access;
443 Node : Node_Access;
444 end record;
446 overriding procedure Finalize (Object : in out Iterator);
448 overriding function First (Object : Iterator) return Cursor;
449 overriding function Last (Object : Iterator) return Cursor;
451 overriding function Next
452 (Object : Iterator;
453 Position : Cursor) return Cursor;
455 overriding function Previous
456 (Object : Iterator;
457 Position : Cursor) return Cursor;
459 end Ada.Containers.Indefinite_Ordered_Sets;