OSDN Git Service

* a-rbtgso.adb, a-crbtgo.ads, a-crbtgo.adb, a-crbtgk.ads,
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-coorse.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --                       ADA.CONTAINERS.ORDERED_SETS                        --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --             Copyright (C) 2004 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,  59 Temple Place - Suite 330,  Boston, --
24 -- MA 02111-1307, 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
42    type Element_Type is private;
43
44    with function "<" (Left, Right : Element_Type) return Boolean is <>;
45    with function "=" (Left, Right : Element_Type) return Boolean is <>;
46
47 package Ada.Containers.Ordered_Sets is
48 pragma Preelaborate (Ordered_Sets);
49
50    type Set is tagged private;
51
52    type Cursor is private;
53
54    Empty_Set : constant Set;
55
56    No_Element : constant Cursor;
57
58    function "=" (Left, Right : Set) return Boolean;
59
60    function Length (Container : Set) return Count_Type;
61
62    function Is_Empty (Container : Set) return Boolean;
63
64    procedure Clear (Container : in out Set);
65
66    function Element (Position : Cursor) return Element_Type;
67
68    procedure Query_Element
69      (Position : Cursor;
70       Process  : not null access procedure (Element : Element_Type));
71
72 --  TODO: resolve in Atlanta. ???
73 --   procedure Replace_Element
74 --     (Container : in out 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       Inserted  : out Boolean);
87
88    procedure Insert
89      (Container : in out Set;
90       New_Item  : Element_Type);
91
92    procedure Include
93      (Container : in out Set;
94       New_Item  : Element_Type);
95
96    procedure Replace
97      (Container : in out Set;
98       New_Item  : Element_Type);
99
100    procedure Delete
101      (Container : in out Set;
102       Item      : Element_Type);
103
104    procedure Exclude
105      (Container : in out Set;
106       Item      : Element_Type);
107
108    procedure Delete
109      (Container : in out Set;
110       Position  : in out Cursor);
111
112    procedure Delete_First (Container : in out Set);
113
114    procedure Delete_Last (Container : in out Set);
115
116    procedure Union (Target : in out Set; Source : Set);
117
118    function Union (Left, Right : Set) return Set;
119
120    function "or" (Left, Right : Set) return Set renames Union;
121
122    procedure Intersection (Target : in out Set; Source : Set);
123
124    function Intersection (Left, Right : Set) return Set;
125
126    function "and" (Left, Right : Set) return Set renames Intersection;
127
128    procedure Difference (Target : in out Set;
129                          Source : Set);
130
131    function Difference (Left, Right : Set) return Set;
132
133    function "-" (Left, Right : Set) return Set renames Difference;
134
135    procedure Symmetric_Difference (Target : in out Set; Source : Set);
136
137    function Symmetric_Difference (Left, Right : Set) return Set;
138
139    function "xor" (Left, Right : Set) return Set renames Symmetric_Difference;
140
141    function Overlap (Left, Right : Set) return Boolean;
142
143    function Is_Subset (Subset : Set; Of_Set : Set) return Boolean;
144
145    function Contains (Container : Set; Item : Element_Type) return Boolean;
146
147    function Find (Container : Set; Item : Element_Type) return Cursor;
148
149    function Floor (Container : Set; Item : Element_Type) return Cursor;
150
151    function Ceiling (Container : Set; Item : Element_Type) return Cursor;
152
153    function First (Container : Set) return Cursor;
154
155    function First_Element (Container : Set) return Element_Type;
156
157    function Last (Container : Set) return Cursor;
158
159    function Last_Element (Container : Set) return Element_Type;
160
161    function Next (Position : Cursor) return Cursor;
162
163    function Previous (Position : Cursor) return Cursor;
164
165    procedure Next (Position : in out Cursor);
166
167    procedure Previous (Position : in out Cursor);
168
169    function Has_Element (Position : Cursor) return Boolean;
170
171    function "<" (Left, Right : Cursor) return Boolean;
172
173    function ">" (Left, Right : Cursor) return Boolean;
174
175    function "<" (Left : Cursor; Right : Element_Type) return Boolean;
176
177    function ">" (Left : Cursor; Right : Element_Type) return Boolean;
178
179    function "<" (Left : Element_Type; Right : Cursor) return Boolean;
180
181    function ">" (Left : Element_Type; Right : Cursor) return Boolean;
182
183    procedure Iterate
184      (Container : Set;
185       Process   : not null access procedure (Position : Cursor));
186
187    procedure Reverse_Iterate
188      (Container : Set;
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 "<"
197         (Left  : Key_Type;
198          Right : Element_Type) return Boolean is <>;
199
200       with function ">"
201         (Left  : Key_Type;
202          Right : Element_Type) return Boolean is <>;
203
204    package Generic_Keys is
205
206       function Contains (Container : Set; Key : Key_Type) return Boolean;
207
208       function Find (Container : Set; Key : Key_Type) return Cursor;
209
210       function Floor (Container : Set; Key : Key_Type) return Cursor;
211
212       function Ceiling (Container : Set; Key : Key_Type) return Cursor;
213
214       function Key (Position : Cursor) return Key_Type;
215
216       function Element (Container : Set; Key : Key_Type) return Element_Type;
217
218 --  TODO: resolve in Atlanta ???
219 --      procedure Replace
220 --        (Container : in out Set;
221 --         Key       : Key_Type;
222 --         New_Item  : Element_Type);
223
224       procedure Delete (Container : in out Set; Key : Key_Type);
225
226       procedure Exclude (Container : in out Set; Key : Key_Type);
227
228       function "<" (Left : Cursor; Right : Key_Type) return Boolean;
229
230       function ">" (Left : Cursor; Right : Key_Type) return Boolean;
231
232       function "<" (Left : Key_Type; Right : Cursor) return Boolean;
233
234       function ">" (Left : Key_Type; Right : Cursor) return Boolean;
235
236 --  TODO: resolve name in Atlanta. Should name be just "Update_Element" ???
237       procedure Checked_Update_Element
238         (Container : in out Set;
239          Position  : Cursor;
240          Process   : not null access
241                        procedure (Element : in out Element_Type));
242
243    end Generic_Keys;
244
245 private
246
247    type Node_Type;
248    type Node_Access is access Node_Type;
249
250    package Tree_Types is
251      new Red_Black_Trees.Generic_Tree_Types (Node_Access);
252
253    use Tree_Types;
254    use Ada.Finalization;
255
256    type Set is new Controlled with record
257       Tree : Tree_Type := (Length => 0, others => null);
258    end record;
259
260    procedure Adjust (Container : in out Set);
261
262    procedure Finalize (Container : in out Set) renames Clear;
263
264    type Set_Access is access constant Set;
265
266    type Cursor is record
267       Container : Set_Access;
268       Node      : Node_Access;
269    end record;
270
271    No_Element : constant Cursor := Cursor'(null, null);
272
273    use Ada.Streams;
274
275    procedure Write
276      (Stream    : access Root_Stream_Type'Class;
277       Container : Set);
278
279    for Set'Write use Write;
280
281    procedure Read
282      (Stream    : access Root_Stream_Type'Class;
283       Container : out Set);
284
285    for Set'Read use Read;
286
287    Empty_Set : constant Set :=
288                  (Controlled with Tree => (Length => 0, others => null));
289
290 end Ada.Containers.Ordered_Sets;