OSDN Git Service

2007-08-14 Bob Duff <duff@adacore.com>
[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-2007, 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    pragma Preelaborate;
53    pragma Remote_Types;
54
55    type Set is tagged private;
56    pragma Preelaborable_Initialization (Set);
57
58    type Cursor is private;
59    pragma Preelaborable_Initialization (Cursor);
60
61    Empty_Set : constant Set;
62
63    No_Element : constant Cursor;
64
65    function "=" (Left, Right : Set) return Boolean;
66
67    function Equivalent_Sets (Left, Right : Set) return Boolean;
68
69    function To_Set (New_Item : Element_Type) return Set;
70
71    function Capacity (Container : Set) return Count_Type;
72
73    procedure Reserve_Capacity
74      (Container : in out Set;
75       Capacity  : Count_Type);
76
77    function Length (Container : Set) return Count_Type;
78
79    function Is_Empty (Container : Set) return Boolean;
80
81    procedure Clear (Container : in out Set);
82
83    function Element (Position : Cursor) return Element_Type;
84
85    procedure Replace_Element
86      (Container : in out Set;
87       Position  : Cursor;
88       New_Item  : Element_Type);
89
90    procedure Query_Element
91      (Position : Cursor;
92       Process  : not null access procedure (Element : Element_Type));
93
94    procedure Move
95      (Target : in out Set;
96       Source : in out Set);
97
98    procedure Insert
99      (Container : in out Set;
100       New_Item  : Element_Type;
101       Position  : out Cursor;
102       Inserted  : out Boolean);
103
104    procedure Insert  (Container : in out Set; New_Item : Element_Type);
105
106    procedure Include (Container : in out Set; New_Item : Element_Type);
107
108    procedure Replace (Container : in out Set; New_Item : Element_Type);
109
110    procedure Exclude (Container : in out Set; Item : Element_Type);
111
112    procedure Delete  (Container : in out Set; Item : Element_Type);
113
114    procedure Delete (Container : in out Set; Position  : in out Cursor);
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; Source : Set);
129
130    function Difference (Left, Right : Set) return Set;
131
132    function "-" (Left, Right : Set) return Set renames Difference;
133
134    procedure Symmetric_Difference (Target : in out Set; Source : Set);
135
136    function Symmetric_Difference (Left, Right : Set) return Set;
137
138    function "xor" (Left, Right : Set) return Set
139      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 First (Container : Set) return Cursor;
146
147    function Next (Position : Cursor) return Cursor;
148
149    procedure Next (Position : in out Cursor);
150
151    function Find (Container : Set; Item : Element_Type) return Cursor;
152
153    function Contains (Container : Set; Item : Element_Type) return Boolean;
154
155    function Has_Element (Position : Cursor) return Boolean;
156
157    function Equivalent_Elements (Left, Right : Cursor) return Boolean;
158
159    function Equivalent_Elements
160      (Left  : Cursor;
161       Right : Element_Type) return Boolean;
162
163    function Equivalent_Elements
164      (Left  : Element_Type;
165       Right : Cursor) return Boolean;
166
167    procedure Iterate
168      (Container : Set;
169       Process   : not null access procedure (Position : Cursor));
170
171    generic
172       type Key_Type (<>) is private;
173
174       with function Key (Element : Element_Type) return Key_Type;
175
176       with function Hash (Key : Key_Type) return Hash_Type;
177
178       with function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
179
180    package Generic_Keys is
181
182       function Key (Position : Cursor) return Key_Type;
183
184       function Element (Container : Set; Key : Key_Type) return Element_Type;
185
186       procedure Replace
187         (Container : in out Set;
188          Key       : Key_Type;
189          New_Item  : Element_Type);
190
191       procedure Exclude (Container : in out Set; Key : Key_Type);
192
193       procedure Delete (Container : in out Set; Key : Key_Type);
194
195       function Find (Container : Set; Key : Key_Type) return Cursor;
196
197       function Contains (Container : Set; Key : Key_Type) return Boolean;
198
199       procedure Update_Element_Preserving_Key
200         (Container : in out Set;
201          Position  : Cursor;
202          Process   : not null access
203                        procedure (Element : in out Element_Type));
204
205    end Generic_Keys;
206
207 private
208
209    pragma Inline (Next);
210
211    type Node_Type;
212    type Node_Access is access Node_Type;
213
214    type Element_Access is access Element_Type;
215
216    type Node_Type is
217       limited record
218          Element : Element_Access;
219          Next    : Node_Access;
220       end record;
221
222    package HT_Types is new Hash_Tables.Generic_Hash_Table_Types
223      (Node_Type,
224       Node_Access);
225
226    type Set is new Ada.Finalization.Controlled with record
227       HT : HT_Types.Hash_Table_Type;
228    end record;
229
230    procedure Adjust (Container : in out Set);
231
232    procedure Finalize (Container : in out Set);
233
234    use HT_Types;
235    use Ada.Finalization;
236    use Ada.Streams;
237
238    type Set_Access is access all Set;
239    for Set_Access'Storage_Size use 0;
240
241    type Cursor is
242       record
243          Container : Set_Access;
244          Node      : Node_Access;
245       end record;
246
247    procedure Write
248      (Stream : not null access Root_Stream_Type'Class;
249       Item   : Cursor);
250
251    for Cursor'Write use Write;
252
253    procedure Read
254      (Stream : not null access Root_Stream_Type'Class;
255       Item   : out Cursor);
256
257    for Cursor'Read use Read;
258
259    No_Element : constant Cursor :=
260                   (Container => null,
261                    Node      => null);
262
263    procedure Write
264      (Stream    : not null access Root_Stream_Type'Class;
265       Container : Set);
266
267    for Set'Write use Write;
268
269    procedure Read
270      (Stream    : not null access Root_Stream_Type'Class;
271       Container : out Set);
272
273    for Set'Read use Read;
274
275    Empty_Set : constant Set := (Controlled with HT => (null, 0, 0, 0));
276
277 end Ada.Containers.Indefinite_Hashed_Sets;