OSDN Git Service

PR preprocessor/20348
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-coormu.ads
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 _ M U L T I S E T S      --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2004-2005 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 2,  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.  See the GNU General Public License --
21 -- for  more details.  You should have  received  a copy of the GNU General --
22 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
23 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
24 -- Boston, MA 02110-1301, USA.                                              --
25 --                                                                          --
26 -- As a special exception,  if other files  instantiate  generics from this --
27 -- unit, or you link  this unit with other files  to produce an executable, --
28 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
29 -- covered  by the  GNU  General  Public  License.  This exception does not --
30 -- however invalidate  any other reasons why  the executable file  might be --
31 -- covered by the  GNU Public License.                                      --
32 --                                                                          --
33 -- This unit was originally developed by Matthew J Heaney.                  --
34 ------------------------------------------------------------------------------
35
36 with Ada.Containers.Red_Black_Trees;
37 with Ada.Finalization;
38 with Ada.Streams;
39
40 generic
41    type Element_Type is private;
42
43    with function "<" (Left, Right : Element_Type) return Boolean is <>;
44    with function "=" (Left, Right : Element_Type) return Boolean is <>;
45
46 package Ada.Containers.Ordered_Multisets is
47 pragma Preelaborate (Ordered_Multisets);
48
49    type Set is tagged private;
50
51    type Cursor is private;
52
53    Empty_Set : constant Set;
54
55    No_Element : constant Cursor;
56
57    function "=" (Left, Right : Set) return Boolean;
58
59    function Equivalent_Sets (Left, Right : Set) return Boolean;
60
61    function Length (Container : Set) return Count_Type;
62
63    function Is_Empty (Container : Set) return Boolean;
64
65    procedure Clear (Container : in out Set);
66
67    function Element (Position : Cursor) return Element_Type;
68
69    procedure Query_Element
70      (Position : Cursor;
71       Process  : not null access procedure (Element : Element_Type));
72
73    procedure Replace_Element
74      (Container : Set;
75       Position  : Cursor;
76       By        : Element_Type);
77
78    procedure Move
79      (Target : in out Set;
80       Source : in out Set);
81
82    procedure Insert
83      (Container : in out Set;
84       New_Item  : Element_Type;
85       Position  : out Cursor);
86
87    procedure Insert
88      (Container : in out Set;
89       New_Item  : Element_Type);
90
91    procedure Delete
92      (Container : in out Set;
93       Item      : Element_Type);
94
95    procedure Delete
96      (Container : in out Set;
97       Position  : in out Cursor);
98
99    procedure Delete_First (Container : in out Set);
100
101    procedure Delete_Last (Container : in out Set);
102
103    procedure Exclude
104      (Container : in out Set;
105       Item      : Element_Type);
106
107    procedure Union (Target : in out Set; Source : Set);
108
109    function Union (Left, Right : Set) return Set;
110
111    function "or" (Left, Right : Set) return Set renames Union;
112
113    procedure Intersection (Target : in out Set; Source : Set);
114
115    function Intersection (Left, Right : Set) return Set;
116
117    function "and" (Left, Right : Set) return Set renames Intersection;
118
119    procedure Difference (Target : in out Set; Source : Set);
120
121    function Difference (Left, Right : Set) return Set;
122
123    function "-" (Left, Right : Set) return Set renames Difference;
124
125    procedure Symmetric_Difference (Target : in out Set; Source : Set);
126
127    function Symmetric_Difference (Left, Right : Set) return Set;
128
129    function "xor" (Left, Right : Set) return Set renames Symmetric_Difference;
130
131    function Overlap (Left, Right : Set) return Boolean;
132
133    function Is_Subset (Subset : Set; Of_Set : Set) return Boolean;
134
135    function Contains (Container : Set; Item : Element_Type) return Boolean;
136
137    function Find (Container : Set; Item : Element_Type) return Cursor;
138
139    function Floor (Container : Set; Item : Element_Type) return Cursor;
140
141    function Ceiling (Container : Set; Item : Element_Type) return Cursor;
142
143    function First (Container : Set) return Cursor;
144
145    function First_Element (Container : Set) return Element_Type;
146
147    function Last (Container : Set) return Cursor;
148
149    function Last_Element (Container : Set) return Element_Type;
150
151    function Next (Position : Cursor) return Cursor;
152
153    procedure Next (Position : in out Cursor);
154
155    function Previous (Position : Cursor) return Cursor;
156
157    procedure Previous (Position : in out Cursor);
158
159    function Has_Element (Position : Cursor) return Boolean;
160
161    function "<" (Left, Right : Cursor) return Boolean;
162
163    function ">" (Left, Right : Cursor) return Boolean;
164
165    function "<" (Left : Cursor; Right : Element_Type) return Boolean;
166
167    function ">" (Left : Cursor; Right : Element_Type) return Boolean;
168
169    function "<" (Left : Element_Type; Right : Cursor) return Boolean;
170
171    function ">" (Left : Element_Type; Right : Cursor) return Boolean;
172
173    procedure Iterate
174      (Container : Set;
175       Process   : not null access procedure (Position : Cursor));
176
177    procedure Reverse_Iterate
178      (Container : Set;
179       Process   : not null access procedure (Position : Cursor));
180
181    procedure Iterate
182      (Container : Set;
183       Item      : Element_Type;
184       Process   : not null access procedure (Position : Cursor));
185
186    procedure Reverse_Iterate
187      (Container : Set;
188       Item      : Element_Type;
189       Process   : not null access procedure (Position : Cursor));
190
191    generic
192       type Key_Type (<>) is limited private;
193
194       with function Key (Element : Element_Type) return Key_Type;
195
196       with function "<" (Left : Key_Type; Right : Element_Type)
197         return Boolean is <>;
198
199       with function ">" (Left : Key_Type; Right : Element_Type)
200         return Boolean is <>;
201
202    package Generic_Keys is
203
204       function Contains (Container : Set; Key : Key_Type) return Boolean;
205
206       function Find (Container : Set; Key : Key_Type) return Cursor;
207
208       function Floor (Container : Set; Key : Key_Type) return Cursor;
209
210       function Ceiling (Container : Set; Key : Key_Type) return Cursor;
211
212       function Key (Position : Cursor) return Key_Type;
213
214       function Element (Container : Set; Key : Key_Type) return Element_Type;
215
216       procedure Delete (Container : in out Set; Key : Key_Type);
217
218       procedure Exclude (Container : in out Set; Key : Key_Type);
219
220       function "<" (Left : Cursor; Right : Key_Type) return Boolean;
221
222       function ">" (Left : Cursor; Right : Key_Type) return Boolean;
223
224       function "<" (Left : Key_Type; Right : Cursor) return Boolean;
225
226       function ">" (Left : Key_Type; Right : Cursor) return Boolean;
227
228       procedure Update_Element_Preserving_Key
229         (Container : in out Set;
230          Position  : Cursor;
231          Process   : not null access
232            procedure (Element : in out Element_Type));
233
234       procedure Iterate
235         (Container : Set;
236          Key       : Key_Type;
237          Process   : not null access procedure (Position : Cursor));
238
239       procedure Reverse_Iterate
240         (Container : Set;
241          Key       : Key_Type;
242          Process   : not null access procedure (Position : Cursor));
243
244    end Generic_Keys;
245
246 private
247
248    type Node_Type;
249    type Node_Access is access Node_Type;
250
251    type Node_Type is limited record
252       Parent  : Node_Access;
253       Left    : Node_Access;
254       Right   : Node_Access;
255       Color   : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
256       Element : Element_Type;
257    end record;
258
259    package Tree_Types is new Red_Black_Trees.Generic_Tree_Types
260      (Node_Type,
261       Node_Access);
262
263    type Set is new Ada.Finalization.Controlled with record
264       Tree : Tree_Types.Tree_Type;
265    end record;
266
267    procedure Adjust (Container : in out Set);
268
269    procedure Finalize (Container : in out Set) renames Clear;
270
271    use Red_Black_Trees;
272    use Tree_Types;
273    use Ada.Finalization;
274
275    type Set_Access is access all Set;
276    for Set_Access'Storage_Size use 0;
277
278    type Cursor is record
279       Container : Set_Access;
280       Node      : Node_Access;
281    end record;
282
283    No_Element : constant Cursor := Cursor'(null, null);
284
285    use Ada.Streams;
286
287    procedure Write
288      (Stream    : access Root_Stream_Type'Class;
289       Container : Set);
290
291    for Set'Write use Write;
292
293    procedure Read
294      (Stream    : access Root_Stream_Type'Class;
295       Container : out Set);
296
297    for Set'Read use Read;
298
299    Empty_Set : constant Set :=
300                  (Controlled with Tree => (First  => null,
301                                            Last   => null,
302                                            Root   => null,
303                                            Length => 0,
304                                            Busy   => 0,
305                                            Lock   => 0));
306
307 end Ada.Containers.Ordered_Multisets;