OSDN Git Service

PR preprocessor/20348
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-cihase.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --                      A D A . C O N T A I N E R S .                       --
6 --               I N D E F I N I T E _ H A S H E D _ S E T S                --
7 --                                                                          --
8 --                                 S p e c                                  --
9 --                                                                          --
10 --          Copyright (C) 2004-2005 Free Software Foundation, Inc.          --
11 --                                                                          --
12 -- This specification is derived from the Ada Reference Manual for use with --
13 -- GNAT. The copyright notice above, and the license provisions that follow --
14 -- apply solely to the  contents of the part following the private keyword. --
15 --                                                                          --
16 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
17 -- terms of the  GNU General Public License as published  by the Free Soft- --
18 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
19 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
20 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
21 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
22 -- for  more details.  You should have  received  a copy of the GNU General --
23 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
24 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
25 -- Boston, MA 02110-1301, USA.                                              --
26 --                                                                          --
27 -- As a special exception,  if other files  instantiate  generics from this --
28 -- unit, or you link  this unit with other files  to produce an executable, --
29 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
30 -- covered  by the  GNU  General  Public  License.  This exception does not --
31 -- however invalidate  any other reasons why  the executable file  might be --
32 -- covered by the  GNU Public License.                                      --
33 --                                                                          --
34 -- This unit was originally developed by Matthew J Heaney.                  --
35 ------------------------------------------------------------------------------
36
37 with Ada.Containers.Hash_Tables;
38 with Ada.Streams;
39 with Ada.Finalization;
40
41 generic
42    type Element_Type (<>) is private;
43
44    with function Hash (Element : Element_Type) return Hash_Type;
45
46    with function Equivalent_Elements (Left, Right : Element_Type)
47                                      return Boolean;
48
49    with function "=" (Left, Right : Element_Type) return Boolean is <>;
50
51 package Ada.Containers.Indefinite_Hashed_Sets is
52
53    pragma Preelaborate (Indefinite_Hashed_Sets);
54
55    type Set is tagged private;
56
57    type Cursor is private;
58
59    Empty_Set : constant Set;
60
61    No_Element : constant Cursor;
62
63    function "=" (Left, Right : Set) return Boolean;
64
65    function Equivalent_Sets (Left, Right : Set) return Boolean;
66
67    function Length (Container : Set) return Count_Type;
68
69    function Is_Empty (Container : Set) return Boolean;
70
71    procedure Clear (Container : in out Set);
72
73    function Element (Position : Cursor) return Element_Type;
74
75    procedure Query_Element
76      (Position : Cursor;
77       Process  : not null access procedure (Element : Element_Type));
78
79    procedure Replace_Element
80      (Container : Set;
81       Position  : Cursor;
82       By        : Element_Type);
83
84    procedure Move
85      (Target : in out Set;
86       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  (Container : in out Set; New_Item : Element_Type);
95
96    procedure Include (Container : in out Set; New_Item : Element_Type);
97
98    procedure Replace (Container : in out Set; New_Item : Element_Type);
99
100    procedure Delete  (Container : in out Set; Item : Element_Type);
101
102    procedure Delete (Container : in out Set; Position  : in out Cursor);
103
104    procedure Exclude (Container : in out Set; Item : Element_Type);
105
106    function Contains (Container : Set; Item : Element_Type) return Boolean;
107
108    function Find (Container : Set; Item : Element_Type) return Cursor;
109
110    function First (Container : Set) return Cursor;
111
112    function Next (Position : Cursor) return Cursor;
113
114    procedure Next (Position : in out Cursor);
115
116    function Has_Element (Position : Cursor) return Boolean;
117
118    function Equivalent_Elements (Left, Right : Cursor) return Boolean;
119
120    function Equivalent_Elements
121      (Left  : Cursor;
122       Right : Element_Type) return Boolean;
123
124    function Equivalent_Elements
125      (Left  : Element_Type;
126       Right : Cursor) return Boolean;
127
128    procedure Iterate
129      (Container : Set;
130       Process   : not null access procedure (Position : Cursor));
131
132    procedure Union (Target : in out Set; Source : Set);
133
134    function Union (Left, Right : Set) return Set;
135
136    function "or" (Left, Right : Set) return Set renames Union;
137
138    procedure Intersection (Target : in out Set; Source : Set);
139
140    function Intersection (Left, Right : Set) return Set;
141
142    function "and" (Left, Right : Set) return Set renames Intersection;
143
144    procedure Difference (Target : in out Set; Source : Set);
145
146    function Difference (Left, Right : Set) return Set;
147
148    function "-" (Left, Right : Set) return Set renames Difference;
149
150    procedure Symmetric_Difference (Target : in out Set; Source : Set);
151
152    function Symmetric_Difference (Left, Right : Set) return Set;
153
154    function "xor" (Left, Right : Set) return Set
155      renames Symmetric_Difference;
156
157    function Overlap (Left, Right : Set) return Boolean;
158
159    function Is_Subset (Subset : Set; Of_Set : Set) return Boolean;
160
161    function Capacity (Container : Set) return Count_Type;
162
163    procedure Reserve_Capacity
164      (Container : in out Set;
165       Capacity  : Count_Type);
166
167    generic
168       type Key_Type (<>) is limited private;
169
170       with function Key (Element : Element_Type) return Key_Type;
171
172       with function Hash (Key : Key_Type) return Hash_Type;
173
174       with function Equivalent_Keys
175         (Key     : Key_Type;
176          Element : Element_Type) return Boolean;
177
178    package Generic_Keys is
179
180       function Contains (Container : Set; Key : Key_Type) return Boolean;
181
182       function Find (Container : Set; Key : Key_Type) return Cursor;
183
184       function Key (Position : Cursor) return Key_Type;
185
186       function Element (Container : Set; Key : Key_Type) return Element_Type;
187
188       procedure Replace
189         (Container : in out Set;
190          Key       : Key_Type;
191          New_Item  : Element_Type);
192
193       procedure Delete (Container : in out Set; Key : Key_Type);
194
195       procedure Exclude (Container : in out Set; Key : Key_Type);
196
197       procedure Update_Element_Preserving_Key
198         (Container : in out Set;
199          Position  : Cursor;
200          Process   : not null access
201                        procedure (Element : in out Element_Type));
202
203       function Equivalent_Keys
204         (Left  : Cursor;
205          Right : Key_Type) return Boolean;
206
207       function Equivalent_Keys
208         (Left  : Key_Type;
209          Right : Cursor) return Boolean;
210    end Generic_Keys;
211
212 private
213    type Node_Type;
214    type Node_Access is access Node_Type;
215
216    type Element_Access is access Element_Type;
217
218    type Node_Type is
219       limited record
220          Element : Element_Access;
221          Next    : Node_Access;
222       end record;
223
224    package HT_Types is new Hash_Tables.Generic_Hash_Table_Types
225      (Node_Type,
226       Node_Access);
227
228    type Set is new Ada.Finalization.Controlled with record
229       HT : HT_Types.Hash_Table_Type;
230    end record;
231
232    procedure Adjust (Container : in out Set);
233
234    procedure Finalize (Container : in out Set);
235
236    use HT_Types;
237    use Ada.Finalization;
238
239    type Set_Access is access all Set;
240    for Set_Access'Storage_Size use 0;
241
242    type Cursor is
243       record
244          Container : Set_Access;
245          Node      : Node_Access;
246       end record;
247
248    No_Element : constant Cursor :=
249                   (Container => null,
250                    Node      => null);
251
252    use Ada.Streams;
253
254    procedure Write
255      (Stream    : access Root_Stream_Type'Class;
256       Container : Set);
257
258    for Set'Write use Write;
259
260    procedure Read
261      (Stream    : access Root_Stream_Type'Class;
262       Container : out Set);
263
264    for Set'Read use Read;
265
266    Empty_Set : constant Set := (Controlled with HT => (null, 0, 0, 0));
267
268 end Ada.Containers.Indefinite_Hashed_Sets;