OSDN Git Service

2010-10-26 Tobias Burnus <burnus@net-b.de>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-cborse.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --   A D A . C O N T A I N E R S . B O U N D E D _ O R D E R E D _ S E T S  --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2004-2010, 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.Streams;
36
37 generic
38    type Element_Type is private;
39
40    with function "<" (Left, Right : Element_Type) return Boolean is <>;
41    with function "=" (Left, Right : Element_Type) return Boolean is <>;
42
43 package Ada.Containers.Bounded_Ordered_Sets is
44    pragma Pure;
45    pragma Remote_Types;
46
47    function Equivalent_Elements (Left, Right : Element_Type) return Boolean;
48
49    type Set (Capacity : Count_Type) is tagged private;
50    pragma Preelaborable_Initialization (Set);
51
52    type Cursor is private;
53    pragma Preelaborable_Initialization (Cursor);
54
55    Empty_Set : constant Set;
56
57    No_Element : constant Cursor;
58
59    function "=" (Left, Right : Set) return Boolean;
60
61    function Equivalent_Sets (Left, Right : Set) return Boolean;
62
63    function To_Set (New_Item : Element_Type) return Set;
64
65    function Length (Container : Set) return Count_Type;
66
67    function Is_Empty (Container : Set) return Boolean;
68
69    procedure Clear (Container : in out Set);
70
71    function Element (Position : Cursor) return Element_Type;
72
73    procedure Replace_Element
74      (Container : in out Set;
75       Position  : Cursor;
76       New_Item  : Element_Type);
77
78    procedure Query_Element
79      (Position : Cursor;
80       Process  : not null access procedure (Element : Element_Type));
81
82    procedure Assign (Target : in out Set; Source : Set);
83
84    function Copy (Source : Set; Capacity : Count_Type := 0) return Set;
85
86    procedure Move (Target : in out Set; Source : in out Set);
87
88    procedure Insert
89      (Container : in out Set;
90       New_Item  : Element_Type;
91       Position  : out Cursor;
92       Inserted  : out Boolean);
93
94    procedure Insert
95      (Container : in out Set;
96       New_Item  : Element_Type);
97
98    procedure Include
99      (Container : in out Set;
100       New_Item  : Element_Type);
101
102    procedure Replace
103      (Container : in out Set;
104       New_Item  : Element_Type);
105
106    procedure Exclude
107      (Container : in out Set;
108       Item      : Element_Type);
109
110    procedure Delete
111      (Container : in out Set;
112       Item      : Element_Type);
113
114    procedure Delete
115      (Container : in out Set;
116       Position  : in out Cursor);
117
118    procedure Delete_First (Container : in out Set);
119
120    procedure Delete_Last (Container : in out Set);
121
122    procedure Union (Target : in out Set; Source : Set);
123
124    function Union (Left, Right : Set) return Set;
125
126    function "or" (Left, Right : Set) return Set renames Union;
127
128    procedure Intersection (Target : in out Set; Source : Set);
129
130    function Intersection (Left, Right : Set) return Set;
131
132    function "and" (Left, Right : Set) return Set renames Intersection;
133
134    procedure Difference (Target : in out Set; Source : Set);
135
136    function Difference (Left, Right : Set) return Set;
137
138    function "-" (Left, Right : Set) return Set renames Difference;
139
140    procedure Symmetric_Difference (Target : in out Set; Source : Set);
141
142    function Symmetric_Difference (Left, Right : Set) return Set;
143
144    function "xor" (Left, Right : Set) return Set renames Symmetric_Difference;
145
146    function Overlap (Left, Right : Set) return Boolean;
147
148    function Is_Subset (Subset : Set; Of_Set : Set) return Boolean;
149
150    function First (Container : Set) return Cursor;
151
152    function First_Element (Container : Set) return Element_Type;
153
154    function Last (Container : Set) return Cursor;
155
156    function Last_Element (Container : Set) return Element_Type;
157
158    function Next (Position : Cursor) return Cursor;
159
160    procedure Next (Position : in out Cursor);
161
162    function Previous (Position : Cursor) return Cursor;
163
164    procedure Previous (Position : in out Cursor);
165
166    function Find (Container : Set; Item : Element_Type) return Cursor;
167
168    function Floor (Container : Set; Item : Element_Type) return Cursor;
169
170    function Ceiling (Container : Set; Item : Element_Type) return Cursor;
171
172    function Contains (Container : Set; Item : Element_Type) return Boolean;
173
174    function Has_Element (Position : Cursor) return Boolean;
175
176    function "<" (Left, Right : Cursor) return Boolean;
177
178    function ">" (Left, Right : Cursor) return Boolean;
179
180    function "<" (Left : Cursor; Right : Element_Type) return Boolean;
181
182    function ">" (Left : Cursor; Right : Element_Type) return Boolean;
183
184    function "<" (Left : Element_Type; Right : Cursor) return Boolean;
185
186    function ">" (Left : Element_Type; Right : Cursor) return Boolean;
187
188    procedure Iterate
189      (Container : Set;
190       Process   : not null access procedure (Position : Cursor));
191
192    procedure Reverse_Iterate
193      (Container : Set;
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 Replace
212         (Container : in out Set;
213          Key       : Key_Type;
214          New_Item  : Element_Type);
215
216       procedure Exclude (Container : in out Set; Key : Key_Type);
217
218       procedure Delete (Container : in out Set; Key : Key_Type);
219
220       function Find (Container : Set; Key : Key_Type) return Cursor;
221
222       function Floor (Container : Set; Key : Key_Type) return Cursor;
223
224       function Ceiling (Container : Set; Key : Key_Type) return Cursor;
225
226       function Contains (Container : Set; Key : Key_Type) 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    end Generic_Keys;
235
236 private
237
238    pragma Inline (Next);
239    pragma Inline (Previous);
240
241    type Node_Type is record
242       Parent  : Count_Type;
243       Left    : Count_Type;
244       Right   : Count_Type;
245       Color   : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
246       Element : Element_Type;
247    end record;
248
249    package Tree_Types is
250      new Red_Black_Trees.Generic_Bounded_Tree_Types (Node_Type);
251
252    type Set (Capacity : Count_Type) is
253      new Tree_Types.Tree_Type (Capacity) with null record;
254
255    type Set_Access is access all Set;
256    for Set_Access'Storage_Size use 0;
257
258    type Cursor is record
259       Container : Set_Access;
260       Node      : Count_Type;
261    end record;
262
263    use Tree_Types;
264    use Ada.Streams;
265
266    procedure Write
267      (Stream : not null access Root_Stream_Type'Class;
268       Item   : Cursor);
269
270    for Cursor'Write use Write;
271
272    procedure Read
273      (Stream : not null access Root_Stream_Type'Class;
274       Item   : out Cursor);
275
276    for Cursor'Read use Read;
277
278    No_Element : constant Cursor := Cursor'(null, 0);
279
280    procedure Write
281      (Stream    : not null access Root_Stream_Type'Class;
282       Container : Set);
283
284    for Set'Write use Write;
285
286    procedure Read
287      (Stream    : not null access Root_Stream_Type'Class;
288       Container : out Set);
289
290    for Set'Read use Read;
291
292    Empty_Set : constant Set := Set'(Tree_Type with Capacity => 0);
293
294 end Ada.Containers.Bounded_Ordered_Sets;