annotate gcc/ada/libgnat/a-cfhama.ads @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
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 . F O R M A L _ 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 -- --
kono
parents:
diff changeset
9 -- Copyright (C) 2004-2017, Free Software Foundation, Inc. --
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
kono
parents:
diff changeset
32 -- This spec is derived from package Ada.Containers.Bounded_Hashed_Maps in the
kono
parents:
diff changeset
33 -- Ada 2012 RM. The modifications are meant to facilitate formal proofs by
kono
parents:
diff changeset
34 -- making it easier to express properties, and by making the specification of
kono
parents:
diff changeset
35 -- this unit compatible with SPARK 2014. Note that the API of this unit may be
kono
parents:
diff changeset
36 -- subject to incompatible changes as SPARK 2014 evolves.
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 -- The modifications are:
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 -- A parameter for the container is added to every function reading the
kono
parents:
diff changeset
41 -- contents of a container: Key, Element, Next, Query_Element, Has_Element,
kono
parents:
diff changeset
42 -- Iterate, Equivalent_Keys. This change is motivated by the need to have
kono
parents:
diff changeset
43 -- cursors which are valid on different containers (typically a container C
kono
parents:
diff changeset
44 -- and its previous version C'Old) for expressing properties, which is not
kono
parents:
diff changeset
45 -- possible if cursors encapsulate an access to the underlying container.
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 -- Iteration over maps is done using the Iterable aspect, which is SPARK
kono
parents:
diff changeset
48 -- compatible. "For of" iteration ranges over keys instead of elements.
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 with Ada.Containers.Functional_Vectors;
kono
parents:
diff changeset
51 with Ada.Containers.Functional_Maps;
kono
parents:
diff changeset
52 private with Ada.Containers.Hash_Tables;
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 generic
kono
parents:
diff changeset
55 type Key_Type is private;
kono
parents:
diff changeset
56 type Element_Type is private;
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 with function Hash (Key : Key_Type) return Hash_Type;
kono
parents:
diff changeset
59 with function Equivalent_Keys
kono
parents:
diff changeset
60 (Left : Key_Type;
kono
parents:
diff changeset
61 Right : Key_Type) return Boolean is "=";
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 package Ada.Containers.Formal_Hashed_Maps with
kono
parents:
diff changeset
64 SPARK_Mode
kono
parents:
diff changeset
65 is
kono
parents:
diff changeset
66 pragma Annotate (CodePeer, Skip_Analysis);
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 type Map (Capacity : Count_Type; Modulus : Hash_Type) is private with
kono
parents:
diff changeset
69 Iterable => (First => First,
kono
parents:
diff changeset
70 Next => Next,
kono
parents:
diff changeset
71 Has_Element => Has_Element,
kono
parents:
diff changeset
72 Element => Key),
kono
parents:
diff changeset
73 Default_Initial_Condition => Is_Empty (Map);
kono
parents:
diff changeset
74 pragma Preelaborable_Initialization (Map);
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 Empty_Map : constant Map;
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 type Cursor is record
kono
parents:
diff changeset
79 Node : Count_Type;
kono
parents:
diff changeset
80 end record;
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 No_Element : constant Cursor := (Node => 0);
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 function Length (Container : Map) return Count_Type with
kono
parents:
diff changeset
85 Global => null,
kono
parents:
diff changeset
86 Post => Length'Result <= Container.Capacity;
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 pragma Unevaluated_Use_Of_Old (Allow);
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 package Formal_Model with Ghost is
kono
parents:
diff changeset
91 subtype Positive_Count_Type is Count_Type range 1 .. Count_Type'Last;
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 package M is new Ada.Containers.Functional_Maps
kono
parents:
diff changeset
94 (Element_Type => Element_Type,
kono
parents:
diff changeset
95 Key_Type => Key_Type,
kono
parents:
diff changeset
96 Equivalent_Keys => Equivalent_Keys);
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 function "="
kono
parents:
diff changeset
99 (Left : M.Map;
kono
parents:
diff changeset
100 Right : M.Map) return Boolean renames M."=";
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 function "<="
kono
parents:
diff changeset
103 (Left : M.Map;
kono
parents:
diff changeset
104 Right : M.Map) return Boolean renames M."<=";
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 package K is new Ada.Containers.Functional_Vectors
kono
parents:
diff changeset
107 (Element_Type => Key_Type,
kono
parents:
diff changeset
108 Index_Type => Positive_Count_Type);
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 function "="
kono
parents:
diff changeset
111 (Left : K.Sequence;
kono
parents:
diff changeset
112 Right : K.Sequence) return Boolean renames K."=";
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 function "<"
kono
parents:
diff changeset
115 (Left : K.Sequence;
kono
parents:
diff changeset
116 Right : K.Sequence) return Boolean renames K."<";
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 function "<="
kono
parents:
diff changeset
119 (Left : K.Sequence;
kono
parents:
diff changeset
120 Right : K.Sequence) return Boolean renames K."<=";
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 function Find (Container : K.Sequence; Key : Key_Type) return Count_Type
kono
parents:
diff changeset
123 -- Search for Key in Container
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 with
kono
parents:
diff changeset
126 Global => null,
kono
parents:
diff changeset
127 Post =>
kono
parents:
diff changeset
128 (if Find'Result > 0 then
kono
parents:
diff changeset
129 Find'Result <= K.Length (Container)
kono
parents:
diff changeset
130 and Equivalent_Keys (Key, K.Get (Container, Find'Result)));
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 function K_Keys_Included
kono
parents:
diff changeset
133 (Left : K.Sequence;
kono
parents:
diff changeset
134 Right : K.Sequence) return Boolean
kono
parents:
diff changeset
135 -- Return True if Right contains all the keys of Left
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 with
kono
parents:
diff changeset
138 Global => null,
kono
parents:
diff changeset
139 Post =>
kono
parents:
diff changeset
140 K_Keys_Included'Result =
kono
parents:
diff changeset
141 (for all I in 1 .. K.Length (Left) =>
kono
parents:
diff changeset
142 Find (Right, K.Get (Left, I)) > 0
kono
parents:
diff changeset
143 and then K.Get (Right, Find (Right, K.Get (Left, I))) =
kono
parents:
diff changeset
144 K.Get (Left, I));
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 package P is new Ada.Containers.Functional_Maps
kono
parents:
diff changeset
147 (Key_Type => Cursor,
kono
parents:
diff changeset
148 Element_Type => Positive_Count_Type,
kono
parents:
diff changeset
149 Equivalent_Keys => "=",
kono
parents:
diff changeset
150 Enable_Handling_Of_Equivalence => False);
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 function "="
kono
parents:
diff changeset
153 (Left : P.Map;
kono
parents:
diff changeset
154 Right : P.Map) return Boolean renames P."=";
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 function "<="
kono
parents:
diff changeset
157 (Left : P.Map;
kono
parents:
diff changeset
158 Right : P.Map) return Boolean renames P."<=";
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 function Mapping_Preserved
kono
parents:
diff changeset
161 (K_Left : K.Sequence;
kono
parents:
diff changeset
162 K_Right : K.Sequence;
kono
parents:
diff changeset
163 P_Left : P.Map;
kono
parents:
diff changeset
164 P_Right : P.Map) return Boolean
kono
parents:
diff changeset
165 with
kono
parents:
diff changeset
166 Global => null,
kono
parents:
diff changeset
167 Post =>
kono
parents:
diff changeset
168 (if Mapping_Preserved'Result then
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 -- Right contains all the cursors of Left
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 P.Keys_Included (P_Left, P_Right)
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 -- Right contains all the keys of Left
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 and K_Keys_Included (K_Left, K_Right)
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 -- Mappings from cursors to elements induced by K_Left, P_Left
kono
parents:
diff changeset
179 -- and K_Right, P_Right are the same.
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 and (for all C of P_Left =>
kono
parents:
diff changeset
182 K.Get (K_Left, P.Get (P_Left, C)) =
kono
parents:
diff changeset
183 K.Get (K_Right, P.Get (P_Right, C))));
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 function Model (Container : Map) return M.Map with
kono
parents:
diff changeset
186 -- The high-level model of a map is a map from keys to elements. Neither
kono
parents:
diff changeset
187 -- cursors nor order of elements are represented in this model. Keys are
kono
parents:
diff changeset
188 -- modeled up to equivalence.
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 Ghost,
kono
parents:
diff changeset
191 Global => null;
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 function Keys (Container : Map) return K.Sequence with
kono
parents:
diff changeset
194 -- The Keys sequence represents the underlying list structure of maps
kono
parents:
diff changeset
195 -- that is used for iteration. It stores the actual values of keys in
kono
parents:
diff changeset
196 -- the map. It does not model cursors nor elements.
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 Ghost,
kono
parents:
diff changeset
199 Global => null,
kono
parents:
diff changeset
200 Post =>
kono
parents:
diff changeset
201 K.Length (Keys'Result) = Length (Container)
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 -- It only contains keys contained in Model
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 and (for all Key of Keys'Result =>
kono
parents:
diff changeset
206 M.Has_Key (Model (Container), Key))
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 -- It contains all the keys contained in Model
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 and (for all Key of Model (Container) =>
kono
parents:
diff changeset
211 (Find (Keys'Result, Key) > 0
kono
parents:
diff changeset
212 and then Equivalent_Keys
kono
parents:
diff changeset
213 (K.Get (Keys'Result, Find (Keys'Result, Key)),
kono
parents:
diff changeset
214 Key)))
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 -- It has no duplicate
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 and (for all I in 1 .. Length (Container) =>
kono
parents:
diff changeset
219 Find (Keys'Result, K.Get (Keys'Result, I)) = I)
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 and (for all I in 1 .. Length (Container) =>
kono
parents:
diff changeset
222 (for all J in 1 .. Length (Container) =>
kono
parents:
diff changeset
223 (if Equivalent_Keys
kono
parents:
diff changeset
224 (K.Get (Keys'Result, I), K.Get (Keys'Result, J))
kono
parents:
diff changeset
225 then
kono
parents:
diff changeset
226 I = J)));
kono
parents:
diff changeset
227 pragma Annotate (GNATprove, Iterable_For_Proof, "Model", Keys);
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 function Positions (Container : Map) return P.Map with
kono
parents:
diff changeset
230 -- The Positions map is used to model cursors. It only contains valid
kono
parents:
diff changeset
231 -- cursors and maps them to their position in the container.
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 Ghost,
kono
parents:
diff changeset
234 Global => null,
kono
parents:
diff changeset
235 Post =>
kono
parents:
diff changeset
236 not P.Has_Key (Positions'Result, No_Element)
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 -- Positions of cursors are smaller than the container's length
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 and then
kono
parents:
diff changeset
241 (for all I of Positions'Result =>
kono
parents:
diff changeset
242 P.Get (Positions'Result, I) in 1 .. Length (Container)
kono
parents:
diff changeset
243
kono
parents:
diff changeset
244 -- No two cursors have the same position. Note that we do not
kono
parents:
diff changeset
245 -- state that there is a cursor in the map for each position, as
kono
parents:
diff changeset
246 -- it is rarely needed.
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 and then
kono
parents:
diff changeset
249 (for all J of Positions'Result =>
kono
parents:
diff changeset
250 (if P.Get (Positions'Result, I) = P.Get (Positions'Result, J)
kono
parents:
diff changeset
251 then I = J)));
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 procedure Lift_Abstraction_Level (Container : Map) with
kono
parents:
diff changeset
254 -- Lift_Abstraction_Level is a ghost procedure that does nothing but
kono
parents:
diff changeset
255 -- assume that we can access the same elements by iterating over
kono
parents:
diff changeset
256 -- positions or cursors.
kono
parents:
diff changeset
257 -- This information is not generally useful except when switching from
kono
parents:
diff changeset
258 -- a low-level, cursor-aware view of a container, to a high-level,
kono
parents:
diff changeset
259 -- position-based view.
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 Ghost,
kono
parents:
diff changeset
262 Global => null,
kono
parents:
diff changeset
263 Post =>
kono
parents:
diff changeset
264 (for all Key of Keys (Container) =>
kono
parents:
diff changeset
265 (for some I of Positions (Container) =>
kono
parents:
diff changeset
266 K.Get (Keys (Container), P.Get (Positions (Container), I)) =
kono
parents:
diff changeset
267 Key));
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 function Contains
kono
parents:
diff changeset
270 (C : M.Map;
kono
parents:
diff changeset
271 K : Key_Type) return Boolean renames M.Has_Key;
kono
parents:
diff changeset
272 -- To improve readability of contracts, we rename the function used to
kono
parents:
diff changeset
273 -- search for a key in the model to Contains.
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275 function Element
kono
parents:
diff changeset
276 (C : M.Map;
kono
parents:
diff changeset
277 K : Key_Type) return Element_Type renames M.Get;
kono
parents:
diff changeset
278 -- To improve readability of contracts, we rename the function used to
kono
parents:
diff changeset
279 -- access an element in the model to Element.
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 end Formal_Model;
kono
parents:
diff changeset
282 use Formal_Model;
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 function "=" (Left, Right : Map) return Boolean with
kono
parents:
diff changeset
285 Global => null,
kono
parents:
diff changeset
286 Post => "="'Result = (Model (Left) = Model (Right));
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 function Capacity (Container : Map) return Count_Type with
kono
parents:
diff changeset
289 Global => null,
kono
parents:
diff changeset
290 Post => Capacity'Result = Container.Capacity;
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 procedure Reserve_Capacity
kono
parents:
diff changeset
293 (Container : in out Map;
kono
parents:
diff changeset
294 Capacity : Count_Type)
kono
parents:
diff changeset
295 with
kono
parents:
diff changeset
296 Global => null,
kono
parents:
diff changeset
297 Pre => Capacity <= Container.Capacity,
kono
parents:
diff changeset
298 Post =>
kono
parents:
diff changeset
299 Model (Container) = Model (Container)'Old
kono
parents:
diff changeset
300 and Length (Container)'Old = Length (Container)
kono
parents:
diff changeset
301
kono
parents:
diff changeset
302 -- Actual keys are preserved
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 and K_Keys_Included (Keys (Container), Keys (Container)'Old)
kono
parents:
diff changeset
305 and K_Keys_Included (Keys (Container)'Old, Keys (Container));
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 function Is_Empty (Container : Map) return Boolean with
kono
parents:
diff changeset
308 Global => null,
kono
parents:
diff changeset
309 Post => Is_Empty'Result = (Length (Container) = 0);
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 procedure Clear (Container : in out Map) with
kono
parents:
diff changeset
312 Global => null,
kono
parents:
diff changeset
313 Post => Length (Container) = 0 and M.Is_Empty (Model (Container));
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 procedure Assign (Target : in out Map; Source : Map) with
kono
parents:
diff changeset
316 Global => null,
kono
parents:
diff changeset
317 Pre => Target.Capacity >= Length (Source),
kono
parents:
diff changeset
318 Post =>
kono
parents:
diff changeset
319 Model (Target) = Model (Source)
kono
parents:
diff changeset
320 and Length (Source) = Length (Target)
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 -- Actual keys are preserved
kono
parents:
diff changeset
323
kono
parents:
diff changeset
324 and K_Keys_Included (Keys (Target), Keys (Source))
kono
parents:
diff changeset
325 and K_Keys_Included (Keys (Source), Keys (Target));
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 function Copy
kono
parents:
diff changeset
328 (Source : Map;
kono
parents:
diff changeset
329 Capacity : Count_Type := 0) return Map
kono
parents:
diff changeset
330 with
kono
parents:
diff changeset
331 Global => null,
kono
parents:
diff changeset
332 Pre => Capacity = 0 or else Capacity >= Source.Capacity,
kono
parents:
diff changeset
333 Post =>
kono
parents:
diff changeset
334 Model (Copy'Result) = Model (Source)
kono
parents:
diff changeset
335 and Keys (Copy'Result) = Keys (Source)
kono
parents:
diff changeset
336 and Positions (Copy'Result) = Positions (Source)
kono
parents:
diff changeset
337 and (if Capacity = 0 then
kono
parents:
diff changeset
338 Copy'Result.Capacity = Source.Capacity
kono
parents:
diff changeset
339 else
kono
parents:
diff changeset
340 Copy'Result.Capacity = Capacity);
kono
parents:
diff changeset
341 -- Copy returns a container stricty equal to Source. It must have the same
kono
parents:
diff changeset
342 -- cursors associated with each element. Therefore:
kono
parents:
diff changeset
343 -- - capacity=0 means use Source.Capacity as capacity of target
kono
parents:
diff changeset
344 -- - the modulus cannot be changed.
kono
parents:
diff changeset
345
kono
parents:
diff changeset
346 function Key (Container : Map; Position : Cursor) return Key_Type with
kono
parents:
diff changeset
347 Global => null,
kono
parents:
diff changeset
348 Pre => Has_Element (Container, Position),
kono
parents:
diff changeset
349 Post =>
kono
parents:
diff changeset
350 Key'Result =
kono
parents:
diff changeset
351 K.Get (Keys (Container), P.Get (Positions (Container), Position));
kono
parents:
diff changeset
352 pragma Annotate (GNATprove, Inline_For_Proof, Key);
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 function Element
kono
parents:
diff changeset
355 (Container : Map;
kono
parents:
diff changeset
356 Position : Cursor) return Element_Type
kono
parents:
diff changeset
357 with
kono
parents:
diff changeset
358 Global => null,
kono
parents:
diff changeset
359 Pre => Has_Element (Container, Position),
kono
parents:
diff changeset
360 Post =>
kono
parents:
diff changeset
361 Element'Result = Element (Model (Container), Key (Container, Position));
kono
parents:
diff changeset
362 pragma Annotate (GNATprove, Inline_For_Proof, Element);
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 procedure Replace_Element
kono
parents:
diff changeset
365 (Container : in out Map;
kono
parents:
diff changeset
366 Position : Cursor;
kono
parents:
diff changeset
367 New_Item : Element_Type)
kono
parents:
diff changeset
368 with
kono
parents:
diff changeset
369 Global => null,
kono
parents:
diff changeset
370 Pre => Has_Element (Container, Position),
kono
parents:
diff changeset
371 Post =>
kono
parents:
diff changeset
372
kono
parents:
diff changeset
373 -- Order of keys and cursors is preserved
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 Keys (Container) = Keys (Container)'Old
kono
parents:
diff changeset
376 and Positions (Container) = Positions (Container)'Old
kono
parents:
diff changeset
377
kono
parents:
diff changeset
378 -- New_Item is now associated with the key at position Position in
kono
parents:
diff changeset
379 -- Container.
kono
parents:
diff changeset
380
kono
parents:
diff changeset
381 and Element (Container, Position) = New_Item
kono
parents:
diff changeset
382
kono
parents:
diff changeset
383 -- Elements associated with other keys are preserved
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 and M.Same_Keys (Model (Container), Model (Container)'Old)
kono
parents:
diff changeset
386 and M.Elements_Equal_Except
kono
parents:
diff changeset
387 (Model (Container),
kono
parents:
diff changeset
388 Model (Container)'Old,
kono
parents:
diff changeset
389 Key (Container, Position));
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 procedure Move (Target : in out Map; Source : in out Map) with
kono
parents:
diff changeset
392 Global => null,
kono
parents:
diff changeset
393 Pre => Target.Capacity >= Length (Source),
kono
parents:
diff changeset
394 Post =>
kono
parents:
diff changeset
395 Model (Target) = Model (Source)'Old
kono
parents:
diff changeset
396 and Length (Source)'Old = Length (Target)
kono
parents:
diff changeset
397 and Length (Source) = 0
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 -- Actual keys are preserved
kono
parents:
diff changeset
400
kono
parents:
diff changeset
401 and K_Keys_Included (Keys (Target), Keys (Source)'Old)
kono
parents:
diff changeset
402 and K_Keys_Included (Keys (Source)'Old, Keys (Target));
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 procedure Insert
kono
parents:
diff changeset
405 (Container : in out Map;
kono
parents:
diff changeset
406 Key : Key_Type;
kono
parents:
diff changeset
407 New_Item : Element_Type;
kono
parents:
diff changeset
408 Position : out Cursor;
kono
parents:
diff changeset
409 Inserted : out Boolean)
kono
parents:
diff changeset
410 with
kono
parents:
diff changeset
411 Global => null,
kono
parents:
diff changeset
412 Pre =>
kono
parents:
diff changeset
413 Length (Container) < Container.Capacity or Contains (Container, Key),
kono
parents:
diff changeset
414 Post =>
kono
parents:
diff changeset
415 Contains (Container, Key)
kono
parents:
diff changeset
416 and Has_Element (Container, Position)
kono
parents:
diff changeset
417 and Equivalent_Keys
kono
parents:
diff changeset
418 (Formal_Hashed_Maps.Key (Container, Position), Key),
kono
parents:
diff changeset
419 Contract_Cases =>
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 -- If Key is already in Container, it is not modified and Inserted is
kono
parents:
diff changeset
422 -- set to False.
kono
parents:
diff changeset
423
kono
parents:
diff changeset
424 (Contains (Container, Key) =>
kono
parents:
diff changeset
425 not Inserted
kono
parents:
diff changeset
426 and Model (Container) = Model (Container)'Old
kono
parents:
diff changeset
427 and Keys (Container) = Keys (Container)'Old
kono
parents:
diff changeset
428 and Positions (Container) = Positions (Container)'Old,
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 -- Otherwise, Key is inserted in Container and Inserted is set to True
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432 others =>
kono
parents:
diff changeset
433 Inserted
kono
parents:
diff changeset
434 and Length (Container) = Length (Container)'Old + 1
kono
parents:
diff changeset
435
kono
parents:
diff changeset
436 -- Key now maps to New_Item
kono
parents:
diff changeset
437
kono
parents:
diff changeset
438 and Formal_Hashed_Maps.Key (Container, Position) = Key
kono
parents:
diff changeset
439 and Element (Model (Container), Key) = New_Item
kono
parents:
diff changeset
440
kono
parents:
diff changeset
441 -- Other keys are preserved
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 and Model (Container)'Old <= Model (Container)
kono
parents:
diff changeset
444 and M.Keys_Included_Except
kono
parents:
diff changeset
445 (Model (Container),
kono
parents:
diff changeset
446 Model (Container)'Old,
kono
parents:
diff changeset
447 Key)
kono
parents:
diff changeset
448
kono
parents:
diff changeset
449 -- Mapping from cursors to keys is preserved
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 and Mapping_Preserved
kono
parents:
diff changeset
452 (K_Left => Keys (Container)'Old,
kono
parents:
diff changeset
453 K_Right => Keys (Container),
kono
parents:
diff changeset
454 P_Left => Positions (Container)'Old,
kono
parents:
diff changeset
455 P_Right => Positions (Container))
kono
parents:
diff changeset
456 and P.Keys_Included_Except
kono
parents:
diff changeset
457 (Positions (Container),
kono
parents:
diff changeset
458 Positions (Container)'Old,
kono
parents:
diff changeset
459 Position));
kono
parents:
diff changeset
460
kono
parents:
diff changeset
461 procedure Insert
kono
parents:
diff changeset
462 (Container : in out Map;
kono
parents:
diff changeset
463 Key : Key_Type;
kono
parents:
diff changeset
464 New_Item : Element_Type)
kono
parents:
diff changeset
465 with
kono
parents:
diff changeset
466 Global => null,
kono
parents:
diff changeset
467 Pre =>
kono
parents:
diff changeset
468 Length (Container) < Container.Capacity
kono
parents:
diff changeset
469 and then (not Contains (Container, Key)),
kono
parents:
diff changeset
470 Post =>
kono
parents:
diff changeset
471 Length (Container) = Length (Container)'Old + 1
kono
parents:
diff changeset
472 and Contains (Container, Key)
kono
parents:
diff changeset
473
kono
parents:
diff changeset
474 -- Key now maps to New_Item
kono
parents:
diff changeset
475
kono
parents:
diff changeset
476 and Formal_Hashed_Maps.Key (Container, Find (Container, Key)) = Key
kono
parents:
diff changeset
477 and Element (Model (Container), Key) = New_Item
kono
parents:
diff changeset
478
kono
parents:
diff changeset
479 -- Other keys are preserved
kono
parents:
diff changeset
480
kono
parents:
diff changeset
481 and Model (Container)'Old <= Model (Container)
kono
parents:
diff changeset
482 and M.Keys_Included_Except
kono
parents:
diff changeset
483 (Model (Container),
kono
parents:
diff changeset
484 Model (Container)'Old,
kono
parents:
diff changeset
485 Key)
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 -- Mapping from cursors to keys is preserved
kono
parents:
diff changeset
488
kono
parents:
diff changeset
489 and Mapping_Preserved
kono
parents:
diff changeset
490 (K_Left => Keys (Container)'Old,
kono
parents:
diff changeset
491 K_Right => Keys (Container),
kono
parents:
diff changeset
492 P_Left => Positions (Container)'Old,
kono
parents:
diff changeset
493 P_Right => Positions (Container))
kono
parents:
diff changeset
494 and P.Keys_Included_Except
kono
parents:
diff changeset
495 (Positions (Container),
kono
parents:
diff changeset
496 Positions (Container)'Old,
kono
parents:
diff changeset
497 Find (Container, Key));
kono
parents:
diff changeset
498
kono
parents:
diff changeset
499 procedure Include
kono
parents:
diff changeset
500 (Container : in out Map;
kono
parents:
diff changeset
501 Key : Key_Type;
kono
parents:
diff changeset
502 New_Item : Element_Type)
kono
parents:
diff changeset
503 with
kono
parents:
diff changeset
504 Global => null,
kono
parents:
diff changeset
505 Pre =>
kono
parents:
diff changeset
506 Length (Container) < Container.Capacity or Contains (Container, Key),
kono
parents:
diff changeset
507 Post =>
kono
parents:
diff changeset
508 Contains (Container, Key) and Element (Container, Key) = New_Item,
kono
parents:
diff changeset
509 Contract_Cases =>
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 -- If Key is already in Container, Key is mapped to New_Item
kono
parents:
diff changeset
512
kono
parents:
diff changeset
513 (Contains (Container, Key) =>
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 -- Cursors are preserved
kono
parents:
diff changeset
516
kono
parents:
diff changeset
517 Positions (Container) = Positions (Container)'Old
kono
parents:
diff changeset
518
kono
parents:
diff changeset
519 -- The key equivalent to Key in Container is replaced by Key
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 and K.Get
kono
parents:
diff changeset
522 (Keys (Container),
kono
parents:
diff changeset
523 P.Get (Positions (Container), Find (Container, Key))) = Key
kono
parents:
diff changeset
524 and K.Equal_Except
kono
parents:
diff changeset
525 (Keys (Container)'Old,
kono
parents:
diff changeset
526 Keys (Container),
kono
parents:
diff changeset
527 P.Get (Positions (Container), Find (Container, Key)))
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529 -- Elements associated with other keys are preserved
kono
parents:
diff changeset
530
kono
parents:
diff changeset
531 and M.Same_Keys (Model (Container), Model (Container)'Old)
kono
parents:
diff changeset
532 and M.Elements_Equal_Except
kono
parents:
diff changeset
533 (Model (Container),
kono
parents:
diff changeset
534 Model (Container)'Old,
kono
parents:
diff changeset
535 Key),
kono
parents:
diff changeset
536
kono
parents:
diff changeset
537 -- Otherwise, Key is inserted in Container
kono
parents:
diff changeset
538
kono
parents:
diff changeset
539 others =>
kono
parents:
diff changeset
540 Length (Container) = Length (Container)'Old + 1
kono
parents:
diff changeset
541
kono
parents:
diff changeset
542 -- Other keys are preserved
kono
parents:
diff changeset
543
kono
parents:
diff changeset
544 and Model (Container)'Old <= Model (Container)
kono
parents:
diff changeset
545 and M.Keys_Included_Except
kono
parents:
diff changeset
546 (Model (Container),
kono
parents:
diff changeset
547 Model (Container)'Old,
kono
parents:
diff changeset
548 Key)
kono
parents:
diff changeset
549
kono
parents:
diff changeset
550 -- Key is inserted in Container
kono
parents:
diff changeset
551
kono
parents:
diff changeset
552 and K.Get
kono
parents:
diff changeset
553 (Keys (Container),
kono
parents:
diff changeset
554 P.Get (Positions (Container), Find (Container, Key))) = Key
kono
parents:
diff changeset
555
kono
parents:
diff changeset
556 -- Mapping from cursors to keys is preserved
kono
parents:
diff changeset
557
kono
parents:
diff changeset
558 and Mapping_Preserved
kono
parents:
diff changeset
559 (K_Left => Keys (Container)'Old,
kono
parents:
diff changeset
560 K_Right => Keys (Container),
kono
parents:
diff changeset
561 P_Left => Positions (Container)'Old,
kono
parents:
diff changeset
562 P_Right => Positions (Container))
kono
parents:
diff changeset
563 and P.Keys_Included_Except
kono
parents:
diff changeset
564 (Positions (Container),
kono
parents:
diff changeset
565 Positions (Container)'Old,
kono
parents:
diff changeset
566 Find (Container, Key)));
kono
parents:
diff changeset
567
kono
parents:
diff changeset
568 procedure Replace
kono
parents:
diff changeset
569 (Container : in out Map;
kono
parents:
diff changeset
570 Key : Key_Type;
kono
parents:
diff changeset
571 New_Item : Element_Type)
kono
parents:
diff changeset
572 with
kono
parents:
diff changeset
573 Global => null,
kono
parents:
diff changeset
574 Pre => Contains (Container, Key),
kono
parents:
diff changeset
575 Post =>
kono
parents:
diff changeset
576
kono
parents:
diff changeset
577 -- Cursors are preserved
kono
parents:
diff changeset
578
kono
parents:
diff changeset
579 Positions (Container) = Positions (Container)'Old
kono
parents:
diff changeset
580
kono
parents:
diff changeset
581 -- The key equivalent to Key in Container is replaced by Key
kono
parents:
diff changeset
582
kono
parents:
diff changeset
583 and K.Get
kono
parents:
diff changeset
584 (Keys (Container),
kono
parents:
diff changeset
585 P.Get (Positions (Container), Find (Container, Key))) = Key
kono
parents:
diff changeset
586 and K.Equal_Except
kono
parents:
diff changeset
587 (Keys (Container)'Old,
kono
parents:
diff changeset
588 Keys (Container),
kono
parents:
diff changeset
589 P.Get (Positions (Container), Find (Container, Key)))
kono
parents:
diff changeset
590
kono
parents:
diff changeset
591 -- New_Item is now associated with the Key in Container
kono
parents:
diff changeset
592
kono
parents:
diff changeset
593 and Element (Model (Container), Key) = New_Item
kono
parents:
diff changeset
594
kono
parents:
diff changeset
595 -- Elements associated with other keys are preserved
kono
parents:
diff changeset
596
kono
parents:
diff changeset
597 and M.Same_Keys (Model (Container), Model (Container)'Old)
kono
parents:
diff changeset
598 and M.Elements_Equal_Except
kono
parents:
diff changeset
599 (Model (Container),
kono
parents:
diff changeset
600 Model (Container)'Old,
kono
parents:
diff changeset
601 Key);
kono
parents:
diff changeset
602
kono
parents:
diff changeset
603 procedure Exclude (Container : in out Map; Key : Key_Type) with
kono
parents:
diff changeset
604 Global => null,
kono
parents:
diff changeset
605 Post => not Contains (Container, Key),
kono
parents:
diff changeset
606 Contract_Cases =>
kono
parents:
diff changeset
607
kono
parents:
diff changeset
608 -- If Key is not in Container, nothing is changed
kono
parents:
diff changeset
609
kono
parents:
diff changeset
610 (not Contains (Container, Key) =>
kono
parents:
diff changeset
611 Model (Container) = Model (Container)'Old
kono
parents:
diff changeset
612 and Keys (Container) = Keys (Container)'Old
kono
parents:
diff changeset
613 and Positions (Container) = Positions (Container)'Old,
kono
parents:
diff changeset
614
kono
parents:
diff changeset
615 -- Otherwise, Key is removed from Container
kono
parents:
diff changeset
616
kono
parents:
diff changeset
617 others =>
kono
parents:
diff changeset
618 Length (Container) = Length (Container)'Old - 1
kono
parents:
diff changeset
619
kono
parents:
diff changeset
620 -- Other keys are preserved
kono
parents:
diff changeset
621
kono
parents:
diff changeset
622 and Model (Container) <= Model (Container)'Old
kono
parents:
diff changeset
623 and M.Keys_Included_Except
kono
parents:
diff changeset
624 (Model (Container)'Old,
kono
parents:
diff changeset
625 Model (Container),
kono
parents:
diff changeset
626 Key)
kono
parents:
diff changeset
627
kono
parents:
diff changeset
628 -- Mapping from cursors to keys is preserved
kono
parents:
diff changeset
629
kono
parents:
diff changeset
630 and Mapping_Preserved
kono
parents:
diff changeset
631 (K_Left => Keys (Container),
kono
parents:
diff changeset
632 K_Right => Keys (Container)'Old,
kono
parents:
diff changeset
633 P_Left => Positions (Container),
kono
parents:
diff changeset
634 P_Right => Positions (Container)'Old)
kono
parents:
diff changeset
635 and P.Keys_Included_Except
kono
parents:
diff changeset
636 (Positions (Container)'Old,
kono
parents:
diff changeset
637 Positions (Container),
kono
parents:
diff changeset
638 Find (Container, Key)'Old));
kono
parents:
diff changeset
639
kono
parents:
diff changeset
640 procedure Delete (Container : in out Map; Key : Key_Type) with
kono
parents:
diff changeset
641 Global => null,
kono
parents:
diff changeset
642 Pre => Contains (Container, Key),
kono
parents:
diff changeset
643 Post =>
kono
parents:
diff changeset
644 Length (Container) = Length (Container)'Old - 1
kono
parents:
diff changeset
645
kono
parents:
diff changeset
646 -- Key is no longer in Container
kono
parents:
diff changeset
647
kono
parents:
diff changeset
648 and not Contains (Container, Key)
kono
parents:
diff changeset
649
kono
parents:
diff changeset
650 -- Other keys are preserved
kono
parents:
diff changeset
651
kono
parents:
diff changeset
652 and Model (Container) <= Model (Container)'Old
kono
parents:
diff changeset
653 and M.Keys_Included_Except
kono
parents:
diff changeset
654 (Model (Container)'Old,
kono
parents:
diff changeset
655 Model (Container),
kono
parents:
diff changeset
656 Key)
kono
parents:
diff changeset
657
kono
parents:
diff changeset
658 -- Mapping from cursors to keys is preserved
kono
parents:
diff changeset
659
kono
parents:
diff changeset
660 and Mapping_Preserved
kono
parents:
diff changeset
661 (K_Left => Keys (Container),
kono
parents:
diff changeset
662 K_Right => Keys (Container)'Old,
kono
parents:
diff changeset
663 P_Left => Positions (Container),
kono
parents:
diff changeset
664 P_Right => Positions (Container)'Old)
kono
parents:
diff changeset
665 and P.Keys_Included_Except
kono
parents:
diff changeset
666 (Positions (Container)'Old,
kono
parents:
diff changeset
667 Positions (Container),
kono
parents:
diff changeset
668 Find (Container, Key)'Old);
kono
parents:
diff changeset
669
kono
parents:
diff changeset
670 procedure Delete (Container : in out Map; Position : in out Cursor) with
kono
parents:
diff changeset
671 Global => null,
kono
parents:
diff changeset
672 Pre => Has_Element (Container, Position),
kono
parents:
diff changeset
673 Post =>
kono
parents:
diff changeset
674 Position = No_Element
kono
parents:
diff changeset
675 and Length (Container) = Length (Container)'Old - 1
kono
parents:
diff changeset
676
kono
parents:
diff changeset
677 -- The key at position Position is no longer in Container
kono
parents:
diff changeset
678
kono
parents:
diff changeset
679 and not Contains (Container, Key (Container, Position)'Old)
kono
parents:
diff changeset
680 and not P.Has_Key (Positions (Container), Position'Old)
kono
parents:
diff changeset
681
kono
parents:
diff changeset
682 -- Other keys are preserved
kono
parents:
diff changeset
683
kono
parents:
diff changeset
684 and Model (Container) <= Model (Container)'Old
kono
parents:
diff changeset
685 and M.Keys_Included_Except
kono
parents:
diff changeset
686 (Model (Container)'Old,
kono
parents:
diff changeset
687 Model (Container),
kono
parents:
diff changeset
688 Key (Container, Position)'Old)
kono
parents:
diff changeset
689
kono
parents:
diff changeset
690 -- Mapping from cursors to keys is preserved
kono
parents:
diff changeset
691
kono
parents:
diff changeset
692 and Mapping_Preserved
kono
parents:
diff changeset
693 (K_Left => Keys (Container),
kono
parents:
diff changeset
694 K_Right => Keys (Container)'Old,
kono
parents:
diff changeset
695 P_Left => Positions (Container),
kono
parents:
diff changeset
696 P_Right => Positions (Container)'Old)
kono
parents:
diff changeset
697 and P.Keys_Included_Except
kono
parents:
diff changeset
698 (Positions (Container)'Old,
kono
parents:
diff changeset
699 Positions (Container),
kono
parents:
diff changeset
700 Position'Old);
kono
parents:
diff changeset
701
kono
parents:
diff changeset
702 function First (Container : Map) return Cursor with
kono
parents:
diff changeset
703 Global => null,
kono
parents:
diff changeset
704 Contract_Cases =>
kono
parents:
diff changeset
705 (Length (Container) = 0 =>
kono
parents:
diff changeset
706 First'Result = No_Element,
kono
parents:
diff changeset
707
kono
parents:
diff changeset
708 others =>
kono
parents:
diff changeset
709 Has_Element (Container, First'Result)
kono
parents:
diff changeset
710 and P.Get (Positions (Container), First'Result) = 1);
kono
parents:
diff changeset
711
kono
parents:
diff changeset
712 function Next (Container : Map; Position : Cursor) return Cursor with
kono
parents:
diff changeset
713 Global => null,
kono
parents:
diff changeset
714 Pre =>
kono
parents:
diff changeset
715 Has_Element (Container, Position) or else Position = No_Element,
kono
parents:
diff changeset
716 Contract_Cases =>
kono
parents:
diff changeset
717 (Position = No_Element
kono
parents:
diff changeset
718 or else P.Get (Positions (Container), Position) = Length (Container)
kono
parents:
diff changeset
719 =>
kono
parents:
diff changeset
720 Next'Result = No_Element,
kono
parents:
diff changeset
721
kono
parents:
diff changeset
722 others =>
kono
parents:
diff changeset
723 Has_Element (Container, Next'Result)
kono
parents:
diff changeset
724 and then P.Get (Positions (Container), Next'Result) =
kono
parents:
diff changeset
725 P.Get (Positions (Container), Position) + 1);
kono
parents:
diff changeset
726
kono
parents:
diff changeset
727 procedure Next (Container : Map; Position : in out Cursor) with
kono
parents:
diff changeset
728 Global => null,
kono
parents:
diff changeset
729 Pre =>
kono
parents:
diff changeset
730 Has_Element (Container, Position) or else Position = No_Element,
kono
parents:
diff changeset
731 Contract_Cases =>
kono
parents:
diff changeset
732 (Position = No_Element
kono
parents:
diff changeset
733 or else P.Get (Positions (Container), Position) = Length (Container)
kono
parents:
diff changeset
734 =>
kono
parents:
diff changeset
735 Position = No_Element,
kono
parents:
diff changeset
736
kono
parents:
diff changeset
737 others =>
kono
parents:
diff changeset
738 Has_Element (Container, Position)
kono
parents:
diff changeset
739 and then P.Get (Positions (Container), Position) =
kono
parents:
diff changeset
740 P.Get (Positions (Container), Position'Old) + 1);
kono
parents:
diff changeset
741
kono
parents:
diff changeset
742 function Find (Container : Map; Key : Key_Type) return Cursor with
kono
parents:
diff changeset
743 Global => null,
kono
parents:
diff changeset
744 Contract_Cases =>
kono
parents:
diff changeset
745
kono
parents:
diff changeset
746 -- If Key is not contained in Container, Find returns No_Element
kono
parents:
diff changeset
747
kono
parents:
diff changeset
748 (not Contains (Model (Container), Key) =>
kono
parents:
diff changeset
749 Find'Result = No_Element,
kono
parents:
diff changeset
750
kono
parents:
diff changeset
751 -- Otherwise, Find returns a valid cursor in Container
kono
parents:
diff changeset
752
kono
parents:
diff changeset
753 others =>
kono
parents:
diff changeset
754 P.Has_Key (Positions (Container), Find'Result)
kono
parents:
diff changeset
755 and P.Get (Positions (Container), Find'Result) =
kono
parents:
diff changeset
756 Find (Keys (Container), Key)
kono
parents:
diff changeset
757
kono
parents:
diff changeset
758 -- The key designated by the result of Find is Key
kono
parents:
diff changeset
759
kono
parents:
diff changeset
760 and Equivalent_Keys
kono
parents:
diff changeset
761 (Formal_Hashed_Maps.Key (Container, Find'Result), Key));
kono
parents:
diff changeset
762
kono
parents:
diff changeset
763 function Contains (Container : Map; Key : Key_Type) return Boolean with
kono
parents:
diff changeset
764 Global => null,
kono
parents:
diff changeset
765 Post => Contains'Result = Contains (Model (Container), Key);
kono
parents:
diff changeset
766 pragma Annotate (GNATprove, Inline_For_Proof, Contains);
kono
parents:
diff changeset
767
kono
parents:
diff changeset
768 function Element (Container : Map; Key : Key_Type) return Element_Type with
kono
parents:
diff changeset
769 Global => null,
kono
parents:
diff changeset
770 Pre => Contains (Container, Key),
kono
parents:
diff changeset
771 Post => Element'Result = Element (Model (Container), Key);
kono
parents:
diff changeset
772 pragma Annotate (GNATprove, Inline_For_Proof, Element);
kono
parents:
diff changeset
773
kono
parents:
diff changeset
774 function Has_Element (Container : Map; Position : Cursor) return Boolean
kono
parents:
diff changeset
775 with
kono
parents:
diff changeset
776 Global => null,
kono
parents:
diff changeset
777 Post =>
kono
parents:
diff changeset
778 Has_Element'Result = P.Has_Key (Positions (Container), Position);
kono
parents:
diff changeset
779 pragma Annotate (GNATprove, Inline_For_Proof, Has_Element);
kono
parents:
diff changeset
780
kono
parents:
diff changeset
781 function Default_Modulus (Capacity : Count_Type) return Hash_Type with
kono
parents:
diff changeset
782 Global => null;
kono
parents:
diff changeset
783
kono
parents:
diff changeset
784 private
kono
parents:
diff changeset
785 pragma SPARK_Mode (Off);
kono
parents:
diff changeset
786
kono
parents:
diff changeset
787 pragma Inline (Length);
kono
parents:
diff changeset
788 pragma Inline (Is_Empty);
kono
parents:
diff changeset
789 pragma Inline (Clear);
kono
parents:
diff changeset
790 pragma Inline (Key);
kono
parents:
diff changeset
791 pragma Inline (Element);
kono
parents:
diff changeset
792 pragma Inline (Contains);
kono
parents:
diff changeset
793 pragma Inline (Capacity);
kono
parents:
diff changeset
794 pragma Inline (Has_Element);
kono
parents:
diff changeset
795 pragma Inline (Equivalent_Keys);
kono
parents:
diff changeset
796 pragma Inline (Next);
kono
parents:
diff changeset
797
kono
parents:
diff changeset
798 type Node_Type is record
kono
parents:
diff changeset
799 Key : Key_Type;
kono
parents:
diff changeset
800 Element : Element_Type;
kono
parents:
diff changeset
801 Next : Count_Type;
kono
parents:
diff changeset
802 Has_Element : Boolean := False;
kono
parents:
diff changeset
803 end record;
kono
parents:
diff changeset
804
kono
parents:
diff changeset
805 package HT_Types is new
kono
parents:
diff changeset
806 Ada.Containers.Hash_Tables.Generic_Bounded_Hash_Table_Types (Node_Type);
kono
parents:
diff changeset
807
kono
parents:
diff changeset
808 type Map (Capacity : Count_Type; Modulus : Hash_Type) is
kono
parents:
diff changeset
809 new HT_Types.Hash_Table_Type (Capacity, Modulus) with null record;
kono
parents:
diff changeset
810
kono
parents:
diff changeset
811 Empty_Map : constant Map := (Capacity => 0, Modulus => 0, others => <>);
kono
parents:
diff changeset
812
kono
parents:
diff changeset
813 end Ada.Containers.Formal_Hashed_Maps;