OSDN Git Service

2012-01-10 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-ciorse.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --                 ADA.CONTAINERS.INDEFINITE_ORDERED_SETS                   --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2004-2011, 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 ------------------------------------------------------------------------------
33
34 private with Ada.Containers.Red_Black_Trees;
35 private with Ada.Finalization;
36 with Ada.Streams; use Ada.Streams;
37 with Ada.Iterator_Interfaces;
38
39 generic
40    type Element_Type (<>) is private;
41
42    with function "<" (Left, Right : Element_Type) return Boolean is <>;
43    with function "=" (Left, Right : Element_Type) return Boolean is <>;
44
45 package Ada.Containers.Indefinite_Ordered_Sets is
46    pragma Preelaborate;
47    pragma Remote_Types;
48
49    function Equivalent_Elements (Left, Right : Element_Type) return Boolean;
50
51    type Set is tagged private with
52       Constant_Indexing => Constant_Reference,
53       Default_Iterator  => Iterate,
54       Iterator_Element  => Element_Type;
55
56    pragma Preelaborable_Initialization (Set);
57
58    type Cursor is private;
59    pragma Preelaborable_Initialization (Cursor);
60
61    Empty_Set : constant Set;
62
63    No_Element : constant Cursor;
64
65    function Has_Element (Position : Cursor) return Boolean;
66
67    package Set_Iterator_Interfaces is new
68      Ada.Iterator_Interfaces (Cursor, Has_Element);
69
70    function "=" (Left, Right : Set) return Boolean;
71
72    function Equivalent_Sets (Left, Right : Set) return Boolean;
73
74    function To_Set (New_Item : Element_Type) return Set;
75
76    function Length (Container : Set) return Count_Type;
77
78    function Is_Empty (Container : Set) return Boolean;
79
80    procedure Clear (Container : in out Set);
81
82    function Element (Position : Cursor) return Element_Type;
83
84    procedure Replace_Element
85      (Container : in out Set;
86       Position  : Cursor;
87       New_Item  : Element_Type);
88
89    procedure Query_Element
90      (Position : Cursor;
91       Process  : not null access procedure (Element : Element_Type));
92
93    type Constant_Reference_Type
94      (Element : not null access constant Element_Type) is
95    private with
96       Implicit_Dereference => Element;
97
98    function Constant_Reference
99      (Container : aliased Set;
100       Position  : Cursor) return Constant_Reference_Type;
101
102    procedure Read
103      (Stream : not null access Root_Stream_Type'Class;
104       Item   : out Constant_Reference_Type);
105
106    for Constant_Reference_Type'Read use Read;
107
108    procedure Write
109      (Stream : not null access Root_Stream_Type'Class;
110       Item   : Constant_Reference_Type);
111
112    for Constant_Reference_Type'Write use Write;
113
114    procedure Assign (Target : in out Set; Source : Set);
115
116    function Copy (Source : Set) return Set;
117
118    procedure Move (Target : in out Set; Source : in out Set);
119
120    procedure Insert
121      (Container : in out Set;
122       New_Item  : Element_Type;
123       Position  : out Cursor;
124       Inserted  : out Boolean);
125
126    procedure Insert
127      (Container : in out Set;
128       New_Item  : Element_Type);
129
130    procedure Include
131      (Container : in out Set;
132       New_Item  : Element_Type);
133
134    procedure Replace
135      (Container : in out Set;
136       New_Item  : Element_Type);
137
138    procedure Exclude
139      (Container : in out Set;
140       Item      : Element_Type);
141
142    procedure Delete
143      (Container : in out Set;
144       Item      : Element_Type);
145
146    procedure Delete
147      (Container : in out Set;
148       Position  : in out Cursor);
149
150    procedure Delete_First (Container : in out Set);
151
152    procedure Delete_Last (Container : in out Set);
153
154    procedure Union (Target : in out Set; Source : Set);
155
156    function Union (Left, Right : Set) return Set;
157
158    function "or" (Left, Right : Set) return Set renames Union;
159
160    procedure Intersection (Target : in out Set; Source : Set);
161
162    function Intersection (Left, Right : Set) return Set;
163
164    function "and" (Left, Right : Set) return Set renames Intersection;
165
166    procedure Difference (Target : in out Set; Source : Set);
167
168    function Difference (Left, Right : Set) return Set;
169
170    function "-" (Left, Right : Set) return Set renames Difference;
171
172    procedure Symmetric_Difference (Target : in out Set; Source : Set);
173
174    function Symmetric_Difference (Left, Right : Set) return Set;
175
176    function "xor" (Left, Right : Set) return Set renames Symmetric_Difference;
177
178    function Overlap (Left, Right : Set) return Boolean;
179
180    function Is_Subset (Subset : Set; Of_Set : Set) return Boolean;
181
182    function First (Container : Set) return Cursor;
183
184    function First_Element (Container : Set) return Element_Type;
185
186    function Last (Container : Set) return Cursor;
187
188    function Last_Element (Container : Set) return Element_Type;
189
190    function Next (Position : Cursor) return Cursor;
191
192    procedure Next (Position : in out Cursor);
193
194    function Previous (Position : Cursor) return Cursor;
195
196    procedure Previous (Position : in out Cursor);
197
198    function Find
199      (Container : Set;
200       Item      : Element_Type) return Cursor;
201
202    function Floor
203      (Container : Set;
204       Item      : Element_Type) return Cursor;
205
206    function Ceiling
207      (Container : Set;
208       Item      : Element_Type) return Cursor;
209
210    function Contains
211      (Container : Set;
212       Item      : Element_Type) return Boolean;
213
214    function "<" (Left, Right : Cursor) return Boolean;
215
216    function ">" (Left, Right : Cursor) return Boolean;
217
218    function "<" (Left : Cursor; Right : Element_Type) return Boolean;
219
220    function ">" (Left : Cursor; Right : Element_Type) return Boolean;
221
222    function "<" (Left : Element_Type; Right : Cursor) return Boolean;
223
224    function ">" (Left : Element_Type; Right : Cursor) return Boolean;
225
226    procedure Iterate
227      (Container : Set;
228       Process   : not null access procedure (Position : Cursor));
229
230    procedure Reverse_Iterate
231      (Container : Set;
232       Process   : not null access procedure (Position : Cursor));
233
234    function Iterate
235      (Container : Set)
236       return Set_Iterator_Interfaces.Reversible_Iterator'class;
237
238    function Iterate
239      (Container : Set;
240       Start     : Cursor)
241       return Set_Iterator_Interfaces.Reversible_Iterator'class;
242
243    generic
244       type Key_Type (<>) is private;
245
246       with function Key (Element : Element_Type) return Key_Type;
247
248       with function "<" (Left, Right : Key_Type) return Boolean is <>;
249
250    package Generic_Keys is
251
252       function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
253
254       function Key (Position : Cursor) return Key_Type;
255
256       function Element (Container : Set; Key : Key_Type) return Element_Type;
257
258       procedure Replace
259         (Container : in out Set;
260          Key       : Key_Type;
261          New_Item  : Element_Type);
262
263       procedure Exclude (Container : in out Set; Key : Key_Type);
264
265       procedure Delete (Container : in out Set; Key : Key_Type);
266
267       function Find
268         (Container : Set;
269          Key       : Key_Type) return Cursor;
270
271       function Floor
272         (Container : Set;
273          Key       : Key_Type) return Cursor;
274
275       function Ceiling
276         (Container : Set;
277          Key       : Key_Type) return Cursor;
278
279       function Contains
280         (Container : Set;
281          Key       : Key_Type) return Boolean;
282
283       procedure Update_Element_Preserving_Key
284         (Container : in out Set;
285          Position  : Cursor;
286          Process   : not null access
287                        procedure (Element : in out Element_Type));
288
289       type Reference_Type (Element : not null access Element_Type) is private
290       with
291          Implicit_Dereference => Element;
292
293       function Reference_Preserving_Key
294         (Container : aliased in out Set;
295          Position  : Cursor) return Reference_Type;
296
297       function Constant_Reference
298         (Container : aliased Set;
299          Key       : Key_Type) return Constant_Reference_Type;
300
301       function Reference_Preserving_Key
302         (Container : aliased in out Set;
303          Key       : Key_Type) return Reference_Type;
304
305    private
306       type Reference_Type
307          (Element : not null access Element_Type) is null record;
308
309       procedure Write
310         (Stream : not null access Root_Stream_Type'Class;
311          Item   : Reference_Type);
312
313       for Reference_Type'Write use Write;
314
315       procedure Read
316         (Stream : not null access Root_Stream_Type'Class;
317          Item   : out Reference_Type);
318
319       for Reference_Type'Read use Read;
320    end Generic_Keys;
321
322 private
323    pragma Inline (Next);
324    pragma Inline (Previous);
325
326    type Node_Type;
327    type Node_Access is access Node_Type;
328
329    type Element_Access is access Element_Type;
330
331    type Node_Type is limited record
332       Parent  : Node_Access;
333       Left    : Node_Access;
334       Right   : Node_Access;
335       Color   : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
336       Element : Element_Access;
337    end record;
338
339    package Tree_Types is new Red_Black_Trees.Generic_Tree_Types
340      (Node_Type,
341       Node_Access);
342
343    type Set is new Ada.Finalization.Controlled with record
344       Tree : Tree_Types.Tree_Type;
345    end record;
346
347    overriding procedure Adjust (Container : in out Set);
348
349    overriding procedure Finalize (Container : in out Set) renames Clear;
350
351    use Red_Black_Trees;
352    use Tree_Types;
353    use Ada.Finalization;
354
355    type Set_Access is access all Set;
356    for Set_Access'Storage_Size use 0;
357
358    type Cursor is record
359       Container : Set_Access;
360       Node      : Node_Access;
361    end record;
362
363    procedure Write
364      (Stream : not null access Root_Stream_Type'Class;
365       Item   : Cursor);
366
367    for Cursor'Write use Write;
368
369    procedure Read
370      (Stream : not null access Root_Stream_Type'Class;
371       Item   : out Cursor);
372
373    for Cursor'Read use Read;
374
375    No_Element : constant Cursor := Cursor'(null, null);
376
377    procedure Write
378      (Stream    : not null access Root_Stream_Type'Class;
379       Container : Set);
380
381    for Set'Write use Write;
382
383    procedure Read
384      (Stream    : not null access Root_Stream_Type'Class;
385       Container : out Set);
386
387    for Set'Read use Read;
388
389    type Constant_Reference_Type
390       (Element : not null access constant Element_Type) is null record;
391
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));
399
400 end Ada.Containers.Indefinite_Ordered_Sets;