PR c++/54038
[official-gcc.git] / gcc / ada / a-coorse.ads
blobe28a71bc29991875ad4393d58d0ce3e9524eafd0
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- A D A . C O N T A I N E R S . O R D E R E D _ S E T S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2004-2012, 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.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
53 with 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 function Has_Element (Position : Cursor) return Boolean;
64 Empty_Set : constant Set;
66 No_Element : constant Cursor;
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
97 with
98 Implicit_Dereference => Element;
100 function Constant_Reference
101 (Container : aliased Set;
102 Position : Cursor) return Constant_Reference_Type;
103 pragma Inline (Constant_Reference);
105 procedure Assign (Target : in out Set; Source : Set);
107 function Copy (Source : Set) return Set;
109 procedure Move (Target : in out Set; Source : in out Set);
111 procedure Insert
112 (Container : in out Set;
113 New_Item : Element_Type;
114 Position : out Cursor;
115 Inserted : out Boolean);
117 procedure Insert
118 (Container : in out Set;
119 New_Item : Element_Type);
121 procedure Include
122 (Container : in out Set;
123 New_Item : Element_Type);
125 procedure Replace
126 (Container : in out Set;
127 New_Item : Element_Type);
129 procedure Exclude
130 (Container : in out Set;
131 Item : Element_Type);
133 procedure Delete
134 (Container : in out Set;
135 Item : Element_Type);
137 procedure Delete
138 (Container : in out Set;
139 Position : in out Cursor);
141 procedure Delete_First (Container : in out Set);
143 procedure Delete_Last (Container : in out Set);
145 procedure Union (Target : in out Set; Source : Set);
147 function Union (Left, Right : Set) return Set;
149 function "or" (Left, Right : Set) return Set renames Union;
151 procedure Intersection (Target : in out Set; Source : Set);
153 function Intersection (Left, Right : Set) return Set;
155 function "and" (Left, Right : Set) return Set renames Intersection;
157 procedure Difference (Target : in out Set; Source : Set);
159 function Difference (Left, Right : Set) return Set;
161 function "-" (Left, Right : Set) return Set renames Difference;
163 procedure Symmetric_Difference (Target : in out Set; Source : Set);
165 function Symmetric_Difference (Left, Right : Set) return Set;
167 function "xor" (Left, Right : Set) return Set renames Symmetric_Difference;
169 function Overlap (Left, Right : Set) return Boolean;
171 function Is_Subset (Subset : Set; Of_Set : Set) return Boolean;
173 function First (Container : Set) return Cursor;
175 function First_Element (Container : Set) return Element_Type;
177 function Last (Container : Set) return Cursor;
179 function Last_Element (Container : Set) return Element_Type;
181 function Next (Position : Cursor) return Cursor;
183 procedure Next (Position : in out Cursor);
185 function Previous (Position : Cursor) return Cursor;
187 procedure Previous (Position : in out Cursor);
189 function Find (Container : Set; Item : Element_Type) return Cursor;
191 function Floor (Container : Set; Item : Element_Type) return Cursor;
193 function Ceiling (Container : Set; Item : Element_Type) return Cursor;
195 function Contains (Container : Set; Item : Element_Type) return Boolean;
197 function "<" (Left, Right : Cursor) return Boolean;
199 function ">" (Left, Right : Cursor) return Boolean;
201 function "<" (Left : Cursor; Right : Element_Type) return Boolean;
203 function ">" (Left : Cursor; Right : Element_Type) return Boolean;
205 function "<" (Left : Element_Type; Right : Cursor) return Boolean;
207 function ">" (Left : Element_Type; Right : Cursor) return Boolean;
209 procedure Iterate
210 (Container : Set;
211 Process : not null access procedure (Position : Cursor));
213 procedure Reverse_Iterate
214 (Container : Set;
215 Process : not null access procedure (Position : Cursor));
217 function Iterate
218 (Container : Set)
219 return Set_Iterator_Interfaces.Reversible_Iterator'class;
221 function Iterate
222 (Container : Set;
223 Start : Cursor)
224 return Set_Iterator_Interfaces.Reversible_Iterator'class;
226 generic
227 type Key_Type (<>) is private;
229 with function Key (Element : Element_Type) return Key_Type;
231 with function "<" (Left, Right : Key_Type) return Boolean is <>;
233 package Generic_Keys is
235 function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
237 function Key (Position : Cursor) return Key_Type;
239 function Element (Container : Set; Key : Key_Type) return Element_Type;
241 procedure Replace
242 (Container : in out Set;
243 Key : Key_Type;
244 New_Item : Element_Type);
246 procedure Exclude (Container : in out Set; Key : Key_Type);
248 procedure Delete (Container : in out Set; Key : Key_Type);
250 function Find (Container : Set; Key : Key_Type) return Cursor;
252 function Floor (Container : Set; Key : Key_Type) return Cursor;
254 function Ceiling (Container : Set; Key : Key_Type) return Cursor;
256 function Contains (Container : Set; Key : Key_Type) return Boolean;
258 procedure Update_Element_Preserving_Key
259 (Container : in out Set;
260 Position : Cursor;
261 Process : not null access
262 procedure (Element : in out Element_Type));
264 type Reference_Type (Element : not null access Element_Type) is private
265 with
266 Implicit_Dereference => Element;
268 function Reference_Preserving_Key
269 (Container : aliased in out Set;
270 Position : Cursor) return Reference_Type;
272 function Constant_Reference
273 (Container : aliased Set;
274 Key : Key_Type) return Constant_Reference_Type;
276 function Reference_Preserving_Key
277 (Container : aliased in out Set;
278 Key : Key_Type) return Reference_Type;
280 private
281 type Reference_Type
282 (Element : not null access Element_Type) is null record;
284 use Ada.Streams;
286 procedure Write
287 (Stream : not null access Root_Stream_Type'Class;
288 Item : Reference_Type);
290 for Reference_Type'Write use Write;
292 procedure Read
293 (Stream : not null access Root_Stream_Type'Class;
294 Item : out Reference_Type);
296 for Reference_Type'Read use Read;
297 end Generic_Keys;
299 private
301 pragma Inline (Next);
302 pragma Inline (Previous);
304 type Node_Type;
305 type Node_Access is access Node_Type;
307 type Node_Type is limited record
308 Parent : Node_Access;
309 Left : Node_Access;
310 Right : Node_Access;
311 Color : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
312 Element : aliased Element_Type;
313 end record;
315 package Tree_Types is
316 new Red_Black_Trees.Generic_Tree_Types (Node_Type, Node_Access);
318 type Set is new Ada.Finalization.Controlled with record
319 Tree : Tree_Types.Tree_Type;
320 end record;
322 overriding procedure Adjust (Container : in out Set);
324 overriding procedure Finalize (Container : in out Set) renames Clear;
326 use Red_Black_Trees;
327 use Tree_Types;
328 use Ada.Finalization;
329 use Ada.Streams;
331 procedure Write
332 (Stream : not null access Root_Stream_Type'Class;
333 Container : Set);
335 for Set'Write use Write;
337 procedure Read
338 (Stream : not null access Root_Stream_Type'Class;
339 Container : out Set);
341 for Set'Read use Read;
343 type Set_Access is access all Set;
344 for Set_Access'Storage_Size use 0;
346 type Cursor is record
347 Container : Set_Access;
348 Node : Node_Access;
349 end record;
351 procedure Write
352 (Stream : not null access Root_Stream_Type'Class;
353 Item : Cursor);
355 for Cursor'Write use Write;
357 procedure Read
358 (Stream : not null access Root_Stream_Type'Class;
359 Item : out Cursor);
361 for Cursor'Read use Read;
363 type Reference_Control_Type is
364 new Controlled with record
365 Container : Set_Access;
366 end record;
368 overriding procedure Adjust (Control : in out Reference_Control_Type);
369 pragma Inline (Adjust);
371 overriding procedure Finalize (Control : in out Reference_Control_Type);
372 pragma Inline (Finalize);
374 type Constant_Reference_Type
375 (Element : not null access constant Element_Type) is
376 record
377 Control : Reference_Control_Type;
378 end record;
380 procedure Write
381 (Stream : not null access Root_Stream_Type'Class;
382 Item : Constant_Reference_Type);
384 for Constant_Reference_Type'Write use Write;
386 procedure Read
387 (Stream : not null access Root_Stream_Type'Class;
388 Item : out Constant_Reference_Type);
390 for Constant_Reference_Type'Read use Read;
392 Empty_Set : constant Set :=
393 (Controlled with Tree => (First => null,
394 Last => null,
395 Root => null,
396 Length => 0,
397 Busy => 0,
398 Lock => 0));
400 No_Element : constant Cursor := Cursor'(null, null);
402 end Ada.Containers.Ordered_Sets;