OSDN Git Service

2008-03-26 Matthew Heaney <heaney@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-ciormu.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --               ADA.CONTAINERS.INDEFINITE_ORDERED_MULTISETS                --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2004-2008, 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 --  Documentation of this unit is needed ???
37
38 private with Ada.Containers.Red_Black_Trees;
39 private with Ada.Finalization;
40 private with Ada.Streams;
41
42 generic
43    type Element_Type (<>) is private;
44
45    with function "<" (Left, Right : Element_Type) return Boolean is <>;
46    with function "=" (Left, Right : Element_Type) return Boolean is <>;
47
48 package Ada.Containers.Indefinite_Ordered_Multisets is
49    pragma Preelaborate;
50    pragma Remote_Types;
51
52    function Equivalent_Elements (Left, Right : Element_Type) return Boolean;
53
54    type Set is tagged private;
55    pragma Preelaborable_Initialization (Set);
56
57    type Cursor is private;
58    pragma Preelaborable_Initialization (Cursor);
59
60    Empty_Set : constant Set;
61
62    No_Element : constant Cursor;
63
64    function "=" (Left, Right : Set) return Boolean;
65
66    function Equivalent_Sets (Left, Right : Set) return Boolean;
67
68    function To_Set (New_Item : Element_Type) return Set;
69
70    function Length (Container : Set) return Count_Type;
71
72    function Is_Empty (Container : Set) return Boolean;
73
74    procedure Clear (Container : in out Set);
75
76    function Element (Position : Cursor) return Element_Type;
77
78    procedure Replace_Element
79      (Container : in out Set;
80       Position  : Cursor;
81       New_Item  : Element_Type);
82
83    procedure Query_Element
84      (Position : Cursor;
85       Process  : not null access procedure (Element : Element_Type));
86
87    procedure Move (Target : in out Set; Source : in out Set);
88
89    procedure Insert
90      (Container : in out Set;
91       New_Item  : Element_Type;
92       Position  : out Cursor);
93
94    procedure Insert (Container : in out Set; New_Item : Element_Type);
95
96 --  TODO: include Replace too???
97 --
98 --     procedure Replace
99 --       (Container : in out Set;
100 --        New_Item  : Element_Type);
101
102    procedure Exclude (Container : in out Set; Item : Element_Type);
103
104    procedure Delete (Container : in out Set; Item : Element_Type);
105
106    procedure Delete (Container : in out Set; Position : in out Cursor);
107
108    procedure Delete_First (Container : in out Set);
109
110    procedure Delete_Last (Container : in out Set);
111
112    procedure Union (Target : in out Set; Source : Set);
113
114    function Union (Left, Right : Set) return Set;
115
116    function "or" (Left, Right : Set) return Set renames Union;
117
118    procedure Intersection (Target : in out Set; Source : Set);
119
120    function Intersection (Left, Right : Set) return Set;
121
122    function "and" (Left, Right : Set) return Set renames Intersection;
123
124    procedure Difference (Target : in out Set; Source : Set);
125
126    function Difference (Left, Right : Set) return Set;
127
128    function "-" (Left, Right : Set) return Set renames Difference;
129
130    procedure Symmetric_Difference (Target : in out Set; Source : Set);
131
132    function Symmetric_Difference (Left, Right : Set) return Set;
133
134    function "xor" (Left, Right : Set) return Set renames Symmetric_Difference;
135
136    function Overlap (Left, Right : Set) return Boolean;
137
138    function Is_Subset (Subset : Set; Of_Set : Set) return Boolean;
139
140    function First (Container : Set) return Cursor;
141
142    function First_Element (Container : Set) return Element_Type;
143
144    function Last (Container : Set) return Cursor;
145
146    function Last_Element (Container : Set) return Element_Type;
147
148    function Next (Position : Cursor) return Cursor;
149
150    procedure Next (Position : in out Cursor);
151
152    function Previous (Position : Cursor) return Cursor;
153
154    procedure Previous (Position : in out Cursor);
155
156    function Find (Container : Set; Item : Element_Type) return Cursor;
157
158    function Floor (Container : Set; Item : Element_Type) return Cursor;
159
160    function Ceiling (Container : Set; Item : Element_Type) return Cursor;
161
162    function Contains (Container : Set; Item : Element_Type) return Boolean;
163
164    function Has_Element (Position : Cursor) return Boolean;
165
166    function "<" (Left, Right : Cursor) return Boolean;
167
168    function ">" (Left, Right : Cursor) return Boolean;
169
170    function "<" (Left : Cursor; Right : Element_Type) return Boolean;
171
172    function ">" (Left : Cursor; Right : Element_Type) return Boolean;
173
174    function "<" (Left : Element_Type; Right : Cursor) return Boolean;
175
176    function ">" (Left : Element_Type; Right : Cursor) return Boolean;
177
178    procedure Iterate
179      (Container : Set;
180       Process   : not null access procedure (Position : Cursor));
181
182    procedure Reverse_Iterate
183      (Container : Set;
184       Process   : not null access procedure (Position : Cursor));
185
186    procedure Iterate
187      (Container : Set;
188       Item      : Element_Type;
189       Process   : not null access procedure (Position : Cursor));
190
191    procedure Reverse_Iterate
192      (Container : Set;
193       Item      : Element_Type;
194       Process   : not null access procedure (Position : Cursor));
195
196    generic
197       type Key_Type (<>) is private;
198
199       with function Key (Element : Element_Type) return Key_Type;
200
201       with function "<" (Left, Right : Key_Type) return Boolean is <>;
202
203    package Generic_Keys is
204
205       function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
206
207       function Key (Position : Cursor) return Key_Type;
208
209       function Element (Container : Set; Key : Key_Type) return Element_Type;
210
211       procedure Exclude (Container : in out Set; Key : Key_Type);
212
213       procedure Delete (Container : in out Set; Key : Key_Type);
214
215       function Find (Container : Set; Key : Key_Type) return Cursor;
216
217       function Floor (Container : Set; Key : Key_Type) return Cursor;
218
219       function Ceiling (Container : Set; Key : Key_Type) return Cursor;
220
221       function Contains (Container : Set; Key : Key_Type) return Boolean;
222
223       procedure Update_Element
224         (Container : in out Set;
225          Position  : Cursor;
226          Process   : not null access
227                        procedure (Element : in out Element_Type));
228
229       procedure Iterate
230         (Container : Set;
231          Key       : Key_Type;
232          Process   : not null access procedure (Position : Cursor));
233
234       procedure Reverse_Iterate
235         (Container : Set;
236          Key       : Key_Type;
237          Process   : not null access procedure (Position : Cursor));
238
239    end Generic_Keys;
240
241 private
242
243    pragma Inline (Next);
244    pragma Inline (Previous);
245
246    type Node_Type;
247    type Node_Access is access Node_Type;
248
249    type Element_Access is access Element_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_Access;
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    overriding
268    procedure Adjust (Container : in out Set);
269
270    overriding
271    procedure Finalize (Container : in out Set) renames Clear;
272
273    use Red_Black_Trees;
274    use Tree_Types;
275    use Ada.Finalization;
276    use Ada.Streams;
277
278    type Set_Access is access all Set;
279    for Set_Access'Storage_Size use 0;
280
281    type Cursor is record
282       Container : Set_Access;
283       Node      : Node_Access;
284    end record;
285
286    procedure Write
287      (Stream : not null access Root_Stream_Type'Class;
288       Item   : Cursor);
289
290    for Cursor'Write use Write;
291
292    procedure Read
293      (Stream : not null access Root_Stream_Type'Class;
294       Item   : out Cursor);
295
296    for Cursor'Read use Read;
297
298    No_Element : constant Cursor := Cursor'(null, null);
299
300    procedure Write
301      (Stream    : not null access Root_Stream_Type'Class;
302       Container : Set);
303
304    for Set'Write use Write;
305
306    procedure Read
307      (Stream    : not null access Root_Stream_Type'Class;
308       Container : out Set);
309
310    for Set'Read use Read;
311
312    Empty_Set : constant Set :=
313                  (Controlled with Tree => (First  => null,
314                                            Last   => null,
315                                            Root   => null,
316                                            Length => 0,
317                                            Busy   => 0,
318                                            Lock   => 0));
319
320 end Ada.Containers.Indefinite_Ordered_Multisets;