annotate gcc/ada/libgnat/a-cbhama.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT LIBRARY COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- A D A . C O N T A I N E R S . B O U N D E D _ H A S H E D _ M A P S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 2004-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- This specification is derived from the Ada Reference Manual for use with --
kono
parents:
diff changeset
12 -- GNAT. The copyright notice above, and the license provisions that follow --
kono
parents:
diff changeset
13 -- apply solely to the contents of the part following the private keyword. --
kono
parents:
diff changeset
14 -- --
kono
parents:
diff changeset
15 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
16 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
23 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
24 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
25 -- --
kono
parents:
diff changeset
26 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
27 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
29 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
30 -- --
kono
parents:
diff changeset
31 -- This unit was originally developed by Matthew J Heaney. --
kono
parents:
diff changeset
32 ------------------------------------------------------------------------------
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 with Ada.Iterator_Interfaces;
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 private with Ada.Containers.Hash_Tables;
kono
parents:
diff changeset
37 private with Ada.Streams;
kono
parents:
diff changeset
38 private with Ada.Finalization;
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 generic
kono
parents:
diff changeset
41 type Key_Type is private;
kono
parents:
diff changeset
42 type Element_Type is private;
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 with function Hash (Key : Key_Type) return Hash_Type;
kono
parents:
diff changeset
45 with function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
kono
parents:
diff changeset
46 with function "=" (Left, Right : Element_Type) return Boolean is <>;
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 package Ada.Containers.Bounded_Hashed_Maps is
kono
parents:
diff changeset
49 pragma Annotate (CodePeer, Skip_Analysis);
kono
parents:
diff changeset
50 pragma Pure;
kono
parents:
diff changeset
51 pragma Remote_Types;
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 type Map (Capacity : Count_Type; Modulus : Hash_Type) is tagged private with
kono
parents:
diff changeset
54 Constant_Indexing => Constant_Reference,
kono
parents:
diff changeset
55 Variable_Indexing => Reference,
kono
parents:
diff changeset
56 Default_Iterator => Iterate,
kono
parents:
diff changeset
57 Iterator_Element => Element_Type;
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 pragma Preelaborable_Initialization (Map);
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 type Cursor is private;
kono
parents:
diff changeset
62 pragma Preelaborable_Initialization (Cursor);
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 Empty_Map : constant Map;
kono
parents:
diff changeset
65 -- Map objects declared without an initialization expression are
kono
parents:
diff changeset
66 -- initialized to the value Empty_Map.
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 No_Element : constant Cursor;
kono
parents:
diff changeset
69 -- Cursor objects declared without an initialization expression are
kono
parents:
diff changeset
70 -- initialized to the value No_Element.
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 function Has_Element (Position : Cursor) return Boolean;
kono
parents:
diff changeset
73 -- Equivalent to Position /= No_Element
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 package Map_Iterator_Interfaces is new
kono
parents:
diff changeset
76 Ada.Iterator_Interfaces (Cursor, Has_Element);
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 function "=" (Left, Right : Map) return Boolean;
kono
parents:
diff changeset
79 -- For each key/element pair in Left, equality attempts to find the key in
kono
parents:
diff changeset
80 -- Right; if a search fails the equality returns False. The search works by
kono
parents:
diff changeset
81 -- calling Hash to find the bucket in the Right map that corresponds to the
kono
parents:
diff changeset
82 -- Left key. If bucket is non-empty, then equality calls Equivalent_Keys
kono
parents:
diff changeset
83 -- to compare the key (in Left) to the key of each node in the bucket (in
kono
parents:
diff changeset
84 -- Right); if the keys are equivalent, then the equality test for this
kono
parents:
diff changeset
85 -- key/element pair (in Left) completes by calling the element equality
kono
parents:
diff changeset
86 -- operator to compare the element (in Left) to the element of the node
kono
parents:
diff changeset
87 -- (in Right) whose key matched.
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 function Capacity (Container : Map) return Count_Type;
kono
parents:
diff changeset
90 -- Returns the current capacity of the map. Capacity is the maximum length
kono
parents:
diff changeset
91 -- before which rehashing in guaranteed not to occur.
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 procedure Reserve_Capacity (Container : in out Map; Capacity : Count_Type);
kono
parents:
diff changeset
94 -- If the value of the Capacity actual parameter is less or equal to
kono
parents:
diff changeset
95 -- Container.Capacity, then the operation has no effect. Otherwise it
kono
parents:
diff changeset
96 -- raises Capacity_Error (as no expansion of capacity is possible for a
kono
parents:
diff changeset
97 -- bounded form).
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 function Default_Modulus (Capacity : Count_Type) return Hash_Type;
kono
parents:
diff changeset
100 -- Returns a modulus value (hash table size) which is optimal for the
kono
parents:
diff changeset
101 -- specified capacity (which corresponds to the maximum number of items).
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 function Length (Container : Map) return Count_Type;
kono
parents:
diff changeset
104 -- Returns the number of items in the map
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 function Is_Empty (Container : Map) return Boolean;
kono
parents:
diff changeset
107 -- Equivalent to Length (Container) = 0
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 procedure Clear (Container : in out Map);
kono
parents:
diff changeset
110 -- Removes all of the items from the map
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 function Key (Position : Cursor) return Key_Type;
kono
parents:
diff changeset
113 -- Returns the key of the node designated by the cursor
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 function Element (Position : Cursor) return Element_Type;
kono
parents:
diff changeset
116 -- Returns the element of the node designated by the cursor
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 procedure Replace_Element
kono
parents:
diff changeset
119 (Container : in out Map;
kono
parents:
diff changeset
120 Position : Cursor;
kono
parents:
diff changeset
121 New_Item : Element_Type);
kono
parents:
diff changeset
122 -- Assigns the value New_Item to the element designated by the cursor
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 procedure Query_Element
kono
parents:
diff changeset
125 (Position : Cursor;
kono
parents:
diff changeset
126 Process : not null access
kono
parents:
diff changeset
127 procedure (Key : Key_Type; Element : Element_Type));
kono
parents:
diff changeset
128 -- Calls Process with the key and element (both having only a constant
kono
parents:
diff changeset
129 -- view) of the node designed by the cursor.
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 procedure Update_Element
kono
parents:
diff changeset
132 (Container : in out Map;
kono
parents:
diff changeset
133 Position : Cursor;
kono
parents:
diff changeset
134 Process : not null access
kono
parents:
diff changeset
135 procedure (Key : Key_Type; Element : in out Element_Type));
kono
parents:
diff changeset
136 -- Calls Process with the key (with only a constant view) and element (with
kono
parents:
diff changeset
137 -- a variable view) of the node designed by the cursor.
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 type Constant_Reference_Type
kono
parents:
diff changeset
140 (Element : not null access constant Element_Type) is
kono
parents:
diff changeset
141 private
kono
parents:
diff changeset
142 with
kono
parents:
diff changeset
143 Implicit_Dereference => Element;
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 type Reference_Type (Element : not null access Element_Type) is private
kono
parents:
diff changeset
146 with
kono
parents:
diff changeset
147 Implicit_Dereference => Element;
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 function Constant_Reference
kono
parents:
diff changeset
150 (Container : aliased Map;
kono
parents:
diff changeset
151 Position : Cursor) return Constant_Reference_Type;
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 function Reference
kono
parents:
diff changeset
154 (Container : aliased in out Map;
kono
parents:
diff changeset
155 Position : Cursor) return Reference_Type;
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 function Constant_Reference
kono
parents:
diff changeset
158 (Container : aliased Map;
kono
parents:
diff changeset
159 Key : Key_Type) return Constant_Reference_Type;
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 function Reference
kono
parents:
diff changeset
162 (Container : aliased in out Map;
kono
parents:
diff changeset
163 Key : Key_Type) return Reference_Type;
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 procedure Assign (Target : in out Map; Source : Map);
kono
parents:
diff changeset
166 -- If Target denotes the same object as Source, then the operation has no
kono
parents:
diff changeset
167 -- effect. If the Target capacity is less than the Source length, then
kono
parents:
diff changeset
168 -- Assign raises Capacity_Error. Otherwise, Assign clears Target and then
kono
parents:
diff changeset
169 -- copies the (active) elements from Source to Target.
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 function Copy
kono
parents:
diff changeset
172 (Source : Map;
kono
parents:
diff changeset
173 Capacity : Count_Type := 0;
kono
parents:
diff changeset
174 Modulus : Hash_Type := 0) return Map;
kono
parents:
diff changeset
175 -- Constructs a new set object whose elements correspond to Source. If the
kono
parents:
diff changeset
176 -- Capacity parameter is 0, then the capacity of the result is the same as
kono
parents:
diff changeset
177 -- the length of Source. If the Capacity parameter is equal or greater than
kono
parents:
diff changeset
178 -- the length of Source, then the capacity of the result is the specified
kono
parents:
diff changeset
179 -- value. Otherwise, Copy raises Capacity_Error. If the Modulus parameter
kono
parents:
diff changeset
180 -- is 0, then the modulus of the result is the value returned by a call to
kono
parents:
diff changeset
181 -- Default_Modulus with the capacity parameter determined as above;
kono
parents:
diff changeset
182 -- otherwise the modulus of the result is the specified value.
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 procedure Move (Target : in out Map; Source : in out Map);
kono
parents:
diff changeset
185 -- Clears Target (if it's not empty), and then moves (not copies) the
kono
parents:
diff changeset
186 -- buckets array and nodes from Source to Target.
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 procedure Insert
kono
parents:
diff changeset
189 (Container : in out Map;
kono
parents:
diff changeset
190 Key : Key_Type;
kono
parents:
diff changeset
191 New_Item : Element_Type;
kono
parents:
diff changeset
192 Position : out Cursor;
kono
parents:
diff changeset
193 Inserted : out Boolean);
kono
parents:
diff changeset
194 -- Conditionally inserts New_Item into the map. If Key is already in the
kono
parents:
diff changeset
195 -- map, then Inserted returns False and Position designates the node
kono
parents:
diff changeset
196 -- containing the existing key/element pair (neither of which is modified).
kono
parents:
diff changeset
197 -- If Key is not already in the map, the Inserted returns True and Position
kono
parents:
diff changeset
198 -- designates the newly-inserted node container Key and New_Item. The
kono
parents:
diff changeset
199 -- search for the key works as follows. Hash is called to determine Key's
kono
parents:
diff changeset
200 -- bucket; if the bucket is non-empty, then Equivalent_Keys is called to
kono
parents:
diff changeset
201 -- compare Key to each node in that bucket. If the bucket is empty, or
kono
parents:
diff changeset
202 -- there were no matching keys in the bucket, the search "fails" and the
kono
parents:
diff changeset
203 -- key/item pair is inserted in the map (and Inserted returns True);
kono
parents:
diff changeset
204 -- otherwise, the search "succeeds" (and Inserted returns False).
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 procedure Insert
kono
parents:
diff changeset
207 (Container : in out Map;
kono
parents:
diff changeset
208 Key : Key_Type;
kono
parents:
diff changeset
209 Position : out Cursor;
kono
parents:
diff changeset
210 Inserted : out Boolean);
kono
parents:
diff changeset
211 -- The same as the (conditional) Insert that accepts an element parameter,
kono
parents:
diff changeset
212 -- with the difference that if Inserted returns True, then the element of
kono
parents:
diff changeset
213 -- the newly-inserted node is initialized to its default value.
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 procedure Insert
kono
parents:
diff changeset
216 (Container : in out Map;
kono
parents:
diff changeset
217 Key : Key_Type;
kono
parents:
diff changeset
218 New_Item : Element_Type);
kono
parents:
diff changeset
219 -- Attempts to insert Key into the map, performing the usual search (which
kono
parents:
diff changeset
220 -- involves calling both Hash and Equivalent_Keys); if the search succeeds
kono
parents:
diff changeset
221 -- (because Key is already in the map), then it raises Constraint_Error.
kono
parents:
diff changeset
222 -- (This version of Insert is similar to Replace, but having the opposite
kono
parents:
diff changeset
223 -- exception behavior. It is intended for use when you want to assert that
kono
parents:
diff changeset
224 -- Key is not already in the map.)
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 procedure Include
kono
parents:
diff changeset
227 (Container : in out Map;
kono
parents:
diff changeset
228 Key : Key_Type;
kono
parents:
diff changeset
229 New_Item : Element_Type);
kono
parents:
diff changeset
230 -- Attempts to insert Key into the map. If Key is already in the map, then
kono
parents:
diff changeset
231 -- both the existing key and element are assigned the values of Key and
kono
parents:
diff changeset
232 -- New_Item, respectively. (This version of Insert only raises an exception
kono
parents:
diff changeset
233 -- if cursor tampering occurs. It is intended for use when you want to
kono
parents:
diff changeset
234 -- insert the key/element pair in the map, and you don't care whether Key
kono
parents:
diff changeset
235 -- is already present.)
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 procedure Replace
kono
parents:
diff changeset
238 (Container : in out Map;
kono
parents:
diff changeset
239 Key : Key_Type;
kono
parents:
diff changeset
240 New_Item : Element_Type);
kono
parents:
diff changeset
241 -- Searches for Key in the map; if the search fails (because Key was not in
kono
parents:
diff changeset
242 -- the map), then it raises Constraint_Error. Otherwise, both the existing
kono
parents:
diff changeset
243 -- key and element are assigned the values of Key and New_Item rsp. (This
kono
parents:
diff changeset
244 -- is similar to Insert, but with the opposite exception behavior. It is to
kono
parents:
diff changeset
245 -- be used when you want to assert that Key is already in the map.)
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 procedure Exclude (Container : in out Map; Key : Key_Type);
kono
parents:
diff changeset
248 -- Searches for Key in the map, and if found, removes its node from the map
kono
parents:
diff changeset
249 -- and then deallocates it. The search works as follows. The operation
kono
parents:
diff changeset
250 -- calls Hash to determine the key's bucket; if the bucket is not empty, it
kono
parents:
diff changeset
251 -- calls Equivalent_Keys to compare Key to each key in the bucket. (This is
kono
parents:
diff changeset
252 -- the deletion analog of Include. It is intended for use when you want to
kono
parents:
diff changeset
253 -- remove the item from the map, but don't care whether the key is already
kono
parents:
diff changeset
254 -- in the map.)
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 procedure Delete (Container : in out Map; Key : Key_Type);
kono
parents:
diff changeset
257 -- Searches for Key in the map (which involves calling both Hash and
kono
parents:
diff changeset
258 -- Equivalent_Keys). If the search fails, then the operation raises
kono
parents:
diff changeset
259 -- Constraint_Error. Otherwise it removes the node from the map and then
kono
parents:
diff changeset
260 -- deallocates it. (This is the deletion analog of non-conditional
kono
parents:
diff changeset
261 -- Insert. It is intended for use when you want to assert that the item is
kono
parents:
diff changeset
262 -- already in the map.)
kono
parents:
diff changeset
263
kono
parents:
diff changeset
264 procedure Delete (Container : in out Map; Position : in out Cursor);
kono
parents:
diff changeset
265 -- Removes the node designated by Position from the map, and then
kono
parents:
diff changeset
266 -- deallocates the node. The operation calls Hash to determine the bucket,
kono
parents:
diff changeset
267 -- and then compares Position to each node in the bucket until there's a
kono
parents:
diff changeset
268 -- match (it does not call Equivalent_Keys).
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 function First (Container : Map) return Cursor;
kono
parents:
diff changeset
271 -- Returns a cursor that designates the first non-empty bucket, by
kono
parents:
diff changeset
272 -- searching from the beginning of the buckets array.
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 function Next (Position : Cursor) return Cursor;
kono
parents:
diff changeset
275 -- Returns a cursor that designates the node that follows the current one
kono
parents:
diff changeset
276 -- designated by Position. If Position designates the last node in its
kono
parents:
diff changeset
277 -- bucket, the operation calls Hash to compute the index of this bucket,
kono
parents:
diff changeset
278 -- and searches the buckets array for the first non-empty bucket, starting
kono
parents:
diff changeset
279 -- from that index; otherwise, it simply follows the link to the next node
kono
parents:
diff changeset
280 -- in the same bucket.
kono
parents:
diff changeset
281
kono
parents:
diff changeset
282 procedure Next (Position : in out Cursor);
kono
parents:
diff changeset
283 -- Equivalent to Position := Next (Position)
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 function Find (Container : Map; Key : Key_Type) return Cursor;
kono
parents:
diff changeset
286 -- Searches for Key in the map. Find calls Hash to determine the key's
kono
parents:
diff changeset
287 -- bucket; if the bucket is not empty, it calls Equivalent_Keys to compare
kono
parents:
diff changeset
288 -- Key to each key in the bucket. If the search succeeds, Find returns a
kono
parents:
diff changeset
289 -- cursor designating the matching node; otherwise, it returns No_Element.
kono
parents:
diff changeset
290
kono
parents:
diff changeset
291 function Contains (Container : Map; Key : Key_Type) return Boolean;
kono
parents:
diff changeset
292 -- Equivalent to Find (Container, Key) /= No_Element
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 function Element (Container : Map; Key : Key_Type) return Element_Type;
kono
parents:
diff changeset
295 -- Equivalent to Element (Find (Container, Key))
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 function Equivalent_Keys (Left, Right : Cursor) return Boolean;
kono
parents:
diff changeset
298 -- Returns the result of calling Equivalent_Keys with the keys of the nodes
kono
parents:
diff changeset
299 -- designated by cursors Left and Right.
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 function Equivalent_Keys (Left : Cursor; Right : Key_Type) return Boolean;
kono
parents:
diff changeset
302 -- Returns the result of calling Equivalent_Keys with key of the node
kono
parents:
diff changeset
303 -- designated by Left and key Right.
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 function Equivalent_Keys (Left : Key_Type; Right : Cursor) return Boolean;
kono
parents:
diff changeset
306 -- Returns the result of calling Equivalent_Keys with key Left and the node
kono
parents:
diff changeset
307 -- designated by Right.
kono
parents:
diff changeset
308
kono
parents:
diff changeset
309 procedure Iterate
kono
parents:
diff changeset
310 (Container : Map;
kono
parents:
diff changeset
311 Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
312 -- Calls Process for each node in the map
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 function Iterate (Container : Map)
kono
parents:
diff changeset
315 return Map_Iterator_Interfaces.Forward_Iterator'class;
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 private
kono
parents:
diff changeset
318 pragma Inline (Length);
kono
parents:
diff changeset
319 pragma Inline (Is_Empty);
kono
parents:
diff changeset
320 pragma Inline (Clear);
kono
parents:
diff changeset
321 pragma Inline (Key);
kono
parents:
diff changeset
322 pragma Inline (Element);
kono
parents:
diff changeset
323 pragma Inline (Move);
kono
parents:
diff changeset
324 pragma Inline (Contains);
kono
parents:
diff changeset
325 pragma Inline (Capacity);
kono
parents:
diff changeset
326 pragma Inline (Reserve_Capacity);
kono
parents:
diff changeset
327 pragma Inline (Has_Element);
kono
parents:
diff changeset
328 pragma Inline (Next);
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 type Node_Type is record
kono
parents:
diff changeset
331 Key : Key_Type;
kono
parents:
diff changeset
332 Element : aliased Element_Type;
kono
parents:
diff changeset
333 Next : Count_Type;
kono
parents:
diff changeset
334 end record;
kono
parents:
diff changeset
335
kono
parents:
diff changeset
336 package HT_Types is
kono
parents:
diff changeset
337 new Hash_Tables.Generic_Bounded_Hash_Table_Types (Node_Type);
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 type Map (Capacity : Count_Type; Modulus : Hash_Type) is
kono
parents:
diff changeset
340 new HT_Types.Hash_Table_Type (Capacity, Modulus) with null record;
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 use HT_Types, HT_Types.Implementation;
kono
parents:
diff changeset
343 use Ada.Streams;
kono
parents:
diff changeset
344 use Ada.Finalization;
kono
parents:
diff changeset
345
kono
parents:
diff changeset
346 procedure Write
kono
parents:
diff changeset
347 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
348 Container : Map);
kono
parents:
diff changeset
349
kono
parents:
diff changeset
350 for Map'Write use Write;
kono
parents:
diff changeset
351
kono
parents:
diff changeset
352 procedure Read
kono
parents:
diff changeset
353 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
354 Container : out Map);
kono
parents:
diff changeset
355
kono
parents:
diff changeset
356 for Map'Read use Read;
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 type Map_Access is access all Map;
kono
parents:
diff changeset
359 for Map_Access'Storage_Size use 0;
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 -- Note: If a Cursor object has no explicit initialization expression,
kono
parents:
diff changeset
362 -- it must default initialize to the same value as constant No_Element.
kono
parents:
diff changeset
363 -- The Node component of type Cursor has scalar type Count_Type, so it
kono
parents:
diff changeset
364 -- requires an explicit initialization expression of its own declaration,
kono
parents:
diff changeset
365 -- in order for objects of record type Cursor to properly initialize.
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 type Cursor is record
kono
parents:
diff changeset
368 Container : Map_Access;
kono
parents:
diff changeset
369 Node : Count_Type := 0;
kono
parents:
diff changeset
370 end record;
kono
parents:
diff changeset
371
kono
parents:
diff changeset
372 procedure Read
kono
parents:
diff changeset
373 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
374 Item : out Cursor);
kono
parents:
diff changeset
375
kono
parents:
diff changeset
376 for Cursor'Read use Read;
kono
parents:
diff changeset
377
kono
parents:
diff changeset
378 procedure Write
kono
parents:
diff changeset
379 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
380 Item : Cursor);
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 for Cursor'Write use Write;
kono
parents:
diff changeset
383
kono
parents:
diff changeset
384 subtype Reference_Control_Type is Implementation.Reference_Control_Type;
kono
parents:
diff changeset
385 -- It is necessary to rename this here, so that the compiler can find it
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 type Constant_Reference_Type
kono
parents:
diff changeset
388 (Element : not null access constant Element_Type) is
kono
parents:
diff changeset
389 record
kono
parents:
diff changeset
390 Control : Reference_Control_Type :=
kono
parents:
diff changeset
391 raise Program_Error with "uninitialized reference";
kono
parents:
diff changeset
392 -- The RM says, "The default initialization of an object of
kono
parents:
diff changeset
393 -- type Constant_Reference_Type or Reference_Type propagates
kono
parents:
diff changeset
394 -- Program_Error."
kono
parents:
diff changeset
395 end record;
kono
parents:
diff changeset
396
kono
parents:
diff changeset
397 procedure Write
kono
parents:
diff changeset
398 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
399 Item : Constant_Reference_Type);
kono
parents:
diff changeset
400
kono
parents:
diff changeset
401 for Constant_Reference_Type'Write use Write;
kono
parents:
diff changeset
402
kono
parents:
diff changeset
403 procedure Read
kono
parents:
diff changeset
404 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
405 Item : out Constant_Reference_Type);
kono
parents:
diff changeset
406
kono
parents:
diff changeset
407 for Constant_Reference_Type'Read use Read;
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 type Reference_Type (Element : not null access Element_Type) is record
kono
parents:
diff changeset
410 Control : Reference_Control_Type :=
kono
parents:
diff changeset
411 raise Program_Error with "uninitialized reference";
kono
parents:
diff changeset
412 -- The RM says, "The default initialization of an object of
kono
parents:
diff changeset
413 -- type Constant_Reference_Type or Reference_Type propagates
kono
parents:
diff changeset
414 -- Program_Error."
kono
parents:
diff changeset
415 end record;
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 procedure Write
kono
parents:
diff changeset
418 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
419 Item : Reference_Type);
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 for Reference_Type'Write use Write;
kono
parents:
diff changeset
422
kono
parents:
diff changeset
423 procedure Read
kono
parents:
diff changeset
424 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
425 Item : out Reference_Type);
kono
parents:
diff changeset
426
kono
parents:
diff changeset
427 for Reference_Type'Read use Read;
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429 -- Three operations are used to optimize in the expansion of "for ... of"
kono
parents:
diff changeset
430 -- loops: the Next(Cursor) procedure in the visible part, and the following
kono
parents:
diff changeset
431 -- Pseudo_Reference and Get_Element_Access functions. See Sem_Ch5 for
kono
parents:
diff changeset
432 -- details.
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 function Pseudo_Reference
kono
parents:
diff changeset
435 (Container : aliased Map'Class) return Reference_Control_Type;
kono
parents:
diff changeset
436 pragma Inline (Pseudo_Reference);
kono
parents:
diff changeset
437 -- Creates an object of type Reference_Control_Type pointing to the
kono
parents:
diff changeset
438 -- container, and increments the Lock. Finalization of this object will
kono
parents:
diff changeset
439 -- decrement the Lock.
kono
parents:
diff changeset
440
kono
parents:
diff changeset
441 type Element_Access is access all Element_Type with
kono
parents:
diff changeset
442 Storage_Size => 0;
kono
parents:
diff changeset
443
kono
parents:
diff changeset
444 function Get_Element_Access
kono
parents:
diff changeset
445 (Position : Cursor) return not null Element_Access;
kono
parents:
diff changeset
446 -- Returns a pointer to the element designated by Position.
kono
parents:
diff changeset
447
kono
parents:
diff changeset
448 Empty_Map : constant Map :=
kono
parents:
diff changeset
449 (Hash_Table_Type with Capacity => 0, Modulus => 0);
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 No_Element : constant Cursor := (Container => null, Node => 0);
kono
parents:
diff changeset
452
kono
parents:
diff changeset
453 type Iterator is new Limited_Controlled and
kono
parents:
diff changeset
454 Map_Iterator_Interfaces.Forward_Iterator with
kono
parents:
diff changeset
455 record
kono
parents:
diff changeset
456 Container : Map_Access;
kono
parents:
diff changeset
457 end record
kono
parents:
diff changeset
458 with Disable_Controlled => not T_Check;
kono
parents:
diff changeset
459
kono
parents:
diff changeset
460 overriding procedure Finalize (Object : in out Iterator);
kono
parents:
diff changeset
461
kono
parents:
diff changeset
462 overriding function First (Object : Iterator) return Cursor;
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 overriding function Next
kono
parents:
diff changeset
465 (Object : Iterator;
kono
parents:
diff changeset
466 Position : Cursor) return Cursor;
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 end Ada.Containers.Bounded_Hashed_Maps;