annotate gcc/ada/libgnat/a-cfhama.ads @ 145:1830386684a0

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