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

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT LIBRARY COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- A D A . C O N T A I N E R S . F O R M A L _ H A S H E D _ S E T S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 2004-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- This specification is derived from the Ada Reference Manual for use with --
kono
parents:
diff changeset
12 -- GNAT. The copyright notice above, and the license provisions that follow --
kono
parents:
diff changeset
13 -- apply solely to the contents of the part following the private keyword. --
kono
parents:
diff changeset
14 -- --
kono
parents:
diff changeset
15 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
16 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
23 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
24 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
25 -- --
kono
parents:
diff changeset
26 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
27 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
29 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This spec is derived from package Ada.Containers.Bounded_Hashed_Sets 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 -- content of a container: Element, Next, Query_Element, Has_Element, Key,
kono
parents:
diff changeset
42 -- Iterate, Equivalent_Elements. This change is motivated by the need to
kono
parents:
diff changeset
43 -- have cursors which are valid on different containers (typically a
kono
parents:
diff changeset
44 -- container C and its previous version C'Old) for expressing properties,
kono
parents:
diff changeset
45 -- which is not possible if cursors encapsulate an access to the underlying
kono
parents:
diff changeset
46 -- container.
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 with Ada.Containers.Functional_Maps;
kono
parents:
diff changeset
49 with Ada.Containers.Functional_Sets;
kono
parents:
diff changeset
50 with Ada.Containers.Functional_Vectors;
kono
parents:
diff changeset
51 private with Ada.Containers.Hash_Tables;
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 generic
kono
parents:
diff changeset
54 type Element_Type is private;
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 with function Hash (Element : Element_Type) return Hash_Type;
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 with function Equivalent_Elements
kono
parents:
diff changeset
59 (Left : Element_Type;
kono
parents:
diff changeset
60 Right : Element_Type) return Boolean is "=";
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 package Ada.Containers.Formal_Hashed_Sets with
kono
parents:
diff changeset
63 SPARK_Mode
kono
parents:
diff changeset
64 is
kono
parents:
diff changeset
65 pragma Annotate (CodePeer, Skip_Analysis);
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 type Set (Capacity : Count_Type; Modulus : Hash_Type) is private with
kono
parents:
diff changeset
68 Iterable => (First => First,
kono
parents:
diff changeset
69 Next => Next,
kono
parents:
diff changeset
70 Has_Element => Has_Element,
kono
parents:
diff changeset
71 Element => Element),
kono
parents:
diff changeset
72 Default_Initial_Condition => Is_Empty (Set);
kono
parents:
diff changeset
73 pragma Preelaborable_Initialization (Set);
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 type Cursor is record
kono
parents:
diff changeset
76 Node : Count_Type;
kono
parents:
diff changeset
77 end record;
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 No_Element : constant Cursor := (Node => 0);
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 function Length (Container : Set) return Count_Type with
kono
parents:
diff changeset
82 Global => null,
kono
parents:
diff changeset
83 Post => Length'Result <= Container.Capacity;
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 pragma Unevaluated_Use_Of_Old (Allow);
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 package Formal_Model with Ghost is
kono
parents:
diff changeset
88 subtype Positive_Count_Type is Count_Type range 1 .. Count_Type'Last;
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 package M is new Ada.Containers.Functional_Sets
kono
parents:
diff changeset
91 (Element_Type => Element_Type,
kono
parents:
diff changeset
92 Equivalent_Elements => Equivalent_Elements);
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 function "="
kono
parents:
diff changeset
95 (Left : M.Set;
kono
parents:
diff changeset
96 Right : M.Set) return Boolean renames M."=";
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 function "<="
kono
parents:
diff changeset
99 (Left : M.Set;
kono
parents:
diff changeset
100 Right : M.Set) return Boolean renames M."<=";
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 package E is new Ada.Containers.Functional_Vectors
kono
parents:
diff changeset
103 (Element_Type => Element_Type,
kono
parents:
diff changeset
104 Index_Type => Positive_Count_Type);
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 function "="
kono
parents:
diff changeset
107 (Left : E.Sequence;
kono
parents:
diff changeset
108 Right : E.Sequence) return Boolean renames E."=";
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 function "<"
kono
parents:
diff changeset
111 (Left : E.Sequence;
kono
parents:
diff changeset
112 Right : E.Sequence) return Boolean renames E."<";
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 function "<="
kono
parents:
diff changeset
115 (Left : E.Sequence;
kono
parents:
diff changeset
116 Right : E.Sequence) return Boolean renames E."<=";
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 function Find
kono
parents:
diff changeset
119 (Container : E.Sequence;
kono
parents:
diff changeset
120 Item : Element_Type) return Count_Type
kono
parents:
diff changeset
121 -- Search for Item in Container
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 with
kono
parents:
diff changeset
124 Global => null,
kono
parents:
diff changeset
125 Post =>
kono
parents:
diff changeset
126 (if Find'Result > 0 then
kono
parents:
diff changeset
127 Find'Result <= E.Length (Container)
kono
parents:
diff changeset
128 and Equivalent_Elements
kono
parents:
diff changeset
129 (Item, E.Get (Container, Find'Result)));
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 function E_Elements_Included
kono
parents:
diff changeset
132 (Left : E.Sequence;
kono
parents:
diff changeset
133 Right : E.Sequence) return Boolean
kono
parents:
diff changeset
134 -- The elements of Left are contained in Right
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 with
kono
parents:
diff changeset
137 Global => null,
kono
parents:
diff changeset
138 Post =>
kono
parents:
diff changeset
139 E_Elements_Included'Result =
kono
parents:
diff changeset
140 (for all I in 1 .. E.Length (Left) =>
kono
parents:
diff changeset
141 Find (Right, E.Get (Left, I)) > 0
kono
parents:
diff changeset
142 and then E.Get (Right, Find (Right, E.Get (Left, I))) =
kono
parents:
diff changeset
143 E.Get (Left, I));
kono
parents:
diff changeset
144 pragma Annotate (GNATprove, Inline_For_Proof, E_Elements_Included);
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 function E_Elements_Included
kono
parents:
diff changeset
147 (Left : E.Sequence;
kono
parents:
diff changeset
148 Model : M.Set;
kono
parents:
diff changeset
149 Right : E.Sequence) return Boolean
kono
parents:
diff changeset
150 -- The elements of Container contained in Model are in Right
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 with
kono
parents:
diff changeset
153 Global => null,
kono
parents:
diff changeset
154 Post =>
kono
parents:
diff changeset
155 E_Elements_Included'Result =
kono
parents:
diff changeset
156 (for all I in 1 .. E.Length (Left) =>
kono
parents:
diff changeset
157 (if M.Contains (Model, E.Get (Left, I)) then
kono
parents:
diff changeset
158 Find (Right, E.Get (Left, I)) > 0
kono
parents:
diff changeset
159 and then E.Get (Right, Find (Right, E.Get (Left, I))) =
kono
parents:
diff changeset
160 E.Get (Left, I)));
kono
parents:
diff changeset
161 pragma Annotate (GNATprove, Inline_For_Proof, E_Elements_Included);
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 function E_Elements_Included
kono
parents:
diff changeset
164 (Container : E.Sequence;
kono
parents:
diff changeset
165 Model : M.Set;
kono
parents:
diff changeset
166 Left : E.Sequence;
kono
parents:
diff changeset
167 Right : E.Sequence) return Boolean
kono
parents:
diff changeset
168 -- The elements of Container contained in Model are in Left and others
kono
parents:
diff changeset
169 -- are in Right.
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 with
kono
parents:
diff changeset
172 Global => null,
kono
parents:
diff changeset
173 Post =>
kono
parents:
diff changeset
174 E_Elements_Included'Result =
kono
parents:
diff changeset
175 (for all I in 1 .. E.Length (Container) =>
kono
parents:
diff changeset
176 (if M.Contains (Model, E.Get (Container, I)) then
kono
parents:
diff changeset
177 Find (Left, E.Get (Container, I)) > 0
kono
parents:
diff changeset
178 and then E.Get (Left, Find (Left, E.Get (Container, I))) =
kono
parents:
diff changeset
179 E.Get (Container, I)
kono
parents:
diff changeset
180 else
kono
parents:
diff changeset
181 Find (Right, E.Get (Container, I)) > 0
kono
parents:
diff changeset
182 and then E.Get
kono
parents:
diff changeset
183 (Right, Find (Right, E.Get (Container, I))) =
kono
parents:
diff changeset
184 E.Get (Container, I)));
kono
parents:
diff changeset
185 pragma Annotate (GNATprove, Inline_For_Proof, E_Elements_Included);
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 package P is new Ada.Containers.Functional_Maps
kono
parents:
diff changeset
188 (Key_Type => Cursor,
kono
parents:
diff changeset
189 Element_Type => Positive_Count_Type,
kono
parents:
diff changeset
190 Equivalent_Keys => "=",
kono
parents:
diff changeset
191 Enable_Handling_Of_Equivalence => False);
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 function "="
kono
parents:
diff changeset
194 (Left : P.Map;
kono
parents:
diff changeset
195 Right : P.Map) return Boolean renames P."=";
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 function "<="
kono
parents:
diff changeset
198 (Left : P.Map;
kono
parents:
diff changeset
199 Right : P.Map) return Boolean renames P."<=";
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 function Mapping_Preserved
kono
parents:
diff changeset
202 (E_Left : E.Sequence;
kono
parents:
diff changeset
203 E_Right : E.Sequence;
kono
parents:
diff changeset
204 P_Left : P.Map;
kono
parents:
diff changeset
205 P_Right : P.Map) return Boolean
kono
parents:
diff changeset
206 with
kono
parents:
diff changeset
207 Ghost,
kono
parents:
diff changeset
208 Global => null,
kono
parents:
diff changeset
209 Post =>
kono
parents:
diff changeset
210 (if Mapping_Preserved'Result then
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 -- Right contains all the cursors of Left
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 P.Keys_Included (P_Left, P_Right)
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 -- Right contains all the elements of Left
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 and E_Elements_Included (E_Left, E_Right)
kono
parents:
diff changeset
219
kono
parents:
diff changeset
220 -- Mappings from cursors to elements induced by E_Left, P_Left
kono
parents:
diff changeset
221 -- and E_Right, P_Right are the same.
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 and (for all C of P_Left =>
kono
parents:
diff changeset
224 E.Get (E_Left, P.Get (P_Left, C)) =
kono
parents:
diff changeset
225 E.Get (E_Right, P.Get (P_Right, C))));
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 function Mapping_Preserved_Except
kono
parents:
diff changeset
228 (E_Left : E.Sequence;
kono
parents:
diff changeset
229 E_Right : E.Sequence;
kono
parents:
diff changeset
230 P_Left : P.Map;
kono
parents:
diff changeset
231 P_Right : P.Map;
kono
parents:
diff changeset
232 Position : Cursor) return Boolean
kono
parents:
diff changeset
233 with
kono
parents:
diff changeset
234 Ghost,
kono
parents:
diff changeset
235 Global => null,
kono
parents:
diff changeset
236 Post =>
kono
parents:
diff changeset
237 (if Mapping_Preserved_Except'Result then
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 -- Right contains all the cursors of Left
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 P.Keys_Included (P_Left, P_Right)
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 -- Mappings from cursors to elements induced by E_Left, P_Left
kono
parents:
diff changeset
244 -- and E_Right, P_Right are the same except for Position.
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 and (for all C of P_Left =>
kono
parents:
diff changeset
247 (if C /= Position then
kono
parents:
diff changeset
248 E.Get (E_Left, P.Get (P_Left, C)) =
kono
parents:
diff changeset
249 E.Get (E_Right, P.Get (P_Right, C)))));
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 function Model (Container : Set) return M.Set with
kono
parents:
diff changeset
252 -- The high-level model of a set is a set of elements. Neither cursors
kono
parents:
diff changeset
253 -- nor order of elements are represented in this model. Elements are
kono
parents:
diff changeset
254 -- modeled up to equivalence.
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 Ghost,
kono
parents:
diff changeset
257 Global => null,
kono
parents:
diff changeset
258 Post => M.Length (Model'Result) = Length (Container);
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 function Elements (Container : Set) return E.Sequence with
kono
parents:
diff changeset
261 -- The Elements sequence represents the underlying list structure of
kono
parents:
diff changeset
262 -- sets that is used for iteration. It stores the actual values of
kono
parents:
diff changeset
263 -- elements in the set. It does not model cursors.
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 Ghost,
kono
parents:
diff changeset
266 Global => null,
kono
parents:
diff changeset
267 Post =>
kono
parents:
diff changeset
268 E.Length (Elements'Result) = Length (Container)
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 -- It only contains keys contained in Model
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 and (for all Item of Elements'Result =>
kono
parents:
diff changeset
273 M.Contains (Model (Container), Item))
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275 -- It contains all the elements contained in Model
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 and (for all Item of Model (Container) =>
kono
parents:
diff changeset
278 (Find (Elements'Result, Item) > 0
kono
parents:
diff changeset
279 and then Equivalent_Elements
kono
parents:
diff changeset
280 (E.Get (Elements'Result,
kono
parents:
diff changeset
281 Find (Elements'Result, Item)),
kono
parents:
diff changeset
282 Item)))
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 -- It has no duplicate
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 and (for all I in 1 .. Length (Container) =>
kono
parents:
diff changeset
287 Find (Elements'Result, E.Get (Elements'Result, I)) = I)
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 and (for all I in 1 .. Length (Container) =>
kono
parents:
diff changeset
290 (for all J in 1 .. Length (Container) =>
kono
parents:
diff changeset
291 (if Equivalent_Elements
kono
parents:
diff changeset
292 (E.Get (Elements'Result, I),
kono
parents:
diff changeset
293 E.Get (Elements'Result, J))
kono
parents:
diff changeset
294 then I = J)));
kono
parents:
diff changeset
295 pragma Annotate (GNATprove, Iterable_For_Proof, "Model", Elements);
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 function Positions (Container : Set) return P.Map with
kono
parents:
diff changeset
298 -- The Positions map is used to model cursors. It only contains valid
kono
parents:
diff changeset
299 -- cursors and maps them to their position in the container.
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 Ghost,
kono
parents:
diff changeset
302 Global => null,
kono
parents:
diff changeset
303 Post =>
kono
parents:
diff changeset
304 not P.Has_Key (Positions'Result, No_Element)
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 -- Positions of cursors are smaller than the container's length
kono
parents:
diff changeset
307
kono
parents:
diff changeset
308 and then
kono
parents:
diff changeset
309 (for all I of Positions'Result =>
kono
parents:
diff changeset
310 P.Get (Positions'Result, I) in 1 .. Length (Container)
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 -- No two cursors have the same position. Note that we do not
kono
parents:
diff changeset
313 -- state that there is a cursor in the map for each position, as
kono
parents:
diff changeset
314 -- it is rarely needed.
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 and then
kono
parents:
diff changeset
317 (for all J of Positions'Result =>
kono
parents:
diff changeset
318 (if P.Get (Positions'Result, I) = P.Get (Positions'Result, J)
kono
parents:
diff changeset
319 then I = J)));
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 procedure Lift_Abstraction_Level (Container : Set) with
kono
parents:
diff changeset
322 -- Lift_Abstraction_Level is a ghost procedure that does nothing but
kono
parents:
diff changeset
323 -- assume that we can access the same elements by iterating over
kono
parents:
diff changeset
324 -- positions or cursors.
kono
parents:
diff changeset
325 -- This information is not generally useful except when switching from
kono
parents:
diff changeset
326 -- a low-level, cursor-aware view of a container, to a high-level,
kono
parents:
diff changeset
327 -- position-based view.
kono
parents:
diff changeset
328
kono
parents:
diff changeset
329 Ghost,
kono
parents:
diff changeset
330 Global => null,
kono
parents:
diff changeset
331 Post =>
kono
parents:
diff changeset
332 (for all Item of Elements (Container) =>
kono
parents:
diff changeset
333 (for some I of Positions (Container) =>
kono
parents:
diff changeset
334 E.Get (Elements (Container), P.Get (Positions (Container), I)) =
kono
parents:
diff changeset
335 Item));
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 function Contains
kono
parents:
diff changeset
338 (C : M.Set;
kono
parents:
diff changeset
339 K : Element_Type) return Boolean renames M.Contains;
kono
parents:
diff changeset
340 -- To improve readability of contracts, we rename the function used to
kono
parents:
diff changeset
341 -- search for an element in the model to Contains.
kono
parents:
diff changeset
342
kono
parents:
diff changeset
343 end Formal_Model;
kono
parents:
diff changeset
344 use Formal_Model;
kono
parents:
diff changeset
345
kono
parents:
diff changeset
346 Empty_Set : constant Set;
kono
parents:
diff changeset
347
kono
parents:
diff changeset
348 function "=" (Left, Right : Set) return Boolean with
kono
parents:
diff changeset
349 Global => null,
kono
parents:
diff changeset
350 Post =>
kono
parents:
diff changeset
351 "="'Result =
kono
parents:
diff changeset
352 (Length (Left) = Length (Right)
kono
parents:
diff changeset
353 and E_Elements_Included (Elements (Left), Elements (Right)))
kono
parents:
diff changeset
354 and
kono
parents:
diff changeset
355 "="'Result =
kono
parents:
diff changeset
356 (E_Elements_Included (Elements (Left), Elements (Right))
kono
parents:
diff changeset
357 and E_Elements_Included (Elements (Right), Elements (Left)));
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 function Equivalent_Sets (Left, Right : Set) return Boolean with
kono
parents:
diff changeset
360 Global => null,
kono
parents:
diff changeset
361 Post => Equivalent_Sets'Result = (Model (Left) = Model (Right));
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 function To_Set (New_Item : Element_Type) return Set with
kono
parents:
diff changeset
364 Global => null,
kono
parents:
diff changeset
365 Post =>
kono
parents:
diff changeset
366 M.Is_Singleton (Model (To_Set'Result), New_Item)
kono
parents:
diff changeset
367 and Length (To_Set'Result) = 1
kono
parents:
diff changeset
368 and E.Get (Elements (To_Set'Result), 1) = New_Item;
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370 function Capacity (Container : Set) return Count_Type with
kono
parents:
diff changeset
371 Global => null,
kono
parents:
diff changeset
372 Post => Capacity'Result = Container.Capacity;
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 procedure Reserve_Capacity
kono
parents:
diff changeset
375 (Container : in out Set;
kono
parents:
diff changeset
376 Capacity : Count_Type)
kono
parents:
diff changeset
377 with
kono
parents:
diff changeset
378 Global => null,
kono
parents:
diff changeset
379 Pre => Capacity <= Container.Capacity,
kono
parents:
diff changeset
380 Post =>
kono
parents:
diff changeset
381 Model (Container) = Model (Container)'Old
kono
parents:
diff changeset
382 and Length (Container)'Old = Length (Container)
kono
parents:
diff changeset
383
kono
parents:
diff changeset
384 -- Actual elements are preserved
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 and E_Elements_Included
kono
parents:
diff changeset
387 (Elements (Container), Elements (Container)'Old)
kono
parents:
diff changeset
388 and E_Elements_Included
kono
parents:
diff changeset
389 (Elements (Container)'Old, Elements (Container));
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 function Is_Empty (Container : Set) return Boolean with
kono
parents:
diff changeset
392 Global => null,
kono
parents:
diff changeset
393 Post => Is_Empty'Result = (Length (Container) = 0);
kono
parents:
diff changeset
394
kono
parents:
diff changeset
395 procedure Clear (Container : in out Set) with
kono
parents:
diff changeset
396 Global => null,
kono
parents:
diff changeset
397 Post => Length (Container) = 0 and M.Is_Empty (Model (Container));
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 procedure Assign (Target : in out Set; Source : Set) with
kono
parents:
diff changeset
400 Global => null,
kono
parents:
diff changeset
401 Pre => Target.Capacity >= Length (Source),
kono
parents:
diff changeset
402 Post =>
kono
parents:
diff changeset
403 Model (Target) = Model (Source)
kono
parents:
diff changeset
404 and Length (Target) = Length (Source)
kono
parents:
diff changeset
405
kono
parents:
diff changeset
406 -- Actual elements are preserved
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 and E_Elements_Included (Elements (Target), Elements (Source))
kono
parents:
diff changeset
409 and E_Elements_Included (Elements (Source), Elements (Target));
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 function Copy
kono
parents:
diff changeset
412 (Source : Set;
kono
parents:
diff changeset
413 Capacity : Count_Type := 0) return Set
kono
parents:
diff changeset
414 with
kono
parents:
diff changeset
415 Global => null,
kono
parents:
diff changeset
416 Pre => Capacity = 0 or else Capacity >= Source.Capacity,
kono
parents:
diff changeset
417 Post =>
kono
parents:
diff changeset
418 Model (Copy'Result) = Model (Source)
kono
parents:
diff changeset
419 and Elements (Copy'Result) = Elements (Source)
kono
parents:
diff changeset
420 and Positions (Copy'Result) = Positions (Source)
kono
parents:
diff changeset
421 and (if Capacity = 0 then
kono
parents:
diff changeset
422 Copy'Result.Capacity = Source.Capacity
kono
parents:
diff changeset
423 else
kono
parents:
diff changeset
424 Copy'Result.Capacity = Capacity);
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 function Element
kono
parents:
diff changeset
427 (Container : Set;
kono
parents:
diff changeset
428 Position : Cursor) return Element_Type
kono
parents:
diff changeset
429 with
kono
parents:
diff changeset
430 Global => null,
kono
parents:
diff changeset
431 Pre => Has_Element (Container, Position),
kono
parents:
diff changeset
432 Post =>
kono
parents:
diff changeset
433 Element'Result =
kono
parents:
diff changeset
434 E.Get (Elements (Container), P.Get (Positions (Container), Position));
kono
parents:
diff changeset
435 pragma Annotate (GNATprove, Inline_For_Proof, Element);
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 procedure Replace_Element
kono
parents:
diff changeset
438 (Container : in out Set;
kono
parents:
diff changeset
439 Position : Cursor;
kono
parents:
diff changeset
440 New_Item : Element_Type)
kono
parents:
diff changeset
441 with
kono
parents:
diff changeset
442 Global => null,
kono
parents:
diff changeset
443 Pre => Has_Element (Container, Position),
kono
parents:
diff changeset
444 Post =>
kono
parents:
diff changeset
445 Length (Container) = Length (Container)'Old
kono
parents:
diff changeset
446
kono
parents:
diff changeset
447 -- Position now maps to New_Item
kono
parents:
diff changeset
448
kono
parents:
diff changeset
449 and Element (Container, Position) = New_Item
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 -- New_Item is contained in Container
kono
parents:
diff changeset
452
kono
parents:
diff changeset
453 and Contains (Model (Container), New_Item)
kono
parents:
diff changeset
454
kono
parents:
diff changeset
455 -- Other elements are preserved
kono
parents:
diff changeset
456
kono
parents:
diff changeset
457 and M.Included_Except
kono
parents:
diff changeset
458 (Model (Container)'Old,
kono
parents:
diff changeset
459 Model (Container),
kono
parents:
diff changeset
460 Element (Container, Position)'Old)
kono
parents:
diff changeset
461 and M.Included_Except
kono
parents:
diff changeset
462 (Model (Container),
kono
parents:
diff changeset
463 Model (Container)'Old,
kono
parents:
diff changeset
464 New_Item)
kono
parents:
diff changeset
465
kono
parents:
diff changeset
466 -- Mapping from cursors to elements is preserved
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 and Mapping_Preserved_Except
kono
parents:
diff changeset
469 (E_Left => Elements (Container)'Old,
kono
parents:
diff changeset
470 E_Right => Elements (Container),
kono
parents:
diff changeset
471 P_Left => Positions (Container)'Old,
kono
parents:
diff changeset
472 P_Right => Positions (Container),
kono
parents:
diff changeset
473 Position => Position)
kono
parents:
diff changeset
474 and Positions (Container) = Positions (Container)'Old;
kono
parents:
diff changeset
475
kono
parents:
diff changeset
476 procedure Move (Target : in out Set; Source : in out Set) with
kono
parents:
diff changeset
477 Global => null,
kono
parents:
diff changeset
478 Pre => Target.Capacity >= Length (Source),
kono
parents:
diff changeset
479 Post =>
kono
parents:
diff changeset
480 Length (Source) = 0
kono
parents:
diff changeset
481 and Model (Target) = Model (Source)'Old
kono
parents:
diff changeset
482 and Length (Target) = Length (Source)'Old
kono
parents:
diff changeset
483
kono
parents:
diff changeset
484 -- Actual elements are preserved
kono
parents:
diff changeset
485
kono
parents:
diff changeset
486 and E_Elements_Included (Elements (Target), Elements (Source)'Old)
kono
parents:
diff changeset
487 and E_Elements_Included (Elements (Source)'Old, Elements (Target));
kono
parents:
diff changeset
488
kono
parents:
diff changeset
489 procedure Insert
kono
parents:
diff changeset
490 (Container : in out Set;
kono
parents:
diff changeset
491 New_Item : Element_Type;
kono
parents:
diff changeset
492 Position : out Cursor;
kono
parents:
diff changeset
493 Inserted : out Boolean)
kono
parents:
diff changeset
494 with
kono
parents:
diff changeset
495 Global => null,
kono
parents:
diff changeset
496 Pre =>
kono
parents:
diff changeset
497 Length (Container) < Container.Capacity
kono
parents:
diff changeset
498 or Contains (Container, New_Item),
kono
parents:
diff changeset
499 Post =>
kono
parents:
diff changeset
500 Contains (Container, New_Item)
kono
parents:
diff changeset
501 and Has_Element (Container, Position)
kono
parents:
diff changeset
502 and Equivalent_Elements (Element (Container, Position), New_Item),
kono
parents:
diff changeset
503 Contract_Cases =>
kono
parents:
diff changeset
504
kono
parents:
diff changeset
505 -- If New_Item is already in Container, it is not modified and Inserted
kono
parents:
diff changeset
506 -- is set to False.
kono
parents:
diff changeset
507
kono
parents:
diff changeset
508 (Contains (Container, New_Item) =>
kono
parents:
diff changeset
509 not Inserted
kono
parents:
diff changeset
510 and Model (Container) = Model (Container)'Old
kono
parents:
diff changeset
511 and Elements (Container) = Elements (Container)'Old
kono
parents:
diff changeset
512 and Positions (Container) = Positions (Container)'Old,
kono
parents:
diff changeset
513
kono
parents:
diff changeset
514 -- Otherwise, New_Item is inserted in Container and Inserted is set to
kono
parents:
diff changeset
515 -- True.
kono
parents:
diff changeset
516
kono
parents:
diff changeset
517 others =>
kono
parents:
diff changeset
518 Inserted
kono
parents:
diff changeset
519 and Length (Container) = Length (Container)'Old + 1
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 -- Position now maps to New_Item
kono
parents:
diff changeset
522
kono
parents:
diff changeset
523 and Element (Container, Position) = New_Item
kono
parents:
diff changeset
524
kono
parents:
diff changeset
525 -- Other elements are preserved
kono
parents:
diff changeset
526
kono
parents:
diff changeset
527 and Model (Container)'Old <= Model (Container)
kono
parents:
diff changeset
528 and M.Included_Except
kono
parents:
diff changeset
529 (Model (Container),
kono
parents:
diff changeset
530 Model (Container)'Old,
kono
parents:
diff changeset
531 New_Item)
kono
parents:
diff changeset
532
kono
parents:
diff changeset
533 -- Mapping from cursors to elements is preserved
kono
parents:
diff changeset
534
kono
parents:
diff changeset
535 and Mapping_Preserved
kono
parents:
diff changeset
536 (E_Left => Elements (Container)'Old,
kono
parents:
diff changeset
537 E_Right => Elements (Container),
kono
parents:
diff changeset
538 P_Left => Positions (Container)'Old,
kono
parents:
diff changeset
539 P_Right => Positions (Container))
kono
parents:
diff changeset
540 and P.Keys_Included_Except
kono
parents:
diff changeset
541 (Positions (Container),
kono
parents:
diff changeset
542 Positions (Container)'Old,
kono
parents:
diff changeset
543 Position));
kono
parents:
diff changeset
544
kono
parents:
diff changeset
545 procedure Insert (Container : in out Set; New_Item : Element_Type) with
kono
parents:
diff changeset
546 Global => null,
kono
parents:
diff changeset
547 Pre => Length (Container) < Container.Capacity
kono
parents:
diff changeset
548 and then (not Contains (Container, New_Item)),
kono
parents:
diff changeset
549 Post =>
kono
parents:
diff changeset
550 Length (Container) = Length (Container)'Old + 1
kono
parents:
diff changeset
551 and Contains (Container, New_Item)
kono
parents:
diff changeset
552 and Element (Container, Find (Container, New_Item)) = New_Item
kono
parents:
diff changeset
553
kono
parents:
diff changeset
554 -- Other elements are preserved
kono
parents:
diff changeset
555
kono
parents:
diff changeset
556 and Model (Container)'Old <= Model (Container)
kono
parents:
diff changeset
557 and M.Included_Except
kono
parents:
diff changeset
558 (Model (Container),
kono
parents:
diff changeset
559 Model (Container)'Old,
kono
parents:
diff changeset
560 New_Item)
kono
parents:
diff changeset
561
kono
parents:
diff changeset
562 -- Mapping from cursors to elements is preserved
kono
parents:
diff changeset
563
kono
parents:
diff changeset
564 and Mapping_Preserved
kono
parents:
diff changeset
565 (E_Left => Elements (Container)'Old,
kono
parents:
diff changeset
566 E_Right => Elements (Container),
kono
parents:
diff changeset
567 P_Left => Positions (Container)'Old,
kono
parents:
diff changeset
568 P_Right => Positions (Container))
kono
parents:
diff changeset
569 and P.Keys_Included_Except
kono
parents:
diff changeset
570 (Positions (Container),
kono
parents:
diff changeset
571 Positions (Container)'Old,
kono
parents:
diff changeset
572 Find (Container, New_Item));
kono
parents:
diff changeset
573
kono
parents:
diff changeset
574 procedure Include (Container : in out Set; New_Item : Element_Type) with
kono
parents:
diff changeset
575 Global => null,
kono
parents:
diff changeset
576 Pre =>
kono
parents:
diff changeset
577 Length (Container) < Container.Capacity
kono
parents:
diff changeset
578 or Contains (Container, New_Item),
kono
parents:
diff changeset
579 Post =>
kono
parents:
diff changeset
580 Contains (Container, New_Item)
kono
parents:
diff changeset
581 and Element (Container, Find (Container, New_Item)) = New_Item,
kono
parents:
diff changeset
582 Contract_Cases =>
kono
parents:
diff changeset
583
kono
parents:
diff changeset
584 -- If an element equivalent to New_Item is already in Container, it is
kono
parents:
diff changeset
585 -- replaced by New_Item.
kono
parents:
diff changeset
586
kono
parents:
diff changeset
587 (Contains (Container, New_Item) =>
kono
parents:
diff changeset
588
kono
parents:
diff changeset
589 -- Elements are preserved modulo equivalence
kono
parents:
diff changeset
590
kono
parents:
diff changeset
591 Model (Container) = Model (Container)'Old
kono
parents:
diff changeset
592
kono
parents:
diff changeset
593 -- Cursors are preserved
kono
parents:
diff changeset
594
kono
parents:
diff changeset
595 and Positions (Container) = Positions (Container)'Old
kono
parents:
diff changeset
596
kono
parents:
diff changeset
597 -- The actual value of other elements is preserved
kono
parents:
diff changeset
598
kono
parents:
diff changeset
599 and E.Equal_Except
kono
parents:
diff changeset
600 (Elements (Container)'Old,
kono
parents:
diff changeset
601 Elements (Container),
kono
parents:
diff changeset
602 P.Get (Positions (Container), Find (Container, New_Item))),
kono
parents:
diff changeset
603
kono
parents:
diff changeset
604 -- Otherwise, New_Item is inserted in Container
kono
parents:
diff changeset
605
kono
parents:
diff changeset
606 others =>
kono
parents:
diff changeset
607 Length (Container) = Length (Container)'Old + 1
kono
parents:
diff changeset
608
kono
parents:
diff changeset
609 -- Other elements are preserved
kono
parents:
diff changeset
610
kono
parents:
diff changeset
611 and Model (Container)'Old <= Model (Container)
kono
parents:
diff changeset
612 and M.Included_Except
kono
parents:
diff changeset
613 (Model (Container),
kono
parents:
diff changeset
614 Model (Container)'Old,
kono
parents:
diff changeset
615 New_Item)
kono
parents:
diff changeset
616
kono
parents:
diff changeset
617 -- Mapping from cursors to elements is preserved
kono
parents:
diff changeset
618
kono
parents:
diff changeset
619 and Mapping_Preserved
kono
parents:
diff changeset
620 (E_Left => Elements (Container)'Old,
kono
parents:
diff changeset
621 E_Right => Elements (Container),
kono
parents:
diff changeset
622 P_Left => Positions (Container)'Old,
kono
parents:
diff changeset
623 P_Right => Positions (Container))
kono
parents:
diff changeset
624 and P.Keys_Included_Except
kono
parents:
diff changeset
625 (Positions (Container),
kono
parents:
diff changeset
626 Positions (Container)'Old,
kono
parents:
diff changeset
627 Find (Container, New_Item)));
kono
parents:
diff changeset
628
kono
parents:
diff changeset
629 procedure Replace (Container : in out Set; New_Item : Element_Type) with
kono
parents:
diff changeset
630 Global => null,
kono
parents:
diff changeset
631 Pre => Contains (Container, New_Item),
kono
parents:
diff changeset
632 Post =>
kono
parents:
diff changeset
633
kono
parents:
diff changeset
634 -- Elements are preserved modulo equivalence
kono
parents:
diff changeset
635
kono
parents:
diff changeset
636 Model (Container) = Model (Container)'Old
kono
parents:
diff changeset
637 and Contains (Container, New_Item)
kono
parents:
diff changeset
638
kono
parents:
diff changeset
639 -- Cursors are preserved
kono
parents:
diff changeset
640
kono
parents:
diff changeset
641 and Positions (Container) = Positions (Container)'Old
kono
parents:
diff changeset
642
kono
parents:
diff changeset
643 -- The element equivalent to New_Item in Container is replaced by
kono
parents:
diff changeset
644 -- New_Item.
kono
parents:
diff changeset
645
kono
parents:
diff changeset
646 and Element (Container, Find (Container, New_Item)) = New_Item
kono
parents:
diff changeset
647 and E.Equal_Except
kono
parents:
diff changeset
648 (Elements (Container)'Old,
kono
parents:
diff changeset
649 Elements (Container),
kono
parents:
diff changeset
650 P.Get (Positions (Container), Find (Container, New_Item)));
kono
parents:
diff changeset
651
kono
parents:
diff changeset
652 procedure Exclude (Container : in out Set; Item : Element_Type) with
kono
parents:
diff changeset
653 Global => null,
kono
parents:
diff changeset
654 Post => not Contains (Container, Item),
kono
parents:
diff changeset
655 Contract_Cases =>
kono
parents:
diff changeset
656
kono
parents:
diff changeset
657 -- If Item is not in Container, nothing is changed
kono
parents:
diff changeset
658
kono
parents:
diff changeset
659 (not Contains (Container, Item) =>
kono
parents:
diff changeset
660 Model (Container) = Model (Container)'Old
kono
parents:
diff changeset
661 and Elements (Container) = Elements (Container)'Old
kono
parents:
diff changeset
662 and Positions (Container) = Positions (Container)'Old,
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664 -- Otherwise, Item is removed from Container
kono
parents:
diff changeset
665
kono
parents:
diff changeset
666 others =>
kono
parents:
diff changeset
667 Length (Container) = Length (Container)'Old - 1
kono
parents:
diff changeset
668
kono
parents:
diff changeset
669 -- Other elements are preserved
kono
parents:
diff changeset
670
kono
parents:
diff changeset
671 and Model (Container) <= Model (Container)'Old
kono
parents:
diff changeset
672 and M.Included_Except
kono
parents:
diff changeset
673 (Model (Container)'Old,
kono
parents:
diff changeset
674 Model (Container),
kono
parents:
diff changeset
675 Item)
kono
parents:
diff changeset
676
kono
parents:
diff changeset
677 -- Mapping from cursors to elements is preserved
kono
parents:
diff changeset
678
kono
parents:
diff changeset
679 and Mapping_Preserved
kono
parents:
diff changeset
680 (E_Left => Elements (Container),
kono
parents:
diff changeset
681 E_Right => Elements (Container)'Old,
kono
parents:
diff changeset
682 P_Left => Positions (Container),
kono
parents:
diff changeset
683 P_Right => Positions (Container)'Old)
kono
parents:
diff changeset
684 and P.Keys_Included_Except
kono
parents:
diff changeset
685 (Positions (Container)'Old,
kono
parents:
diff changeset
686 Positions (Container),
kono
parents:
diff changeset
687 Find (Container, Item)'Old));
kono
parents:
diff changeset
688
kono
parents:
diff changeset
689 procedure Delete (Container : in out Set; Item : Element_Type) with
kono
parents:
diff changeset
690 Global => null,
kono
parents:
diff changeset
691 Pre => Contains (Container, Item),
kono
parents:
diff changeset
692 Post =>
kono
parents:
diff changeset
693 Length (Container) = Length (Container)'Old - 1
kono
parents:
diff changeset
694
kono
parents:
diff changeset
695 -- Item is no longer in Container
kono
parents:
diff changeset
696
kono
parents:
diff changeset
697 and not Contains (Container, Item)
kono
parents:
diff changeset
698
kono
parents:
diff changeset
699 -- Other elements are preserved
kono
parents:
diff changeset
700
kono
parents:
diff changeset
701 and Model (Container) <= Model (Container)'Old
kono
parents:
diff changeset
702 and M.Included_Except
kono
parents:
diff changeset
703 (Model (Container)'Old,
kono
parents:
diff changeset
704 Model (Container),
kono
parents:
diff changeset
705 Item)
kono
parents:
diff changeset
706
kono
parents:
diff changeset
707 -- Mapping from cursors to elements is preserved
kono
parents:
diff changeset
708
kono
parents:
diff changeset
709 and Mapping_Preserved
kono
parents:
diff changeset
710 (E_Left => Elements (Container),
kono
parents:
diff changeset
711 E_Right => Elements (Container)'Old,
kono
parents:
diff changeset
712 P_Left => Positions (Container),
kono
parents:
diff changeset
713 P_Right => Positions (Container)'Old)
kono
parents:
diff changeset
714 and P.Keys_Included_Except
kono
parents:
diff changeset
715 (Positions (Container)'Old,
kono
parents:
diff changeset
716 Positions (Container),
kono
parents:
diff changeset
717 Find (Container, Item)'Old);
kono
parents:
diff changeset
718
kono
parents:
diff changeset
719 procedure Delete (Container : in out Set; Position : in out Cursor) with
kono
parents:
diff changeset
720 Global => null,
kono
parents:
diff changeset
721 Pre => Has_Element (Container, Position),
kono
parents:
diff changeset
722 Post =>
kono
parents:
diff changeset
723 Position = No_Element
kono
parents:
diff changeset
724 and Length (Container) = Length (Container)'Old - 1
kono
parents:
diff changeset
725
kono
parents:
diff changeset
726 -- The element at position Position is no longer in Container
kono
parents:
diff changeset
727
kono
parents:
diff changeset
728 and not Contains (Container, Element (Container, Position)'Old)
kono
parents:
diff changeset
729 and not P.Has_Key (Positions (Container), Position'Old)
kono
parents:
diff changeset
730
kono
parents:
diff changeset
731 -- Other elements are preserved
kono
parents:
diff changeset
732
kono
parents:
diff changeset
733 and Model (Container) <= Model (Container)'Old
kono
parents:
diff changeset
734 and M.Included_Except
kono
parents:
diff changeset
735 (Model (Container)'Old,
kono
parents:
diff changeset
736 Model (Container),
kono
parents:
diff changeset
737 Element (Container, Position)'Old)
kono
parents:
diff changeset
738
kono
parents:
diff changeset
739 -- Mapping from cursors to elements is preserved
kono
parents:
diff changeset
740
kono
parents:
diff changeset
741 and Mapping_Preserved
kono
parents:
diff changeset
742 (E_Left => Elements (Container),
kono
parents:
diff changeset
743 E_Right => Elements (Container)'Old,
kono
parents:
diff changeset
744 P_Left => Positions (Container),
kono
parents:
diff changeset
745 P_Right => Positions (Container)'Old)
kono
parents:
diff changeset
746 and P.Keys_Included_Except
kono
parents:
diff changeset
747 (Positions (Container)'Old,
kono
parents:
diff changeset
748 Positions (Container),
kono
parents:
diff changeset
749 Position'Old);
kono
parents:
diff changeset
750
kono
parents:
diff changeset
751 procedure Union (Target : in out Set; Source : Set) with
kono
parents:
diff changeset
752 Global => null,
kono
parents:
diff changeset
753 Pre =>
kono
parents:
diff changeset
754 Length (Source) - Length (Target and Source) <=
kono
parents:
diff changeset
755 Target.Capacity - Length (Target),
kono
parents:
diff changeset
756 Post =>
kono
parents:
diff changeset
757 Length (Target) = Length (Target)'Old
kono
parents:
diff changeset
758 - M.Num_Overlaps (Model (Target)'Old, Model (Source))
kono
parents:
diff changeset
759 + Length (Source)
kono
parents:
diff changeset
760
kono
parents:
diff changeset
761 -- Elements already in Target are still in Target
kono
parents:
diff changeset
762
kono
parents:
diff changeset
763 and Model (Target)'Old <= Model (Target)
kono
parents:
diff changeset
764
kono
parents:
diff changeset
765 -- Elements of Source are included in Target
kono
parents:
diff changeset
766
kono
parents:
diff changeset
767 and Model (Source) <= Model (Target)
kono
parents:
diff changeset
768
kono
parents:
diff changeset
769 -- Elements of Target come from either Source or Target
kono
parents:
diff changeset
770
kono
parents:
diff changeset
771 and M.Included_In_Union
kono
parents:
diff changeset
772 (Model (Target), Model (Source), Model (Target)'Old)
kono
parents:
diff changeset
773
kono
parents:
diff changeset
774 -- Actual value of elements come from either Left or Right
kono
parents:
diff changeset
775
kono
parents:
diff changeset
776 and E_Elements_Included
kono
parents:
diff changeset
777 (Elements (Target),
kono
parents:
diff changeset
778 Model (Target)'Old,
kono
parents:
diff changeset
779 Elements (Target)'Old,
kono
parents:
diff changeset
780 Elements (Source))
kono
parents:
diff changeset
781
kono
parents:
diff changeset
782 and E_Elements_Included
kono
parents:
diff changeset
783 (Elements (Target)'Old, Model (Target)'Old, Elements (Target))
kono
parents:
diff changeset
784
kono
parents:
diff changeset
785 and E_Elements_Included
kono
parents:
diff changeset
786 (Elements (Source),
kono
parents:
diff changeset
787 Model (Target)'Old,
kono
parents:
diff changeset
788 Elements (Source),
kono
parents:
diff changeset
789 Elements (Target))
kono
parents:
diff changeset
790
kono
parents:
diff changeset
791 -- Mapping from cursors of Target to elements is preserved
kono
parents:
diff changeset
792
kono
parents:
diff changeset
793 and Mapping_Preserved
kono
parents:
diff changeset
794 (E_Left => Elements (Target)'Old,
kono
parents:
diff changeset
795 E_Right => Elements (Target),
kono
parents:
diff changeset
796 P_Left => Positions (Target)'Old,
kono
parents:
diff changeset
797 P_Right => Positions (Target));
kono
parents:
diff changeset
798
kono
parents:
diff changeset
799 function Union (Left, Right : Set) return Set with
kono
parents:
diff changeset
800 Global => null,
kono
parents:
diff changeset
801 Pre => Length (Left) <= Count_Type'Last - Length (Right),
kono
parents:
diff changeset
802 Post =>
kono
parents:
diff changeset
803 Length (Union'Result) = Length (Left)
kono
parents:
diff changeset
804 - M.Num_Overlaps (Model (Left), Model (Right))
kono
parents:
diff changeset
805 + Length (Right)
kono
parents:
diff changeset
806
kono
parents:
diff changeset
807 -- Elements of Left and Right are in the result of Union
kono
parents:
diff changeset
808
kono
parents:
diff changeset
809 and Model (Left) <= Model (Union'Result)
kono
parents:
diff changeset
810 and Model (Right) <= Model (Union'Result)
kono
parents:
diff changeset
811
kono
parents:
diff changeset
812 -- Elements of the result of union come from either Left or Right
kono
parents:
diff changeset
813
kono
parents:
diff changeset
814 and
kono
parents:
diff changeset
815 M.Included_In_Union
kono
parents:
diff changeset
816 (Model (Union'Result), Model (Left), Model (Right))
kono
parents:
diff changeset
817
kono
parents:
diff changeset
818 -- Actual value of elements come from either Left or Right
kono
parents:
diff changeset
819
kono
parents:
diff changeset
820 and E_Elements_Included
kono
parents:
diff changeset
821 (Elements (Union'Result),
kono
parents:
diff changeset
822 Model (Left),
kono
parents:
diff changeset
823 Elements (Left),
kono
parents:
diff changeset
824 Elements (Right))
kono
parents:
diff changeset
825
kono
parents:
diff changeset
826 and E_Elements_Included
kono
parents:
diff changeset
827 (Elements (Left), Model (Left), Elements (Union'Result))
kono
parents:
diff changeset
828
kono
parents:
diff changeset
829 and E_Elements_Included
kono
parents:
diff changeset
830 (Elements (Right),
kono
parents:
diff changeset
831 Model (Left),
kono
parents:
diff changeset
832 Elements (Right),
kono
parents:
diff changeset
833 Elements (Union'Result));
kono
parents:
diff changeset
834
kono
parents:
diff changeset
835 function "or" (Left, Right : Set) return Set renames Union;
kono
parents:
diff changeset
836
kono
parents:
diff changeset
837 procedure Intersection (Target : in out Set; Source : Set) with
kono
parents:
diff changeset
838 Global => null,
kono
parents:
diff changeset
839 Post =>
kono
parents:
diff changeset
840 Length (Target) =
kono
parents:
diff changeset
841 M.Num_Overlaps (Model (Target)'Old, Model (Source))
kono
parents:
diff changeset
842
kono
parents:
diff changeset
843 -- Elements of Target were already in Target
kono
parents:
diff changeset
844
kono
parents:
diff changeset
845 and Model (Target) <= Model (Target)'Old
kono
parents:
diff changeset
846
kono
parents:
diff changeset
847 -- Elements of Target are in Source
kono
parents:
diff changeset
848
kono
parents:
diff changeset
849 and Model (Target) <= Model (Source)
kono
parents:
diff changeset
850
kono
parents:
diff changeset
851 -- Elements both in Source and Target are in the intersection
kono
parents:
diff changeset
852
kono
parents:
diff changeset
853 and M.Includes_Intersection
kono
parents:
diff changeset
854 (Model (Target), Model (Source), Model (Target)'Old)
kono
parents:
diff changeset
855
kono
parents:
diff changeset
856 -- Actual value of elements of Target is preserved
kono
parents:
diff changeset
857
kono
parents:
diff changeset
858 and E_Elements_Included (Elements (Target), Elements (Target)'Old)
kono
parents:
diff changeset
859 and E_Elements_Included
kono
parents:
diff changeset
860 (Elements (Target)'Old, Model (Source), Elements (Target))
kono
parents:
diff changeset
861
kono
parents:
diff changeset
862 -- Mapping from cursors of Target to elements is preserved
kono
parents:
diff changeset
863
kono
parents:
diff changeset
864 and Mapping_Preserved
kono
parents:
diff changeset
865 (E_Left => Elements (Target),
kono
parents:
diff changeset
866 E_Right => Elements (Target)'Old,
kono
parents:
diff changeset
867 P_Left => Positions (Target),
kono
parents:
diff changeset
868 P_Right => Positions (Target)'Old);
kono
parents:
diff changeset
869
kono
parents:
diff changeset
870 function Intersection (Left, Right : Set) return Set with
kono
parents:
diff changeset
871 Global => null,
kono
parents:
diff changeset
872 Post =>
kono
parents:
diff changeset
873 Length (Intersection'Result) =
kono
parents:
diff changeset
874 M.Num_Overlaps (Model (Left), Model (Right))
kono
parents:
diff changeset
875
kono
parents:
diff changeset
876 -- Elements in the result of Intersection are in Left and Right
kono
parents:
diff changeset
877
kono
parents:
diff changeset
878 and Model (Intersection'Result) <= Model (Left)
kono
parents:
diff changeset
879 and Model (Intersection'Result) <= Model (Right)
kono
parents:
diff changeset
880
kono
parents:
diff changeset
881 -- Elements both in Left and Right are in the result of Intersection
kono
parents:
diff changeset
882
kono
parents:
diff changeset
883 and M.Includes_Intersection
kono
parents:
diff changeset
884 (Model (Intersection'Result), Model (Left), Model (Right))
kono
parents:
diff changeset
885
kono
parents:
diff changeset
886 -- Actual value of elements come from Left
kono
parents:
diff changeset
887
kono
parents:
diff changeset
888 and E_Elements_Included
kono
parents:
diff changeset
889 (Elements (Intersection'Result), Elements (Left))
kono
parents:
diff changeset
890
kono
parents:
diff changeset
891 and E_Elements_Included
kono
parents:
diff changeset
892 (Elements (Left), Model (Right),
kono
parents:
diff changeset
893 Elements (Intersection'Result));
kono
parents:
diff changeset
894
kono
parents:
diff changeset
895 function "and" (Left, Right : Set) return Set renames Intersection;
kono
parents:
diff changeset
896
kono
parents:
diff changeset
897 procedure Difference (Target : in out Set; Source : Set) with
kono
parents:
diff changeset
898 Global => null,
kono
parents:
diff changeset
899 Post =>
kono
parents:
diff changeset
900 Length (Target) = Length (Target)'Old -
kono
parents:
diff changeset
901 M.Num_Overlaps (Model (Target)'Old, Model (Source))
kono
parents:
diff changeset
902
kono
parents:
diff changeset
903 -- Elements of Target were already in Target
kono
parents:
diff changeset
904
kono
parents:
diff changeset
905 and Model (Target) <= Model (Target)'Old
kono
parents:
diff changeset
906
kono
parents:
diff changeset
907 -- Elements of Target are not in Source
kono
parents:
diff changeset
908
kono
parents:
diff changeset
909 and M.No_Overlap (Model (Target), Model (Source))
kono
parents:
diff changeset
910
kono
parents:
diff changeset
911 -- Elements in Target but not in Source are in the difference
kono
parents:
diff changeset
912
kono
parents:
diff changeset
913 and M.Included_In_Union
kono
parents:
diff changeset
914 (Model (Target)'Old, Model (Target), Model (Source))
kono
parents:
diff changeset
915
kono
parents:
diff changeset
916 -- Actual value of elements of Target is preserved
kono
parents:
diff changeset
917
kono
parents:
diff changeset
918 and E_Elements_Included (Elements (Target), Elements (Target)'Old)
kono
parents:
diff changeset
919 and E_Elements_Included
kono
parents:
diff changeset
920 (Elements (Target)'Old, Model (Target), Elements (Target))
kono
parents:
diff changeset
921
kono
parents:
diff changeset
922 -- Mapping from cursors of Target to elements is preserved
kono
parents:
diff changeset
923
kono
parents:
diff changeset
924 and Mapping_Preserved
kono
parents:
diff changeset
925 (E_Left => Elements (Target),
kono
parents:
diff changeset
926 E_Right => Elements (Target)'Old,
kono
parents:
diff changeset
927 P_Left => Positions (Target),
kono
parents:
diff changeset
928 P_Right => Positions (Target)'Old);
kono
parents:
diff changeset
929
kono
parents:
diff changeset
930 function Difference (Left, Right : Set) return Set with
kono
parents:
diff changeset
931 Global => null,
kono
parents:
diff changeset
932 Post =>
kono
parents:
diff changeset
933 Length (Difference'Result) = Length (Left) -
kono
parents:
diff changeset
934 M.Num_Overlaps (Model (Left), Model (Right))
kono
parents:
diff changeset
935
kono
parents:
diff changeset
936 -- Elements of the result of Difference are in Left
kono
parents:
diff changeset
937
kono
parents:
diff changeset
938 and Model (Difference'Result) <= Model (Left)
kono
parents:
diff changeset
939
kono
parents:
diff changeset
940 -- Elements of the result of Difference are in Right
kono
parents:
diff changeset
941
kono
parents:
diff changeset
942 and M.No_Overlap (Model (Difference'Result), Model (Right))
kono
parents:
diff changeset
943
kono
parents:
diff changeset
944 -- Elements in Left but not in Right are in the difference
kono
parents:
diff changeset
945
kono
parents:
diff changeset
946 and M.Included_In_Union
kono
parents:
diff changeset
947 (Model (Left), Model (Difference'Result), Model (Right))
kono
parents:
diff changeset
948
kono
parents:
diff changeset
949 -- Actual value of elements come from Left
kono
parents:
diff changeset
950
kono
parents:
diff changeset
951 and E_Elements_Included
kono
parents:
diff changeset
952 (Elements (Difference'Result), Elements (Left))
kono
parents:
diff changeset
953
kono
parents:
diff changeset
954 and E_Elements_Included
kono
parents:
diff changeset
955 (Elements (Left),
kono
parents:
diff changeset
956 Model (Difference'Result),
kono
parents:
diff changeset
957 Elements (Difference'Result));
kono
parents:
diff changeset
958
kono
parents:
diff changeset
959 function "-" (Left, Right : Set) return Set renames Difference;
kono
parents:
diff changeset
960
kono
parents:
diff changeset
961 procedure Symmetric_Difference (Target : in out Set; Source : Set) with
kono
parents:
diff changeset
962 Global => null,
kono
parents:
diff changeset
963 Pre =>
kono
parents:
diff changeset
964 Length (Source) - Length (Target and Source) <=
kono
parents:
diff changeset
965 Target.Capacity - Length (Target) + Length (Target and Source),
kono
parents:
diff changeset
966 Post =>
kono
parents:
diff changeset
967 Length (Target) = Length (Target)'Old -
kono
parents:
diff changeset
968 2 * M.Num_Overlaps (Model (Target)'Old, Model (Source)) +
kono
parents:
diff changeset
969 Length (Source)
kono
parents:
diff changeset
970
kono
parents:
diff changeset
971 -- Elements of the difference were not both in Source and in Target
kono
parents:
diff changeset
972
kono
parents:
diff changeset
973 and M.Not_In_Both (Model (Target), Model (Target)'Old, Model (Source))
kono
parents:
diff changeset
974
kono
parents:
diff changeset
975 -- Elements in Target but not in Source are in the difference
kono
parents:
diff changeset
976
kono
parents:
diff changeset
977 and M.Included_In_Union
kono
parents:
diff changeset
978 (Model (Target)'Old, Model (Target), Model (Source))
kono
parents:
diff changeset
979
kono
parents:
diff changeset
980 -- Elements in Source but not in Target are in the difference
kono
parents:
diff changeset
981
kono
parents:
diff changeset
982 and M.Included_In_Union
kono
parents:
diff changeset
983 (Model (Source), Model (Target), Model (Target)'Old)
kono
parents:
diff changeset
984
kono
parents:
diff changeset
985 -- Actual value of elements come from either Left or Right
kono
parents:
diff changeset
986
kono
parents:
diff changeset
987 and E_Elements_Included
kono
parents:
diff changeset
988 (Elements (Target),
kono
parents:
diff changeset
989 Model (Target)'Old,
kono
parents:
diff changeset
990 Elements (Target)'Old,
kono
parents:
diff changeset
991 Elements (Source))
kono
parents:
diff changeset
992
kono
parents:
diff changeset
993 and E_Elements_Included
kono
parents:
diff changeset
994 (Elements (Target)'Old, Model (Target), Elements (Target))
kono
parents:
diff changeset
995
kono
parents:
diff changeset
996 and E_Elements_Included
kono
parents:
diff changeset
997 (Elements (Source), Model (Target), Elements (Target));
kono
parents:
diff changeset
998
kono
parents:
diff changeset
999 function Symmetric_Difference (Left, Right : Set) return Set with
kono
parents:
diff changeset
1000 Global => null,
kono
parents:
diff changeset
1001 Pre => Length (Left) <= Count_Type'Last - Length (Right),
kono
parents:
diff changeset
1002 Post =>
kono
parents:
diff changeset
1003 Length (Symmetric_Difference'Result) = Length (Left) -
kono
parents:
diff changeset
1004 2 * M.Num_Overlaps (Model (Left), Model (Right)) +
kono
parents:
diff changeset
1005 Length (Right)
kono
parents:
diff changeset
1006
kono
parents:
diff changeset
1007 -- Elements of the difference were not both in Left and Right
kono
parents:
diff changeset
1008
kono
parents:
diff changeset
1009 and M.Not_In_Both
kono
parents:
diff changeset
1010 (Model (Symmetric_Difference'Result),
kono
parents:
diff changeset
1011 Model (Left),
kono
parents:
diff changeset
1012 Model (Right))
kono
parents:
diff changeset
1013
kono
parents:
diff changeset
1014 -- Elements in Left but not in Right are in the difference
kono
parents:
diff changeset
1015
kono
parents:
diff changeset
1016 and M.Included_In_Union
kono
parents:
diff changeset
1017 (Model (Left),
kono
parents:
diff changeset
1018 Model (Symmetric_Difference'Result),
kono
parents:
diff changeset
1019 Model (Right))
kono
parents:
diff changeset
1020
kono
parents:
diff changeset
1021 -- Elements in Right but not in Left are in the difference
kono
parents:
diff changeset
1022
kono
parents:
diff changeset
1023 and M.Included_In_Union
kono
parents:
diff changeset
1024 (Model (Right),
kono
parents:
diff changeset
1025 Model (Symmetric_Difference'Result),
kono
parents:
diff changeset
1026 Model (Left))
kono
parents:
diff changeset
1027
kono
parents:
diff changeset
1028 -- Actual value of elements come from either Left or Right
kono
parents:
diff changeset
1029
kono
parents:
diff changeset
1030 and E_Elements_Included
kono
parents:
diff changeset
1031 (Elements (Symmetric_Difference'Result),
kono
parents:
diff changeset
1032 Model (Left),
kono
parents:
diff changeset
1033 Elements (Left),
kono
parents:
diff changeset
1034 Elements (Right))
kono
parents:
diff changeset
1035
kono
parents:
diff changeset
1036 and E_Elements_Included
kono
parents:
diff changeset
1037 (Elements (Left),
kono
parents:
diff changeset
1038 Model (Symmetric_Difference'Result),
kono
parents:
diff changeset
1039 Elements (Symmetric_Difference'Result))
kono
parents:
diff changeset
1040
kono
parents:
diff changeset
1041 and E_Elements_Included
kono
parents:
diff changeset
1042 (Elements (Right),
kono
parents:
diff changeset
1043 Model (Symmetric_Difference'Result),
kono
parents:
diff changeset
1044 Elements (Symmetric_Difference'Result));
kono
parents:
diff changeset
1045
kono
parents:
diff changeset
1046 function "xor" (Left, Right : Set) return Set
kono
parents:
diff changeset
1047 renames Symmetric_Difference;
kono
parents:
diff changeset
1048
kono
parents:
diff changeset
1049 function Overlap (Left, Right : Set) return Boolean with
kono
parents:
diff changeset
1050 Global => null,
kono
parents:
diff changeset
1051 Post =>
kono
parents:
diff changeset
1052 Overlap'Result = not (M.No_Overlap (Model (Left), Model (Right)));
kono
parents:
diff changeset
1053
kono
parents:
diff changeset
1054 function Is_Subset (Subset : Set; Of_Set : Set) return Boolean with
kono
parents:
diff changeset
1055 Global => null,
kono
parents:
diff changeset
1056 Post => Is_Subset'Result = (Model (Subset) <= Model (Of_Set));
kono
parents:
diff changeset
1057
kono
parents:
diff changeset
1058 function First (Container : Set) return Cursor with
kono
parents:
diff changeset
1059 Global => null,
kono
parents:
diff changeset
1060 Contract_Cases =>
kono
parents:
diff changeset
1061 (Length (Container) = 0 =>
kono
parents:
diff changeset
1062 First'Result = No_Element,
kono
parents:
diff changeset
1063
kono
parents:
diff changeset
1064 others =>
kono
parents:
diff changeset
1065 Has_Element (Container, First'Result)
kono
parents:
diff changeset
1066 and P.Get (Positions (Container), First'Result) = 1);
kono
parents:
diff changeset
1067
kono
parents:
diff changeset
1068 function Next (Container : Set; Position : Cursor) return Cursor with
kono
parents:
diff changeset
1069 Global => null,
kono
parents:
diff changeset
1070 Pre =>
kono
parents:
diff changeset
1071 Has_Element (Container, Position) or else Position = No_Element,
kono
parents:
diff changeset
1072 Contract_Cases =>
kono
parents:
diff changeset
1073 (Position = No_Element
kono
parents:
diff changeset
1074 or else P.Get (Positions (Container), Position) = Length (Container)
kono
parents:
diff changeset
1075 =>
kono
parents:
diff changeset
1076 Next'Result = No_Element,
kono
parents:
diff changeset
1077
kono
parents:
diff changeset
1078 others =>
kono
parents:
diff changeset
1079 Has_Element (Container, Next'Result)
kono
parents:
diff changeset
1080 and then P.Get (Positions (Container), Next'Result) =
kono
parents:
diff changeset
1081 P.Get (Positions (Container), Position) + 1);
kono
parents:
diff changeset
1082
kono
parents:
diff changeset
1083 procedure Next (Container : Set; Position : in out Cursor) with
kono
parents:
diff changeset
1084 Global => null,
kono
parents:
diff changeset
1085 Pre =>
kono
parents:
diff changeset
1086 Has_Element (Container, Position) or else Position = No_Element,
kono
parents:
diff changeset
1087 Contract_Cases =>
kono
parents:
diff changeset
1088 (Position = No_Element
kono
parents:
diff changeset
1089 or else P.Get (Positions (Container), Position) = Length (Container)
kono
parents:
diff changeset
1090 =>
kono
parents:
diff changeset
1091 Position = No_Element,
kono
parents:
diff changeset
1092
kono
parents:
diff changeset
1093 others =>
kono
parents:
diff changeset
1094 Has_Element (Container, Position)
kono
parents:
diff changeset
1095 and then P.Get (Positions (Container), Position) =
kono
parents:
diff changeset
1096 P.Get (Positions (Container), Position'Old) + 1);
kono
parents:
diff changeset
1097
kono
parents:
diff changeset
1098 function Find
kono
parents:
diff changeset
1099 (Container : Set;
kono
parents:
diff changeset
1100 Item : Element_Type) return Cursor
kono
parents:
diff changeset
1101 with
kono
parents:
diff changeset
1102 Global => null,
kono
parents:
diff changeset
1103 Contract_Cases =>
kono
parents:
diff changeset
1104
kono
parents:
diff changeset
1105 -- If Item is not contained in Container, Find returns No_Element
kono
parents:
diff changeset
1106
kono
parents:
diff changeset
1107 (not Contains (Model (Container), Item) =>
kono
parents:
diff changeset
1108 Find'Result = No_Element,
kono
parents:
diff changeset
1109
kono
parents:
diff changeset
1110 -- Otherwise, Find returns a valid cursor in Container
kono
parents:
diff changeset
1111
kono
parents:
diff changeset
1112 others =>
kono
parents:
diff changeset
1113 P.Has_Key (Positions (Container), Find'Result)
kono
parents:
diff changeset
1114 and P.Get (Positions (Container), Find'Result) =
kono
parents:
diff changeset
1115 Find (Elements (Container), Item)
kono
parents:
diff changeset
1116
kono
parents:
diff changeset
1117 -- The element designated by the result of Find is Item
kono
parents:
diff changeset
1118
kono
parents:
diff changeset
1119 and Equivalent_Elements
kono
parents:
diff changeset
1120 (Element (Container, Find'Result), Item));
kono
parents:
diff changeset
1121
kono
parents:
diff changeset
1122 function Contains (Container : Set; Item : Element_Type) return Boolean with
kono
parents:
diff changeset
1123 Global => null,
kono
parents:
diff changeset
1124 Post => Contains'Result = Contains (Model (Container), Item);
kono
parents:
diff changeset
1125 pragma Annotate (GNATprove, Inline_For_Proof, Contains);
kono
parents:
diff changeset
1126
kono
parents:
diff changeset
1127 function Has_Element (Container : Set; Position : Cursor) return Boolean
kono
parents:
diff changeset
1128 with
kono
parents:
diff changeset
1129 Global => null,
kono
parents:
diff changeset
1130 Post =>
kono
parents:
diff changeset
1131 Has_Element'Result = P.Has_Key (Positions (Container), Position);
kono
parents:
diff changeset
1132 pragma Annotate (GNATprove, Inline_For_Proof, Has_Element);
kono
parents:
diff changeset
1133
kono
parents:
diff changeset
1134 function Default_Modulus (Capacity : Count_Type) return Hash_Type with
kono
parents:
diff changeset
1135 Global => null;
kono
parents:
diff changeset
1136
kono
parents:
diff changeset
1137 generic
kono
parents:
diff changeset
1138 type Key_Type (<>) is private;
kono
parents:
diff changeset
1139
kono
parents:
diff changeset
1140 with function Key (Element : Element_Type) return Key_Type;
kono
parents:
diff changeset
1141
kono
parents:
diff changeset
1142 with function Hash (Key : Key_Type) return Hash_Type;
kono
parents:
diff changeset
1143
kono
parents:
diff changeset
1144 with function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
kono
parents:
diff changeset
1145
kono
parents:
diff changeset
1146 package Generic_Keys with SPARK_Mode is
kono
parents:
diff changeset
1147
kono
parents:
diff changeset
1148 package Formal_Model with Ghost is
kono
parents:
diff changeset
1149
kono
parents:
diff changeset
1150 function M_Included_Except
kono
parents:
diff changeset
1151 (Left : M.Set;
kono
parents:
diff changeset
1152 Right : M.Set;
kono
parents:
diff changeset
1153 Key : Key_Type) return Boolean
kono
parents:
diff changeset
1154 with
kono
parents:
diff changeset
1155 Global => null,
kono
parents:
diff changeset
1156 Post =>
kono
parents:
diff changeset
1157 M_Included_Except'Result =
kono
parents:
diff changeset
1158 (for all E of Left =>
kono
parents:
diff changeset
1159 Contains (Right, E)
kono
parents:
diff changeset
1160 or Equivalent_Keys (Generic_Keys.Key (E), Key));
kono
parents:
diff changeset
1161
kono
parents:
diff changeset
1162 end Formal_Model;
kono
parents:
diff changeset
1163 use Formal_Model;
kono
parents:
diff changeset
1164
kono
parents:
diff changeset
1165 function Key (Container : Set; Position : Cursor) return Key_Type with
kono
parents:
diff changeset
1166 Global => null,
kono
parents:
diff changeset
1167 Post => Key'Result = Key (Element (Container, Position));
kono
parents:
diff changeset
1168 pragma Annotate (GNATprove, Inline_For_Proof, Key);
kono
parents:
diff changeset
1169
kono
parents:
diff changeset
1170 function Element (Container : Set; Key : Key_Type) return Element_Type
kono
parents:
diff changeset
1171 with
kono
parents:
diff changeset
1172 Global => null,
kono
parents:
diff changeset
1173 Pre => Contains (Container, Key),
kono
parents:
diff changeset
1174 Post =>
kono
parents:
diff changeset
1175 Element'Result = Element (Container, Find (Container, Key));
kono
parents:
diff changeset
1176 pragma Annotate (GNATprove, Inline_For_Proof, Element);
kono
parents:
diff changeset
1177
kono
parents:
diff changeset
1178 procedure Replace
kono
parents:
diff changeset
1179 (Container : in out Set;
kono
parents:
diff changeset
1180 Key : Key_Type;
kono
parents:
diff changeset
1181 New_Item : Element_Type)
kono
parents:
diff changeset
1182 with
kono
parents:
diff changeset
1183 Global => null,
kono
parents:
diff changeset
1184 Pre => Contains (Container, Key),
kono
parents:
diff changeset
1185 Post =>
kono
parents:
diff changeset
1186 Length (Container) = Length (Container)'Old
kono
parents:
diff changeset
1187
kono
parents:
diff changeset
1188 -- Key now maps to New_Item
kono
parents:
diff changeset
1189
kono
parents:
diff changeset
1190 and Element (Container, Key) = New_Item
kono
parents:
diff changeset
1191
kono
parents:
diff changeset
1192 -- New_Item is contained in Container
kono
parents:
diff changeset
1193
kono
parents:
diff changeset
1194 and Contains (Model (Container), New_Item)
kono
parents:
diff changeset
1195
kono
parents:
diff changeset
1196 -- Other elements are preserved
kono
parents:
diff changeset
1197
kono
parents:
diff changeset
1198 and M_Included_Except
kono
parents:
diff changeset
1199 (Model (Container)'Old,
kono
parents:
diff changeset
1200 Model (Container),
kono
parents:
diff changeset
1201 Key)
kono
parents:
diff changeset
1202 and M.Included_Except
kono
parents:
diff changeset
1203 (Model (Container),
kono
parents:
diff changeset
1204 Model (Container)'Old,
kono
parents:
diff changeset
1205 New_Item)
kono
parents:
diff changeset
1206
kono
parents:
diff changeset
1207 -- Mapping from cursors to elements is preserved
kono
parents:
diff changeset
1208
kono
parents:
diff changeset
1209 and Mapping_Preserved_Except
kono
parents:
diff changeset
1210 (E_Left => Elements (Container)'Old,
kono
parents:
diff changeset
1211 E_Right => Elements (Container),
kono
parents:
diff changeset
1212 P_Left => Positions (Container)'Old,
kono
parents:
diff changeset
1213 P_Right => Positions (Container),
kono
parents:
diff changeset
1214 Position => Find (Container, Key))
kono
parents:
diff changeset
1215 and Positions (Container) = Positions (Container)'Old;
kono
parents:
diff changeset
1216
kono
parents:
diff changeset
1217 procedure Exclude (Container : in out Set; Key : Key_Type) with
kono
parents:
diff changeset
1218 Global => null,
kono
parents:
diff changeset
1219 Post => not Contains (Container, Key),
kono
parents:
diff changeset
1220 Contract_Cases =>
kono
parents:
diff changeset
1221
kono
parents:
diff changeset
1222 -- If Key is not in Container, nothing is changed
kono
parents:
diff changeset
1223
kono
parents:
diff changeset
1224 (not Contains (Container, Key) =>
kono
parents:
diff changeset
1225 Model (Container) = Model (Container)'Old
kono
parents:
diff changeset
1226 and Elements (Container) = Elements (Container)'Old
kono
parents:
diff changeset
1227 and Positions (Container) = Positions (Container)'Old,
kono
parents:
diff changeset
1228
kono
parents:
diff changeset
1229 -- Otherwise, Key is removed from Container
kono
parents:
diff changeset
1230
kono
parents:
diff changeset
1231 others =>
kono
parents:
diff changeset
1232 Length (Container) = Length (Container)'Old - 1
kono
parents:
diff changeset
1233
kono
parents:
diff changeset
1234 -- Other elements are preserved
kono
parents:
diff changeset
1235
kono
parents:
diff changeset
1236 and Model (Container) <= Model (Container)'Old
kono
parents:
diff changeset
1237 and M_Included_Except
kono
parents:
diff changeset
1238 (Model (Container)'Old,
kono
parents:
diff changeset
1239 Model (Container),
kono
parents:
diff changeset
1240 Key)
kono
parents:
diff changeset
1241
kono
parents:
diff changeset
1242 -- Mapping from cursors to elements is preserved
kono
parents:
diff changeset
1243
kono
parents:
diff changeset
1244 and Mapping_Preserved
kono
parents:
diff changeset
1245 (E_Left => Elements (Container),
kono
parents:
diff changeset
1246 E_Right => Elements (Container)'Old,
kono
parents:
diff changeset
1247 P_Left => Positions (Container),
kono
parents:
diff changeset
1248 P_Right => Positions (Container)'Old)
kono
parents:
diff changeset
1249 and P.Keys_Included_Except
kono
parents:
diff changeset
1250 (Positions (Container)'Old,
kono
parents:
diff changeset
1251 Positions (Container),
kono
parents:
diff changeset
1252 Find (Container, Key)'Old));
kono
parents:
diff changeset
1253
kono
parents:
diff changeset
1254 procedure Delete (Container : in out Set; Key : Key_Type) with
kono
parents:
diff changeset
1255 Global => null,
kono
parents:
diff changeset
1256 Pre => Contains (Container, Key),
kono
parents:
diff changeset
1257 Post =>
kono
parents:
diff changeset
1258 Length (Container) = Length (Container)'Old - 1
kono
parents:
diff changeset
1259
kono
parents:
diff changeset
1260 -- Key is no longer in Container
kono
parents:
diff changeset
1261
kono
parents:
diff changeset
1262 and not Contains (Container, Key)
kono
parents:
diff changeset
1263
kono
parents:
diff changeset
1264 -- Other elements are preserved
kono
parents:
diff changeset
1265
kono
parents:
diff changeset
1266 and Model (Container) <= Model (Container)'Old
kono
parents:
diff changeset
1267 and M_Included_Except
kono
parents:
diff changeset
1268 (Model (Container)'Old,
kono
parents:
diff changeset
1269 Model (Container),
kono
parents:
diff changeset
1270 Key)
kono
parents:
diff changeset
1271
kono
parents:
diff changeset
1272 -- Mapping from cursors to elements is preserved
kono
parents:
diff changeset
1273
kono
parents:
diff changeset
1274 and Mapping_Preserved
kono
parents:
diff changeset
1275 (E_Left => Elements (Container),
kono
parents:
diff changeset
1276 E_Right => Elements (Container)'Old,
kono
parents:
diff changeset
1277 P_Left => Positions (Container),
kono
parents:
diff changeset
1278 P_Right => Positions (Container)'Old)
kono
parents:
diff changeset
1279 and P.Keys_Included_Except
kono
parents:
diff changeset
1280 (Positions (Container)'Old,
kono
parents:
diff changeset
1281 Positions (Container),
kono
parents:
diff changeset
1282 Find (Container, Key)'Old);
kono
parents:
diff changeset
1283
kono
parents:
diff changeset
1284 function Find (Container : Set; Key : Key_Type) return Cursor with
kono
parents:
diff changeset
1285 Global => null,
kono
parents:
diff changeset
1286 Contract_Cases =>
kono
parents:
diff changeset
1287
kono
parents:
diff changeset
1288 -- If Key is not contained in Container, Find returns No_Element
kono
parents:
diff changeset
1289
kono
parents:
diff changeset
1290 ((for all E of Model (Container) =>
kono
parents:
diff changeset
1291 not Equivalent_Keys (Key, Generic_Keys.Key (E))) =>
kono
parents:
diff changeset
1292 Find'Result = No_Element,
kono
parents:
diff changeset
1293
kono
parents:
diff changeset
1294 -- Otherwise, Find returns a valid cursor in Container
kono
parents:
diff changeset
1295
kono
parents:
diff changeset
1296 others =>
kono
parents:
diff changeset
1297 P.Has_Key (Positions (Container), Find'Result)
kono
parents:
diff changeset
1298
kono
parents:
diff changeset
1299 -- The key designated by the result of Find is Key
kono
parents:
diff changeset
1300
kono
parents:
diff changeset
1301 and Equivalent_Keys
kono
parents:
diff changeset
1302 (Generic_Keys.Key (Container, Find'Result), Key));
kono
parents:
diff changeset
1303
kono
parents:
diff changeset
1304 function Contains (Container : Set; Key : Key_Type) return Boolean with
kono
parents:
diff changeset
1305 Global => null,
kono
parents:
diff changeset
1306 Post =>
kono
parents:
diff changeset
1307 Contains'Result =
kono
parents:
diff changeset
1308 (for some E of Model (Container) =>
kono
parents:
diff changeset
1309 Equivalent_Keys (Key, Generic_Keys.Key (E)));
kono
parents:
diff changeset
1310
kono
parents:
diff changeset
1311 end Generic_Keys;
kono
parents:
diff changeset
1312
kono
parents:
diff changeset
1313 private
kono
parents:
diff changeset
1314 pragma SPARK_Mode (Off);
kono
parents:
diff changeset
1315
kono
parents:
diff changeset
1316 pragma Inline (Next);
kono
parents:
diff changeset
1317
kono
parents:
diff changeset
1318 type Node_Type is
kono
parents:
diff changeset
1319 record
kono
parents:
diff changeset
1320 Element : Element_Type;
kono
parents:
diff changeset
1321 Next : Count_Type;
kono
parents:
diff changeset
1322 Has_Element : Boolean := False;
kono
parents:
diff changeset
1323 end record;
kono
parents:
diff changeset
1324
kono
parents:
diff changeset
1325 package HT_Types is new
kono
parents:
diff changeset
1326 Ada.Containers.Hash_Tables.Generic_Bounded_Hash_Table_Types (Node_Type);
kono
parents:
diff changeset
1327
kono
parents:
diff changeset
1328 type Set (Capacity : Count_Type; Modulus : Hash_Type) is
kono
parents:
diff changeset
1329 new HT_Types.Hash_Table_Type (Capacity, Modulus) with null record;
kono
parents:
diff changeset
1330
kono
parents:
diff changeset
1331 use HT_Types;
kono
parents:
diff changeset
1332
kono
parents:
diff changeset
1333 Empty_Set : constant Set := (Capacity => 0, Modulus => 0, others => <>);
kono
parents:
diff changeset
1334
kono
parents:
diff changeset
1335 end Ada.Containers.Formal_Hashed_Sets;