annotate gcc/ada/libgnat/a-cihama.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 -- ADA.CONTAINERS.INDEFINITE_HASHED_MAPS --
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.Finalization;
kono
parents:
diff changeset
38 private with Ada.Streams;
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.Indefinite_Hashed_Maps is
kono
parents:
diff changeset
49 pragma Annotate (CodePeer, Skip_Analysis);
kono
parents:
diff changeset
50 pragma Preelaborate;
kono
parents:
diff changeset
51 pragma Remote_Types;
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 type Map 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 overriding 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 -- Adjusts the current capacity, by allocating a new buckets array. If the
kono
parents:
diff changeset
95 -- requested capacity is less than the current capacity, then the capacity
kono
parents:
diff changeset
96 -- is contracted (to a value not less than the current length). If the
kono
parents:
diff changeset
97 -- requested capacity is greater than the current capacity, then the
kono
parents:
diff changeset
98 -- capacity is expanded (to a value not less than what is requested). In
kono
parents:
diff changeset
99 -- either case, the nodes are rehashed from the old buckets array onto the
kono
parents:
diff changeset
100 -- new buckets array (Hash is called once for each existing key in order to
kono
parents:
diff changeset
101 -- compute the new index), and then the old buckets array is deallocated.
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 procedure (Key : Key_Type;
kono
parents:
diff changeset
127 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 procedure (Key : Key_Type;
kono
parents:
diff changeset
135 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 private
kono
parents:
diff changeset
141 with
kono
parents:
diff changeset
142 Implicit_Dereference => Element;
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 type Reference_Type (Element : not null access Element_Type) is private
kono
parents:
diff changeset
145 with
kono
parents:
diff changeset
146 Implicit_Dereference => Element;
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 function Constant_Reference
kono
parents:
diff changeset
149 (Container : aliased Map;
kono
parents:
diff changeset
150 Position : Cursor) return Constant_Reference_Type;
kono
parents:
diff changeset
151 pragma Inline (Constant_Reference);
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 pragma Inline (Reference);
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 function Constant_Reference
kono
parents:
diff changeset
159 (Container : aliased Map;
kono
parents:
diff changeset
160 Key : Key_Type) return Constant_Reference_Type;
kono
parents:
diff changeset
161 pragma Inline (Constant_Reference);
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 function Reference
kono
parents:
diff changeset
164 (Container : aliased in out Map;
kono
parents:
diff changeset
165 Key : Key_Type) return Reference_Type;
kono
parents:
diff changeset
166 pragma Inline (Reference);
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 procedure Assign (Target : in out Map; Source : Map);
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 function Copy (Source : Map; Capacity : Count_Type := 0) return Map;
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 procedure Move (Target : in out Map; Source : in out Map);
kono
parents:
diff changeset
173 -- Clears Target (if it's not empty), and then moves (not copies) the
kono
parents:
diff changeset
174 -- buckets array and nodes from Source to Target.
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 procedure Insert
kono
parents:
diff changeset
177 (Container : in out Map;
kono
parents:
diff changeset
178 Key : Key_Type;
kono
parents:
diff changeset
179 New_Item : Element_Type;
kono
parents:
diff changeset
180 Position : out Cursor;
kono
parents:
diff changeset
181 Inserted : out Boolean);
kono
parents:
diff changeset
182 -- Conditionally inserts New_Item into the map. If Key is already in the
kono
parents:
diff changeset
183 -- map, then Inserted returns False and Position designates the node
kono
parents:
diff changeset
184 -- containing the existing key/element pair (neither of which is modified).
kono
parents:
diff changeset
185 -- If Key is not already in the map, the Inserted returns True and Position
kono
parents:
diff changeset
186 -- designates the newly-inserted node container Key and New_Item. The
kono
parents:
diff changeset
187 -- search for the key works as follows. Hash is called to determine Key's
kono
parents:
diff changeset
188 -- bucket; if the bucket is non-empty, then Equivalent_Keys is called to
kono
parents:
diff changeset
189 -- compare Key to each node in that bucket. If the bucket is empty, or
kono
parents:
diff changeset
190 -- there were no matching keys in the bucket, the search "fails" and the
kono
parents:
diff changeset
191 -- key/item pair is inserted in the map (and Inserted returns True);
kono
parents:
diff changeset
192 -- otherwise, the search "succeeds" (and Inserted returns False).
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 procedure Insert
kono
parents:
diff changeset
195 (Container : in out Map;
kono
parents:
diff changeset
196 Key : Key_Type;
kono
parents:
diff changeset
197 New_Item : Element_Type);
kono
parents:
diff changeset
198 -- Attempts to insert Key into the map, performing the usual search (which
kono
parents:
diff changeset
199 -- involves calling both Hash and Equivalent_Keys); if the search succeeds
kono
parents:
diff changeset
200 -- (because Key is already in the map), then it raises Constraint_Error.
kono
parents:
diff changeset
201 -- (This version of Insert is similar to Replace, but having the opposite
kono
parents:
diff changeset
202 -- exception behavior. It is intended for use when you want to assert that
kono
parents:
diff changeset
203 -- Key is not already in the map.)
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 procedure Include
kono
parents:
diff changeset
206 (Container : in out Map;
kono
parents:
diff changeset
207 Key : Key_Type;
kono
parents:
diff changeset
208 New_Item : Element_Type);
kono
parents:
diff changeset
209 -- Attempts to insert Key into the map. If Key is already in the map, then
kono
parents:
diff changeset
210 -- both the existing key and element are assigned the values of Key and
kono
parents:
diff changeset
211 -- New_Item, respectively. (This version of Insert only raises an exception
kono
parents:
diff changeset
212 -- if cursor tampering occurs. It is intended for use when you want to
kono
parents:
diff changeset
213 -- insert the key/element pair in the map, and you don't care whether Key
kono
parents:
diff changeset
214 -- is already present.)
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 procedure Replace
kono
parents:
diff changeset
217 (Container : in out Map;
kono
parents:
diff changeset
218 Key : Key_Type;
kono
parents:
diff changeset
219 New_Item : Element_Type);
kono
parents:
diff changeset
220 -- Searches for Key in the map; if the search fails (because Key was not in
kono
parents:
diff changeset
221 -- the map), then it raises Constraint_Error. Otherwise, both the existing
kono
parents:
diff changeset
222 -- key and element are assigned the values of Key and New_Item rsp. (This
kono
parents:
diff changeset
223 -- is similar to Insert, but with the opposite exception behavior. It is
kono
parents:
diff changeset
224 -- intended for use when you want to assert that Key is already in the
kono
parents:
diff changeset
225 -- map.)
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 procedure Exclude (Container : in out Map; Key : Key_Type);
kono
parents:
diff changeset
228 -- Searches for Key in the map, and if found, removes its node from the map
kono
parents:
diff changeset
229 -- and then deallocates it. The search works as follows. The operation
kono
parents:
diff changeset
230 -- calls Hash to determine the key's bucket; if the bucket is not empty, it
kono
parents:
diff changeset
231 -- calls Equivalent_Keys to compare Key to each key in the bucket. (This is
kono
parents:
diff changeset
232 -- the deletion analog of Include. It is intended for use when you want to
kono
parents:
diff changeset
233 -- remove the item from the map, but don't care whether the key is already
kono
parents:
diff changeset
234 -- in the map.)
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 procedure Delete (Container : in out Map; Key : Key_Type);
kono
parents:
diff changeset
237 -- Searches for Key in the map (which involves calling both Hash and
kono
parents:
diff changeset
238 -- Equivalent_Keys). If the search fails, then the operation raises
kono
parents:
diff changeset
239 -- Constraint_Error. Otherwise it removes the node from the map and then
kono
parents:
diff changeset
240 -- deallocates it. (This is the deletion analog of non-conditional
kono
parents:
diff changeset
241 -- Insert. It is intended for use when you want to assert that the item is
kono
parents:
diff changeset
242 -- already in the map.)
kono
parents:
diff changeset
243
kono
parents:
diff changeset
244 procedure Delete (Container : in out Map; Position : in out Cursor);
kono
parents:
diff changeset
245 -- Removes the node designated by Position from the map, and then
kono
parents:
diff changeset
246 -- deallocates the node. The operation calls Hash to determine the bucket,
kono
parents:
diff changeset
247 -- and then compares Position to each node in the bucket until there's a
kono
parents:
diff changeset
248 -- match (it does not call Equivalent_Keys).
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 function First (Container : Map) return Cursor;
kono
parents:
diff changeset
251 -- Returns a cursor that designates the first non-empty bucket, by
kono
parents:
diff changeset
252 -- searching from the beginning of the buckets array.
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 function Next (Position : Cursor) return Cursor;
kono
parents:
diff changeset
255 -- Returns a cursor that designates the node that follows the current one
kono
parents:
diff changeset
256 -- designated by Position. If Position designates the last node in its
kono
parents:
diff changeset
257 -- bucket, the operation calls Hash to compute the index of this bucket,
kono
parents:
diff changeset
258 -- and searches the buckets array for the first non-empty bucket, starting
kono
parents:
diff changeset
259 -- from that index; otherwise, it simply follows the link to the next node
kono
parents:
diff changeset
260 -- in the same bucket.
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 procedure Next (Position : in out Cursor);
kono
parents:
diff changeset
263 -- Equivalent to Position := Next (Position)
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 function Find (Container : Map; Key : Key_Type) return Cursor;
kono
parents:
diff changeset
266 -- Searches for Key in the map. Find calls Hash to determine the key's
kono
parents:
diff changeset
267 -- bucket; if the bucket is not empty, it calls Equivalent_Keys to compare
kono
parents:
diff changeset
268 -- Key to each key in the bucket. If the search succeeds, Find returns a
kono
parents:
diff changeset
269 -- cursor designating the matching node; otherwise, it returns No_Element.
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 function Contains (Container : Map; Key : Key_Type) return Boolean;
kono
parents:
diff changeset
272 -- Equivalent to Find (Container, Key) /= No_Element
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 function Element (Container : Map; Key : Key_Type) return Element_Type;
kono
parents:
diff changeset
275 -- Equivalent to Element (Find (Container, Key))
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 function Equivalent_Keys (Left, Right : Cursor) return Boolean;
kono
parents:
diff changeset
278 -- Returns the result of calling Equivalent_Keys with the keys of the nodes
kono
parents:
diff changeset
279 -- designated by cursors Left and Right.
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 function Equivalent_Keys (Left : Cursor; Right : Key_Type) return Boolean;
kono
parents:
diff changeset
282 -- Returns the result of calling Equivalent_Keys with key of the node
kono
parents:
diff changeset
283 -- designated by Left and key Right.
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 function Equivalent_Keys (Left : Key_Type; Right : Cursor) return Boolean;
kono
parents:
diff changeset
286 -- Returns the result of calling Equivalent_Keys with key Left and the node
kono
parents:
diff changeset
287 -- designated by Right.
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 procedure Iterate
kono
parents:
diff changeset
290 (Container : Map;
kono
parents:
diff changeset
291 Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
292 -- Calls Process for each node in the map
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 function Iterate (Container : Map)
kono
parents:
diff changeset
295 return Map_Iterator_Interfaces.Forward_Iterator'class;
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 private
kono
parents:
diff changeset
298 pragma Inline ("=");
kono
parents:
diff changeset
299 pragma Inline (Length);
kono
parents:
diff changeset
300 pragma Inline (Is_Empty);
kono
parents:
diff changeset
301 pragma Inline (Clear);
kono
parents:
diff changeset
302 pragma Inline (Key);
kono
parents:
diff changeset
303 pragma Inline (Element);
kono
parents:
diff changeset
304 pragma Inline (Move);
kono
parents:
diff changeset
305 pragma Inline (Contains);
kono
parents:
diff changeset
306 pragma Inline (Capacity);
kono
parents:
diff changeset
307 pragma Inline (Reserve_Capacity);
kono
parents:
diff changeset
308 pragma Inline (Has_Element);
kono
parents:
diff changeset
309 pragma Inline (Equivalent_Keys);
kono
parents:
diff changeset
310 pragma Inline (Next);
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 type Node_Type;
kono
parents:
diff changeset
313 type Node_Access is access Node_Type;
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 type Key_Access is access Key_Type;
kono
parents:
diff changeset
316 type Element_Access is access all Element_Type;
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 type Node_Type is limited record
kono
parents:
diff changeset
319 Key : Key_Access;
kono
parents:
diff changeset
320 Element : Element_Access;
kono
parents:
diff changeset
321 Next : Node_Access;
kono
parents:
diff changeset
322 end record;
kono
parents:
diff changeset
323
kono
parents:
diff changeset
324 package HT_Types is
kono
parents:
diff changeset
325 new Hash_Tables.Generic_Hash_Table_Types (Node_Type, Node_Access);
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 type Map is new Ada.Finalization.Controlled with record
kono
parents:
diff changeset
328 HT : HT_Types.Hash_Table_Type;
kono
parents:
diff changeset
329 end record;
kono
parents:
diff changeset
330
kono
parents:
diff changeset
331 overriding procedure Adjust (Container : in out Map);
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 overriding procedure Finalize (Container : in out Map);
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 use HT_Types, HT_Types.Implementation;
kono
parents:
diff changeset
336 use Ada.Finalization;
kono
parents:
diff changeset
337 use Ada.Streams;
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 procedure Write
kono
parents:
diff changeset
340 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
341 Container : Map);
kono
parents:
diff changeset
342
kono
parents:
diff changeset
343 for Map'Write use Write;
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 procedure Read
kono
parents:
diff changeset
346 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
347 Container : out Map);
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 for Map'Read use Read;
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 type Map_Access is access all Map;
kono
parents:
diff changeset
352 for Map_Access'Storage_Size use 0;
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 type Cursor is record
kono
parents:
diff changeset
355 Container : Map_Access;
kono
parents:
diff changeset
356 Node : Node_Access;
kono
parents:
diff changeset
357 Position : Hash_Type := Hash_Type'Last;
kono
parents:
diff changeset
358 end record;
kono
parents:
diff changeset
359
kono
parents:
diff changeset
360 procedure Write
kono
parents:
diff changeset
361 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
362 Item : Cursor);
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 for Cursor'Write use Write;
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 procedure Read
kono
parents:
diff changeset
367 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
368 Item : out Cursor);
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370 for Cursor'Read use Read;
kono
parents:
diff changeset
371
kono
parents:
diff changeset
372 subtype Reference_Control_Type is Implementation.Reference_Control_Type;
kono
parents:
diff changeset
373 -- It is necessary to rename this here, so that the compiler can find it
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 type Constant_Reference_Type
kono
parents:
diff changeset
376 (Element : not null access constant Element_Type) is
kono
parents:
diff changeset
377 record
kono
parents:
diff changeset
378 Control : Reference_Control_Type :=
kono
parents:
diff changeset
379 raise Program_Error with "uninitialized reference";
kono
parents:
diff changeset
380 -- The RM says, "The default initialization of an object of
kono
parents:
diff changeset
381 -- type Constant_Reference_Type or Reference_Type propagates
kono
parents:
diff changeset
382 -- Program_Error."
kono
parents:
diff changeset
383 end record;
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 procedure Write
kono
parents:
diff changeset
386 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
387 Item : Constant_Reference_Type);
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 for Constant_Reference_Type'Write use Write;
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 procedure Read
kono
parents:
diff changeset
392 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
393 Item : out Constant_Reference_Type);
kono
parents:
diff changeset
394
kono
parents:
diff changeset
395 for Constant_Reference_Type'Read use Read;
kono
parents:
diff changeset
396
kono
parents:
diff changeset
397 type Reference_Type
kono
parents:
diff changeset
398 (Element : not null access Element_Type) is
kono
parents:
diff changeset
399 record
kono
parents:
diff changeset
400 Control : Reference_Control_Type :=
kono
parents:
diff changeset
401 raise Program_Error with "uninitialized reference";
kono
parents:
diff changeset
402 -- The RM says, "The default initialization of an object of
kono
parents:
diff changeset
403 -- type Constant_Reference_Type or Reference_Type propagates
kono
parents:
diff changeset
404 -- Program_Error."
kono
parents:
diff changeset
405 end record;
kono
parents:
diff changeset
406
kono
parents:
diff changeset
407 procedure Write
kono
parents:
diff changeset
408 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
409 Item : Reference_Type);
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 for Reference_Type'Write use Write;
kono
parents:
diff changeset
412
kono
parents:
diff changeset
413 procedure Read
kono
parents:
diff changeset
414 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
415 Item : out Reference_Type);
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 for Reference_Type'Read use Read;
kono
parents:
diff changeset
418
kono
parents:
diff changeset
419 -- Three operations are used to optimize in the expansion of "for ... of"
kono
parents:
diff changeset
420 -- loops: the Next(Cursor) procedure in the visible part, and the following
kono
parents:
diff changeset
421 -- Pseudo_Reference and Get_Element_Access functions. See Sem_Ch5 for
kono
parents:
diff changeset
422 -- details.
kono
parents:
diff changeset
423
kono
parents:
diff changeset
424 function Pseudo_Reference
kono
parents:
diff changeset
425 (Container : aliased Map'Class) return Reference_Control_Type;
kono
parents:
diff changeset
426 pragma Inline (Pseudo_Reference);
kono
parents:
diff changeset
427 -- Creates an object of type Reference_Control_Type pointing to the
kono
parents:
diff changeset
428 -- container, and increments the Lock. Finalization of this object will
kono
parents:
diff changeset
429 -- decrement the Lock.
kono
parents:
diff changeset
430
kono
parents:
diff changeset
431 function Get_Element_Access
kono
parents:
diff changeset
432 (Position : Cursor) return not null Element_Access;
kono
parents:
diff changeset
433 -- Returns a pointer to the element designated by Position.
kono
parents:
diff changeset
434
kono
parents:
diff changeset
435 Empty_Map : constant Map := (Controlled with others => <>);
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 No_Element : constant Cursor :=
kono
parents:
diff changeset
438 (Container => null, Node => null, Position => Hash_Type'Last);
kono
parents:
diff changeset
439
kono
parents:
diff changeset
440 type Iterator is new Limited_Controlled and
kono
parents:
diff changeset
441 Map_Iterator_Interfaces.Forward_Iterator with
kono
parents:
diff changeset
442 record
kono
parents:
diff changeset
443 Container : Map_Access;
kono
parents:
diff changeset
444 end record
kono
parents:
diff changeset
445 with Disable_Controlled => not T_Check;
kono
parents:
diff changeset
446
kono
parents:
diff changeset
447 overriding procedure Finalize (Object : in out Iterator);
kono
parents:
diff changeset
448
kono
parents:
diff changeset
449 overriding function First (Object : Iterator) return Cursor;
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 overriding function Next
kono
parents:
diff changeset
452 (Object : Iterator;
kono
parents:
diff changeset
453 Position : Cursor) return Cursor;
kono
parents:
diff changeset
454
kono
parents:
diff changeset
455 end Ada.Containers.Indefinite_Hashed_Maps;