Debian Codegraph @

source_2020/pre_con2.mss

raw
1 @Part(precontainers-2, Root="ada.mss")
2 @comment{ $Source: e:\\cvsroot/ARM/Source/pre_con2.mss,v $ }
3 @comment{ $Revision: 1.40 $ $Date: 2020/06/03 00:09:01 $ $Author: randy $ }
4
5 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Multiway_Trees]}
6
7 @begin{Intro}
8 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
9 @ChgAdded{Version=[3],Text=[The language-defined generic package
10 Containers.Multiway_Trees provides private types Tree and Cursor, and a set of
11 operations for each type. A multiway tree container is well-suited to represent
12 nested structures.]}
13
14 @begin{Discussion}
15 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
16 @ChgAdded{Version=[3],Text=[This tree just provides a basic structure, and
17 make no promises about balancing or other automatic organization. In this
18 sense, it is different than the indexed (Map, Set) forms. Rather, it
19 provides a building block on which to construct more complex and more
20 specialized tree containers.]}
21 @end{Discussion}
22
23 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
24 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0078-1],ARef=[AI12-0159-1]}
25 @ChgAdded{Version=[3],Text=[A multiway tree container object manages a tree of
26 @Chg{Version=[4],New=[],Old=[internal ]}@i<nodes>,
27 @Chg{Version=[4],New=[consisting of a @i<root node>@Defn2{Term=[root],Sec=[of a tree]}@Defn2{Term=[root node],Sec=[of a tree]}
28 and a set of@Defn2{Term=[internal node],Sec=[of a tree]}
29 @i<internal nodes>;],Old=[]} each @Chg{Version=[4],New=[internal node],Old=[of
30 which]} contains an element and pointers to the parent,
31 first child, last child, next (successor) sibling, and previous (predecessor)
32 sibling internal nodes.@Defn2{Term=[node],Sec=[of a tree]} A cursor designates a
33 particular node within a tree (and by extension the element contained in that
34 node, if any). A cursor keeps designating the same node (and element) as long as
35 the node is part of the container, even if the node is moved within
36 the container.]}
37
38 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0269-1]}
39 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0078-1]}
40 @ChgAdded{Version=[3],Text=[A @i<subtree> is a particular node (which @i<roots the subtree>) and all of its child
41 nodes (including all of the children of the child nodes, recursively).
42 @Defn2{Term=[subtree],Sec=[of a tree]}@Defn{roots the subtree}@Defn2{Term=[subtree],Sec=[node which roots]}
43 @Chg{Version=[4],New=[The root node],Old=[There is
44 a special node, the @i<root>, which]} is always present and has neither an
45 associated element value nor any parent node@Chg{Version=[4],New=[; it has
46 pointers to its first child and its last child, if any],Old=[]}. The root node
47 provides a place to add nodes to an otherwise empty tree and
48 represents the base of the
49 tree.@Chg{Version=[4],New=[],Old=[@Defn2{Term=[root],Sec=[of a tree]}@Defn2{Term=[root node],Sec=[of a tree]}]}]}
50
51 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0269-1]}
52 @ChgAdded{Version=[3],Text=[A node that has no children is called a
53 @i<leaf node>.@Defn2{Term=[leaf node],Sec=[of a tree]} The @i<ancestors> of
54 a node are the node itself, its parent node, the parent of the parent node,
55 and so on until a node with no parent is reached.@Defn2{Term=[ancestor],Sec=[of a tree node]}
56 Similarly, the @i<descendants> of a node are the node itself, its child nodes,
57 the children of each child node, and so on.@Defn2{Term=[descendant],Sec=[of a tree node]}]}
58
59 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0262-1],ARef=[AI05-0269-1]}
60 @ChgAdded{Version=[3],Text=[The nodes of a subtree can be visited in several
61 different orders. For a @i<depth-first order>, after visiting a node, the nodes
62 of its child list are each visited in depth-first order, with each child node
63 visited in natural order (first child to last child).@Defn{depth-first order}]}
64
65 @begin{Ramification}
66 @ChgRef{Version=[3],Kind=[AddedNormal]}
67 @ChgAdded{Version=[3],Text=[For the depth-first order, when each child node is
68 visited, the child list of the child node is visited before the next sibling
69 of the child node is visited.]}
70 @end{Ramification}
71 @end{Intro}
72
73 @begin{StaticSem}
74
75 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
76 @ChgAdded{Version=[3],KeepNext=[T],Type=[Leading],Text=[The generic library
77 package Containers.Multiway_Trees has the following declaration:]}
78 @begin{Example}
79 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0212-1]}
80 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
81 @ChgAdded{Version=[3],Text=[@key{with} Ada.Iterator_Interfaces;
82 @key{generic}
83 @key{type} Element_Type @key{is private};
84 @key{with function} "=" (Left, Right : Element_Type) @key{return} Boolean @key{is} <>;
85 @key{package} Ada.Containers.Multiway_Trees@Chg{Version=[5],New=[],Old=[ @key{is}]}@ChildUnit{Parent=[Ada.Containers],Child=[Multiway_Trees]}@Chg{Version=[5],New=[
86 @key[with] Preelaborate, Remote_Types,
87 Nonblocking, Global => @key[null] @key[is]],Old=[
88 @key{pragma} Preelaborate(Multiway_Trees);@Chg{Version=[3],New=[
89 @key{pragma} Remote_Types(Multiway_Trees);],Old=[]}]}]}
90
91 @begin{Discussion}
92 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
93 @ChgAdded{Version=[5],Text=[For discussion on the reasons and meaning of
94 the specifications of the Global and Nonblocking aspects in this generic
95 package, see the notes on the equivalent operations in the specification
96 of the Containers.Vectors package (see
97 @RefSecNum{The Generic Package Containers.Vectors}).]}
98 @end{Discussion}
99
100 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0212-1]}
101 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0111-1],ARef=[AI12-0112-1]}
102 @ChgAdded{Version=[3],Text=[ @key{type} @AdaTypeDefn{Tree} @key{is tagged private}
103 @key{with} Constant_Indexing => Constant_Reference,
104 Variable_Indexing => Reference,
105 Default_Iterator => Iterate,
106 Iterator_Element => Element_Type@Chg{Version=[5],New=[,
107 Iterator_View => Stable.Tree,
108 Stable_Properties => (Node_Count,
109 Tampering_With_Cursors_Prohibited,
110 Tampering_With_Elements_Prohibited),
111 Default_Initial_Condition =>
112 Node_Count (Tree) = 1 @key{and then}
113 (@key{not} Tampering_With_Cursors_Prohibited (Tree)) @key{and then}
114 (@key{not} Tampering_With_Elements_Prohibited (Tree))],Old=[]};
115 @key{pragma} Preelaborable_Initialization(Tree);]}
116
117 @ChgRef{Version=[3],Kind=[AddedNormal]}
118 @ChgAdded{Version=[3],Text=[ @key{type} @AdaTypeDefn{Cursor} @key{is private};
119 @key{pragma} Preelaborable_Initialization(Cursor);]}
120
121 @ChgRef{Version=[3],Kind=[AddedNormal]}
122 @ChgAdded{Version=[3],Text=[ @AdaObjDefn{Empty_Tree} : @key{constant} Tree;]}
123
124 @ChgRef{Version=[3],Kind=[AddedNormal]}
125 @ChgAdded{Version=[3],Text=[ @AdaObjDefn{No_Element} : @key{constant} Cursor;]}
126
127 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
128 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Equal_Element} (Left, Right : Element_Type)
129 @key{return} Boolean @key{renames} "=";]}
130
131 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
132 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
133 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Has_Element} (Position : Cursor) @key{return} Boolean@Chg{Version=[5],New=[
134 @key[with] Nonblocking, Global => (@key[in all], @key[use null])],Old=[]};]}
135
136 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
137 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Has_Element} (Container : Tree; Position : Cursor)
138 @key{return} Boolean
139 @key[with] Nonblocking, Global => (@key[null], @key[use null]);]}
140
141 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
142 @ChgAdded{Version=[3],Text=[ @key{package} @AdaPackDefn{Tree_Iterator_Interfaces} @key{is new}
143 Ada.Iterator_Interfaces (Cursor, Has_Element);]}
144
145 @ChgRef{Version=[3],Kind=[AddedNormal]}
146 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Equal_Subtree} (Left_Position : Cursor;
147 Right_Position: Cursor) @key{return} Boolean;]}
148
149 @ChgRef{Version=[3],Kind=[AddedNormal]}
150 @ChgAdded{Version=[3],Text=[ @key{function} "=" (Left, Right : Tree) @key{return} Boolean;]}
151
152 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
153 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Same_Object} (Left, Right : Tree) @key{return} Boolean
154 @key[with] Nonblocking, Global => (@key[null], @key[use null]);]}
155
156 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
157 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Tampering_With_Cursors_Prohibited}
158 (Container : Tree) @key{return} Boolean
159 @key[with] Nonblocking, Global => (@key[null], @key[use null]);]}
160
161 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
162 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Tampering_With_Elements_Prohibited}
163 (Container : Tree) @key{return} Boolean
164 @key[with] Nonblocking, Global => (@key[null], @key[use null]);]}
165
166 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0339-1]}
167 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Empty} @key{return} Tree
168 @key[is] (Empty_Tree)
169 @key[with] Post =>
170 @key[not] Tampering_With_Elements_Prohibited (Empty'Result) @key[and then]
171 @key[not] Tampering_With_Cursors_Prohibited (Empty'Result) @key[and then]
172 Node_Count (Empty'Result) = 1;]}
173
174 @ChgRef{Version=[3],Kind=[AddedNormal]}
175 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
176 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Is_Empty} (Container : Tree) @key{return} Boolean@Chg{Version=[5],New=[
177 @key[with] Nonblocking, Global => (@key[null], @key[use null]),
178 Post => Is_Empty'Result = (Node_Count (Container) = 1)],Old=[]};]}
179
180 @ChgRef{Version=[3],Kind=[AddedNormal]}
181 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
182 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Node_Count} (Container : Tree) @key{return} Count_Type@Chg{Version=[5],New=[
183 @key[with] Nonblocking, Global => (@key[null], @key[use null])],Old=[]};]}
184
185 @ChgRef{Version=[3],Kind=[AddedNormal]}
186 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
187 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Subtree_Node_Count} (Position : Cursor) @key{return} Count_Type@Chg{Version=[5],New=[
188 @key[with] Nonblocking, Global => (@key[in all], @key[use null])],Old=[]};]}
189
190 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
191 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Subtree_Node_Count} (Container : Tree; Position : Cursor)
192 @key{return} Count_Type
193 @key{with} Pre => Meaningful_For (Container, Position)
194 @key{or else raise} Program_Error,
195 Nonblocking, Global => (@key{null}, @key{use null});]}
196
197 @ChgRef{Version=[3],Kind=[AddedNormal]}
198 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
199 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Depth} (Position : Cursor) @key{return} Count_Type@Chg{Version=[5],New=[
200 @key{with} Nonblocking, Global => (@key{in all}, @key{use null})],Old=[]};]}
201
202 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
203 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Depth} (Container : Tree; Position : Cursor)
204 @key{return} Count_Type
205 @key{with} Pre => Meaningful_For (Container, Position)
206 @key{or else raise} Program_Error,
207 Nonblocking, Global => (@key{null}, @key{use null});]}
208
209 @ChgRef{Version=[3],Kind=[AddedNormal]}
210 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
211 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Is_Root} (Position : Cursor) @key{return} Boolean@Chg{Version=[5],New=[
212 @key{with} Nonblocking, Global => (@key{in all}, @key{use null})],Old=[]};]}
213
214 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
215 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Is_Root} (Container : Tree; Position : Cursor)
216 @key{return} Boolean
217 @key{with} Nonblocking, Global => (@key{null}, @key{use null});]}
218
219 @ChgRef{Version=[3],Kind=[AddedNormal]}
220 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
221 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Is_Leaf} (Position : Cursor) @key{return} Boolean@Chg{Version=[5],New=[
222 @key{with} Nonblocking, Global => (@key{in all}, @key{use null})],Old=[]};]}
223
224 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
225 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Is_Leaf} (Container : Tree; Position : Cursor)
226 @key{return} Boolean
227 @key{with} Pre => Meaningful_For (Container, Position)
228 @key{or else raise} Program_Error,
229 Nonblocking, Global => (@key{null}, @key{use null});]}
230
231 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
232 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Is_Ancestor_Of} (Container : Tree;
233 Parent : Cursor;
234 Position : Cursor) @key{return} Boolean
235 @key{with} Pre => (Meaningful_For (Container, Position)
236 @key{or else raise} Program_Error) @key{and then}
237 (Meaningful_For (Container, Parent)
238 @key{or else raise} Program_Error),
239 Nonblocking, Global => (@key{null}, @key{use null});]}
240
241 @ChgRef{Version=[3],Kind=[AddedNormal]}
242 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
243 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Root} (Container : Tree) @key{return} Cursor@Chg{Version=[5],New=[
244 @key[with] Nonblocking, Global => (@key[null], @key[use null]),
245 Post => Root'Result /= No_Element @key[and then]
246 @key[not] Has_Element (Container, Root'Result)],Old=[]};]}
247
248 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
249 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Meaningful_For}
250 (Container : Tree; Position : Cursor) @key{return} Boolean @key{is}
251 (Position = No_Element @key{or else}
252 Is_Root (Container, Position) @key{or else}
253 Has_Element (Container, Position))
254 @key[with] Nonblocking, Global => (@key[null], @key[use null]);]}
255
256 @begin{Reason}
257 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
258 @ChgAdded{Version=[5],Text=[When this function is true, the Position can be
259 meaningfully used with operations for Container. We define this because
260 many operations allow the root (which does not have an element, so
261 Has_Element returns False), so many preconditions get unwieldy.
262 We allow No_Element as it is allowed by many queries, and for existing
263 routines, it raises a different exception (Constraint_Error rather than
264 Program_Error) than a cursor for the wrong container does.]}
265 @end{Reason}
266 @ChgRef{Version=[3],Kind=[AddedNormal]}
267 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
268 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Clear} (Container : @key{in out} Tree)@Chg{Version=[5],New=[
269 @key[with] Pre => @key[not] Tampering_With_Cursors_Prohibited (Container)
270 @key[or else raise] Program_Error,
271 Post => Node_Count (Container) = 1],Old=[]};]}
272
273 @ChgRef{Version=[3],Kind=[AddedNormal]}
274 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
275 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Element} (Position : Cursor) @key{return} Element_Type@Chg{Version=[5],New=[
276 @key{with} Pre => (Position /= No_Element @key{or else}
277 @key{raise} Constraint_Error) @key{and then}
278 (Has_Element (Position) @key{or else raise} Program_Error),
279 Nonblocking => Element_Type'Nonblocking,
280 Global => (@key{in all}, @key{use} Element_Type)],Old=[]};]}
281
282 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
283 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Element} (Container : Tree;
284 Position : Cursor) @key{return} Element_Type
285 @key{with} Pre => (Position /= No_Element @key{or else}
286 @key{raise} Constraint_Error) @key{and then}
287 (Has_Element (Container, Position) @key{or else raise} Program_Error),
288 Nonblocking => Element_Type'Nonblocking,
289 Global => (@key{null}, @key{use} Element_Type);]}
290
291 @ChgRef{Version=[3],Kind=[AddedNormal]}
292 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
293 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Replace_Element} (Container : @key{in out} Tree;
294 Position : @key{in} Cursor;
295 New_item : @key{in} Element_Type)@Chg{Version=[5],New=[
296 @key{with} Pre => (@key{not} Tampering_With_Elements_Prohibited (Container)
297 @key{or else raise} Program_Error) @key{and then}
298 (Position /= No_Element
299 @key{or else raise} Constraint_Error) @key{and then}
300 (Has_Element (Container, Position) @key{or else raise} Program_Error)],Old=[]};]}
301
302 @ChgRef{Version=[3],Kind=[AddedNormal]}
303 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
304 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Query_Element}
305 (Position : @key{in} Cursor;
306 Process : @key{not null access procedure} (Element : @key{in} Element_Type))@Chg{Version=[5],New=[
307 @key{with} Pre => (Position /= No_Element @key{or else raise} Constraint_Error) @key{and then}
308 (Has_Element (Position) @key{or else raise} Program_Error),
309 Global => @key{in all}],Old=[]};]}
310
311 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
312 @ChgAdded{Version=[5],Text=[ @key{procedure} @AdaSubDefn{Query_Element}
313 (Container : @key{in} Tree;
314 Position : @key{in} Cursor;
315 Process : @key{not null access procedure} (Element : @key{in} Element_Type))
316 @key{with} Pre => (Position /= No_Element
317 @key{or else raise} Constraint_Error) @key{and then}
318 (Has_Element (Container, Position)
319 @key{or else raise} Program_Error);]}
320
321 @ChgRef{Version=[3],Kind=[AddedNormal]}
322 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
323 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Update_Element}
324 (Container : @key{in out} Tree;
325 Position : @key{in} Cursor;
326 Process : @key{not null access procedure}
327 (Element : @key{in out} Element_Type))@Chg{Version=[5],New=[
328 @key{with} Pre => (Position /= No_Element @key{or else raise} Constraint_Error) @key{and then}
329 (Has_Element (Container, Position) @key{or else raise} Program_Error)],Old=[]};]}
330
331 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
332 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
333 @ChgAdded{Version=[3],Text=[ @key[type] Constant_Reference_Type
334 (Element : @key[not null access constant] Element_Type) @key[is private]
335 @key[with] Implicit_Dereference => Element@Chg{Version=[5],New=[,
336 Nonblocking, Global => @key[in out synchronized],
337 Default_Initial_Condition => (@key[raise] Program_Error)],Old=[]};]}
338
339 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
340 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
341 @ChgAdded{Version=[3],Text=[ @key[type] @AdaTypeDefn{Reference_Type} (Element : @key[not null access] Element_Type) @key[is private]
342 @key[with] Implicit_Dereference => Element@Chg{Version=[5],New=[,
343 Nonblocking, Global => @key[in out synchronized],
344 Default_Initial_Condition => (@key[raise] Program_Error)],Old=[]};]}
345
346 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
347 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
348 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Constant_Reference} (Container : @key[aliased in] Tree;
349 Position : @key[in] Cursor)
350 @key[return] Constant_Reference_Type@Chg{Version=[5],New=[
351 @key[with] Pre => (Position /= No_Element @key[or else]
352 @key[raise] Constraint_Error) @key[and then]
353 (Has_Element (Container, Position) @key[or else raise] Program_Error),
354 Post => Tampering_With_Cursors_Prohibited (Container),
355 Nonblocking, Global => (@key[null], @key[use null])],Old=[]};]}
356
357 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
358 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
359 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Reference} (Container : @key[aliased in out] Tree;
360 Position : @key[in] Cursor)
361 @key[return] Reference_Type@Chg{Version=[5],New=[
362 @key[with] Pre => (Position /= No_Element @key[or else]
363 @key[raise] Constraint_Error) @key[and then]
364 (Has_Element (Container, Position) @key[or else raise] Program_Error),
365 Post => Tampering_With_Cursors_Prohibited (Container),
366 Nonblocking, Global => (@key[null], @key[use null])],Old=[]};]}
367
368 @ChgRef{Version=[3],Kind=[AddedNormal]}
369 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
370 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Assign} (Target : @key{in out} Tree; Source : @key{in} Tree)@Chg{Version=[5],New=[
371 @key[with] Pre => @key[not] Tampering_With_Cursors_Prohibited (Target)
372 @key[or else raise] Program_Error,
373 Post => Node_Count (Source) = Node_Count (Target)],Old=[]};]}
374
375 @ChgRef{Version=[3],Kind=[AddedNormal]}
376 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
377 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Copy} (Source : Tree) @key[return] Tree@Chg{Version=[5],New=[
378 @key[with] Post =>
379 Node_Count (Copy'Result) = Node_Count (Source) @key[and then]
380 @key[not] Tampering_With_Elements_Prohibited (Copy'Result) @key[and then]
381 @key[not] Tampering_With_Cursors_Prohibited (Copy'Result)],Old=[]};]}
382
383 @ChgRef{Version=[3],Kind=[AddedNormal]}
384 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
385 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Move} (Target : @key{in out} Tree;
386 Source : @key{in out} Tree)@Chg{Version=[5],New=[
387 @key{with} Pre => (@key{not} Tampering_With_Cursors_Prohibited (Target)
388 @key{or else raise} Program_Error) @key{and then}
389 (@key{not} Tampering_With_Cursors_Prohibited (Source)
390 @key{or else raise} Program_Error),
391 Post =>
392 (@key{if} Same_Object (Target, Source) @key{then} True
393 @key{else}
394 Node_Count (Target) = Node_Count (Source'Old) @key{and then}
395 Node_Count (Source) = 1)],Old=[]};]}
396
397 @ChgRef{Version=[3],Kind=[AddedNormal]}
398 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
399 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Delete_Leaf} (Container : @key{in out} Tree;
400 Position : @key{in out} Cursor)@Chg{Version=[5],New=[
401 @key{with} Pre => (@key{not} Tampering_With_Cursors_Prohibited (Container)
402 @key{or else raise} Program_Error) @key{and then}
403 (Position /= No_Element
404 @key{or else raise} Constraint_Error) @key{and then}
405 (Has_Element (Container, Position)
406 @key{or else raise} Program_Error) @key{and then}
407 (Is_Leaf (Container, Position)
408 @key{or else raise} Constraint_Error),
409 Post =>
410 Node_Count (Container)'Old = Node_Count (Container) + 1 @key{and then}
411 Position = No_Element],Old=[]};]}
412
413 @ChgRef{Version=[3],Kind=[AddedNormal]}
414 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
415 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Delete_Subtree} (Container : @key{in out} Tree;
416 Position : @key{in out} Cursor)@Chg{Version=[5],New=[
417 @key{with} Pre => (@key{not} Tampering_With_Cursors_Prohibited (Container)
418 @key{or else raise} Program_Error) @key{and then}
419 (Position /= No_Element
420 @key{or else raise} Constraint_Error) @key{and then}
421 (Has_Element (Container, Position)
422 @key{or else raise} Program_Error),
423 Post => Node_Count (Container)'Old = Node_Count (Container) +
424 Subtree_Node_Count (Container, Position)'Old @key{and then}
425 Position = No_Element],Old=[]};]}
426
427 @ChgRef{Version=[3],Kind=[AddedNormal]}
428 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
429 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Swap} (Container : @key{in out} Tree;
430 I, J : @key{in} Cursor)@Chg{Version=[5],New=[
431 @key{with} Pre => (@key{not} Tampering_With_Cursors_Prohibited (Container)
432 @key{or else raise} Program_Error) @key{and then}
433 (I /= No_Element @key{or else} Constraint_Error) @key{and then}
434 (J /= No_Element @key{or else} Constraint_Error) @key{and then}
435 (Has_Element (Container, I)
436 @key{or else raise} Program_Error) @key{and then}
437 (Has_Element (Container, J)
438 @key{or else raise} Program_Error)],Old=[]};]}
439
440 @ChgRef{Version=[3],Kind=[AddedNormal]}
441 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
442 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Find} (Container : Tree;
443 Item : Element_Type)
444 @key{return} Cursor@Chg{Version=[5],New=[
445 @key{with} Post => (@key{if} Find'Result = No_Element @key{then} True
446 @key{else} Has_Element (Container, Find'Result))],Old=[]};]}
447
448 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
449 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
450 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Find_In_Subtree} (Position : Cursor;
451 Item : Element_Type)
452 @key{return} Cursor@Chg{Version=[5],New=[
453 @key{with} Pre => Position /= No_Element @key[or else raise] Constraint_Error,
454 Post => (@key{if} Find_In_Subtree'Result = No_Element @key{then} True
455 @key{else} Has_Element (Find_In_Subtree'Result)),
456 Global => @key[in all]],Old=[]};]}
457
458 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
459 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Find_In_Subtree} (Container : Tree;
460 Position : Cursor;
461 Item : Element_Type)
462 @key{return} Cursor
463 @key{with} Pre => (Position /= No_Element
464 @key[or else raise] Constraint_Error) @key[and then]
465 (Meaningful_For (Container, Position)
466 @key[or else raise] Program_Error),
467 Post => (@key{if} Find_In_Subtree'Result = No_Element @key{then} True
468 @key{else} Has_Element (Container, Find_In_Subtree'Result));]}
469
470 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
471 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
472 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Ancestor_Find} (Position : Cursor;
473 Item : Element_Type)
474 @key{return} Cursor@Chg{Version=[5],New=[
475 @key{with} Pre => Position /= No_Element @key[or else raise] Constraint_Error,
476 Post => (@key{if} Ancestor_Find'Result = No_Element @key{then} True
477 @key{else} Has_Element (Ancestor_Find'Result)),
478 Global => @key[in all]],Old=[]};]}
479
480 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
481 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Ancestor_Find} (Container : Tree;
482 Position : Cursor;
483 Item : Element_Type)
484 @key{return} Cursor@Chg{Version=[5],New=[
485 @key{with} Pre => (Position /= No_Element
486 @key[or else raise] Constraint_Error) @key[and then]
487 (Meaningful_For (Container, Position)
488 @key[or else raise] Program_Error),
489 Post => (@key{if} Ancestor_Find'Result = No_Element @key{then} True
490 @key{else} Has_Element (Container, Ancestor_Find'Result))],Old=[]};]}
491
492 @ChgRef{Version=[3],Kind=[AddedNormal]}
493 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Contains} (Container : Tree;
494 Item : Element_Type) @key{return} Boolean;]}
495
496 @ChgRef{Version=[3],Kind=[AddedNormal]}
497 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
498 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Iterate}
499 (Container : @key{in} Tree;
500 Process : @key{not null access procedure} (Position : @key{in} Cursor))@Chg{Version=[5],New=[
501 @key{with} Allows_Exit],Old=[]};]}
502
503 @ChgRef{Version=[3],Kind=[AddedNormal]}
504 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
505 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Iterate_Subtree}
506 (Position : @key{in} Cursor;
507 Process : @key{not null access procedure} (Position : @key{in} Cursor))@Chg{Version=[5],New=[
508 @key{with} Allows_Exit,
509 Pre => Position /= No_Element @key{or else raise} Constraint_Error,
510 Global => (@key{in all}, @key{use null})],Old=[]};]}
511
512 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
513 @ChgAdded{Version=[5],Text=[ @key{procedure} @AdaSubDefn{Iterate_Subtree}
514 (Container : @key{in} Tree;
515 Position : @key{in} Cursor;
516 Process : @key{not null access procedure} (Position : @key{in} Cursor))
517 @key{with} Allows_Exit,
518 Pre => (Position /= No_Element
519 @key{or else raise} Constraint_Error) @key{and then}
520 (Meaningful_For (Container, Position)
521 @key{or else raise} Program_Error);]}
522
523 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
524 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1],ARef=[AI12-0266-1]}
525 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Iterate} (Container : @key{in} Tree)
526 @key{return} Tree_Iterator_Interfaces.@Chg{Version=[5],New=[Parallel_Iterator],Old=[Forward_Iterator]}'Class@Chg{Version=[5],New=[
527 @key{with} Post => Tampering_With_Cursors_Prohibited (Container)],Old=[]};]}
528
529 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
530 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1],ARef=[AI12-0266-1]}
531 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Iterate_Subtree} (Position : @key{in} Cursor)
532 @key{return} Tree_Iterator_Interfaces.@Chg{Version=[5],New=[Parallel_Iterator],Old=[Forward_Iterator]}'Class@Chg{Version=[5],New=[
533 @key{with} Pre => Position /= No_Element @key{or else raise} Constraint_Error,
534 Global => (@key{in all}, @key{use null})],Old=[]};]}
535
536 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
537 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Iterate_Subtree} (Container : @key{in} Tree; Position : @key{in} Cursor)
538 @key{return} Tree_Iterator_Interfaces.Parallel_Iterator'Class
539 @key{with} Pre => (Position /= No_Element
540 @key{or else raise} Constraint_Error) @key{and then}
541 (Meaningful_For (Container, Position)
542 @key{or else raise} Program_Error),
543 Post => Tampering_With_Cursors_Prohibited (Container);]}
544
545 @ChgRef{Version=[3],Kind=[AddedNormal]}
546 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
547 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Child_Count} (Parent : Cursor) @key{return} Count_Type@Chg{Version=[5],New=[
548 @key{with} Post => (@key{if} Parent = No_Element @key{then} Child_Count'Result = 0
549 @key{else} True),
550 Nonblocking, Global => (@key{in all}, @key{use null})],Old=[]};]}
551
552 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
553 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Child_Count} (Container : Tree; Parent : Cursor)
554 @key{return} Count_Type
555 @key{with} Pre => Meaningful_For (Container, Parent) @key{or else raise} Program_Error,
556 Post => (@key{if} Parent = No_Element @key{then} Child_Count'Result = 0
557 @key{else} True),
558 Nonblocking, Global => (@key{null}, @key{use null});]}
559
560 @ChgRef{Version=[3],Kind=[AddedNormal]}
561 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
562 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Child_Depth} (Parent, Child : Cursor) @key{return} Count_Type@Chg{Version=[5],New=[
563 @key{with} Pre => (Parent = No_Element @key{and then} Child = No_Element)
564 @key{or else raise} Constraint_Error,
565 Nonblocking, Global => (@key{in all}, @key{use null})],Old=[]};]}
566
567 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
568 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Child_Depth} (Container : Tree; Parent, Child : Cursor)
569 @key{return} Count_Type
570 @key{with} Pre => ((Parent = No_Element @key{and then} Child = No_Element)
571 @key{or else raise} Constraint_Error) @key{and then}
572 (Meaningful_For (Container, Parent)
573 @key{or else raise} Program_Error) @key{and then}
574 (Meaningful_For (Container, Child)
575 @key{or else raise} Program_Error),
576 Nonblocking, Global => (@key{null}, @key{use null});]}
577
578 @ChgRef{Version=[3],Kind=[AddedNormal]}
579 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
580 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Insert_Child} (Container : @key{in out} Tree;
581 Parent : @key{in} Cursor;
582 Before : @key{in} Cursor;
583 New_Item : @key{in} Element_Type;
584 Count : @key{in} Count_Type := 1)@Chg{Version=[5],New=[
585 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Container)
586 @key{or else raise} Program_Error) @key{and then}
587 (Parent /= No_Element
588 @key{or else raise} Constraint_Error) @key{and then}
589 (Meaningful_For (Container, Parent)
590 @key{or else raise} Program_Error) @key{and then}
591 (Meaningful_For (Container, Before)
592 @key{or else raise} Program_Error) @key{and then}
593 (Before = No_Element @key{or else}
594 Container.Parent (Before) = Parent
595 @key{or else raise} Constraint_Error),
596 Post => Node_Count (Container) =
597 Node_Count (Container)'Old + Count],Old=[]};]}
598
599 @ChgRef{Version=[3],Kind=[AddedNormal]}
600 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
601 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Insert_Child} (Container : @key{in out} Tree;
602 Parent : @key{in} Cursor;
603 Before : @key{in} Cursor;
604 New_Item : @key{in} Element_Type;
605 Position : @key{out} Cursor;
606 Count : @key{in} Count_Type := 1)@Chg{Version=[5],New=[
607 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Container)
608 @key{or else raise} Program_Error) @key{and then}
609 (Parent /= No_Element
610 @key{or else raise} Constraint_Error) @key{and then}
611 (Meaningful_For (Container, Parent)
612 @key{or else raise} Program_Error) @key{and then}
613 (Meaningful_For (Container, Before)
614 @key{or else raise} Program_Error) @key{and then}
615 (Before = No_Element @key{or else}
616 Container.Parent (Before) = Parent
617 @key{or else raise} Constraint_Error),
618 Post => (Node_Count (Container) =
619 Node_Count (Container)'Old + Count) @key{and then}
620 Has_Element (Container, Position)],Old=[]};]}
621
622 @ChgRef{Version=[3],Kind=[AddedNormal]}
623 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
624 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Insert_Child} (Container : @key{in out} Tree;
625 Parent : @key{in} Cursor;
626 Before : @key{in} Cursor;
627 Position : @key{out} Cursor;
628 Count : @key{in} Count_Type := 1)@Chg{Version=[5],New=[
629 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Container)
630 @key{or else raise} Program_Error) @key{and then}
631 (Parent /= No_Element
632 @key{or else raise} Constraint_Error) @key{and then}
633 (Meaningful_For (Container, Parent)
634 @key{or else raise} Program_Error) @key{and then}
635 (Meaningful_For (Container, Before)
636 @key{or else raise} Program_Error) @key{and then}
637 (Before = No_Element @key{or else}
638 Container.Parent (Before) = Parent
639 @key{or else raise} Constraint_Error),
640 Post => (Node_Count (Container) =
641 Node_Count (Container)'Old + Count) @key{and then}
642 Has_Element (Container, Position)],Old=[]};]}
643
644 @ChgRef{Version=[3],Kind=[AddedNormal]}
645 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
646 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Prepend_Child} (Container : @key{in out} Tree;
647 Parent : @key{in} Cursor;
648 New_Item : @key{in} Element_Type;
649 Count : @key{in} Count_Type := 1)@Chg{Version=[5],New=[
650 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Container)
651 @key{or else raise} Program_Error) @key{and then}
652 (Parent /= No_Element
653 @key{or else raise} Constraint_Error) @key{and then}
654 (Meaningful_For (Container, Parent)
655 @key{or else raise} Program_Error),
656 Post => Node_Count (Container) =
657 Node_Count (Container)'Old + Count],Old=[]};]}
658
659 @ChgRef{Version=[3],Kind=[AddedNormal]}
660 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
661 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Append_Child} (Container : @key{in out} Tree;
662 Parent : @key{in} Cursor;
663 New_Item : @key{in} Element_Type;
664 Count : @key{in} Count_Type := 1)@Chg{Version=[5],New=[
665 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Container)
666 @key{or else raise} Program_Error) @key{and then}
667 (Parent /= No_Element
668 @key{or else raise} Constraint_Error) @key{and then}
669 (Meaningful_For (Container, Parent)
670 @key{or else raise} Program_Error),
671 Post => Node_Count (Container) =
672 Node_Count (Container)'Old + Count],Old=[]};]}
673
674 @ChgRef{Version=[3],Kind=[AddedNormal]}
675 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
676 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Delete_Children} (Container : @key{in out} Tree;
677 Parent : @key{in} Cursor)@Chg{Version=[5],New=[
678 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Container)
679 @key{or else raise} Program_Error) @key{and then}
680 (Parent /= No_Element
681 @key{or else raise} Constraint_Error) @key{and then}
682 (Meaningful_For (Container, Parent)
683 @key{or else raise} Program_Error),
684 Post => (Node_Count (Container) = Node_Count (Container)'Old -
685 Child_Count (Container, Parent)'Old) @key{and then}
686 Child_Count (Container, Parent) = 0],Old=[]};]}
687
688 @ChgRef{Version=[3],Kind=[AddedNormal]}
689 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
690 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Copy_Subtree} (Target : @key{in out} Tree;
691 Parent : @key{in} Cursor;
692 Before : @key{in} Cursor;
693 Source : @key{in} Cursor)@Chg{Version=[5],New=[
694 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Target)
695 @key{or else raise} Program_Error) @key{and then}
696 (Parent /= No_Element
697 @key{or else raise} Constraint_Error) @key{and then}
698 (Meaningful_For (Target, Parent)
699 @key{or else raise} Program_Error) @key{and then}
700 (Meaningful_For (Target, Before)
701 @key{or else raise} Program_Error) @key{and then}
702 (Before = No_Element @key{or else}
703 Target.Parent (Before) = Parent
704 @key{or else raise} Constraint_Error) @key{and then}
705 (@key{not} Is_Root (Source)
706 @key{or else raise} Constraint_Error),
707 Post => Node_Count (Target) =
708 Node_Count (Target)'Old + Subtree_Node_Count (Source),
709 Global => @key{in all}],Old=[]};]}
710
711 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
712 @ChgAdded{Version=[5],Text=[ @key{procedure} @AdaSubDefn{Copy_Local_Subtree} (Target : @key{in out} Tree;
713 Parent : @key{in} Cursor;
714 Before : @key{in} Cursor;
715 Source : @key{in} Cursor)
716 @key{with} Pre => (@key{not} Tampering_With_Cursors_Prohibited (Target)
717 @key{or else raise} Program_Error) @key{and then}
718 (Parent /= No_Element
719 @key{or else raise} Constraint_Error) @key{and then}
720 (Meaningful_For (Target, Parent)
721 @key{or else raise} Program_Error) @key{and then}
722 (Meaningful_For (Target, Before)
723 @key{or else raise} Program_Error) @key{and then}
724 (Before = No_Element @key{or else}
725 Target.Parent (Before) = Parent
726 @key{or else raise} Constraint_Error) @key{and then}
727 (Meaningful_For (Target, Source)
728 @key{or else raise} Program_Error) @key{and then}
729 (@key{not} Is_Root (Source)
730 @key{or else raise} Constraint_Error),
731 Post => Node_Count (Target) = Node_Count (Target)'Old +
732 Subtree_Node_Count (Target, Source);]}
733
734 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
735 @ChgAdded{Version=[5],Text=[ @key{procedure} @AdaSubDefn{Copy_Subtree} (Target : @key{in out} Tree;
736 Parent : @key{in} Cursor;
737 Before : @key{in} Cursor;
738 Source : @key{in} Tree;
739 Subtree : @key{in} Cursor)
740 @key{with} Pre => (@key{not} Tampering_With_Cursors_Prohibited (Target)
741 @key{or else raise} Program_Error) @key{and then}
742 (Parent /= No_Element
743 @key{or else raise} Constraint_Error) @key{and then}
744 (Meaningful_For (Target, Parent)
745 @key{or else raise} Program_Error) @key{and then}
746 (Meaningful_For (Target, Before)
747 @key{or else raise} Program_Error) @key{and then}
748 (Before = No_Element @key{or else}
749 Target.Parent (Before) = Parent
750 @key{or else raise} Constraint_Error) @key{and then}
751 (Meaningful_For (Source, Subtree)
752 @key{or else raise} Program_Error) @key{and then}
753 (@key{not} Is_Root (Source, Subtree)
754 @key{or else raise} Constraint_Error),
755 Post => Node_Count (Target) = Node_Count (Target)'Old +
756 Subtree_Node_Count (Source, Subtree);]}
757
758 @ChgRef{Version=[3],Kind=[AddedNormal]}
759 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
760 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Splice_Subtree} (Target : @key{in out} Tree;
761 Parent : @key{in} Cursor;
762 Before : @key{in} Cursor;
763 Source : @key{in out} Tree;
764 Position : @key{in out} Cursor)@Chg{Version=[5],New=[
765 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Target)
766 @key{or else raise} Program_Error) @key{and then}
767 (@key{not} Tampering_With_Cursors_Prohibited (Source)
768 @key{or else raise} Program_Error) @key{and then}
769 (Parent /= No_Element
770 @key{or else raise} Constraint_Error) @key{and then}
771 (Meaningful_For (Target, Parent)
772 @key{or else raise} Program_Error) @key{and then}
773 (Meaningful_For (Target, Before)
774 @key{or else raise} Program_Error) @key{and then}
775 (Before = No_Element @key{or else}
776 Target.Parent (Before) /= Parent
777 @key{or else raise} Constraint_Error) @key{and then}
778 (Position /= No_Element
779 @key{or else raise} Constraint_Error) @key{and then}
780 (Has_Element (Source, Position)
781 @key{or else raise} Program_Error) @key{and then}
782 (Same_Object (Source, Target) @key{or else}
783 Position = Before @key{or else}
784 Is_Ancestor_Of (Target, Position, Parent)
785 @key{or else raise} Constraint_Error),
786 Post => (@key{declare}
787 Org_Sub_Count @key{renames }
788 Subtree_Node_Count (Source, Position)'Old;
789 Org_Target_Count @key{renames} Node_Count (Target)'Old;
790 @key{begin}
791 (@key{if not} Same_Object (Target, Source) @key{then}
792 Node_Count (Target) = Org_Target_Count +
793 Org_Sub_Count @key{and then}
794 Node_Count (Source) = Node_Count (Source)'Old -
795 Org_Sub_Count @key{and then}
796 Has_Element (Target, Position)
797 @key{else}
798 Target.Parent (Position) = Parent @key{and then}
799 Node_Count (Target) = Org_Target_Count))],Old=[]};]}
800
801 @ChgRef{Version=[3],Kind=[AddedNormal]}
802 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
803 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Splice_Subtree} (Container: @key{in out} Tree;
804 Parent : @key{in} Cursor;
805 Before : @key{in} Cursor;
806 Position : @key{in} Cursor)@Chg{Version=[5],New=[
807 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Container)
808 @key{or else raise} Program_Error) @key{and then}
809 (Parent /= No_Element
810 @key{or else raise} Constraint_Error) @key{and then}
811 (Meaningful_For (Container, Parent)
812 @key{or else raise} Program_Error) @key{and then}
813 (Meaningful_For (Container, Before)
814 @key{or else raise} Program_Error) @key{and then}
815 (Before = No_Element @key{or else}
816 Container.Parent (Before) /= Parent
817 @key{or else raise} Constraint_Error) @key{and then}
818 (Position /= No_Element
819 @key{or else raise} Constraint_Error) @key{and then}
820 (Has_Element (Container, Position)
821 @key{or else raise} Program_Error) @key{and then}
822 (Position = Before @key{or else}
823 Is_Ancestor_Of (Container, Position, Parent)
824 @key{or else raise} Constraint_Error),
825 Post => (Node_Count (Container) =
826 Node_Count (Container)'Old @key{and then}
827 Container.Parent (Position) = Parent)],Old=[]};]}
828
829 @ChgRef{Version=[3],Kind=[AddedNormal]}
830 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
831 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Splice_Children} (Target : @key{in out} Tree;
832 Target_Parent : @key{in} Cursor;
833 Before : @key{in} Cursor;
834 Source : @key{in out} Tree;
835 Source_Parent : @key{in} Cursor)@Chg{Version=[5],New=[
836 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Target)
837 @key{or else raise} Program_Error) @key{and then}
838 (@key{not} Tampering_With_Cursors_Prohibited (Source)
839 @key{or else raise} Program_Error) @key{and then}
840 (Target_Parent /= No_Element
841 @key{or else raise} Constraint_Error) @key{and then}
842 (Meaningful_For (Target, Target_Parent)
843 @key{or else raise} Program_Error) @key{and then}
844 (Meaningful_For (Target, Before)
845 @key{or else raise} Program_Error) @key{and then}
846 (Source_Parent /= No_Element
847 @key{or else raise} Constraint_Error) @key{and then}
848 (Meaningful_For (Source, Source_Parent)
849 @key{or else raise} Program_Error) @key{and then}
850 (Before = No_Element @key{or else}
851 Parent (Target, Before) /= Target_Parent
852 @key{or else raise} Constraint_Error) @key{and then}
853 (Same_Object (Target, Source) @key{or else}
854 Target_Parent = Source_Parent @key{or else}
855 Is_Ancestor_Of (Target, Source_Parent, Target_Parent)
856 @key{or else raise} Constraint_Error),
857 Post => (@key{declare}
858 Org_Child_Count @key{renames}
859 Child_Count (Source, Source_Parent)'Old;
860 Org_Target_Count @key{renames} Node_Count (Target)'Old;
861 @key{begin}
862 (@key{if not} Same_Object (Target, Source) @key{then}
863 Node_Count (Target) = Org_Target_Count +
864 Org_Child_Count @key{and then}
865 Node_Count (Source) = Node_Count (Source)'Old -
866 Org_Child_Count
867 @key{else}
868 Node_Count (Target) = Org_Target_Count))],Old=[]};]}
869
870 @ChgRef{Version=[3],Kind=[AddedNormal]}
871 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
872 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Splice_Children} (Container : @key{in out} Tree;
873 Target_Parent : @key{in} Cursor;
874 Before : @key{in} Cursor;
875 Source_Parent : @key{in} Cursor)@Chg{Version=[5],New=[
876 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Container)
877 @key{or else raise} Program_Error) @key{and then}
878 (Target_Parent /= No_Element
879 @key{or else raise} Constraint_Error) @key{and then}
880 (Meaningful_For (Container, Target_Parent)
881 @key{or else raise} Program_Error) @key{and then}
882 (Meaningful_For (Container, Before)
883 @key{or else raise} Program_Error) @key{and then}
884 (Source_Parent /= No_Element
885 @key{or else raise} Constraint_Error) @key{and then}
886 (Meaningful_For (Container, Source_Parent)
887 @key{or else raise} Program_Error) @key{and then}
888 (Before = No_Element @key{or else}
889 Parent (Container, Before) /= Target_Parent
890 @key{or else raise} Constraint_Error) @key{and then}
891 (Target_Parent = Source_Parent @key{or else}
892 Is_Ancestor_Of (Container, Source_Parent, Target_Parent)
893 @key{or else raise} Constraint_Error),
894 Post => Node_Count (Container) = Node_Count (Container)'Old],Old=[]};]}
895
896 @ChgRef{Version=[3],Kind=[AddedNormal]}
897 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
898 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Parent} (Position : Cursor) @key{return} Cursor@Chg{Version=[5],New=[
899 @key{with} Nonblocking, Global => (@key{in all}, @key{use null}),
900 Post => (@key{if} Position = No_Element @key{or else}
901 Is_Root (Position) @key{then} Parent'Result = No_Element
902 @key{else} True)],Old=[]};]}
903
904 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
905 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Parent} (Container : Tree;
906 Position : Cursor) @key{return} Cursor
907 @key{with} Nonblocking, Global => (@key{null}, @key{use null}),
908 Pre => Meaningful_For (Container, Position) @key{or else raise} Program_Error,
909 Post => (@key{if} Position = No_Element @key{or else}
910 Is_Root (Container, Position)
911 @key{then} Parent'Result = No_Element
912 @key{else} Has_Element (Container, Parent'Result));]}
913
914 @ChgRef{Version=[3],Kind=[AddedNormal]}
915 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
916 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{First_Child} (Parent : Cursor) @key{return} Cursor@Chg{Version=[5],New=[
917 @key{with} Nonblocking, Global => (@key{in all}, @key{use null}),
918 Pre => Parent /= No_Element @key{or else raise} Constraint_Error],Old=[]};]}
919
920 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
921 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{First_Child} (Container : Tree;
922 Parent : Cursor) @key{return} Cursor
923 @key{with} Nonblocking, Global => (@key{null}, @key{use null}),
924 Pre => (Parent /= No_Element
925 @key{or else raise} Constraint_Error) @key{and then}
926 (Meaningful_For (Container, Parent)
927 @key{or else raise} Program_Error),
928 Post => First_Child'Result = No_Element @key{or else}
929 Has_Element (Container, First_Child'Result);]}
930
931 @ChgRef{Version=[3],Kind=[AddedNormal]}
932 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
933 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{First_Child_Element} (Parent : Cursor) @key{return} Element_Type@Chg{Version=[5],New=[
934 @key{with} Nonblocking => Element_Type'Nonblocking,
935 Global => (@key{in all}, @key{use} Element_Type),
936 Pre => (Parent /= No_Element @key{and then}
937 Last_Child (Parent) /= No_Element)
938 @key{or else raise} Constraint_Error],Old=[]};]}
939
940 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
941 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{First_Child_Element} (Container : Tree;
942 Parent : Cursor) @key{return} Element_Type
943 @key{with} Nonblocking => Element_Type'Nonblocking,
944 Global => (@key{null}, @key{use} Element_Type),
945 Pre => (Parent /= No_Element
946 @key{or else raise} Constraint_Error) @key{and then}
947 (Meaningful_For (Container, Parent)
948 @key{or else raise} Program_Error) @key{and then}
949 (First_Child (Container, Parent) /= No_Element
950 @key{or else raise} Constraint_Error);]}
951
952 @ChgRef{Version=[3],Kind=[AddedNormal]}
953 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
954 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Last_Child} (Parent : Cursor) @key{return} Cursor@Chg{Version=[5],New=[
955 @key{with} Nonblocking, Global => (@key{in all}, @key{use null}),
956 Pre => Parent /= No_Element @key{or else raise} Constraint_Error],Old=[]};]}
957
958 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
959 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Last_Child} (Container : Tree;
960 Parent : Cursor) @key{return} Cursor
961 @key{with} Nonblocking, Global => (@key{null}, @key{use null}),
962 Pre => (Parent /= No_Element
963 @key{or else raise} Constraint_Error) @key{and then}
964 (Meaningful_For (Container, Parent)
965 @key{or else raise} Program_Error),
966 Post => Last_Child'Result = No_Element @key{or else}
967 Has_Element (Container, Last_Child'Result);]}
968
969 @ChgRef{Version=[3],Kind=[AddedNormal]}
970 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
971 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Last_Child_Element} (Parent : Cursor) @key{return} Element_Type@Chg{Version=[5],New=[
972 @key{with} Nonblocking => Element_Type'Nonblocking,
973 Global => (@key{in all}, @key{use} Element_Type),
974 Pre => (Parent /= No_Element @key{and then}
975 Last_Child (Parent) /= No_Element)
976 @key{or else raise} Constraint_Error],Old=[]};]}
977
978 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
979 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Last_Child_Element} (Container : Tree;
980 Parent : Cursor) @key{return} Element_Type
981 @key{with} Nonblocking => Element_Type'Nonblocking,
982 Global => (@key{null}, @key{use} Element_Type),
983 Pre => (Parent /= No_Element
984 @key{or else raise} Constraint_Error) @key{and then}
985 (Meaningful_For (Container, Parent)
986 @key{or else raise} Program_Error) @key{and then}
987 (Last_Child (Container, Parent) /= No_Element
988 @key{or else raise} Constraint_Error);]}
989
990 @ChgRef{Version=[3],Kind=[AddedNormal]}
991 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
992 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Next_Sibling} (Position : Cursor) @key{return} Cursor@Chg{Version=[5],New=[
993 @key{with} Nonblocking, Global => (@key{in all}, @key{use null}),
994 Post => (@key{if} Position = No_Element
995 @key{then} Next_Sibling'Result = No_Element
996 @key{else} True)],Old=[]};]}
997
998 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
999 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Next_Sibling} (Container : Tree;
1000 Position : Cursor) @key{return} Cursor
1001 @key{with} Nonblocking, Global => (@key{null}, @key{use null}),
1002 Pre => Meaningful_For (Container, Position)
1003 @key{or else raise} Program_Error,
1004 Post => (@key{if} Next_Sibling'Result = No_Element @key{then}
1005 Position = No_Element @key{or else}
1006 Is_Root (Container, Position) @key{or else}
1007 Last_Child (Container, Parent (Container, Position))
1008 = Position
1009 @key{else} Has_Element (Container, Next_Sibling'Result));]}
1010
1011 @ChgRef{Version=[3],Kind=[AddedNormal]}
1012 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1013 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Next_Sibling} (Position : @key{in out} Cursor)@Chg{Version=[5],New=[
1014 @key{with} Nonblocking, Global => (@key{in all}, @key{use null})],Old=[]};]}
1015
1016 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
1017 @ChgAdded{Version=[5],Text=[ @key{procedure} @AdaSubDefn{Next_Sibling} (Container : @key{in} Tree;
1018 Position : @key{in out} Cursor)
1019 @key{with} Nonblocking, Global => (@key{null}, @key{use null}),
1020 Pre => Meaningful_For (Container, Position)
1021 @key{or else raise} Program_Error,
1022 Post => (@key{if} Position /= No_Element
1023 @key{then} Has_Element (Container, Position));]}
1024
1025 @ChgRef{Version=[3],Kind=[AddedNormal]}
1026 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1027 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Previous_Sibling} (Position : Cursor) @key{return} Cursor@Chg{Version=[5],New=[
1028 @key{with} Nonblocking, Global => (@key{in all}, @key{use null}),
1029 Post => (@key{if} Position = No_Element
1030 @key{then} Previous_Sibling'Result = No_Element
1031 @key{else} True)],Old=[]};]}
1032
1033 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
1034 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Previous_Sibling} (Container : Tree;
1035 Position : Cursor) @key{return} Cursor
1036 @key{with} Nonblocking, Global => (@key{null}, @key{use null}),
1037 Pre => Meaningful_For (Container, Position)
1038 @key{or else raise} Program_Error,
1039 Post => (@key{if} Previous_Sibling'Result = No_Element @key{then}
1040 Position = No_Element @key{or else}
1041 Is_Root (Container, Position) @key{or else}
1042 First_Child (Container, Parent (Container, Position))
1043 = Position
1044 @key{else} Has_Element (Container, Previous_Sibling'Result));]}
1045
1046 @ChgRef{Version=[3],Kind=[AddedNormal]}
1047 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1048 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Previous_Sibling} (Position : @key{in out} Cursor)@Chg{Version=[5],New=[
1049 @key{with} Nonblocking, Global => (@key{in all}, @key{use null})],Old=[]};]}
1050
1051 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
1052 @ChgAdded{Version=[5],Text=[ @key{procedure} @AdaSubDefn{Previous_Sibling} (Container : @key{in} Tree;
1053 Position : @key{in out} Cursor)
1054 @key{with} Nonblocking, Global => (@key{null}, @key{use null}),
1055 Pre => Meaningful_For (Container, Position)
1056 @key{or else raise} Program_Error,
1057 Post => (@key{if} Position /= No_Element
1058 @key{then} Has_Element (Container, Position));]}
1059
1060 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
1061 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1062 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Iterate_Children}
1063 (Parent : @key{in} Cursor;
1064 Process : @key{not null access procedure} (Position : @key{in} Cursor))@Chg{Version=[5],New=[
1065 @key{with} Allows_Exit,
1066 Pre => Parent /= No_Element @key{or else raise} Constraint_Error,
1067 Global => (@key{in all}, @key{use null})],Old=[]};]}
1068
1069 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
1070 @ChgAdded{Version=[5],Text=[ @key{procedure} @AdaSubDefn{Iterate_Children}
1071 (Container : @key{in} Tree;
1072 Parent : @key{in} Cursor;
1073 Process : @key{not null access procedure} (Position : @key{in} Cursor))
1074 @key{with} Allows_Exit,
1075 Pre => (Parent /= No_Element
1076 @key{or else raise} Constraint_Error) @key{and then}
1077 (Meaningful_For (Container, Parent)
1078 @key{or else raise} Program_Error);]}
1079
1080 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
1081 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1082 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Reverse_Iterate_Children}
1083 (Parent : @key{in} Cursor;
1084 Process : @key{not null access procedure} (Position : @key{in} Cursor))@Chg{Version=[5],New=[
1085 @key{with} Allows_Exit,
1086 Pre => Parent /= No_Element @key{or else raise} Constraint_Error,
1087 Global => (@key{in all}, @key{use null})],Old=[]};]}
1088
1089 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
1090 @ChgAdded{Version=[5],Text=[ @key{procedure} @AdaSubDefn{Reverse_Iterate_Children}
1091 (Container : @key{in} Tree;
1092 Parent : @key{in} Cursor;
1093 Process : @key{not null access procedure} (Position : @key{in} Cursor))
1094 @key{with} Allows_Exit,
1095 Pre => (Parent /= No_Element
1096 @key{or else raise} Constraint_Error) @key{and then}
1097 (Meaningful_For (Container, Parent)
1098 @key{or else raise} Program_Error);]}
1099
1100 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
1101 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1],ARef=[AI12-0266-1]}
1102 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Iterate_Children} (Container : @key{in} Tree; Parent : @key{in} Cursor)
1103 @key{return} Tree_Iterator_Interfaces.@Chg{Version=[5],New=[Parallel_Reversible_Iterator],Old=[Reversible_Iterator]}'Class@Chg{Version=[5],New=[
1104 @key{with} Pre => (Parent /= No_Element
1105 @key{or else raise} Constraint_Error) @key{and then}
1106 (Meaningful_For (Container, Parent)
1107 @key{or else raise} Program_Error),
1108 Post => Tampering_With_Cursors_Prohibited (Container)],Old=[]};]}
1109
1110 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0111-1]}
1111 @ChgAdded{Version=[5],Text=[ @key{package} @AdaPackDefn{Stable} @key{is}]}
1112
1113 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0111-1]}
1114 @ChgAdded{Version=[5],Text=[ @key{type} @AdaTypeDefn{Tree} (Base : @key{not null access} Multiway_Trees.Tree) @key{is}
1115 @key{tagged limited private}
1116 @key{with} Constant_Indexing => Constant_Reference,
1117 Variable_Indexing => Reference,
1118 Default_Iterator => Iterate,
1119 Iterator_Element => Element_Type,
1120 Stable_Properties => (Node_Count),
1121 Global => @key[null],
1122 Default_Initial_Condition => Node_Count (Tree) = 1;
1123 @key{pragma} Preelaborable_Initialization(Tree);]}
1124
1125 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0111-1]}
1126 @ChgAdded{Version=[5],Text=[ @key{type} @AdaTypeDefn{Cursor} @key{is private};
1127 @key{pragma} Preelaborable_Initialization(Cursor);]}
1128
1129 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0111-1]}
1130 @ChgAdded{Version=[5],Text=[ @AdaObjDefn{Empty_Tree} : @key{constant} Tree;]}
1131
1132 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0111-1]}
1133 @ChgAdded{Version=[5],Text=[ @AdaObjDefn{No_Element} : @key{constant} Cursor;]}
1134
1135 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0111-1]}
1136 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Has_Element} (Position : Cursor) @key{return} Boolean
1137 @key{with} Nonblocking, Global => (@key{in all}, @key{use null});]}
1138
1139 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0111-1]}
1140 @ChgAdded{Version=[5],Text=[ @key{package} @AdaPackDefn{Tree_Iterator_Interfaces} @key[is new]
1141 Ada.Iterator_Interfaces (Cursor, Has_Element);]}
1142
1143 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0111-1]}
1144 @ChgAdded{Version=[5],Text=[ @key{procedure} @AdaSubDefn{Assign} (Target : @key{in out} Multiway_Trees.Tree;
1145 Source : @key{in} Tree)
1146 @key{with} Post => Node_Count (Source) = Node_Count (Target);]}
1147
1148 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0111-1]}
1149 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Copy} (Source : Multiway_Trees.Tree) @key{return} Tree
1150 @key{with} Post => Node_Count (Copy'Result) = Node_Count (Source);]}
1151
1152 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0111-1]}
1153 @ChgAdded{Version=[5],Text=[ @key{type} @AdaTypeDefn{Constant_Reference_Type}
1154 (Element : @key{not null access constant} Element_Type) @key{is private}
1155 @key{with} Implicit_Dereference => Element,
1156 Nonblocking, Global => @key{null},
1157 Default_Initial_Condition => (@key{raise} Program_Error);]}
1158
1159 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0111-1]}
1160 @ChgAdded{Version=[5],Text=[ @key{type} @AdaTypeDefn{Reference_Type}
1161 (Element : @key{not null access} Element_Type) @key{is private}
1162 @key{with} Implicit_Dereference => Element,
1163 Nonblocking, Global => @key{null},
1164 Default_Initial_Condition => (@key{raise} Program_Error);]}
1165
1166 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0111-1]}
1167 @ChgAdded{Version=[5],Text=[ -- @examcom{Additional subprograms as described in the text}
1168 -- @examcom{are declared here.}]}
1169
1170 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0111-1]}
1171 @ChgAdded{Version=[5],Text=[ @key{private}]}
1172
1173 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0111-1]}
1174 @ChgAdded{Version=[5],Text=[ ... -- @Examcom{not specified by the language}]}
1175
1176 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0111-1]}
1177 @ChgAdded{Version=[5],Text=[ @key{end} Stable;]}
1178
1179 @ChgRef{Version=[3],Kind=[AddedNormal]}
1180 @ChgAdded{Version=[3],Text=[@key{private}
1181 ... -- @Examcom[not specified by the language]
1182 @key[end] Ada.Containers.Multiway_Trees;]}
1183
1184 @end{Example}
1185
1186 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1187 @ChgAdded{Version=[3],Text=[The actual function for the generic formal function "=" on Element_Type values
1188 is expected to define a reflexive and symmetric relationship and return the same
1189 result value each time it is called with a particular pair of values. If it
1190 behaves in some other manner, the functions Find, Reverse_Find, Equal_Subtree,
1191 and "=" on tree values return an unspecified value. The exact arguments and
1192 number of calls of this generic formal function by the functions Find,
1193 Reverse_Find, Equal_Subtree, and "=" on tree values are unspecified.@PDefn{unspecified}]}
1194
1195 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1196 @ChgAdded{Version=[3],Text=[The type Tree is used to represent trees. The
1197 type Tree needs finalization@PDefn2{Term=<needs finalization>,Sec=<language-defined type>}
1198 (see @RefSecNum{Assignment and Finalization}).]}
1199
1200 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
1201 @ChgAdded{Version=[3],Text=[Empty_Tree represents the empty Tree object. It
1202 contains only the root node (Node_Count (Empty_Tree) returns 1). If an object of type
1203 Tree is not otherwise initialized, it is initialized to the same value as
1204 Empty_Tree.]}
1205
1206 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1207 @ChgAdded{Version=[3],Text=[No_Element represents a cursor that designates no
1208 element. If an object of type Cursor is not otherwise initialized, it is
1209 initialized to the same value as No_Element.]}
1210
1211 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1212 @ChgAdded{Version=[3],Text=[The predefined "=" operator for type Cursor returns
1213 True if both cursors are No_Element, or designate the same element in the same
1214 container.]}
1215
1216 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1217 @ChgAdded{Version=[3],Text=[Execution of the default implementation of the
1218 Input, Output, Read, or Write attribute of type Cursor raises Program_Error.]}
1219
1220 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1]}
1221 @ChgAdded{Version=[3],Text=[Tree'Write for a Tree object @i<T> writes
1222 Node_Count(@i<T>) - 1 elements of the tree to the stream. It also may write
1223 additional information about the tree.]}
1224
1225 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1]}
1226 @ChgAdded{Version=[3],Text=[Tree'Read reads the representation of a tree
1227 from the stream, and assigns to @i<Item> a tree with the same elements and
1228 structure as was written by Tree'Write.]}
1229
1230 @begin{Ramification}
1231 @ChgRef{Version=[3],Kind=[AddedNormal]}
1232 @ChgAdded{Version=[3],Text=[Streaming more elements than the container
1233 holds is wrong. For implementation implications of this rule, see the Implementation Note in
1234 @RefSecNum{The Generic Package Containers.Vectors}.]}
1235 @end{Ramification}
1236
1237 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1238 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0111-1],ARef=[AI12-0112-1]}
1239 @ChgAdded{Version=[3],Text=[@Redundant[Some
1240 operations @Chg{Version=[5],New=[@Defn2{Term=[tamper with cursors],Sec=[of a tree]}@Defn2{Term=[tamper with elements],Sec=[of a tree]}],Old=[of
1241 this generic package have access-to-subprogram parameters. To
1242 ensure such operations are well-defined, they guard against certain actions by
1243 the designated subprogram. In particular, some operations]} check for
1244 @lquotes@;tampering with cursors@rquotes of a container because they depend on
1245 the set of elements of the container remaining constant, and others check for
1246 @lquotes@;tampering with elements@rquotes of a container because they depend on
1247 elements of the container not being replaced.]@Chg{Version=[5],New=[ When
1248 tampering with cursors is @i<prohibited>@Defn2{Term=[prohibited],Sec=[tampering with a tree]}
1249 @Defn2{Term=[tampering],Sec=[prohibited for a tree]}for a particular
1250 tree object @i<T>, Program_Error is propagated by the finalization
1251 of @i<T>@Redundant[, as well as by a call that passes @i<T> to
1252 certain of the operations of this package, as indicated by the precondition
1253 of such an operation]. Similarly, when tampering with elements is @i<prohibited>
1254 for @i<T>, Program_Error is propagated by a call that passes @i<T> to
1255 certain of other operations of this package, as indicated by the precondition
1256 of such an operation.],Old=[]}]}
1257
1258 @begin{NotIso}
1259 @ChgAdded{Version=[5],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 81 through 90
1260 are removed as preconditions now describe these rules.>}]}@Comment{This message
1261 should be deleted if the paragraphs are ever renumbered.}
1262 @end{NotIso}
1263
1264
1265
1266 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1267 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg],ARef=[AI12-0111-1],ARef=[AI12-0112-1]}
1268 @ChgDeleted{Version=[5],Type=[Leading],Text=[@Chg{Version=[3],New=[@Defn2{Term=[tamper with cursors],Sec=[of a tree]}
1269 A subprogram is said to
1270 @i{tamper with cursors} of a tree object @i<L> if:],Old=[]}]}
1271
1272 @begin{Itemize}
1273 @ChgRef{Version=[3],Kind=[AddedNormal]}
1274 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
1275 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[it
1276 inserts or deletes elements of @i<T>, that is,
1277 it calls the Clear, Delete_Leaf, Insert_Child, Delete_Children,
1278 Delete_Subtree, or Copy_Subtree procedures
1279 with @i<T> as a parameter; or]}]}
1280
1281 @begin{Honest}
1282 @ChgRef{Version=[3],Kind=[AddedNormal]}
1283 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
1284 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[Operations which
1285 are defined to be equivalent to
1286 a call on one of these operations also are included. Similarly, operations
1287 which call one of these as part of their definition are included.]}]}
1288 @end{Honest}
1289
1290 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
1291 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
1292 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[it
1293 reorders the elements of @i<T>, that is, it
1294 calls the Splice_Subtree or Splice_Children procedures with @i<T> as a
1295 parameter; or]}]}
1296
1297 @ChgRef{Version=[3],Kind=[AddedNormal]}
1298 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
1299 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[it
1300 finalizes @i<T>; or]}]}
1301
1302 @ChgRef{Version=[3],Kind=[AddedNormal]}
1303 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
1304 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[it
1305 calls Assign with @i<T> as the Target parameter; or]}]}
1306
1307 @begin{Ramification}
1308 @ChgRef{Version=[3],Kind=[Added]}
1309 @ChgAdded{Version=[3],Text=[We don't need to explicitly mention
1310 @nt{assignment_statement}, because that finalizes the target object
1311 as part of the operation, and finalization of an object is already defined
1312 as tampering with cursors.]}
1313 @end{Ramification}
1314
1315 @ChgRef{Version=[3],Kind=[AddedNormal]}
1316 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
1317 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[it
1318 calls the Move procedure with @i<T> as a parameter.]}]}
1319
1320 @begin{Reason}
1321 @ChgRef{Version=[3],Kind=[AddedNormal]}
1322 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
1323 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[Swap
1324 copies elements rather than reordering
1325 them, so it doesn't tamper with cursors.]}]}
1326 @end{Reason}
1327 @end{Itemize}
1328
1329 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1330 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg],ARef=[AI12-0111-1],ARef=[AI12-0112-1]}
1331 @ChgDeleted{Version=[5],Type=[Leading],Text=[@Chg{Version=[3],New=[@Defn2{Term=[tamper with elements],Sec=[of a tree]}
1332 A subprogram is said to @i{tamper with elements} of a tree
1333 object @i<T> if:],Old=[]}]}
1334
1335 @begin{Itemize}
1336 @ChgRef{Version=[3],Kind=[AddedNormal]}
1337 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
1338 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[it
1339 tampers with cursors of @i<T>; or]}]}
1340
1341 @ChgRef{Version=[3],Kind=[AddedNormal]}
1342 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
1343 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[it
1344 replaces one or more elements of @i<T>, that is, it calls the Replace_Element or Swap
1345 procedures with @i<T> as a parameter.]}]}
1346
1347 @begin{Reason}
1348 @ChgRef{Version=[3],Kind=[AddedNormal]}
1349 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
1350 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[Complete
1351 replacement of an element can cause its
1352 memory to be deallocated while another operation is holding onto a reference
1353 to it. That can't be allowed. However, a simple modification of (part of) an
1354 element is not a problem, so Update_Element does not cause a problem.]}]}
1355 @end{Reason}
1356 @begin{Ramification}
1357 @ChgRef{Version=[3],Kind=[Added]}
1358 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[Assign
1359 is defined in terms of Clear and Replace_Element,
1360 so we don't need to mention it explicitly. Similarly, we don't need to
1361 explicitly mention @nt{assignment_statement}, because that finalizes the
1362 target object as part of the operation, and finalization of an object is
1363 already defined as tampering with the element.]}]}
1364 @end{Ramification}
1365 @end{Itemize}
1366
1367 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
1368 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0110-1]}
1369 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg],ARef=[AI12-0111-1],ARef=[AI12-0112-1]}
1370 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[@Defn2{Term=[prohibited],Sec=[tampering with a tree]}
1371 @Defn2{Term=[tampering],Sec=[prohibited for a tree]}
1372 When tampering with cursors is @i<prohibited> for a particular tree object
1373 @i<T>, Program_Error is propagated by a call of any language-defined subprogram
1374 that is defined to tamper with the cursors of @i<T>, leaving @i<T> unmodified.
1375 Similarly, when tampering with elements is @i<prohibited> for a particular tree
1376 object @i<T>, Program_Error is propagated by a call of any language-defined
1377 subprogram that is defined to tamper with the elements of @i<T> @Redundant[(or
1378 tamper with the cursors of @i<T>)], leaving @i<T>
1379 unmodified.@Chg{Version=[4],New=[ These checks are made before any other
1380 defined behavior of the body of the language-defined subprogram.],Old=[]}]}]}
1381 @begin{TheProof}
1382 @ChgRef{Version=[3],Kind=[AddedNormal]}
1383 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
1384 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[Tampering
1385 with elements includes tampering with
1386 cursors, so we mention it only from completeness in the second sentence.]}]}
1387 @end{TheProof}
1388
1389 @begin{DescribeCode}
1390
1391 @begin{Example}
1392 @ChgRef{Version=[3],Kind=[AddedNormal]}
1393 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1394
1395 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Has_Element (Position : Cursor) @key{return} Boolean@Chg{Version=[5],New=[
1396 @key[with] Nonblocking, Global => (@key{in all}, @key{use null})],Old=[]};]}
1397 @end{Example}
1398
1399 @ChgRef{Version=[3],Kind=[AddedNormal]}
1400 @ChgAdded{Version=[3],Type=[Trailing],Text=[Returns True if Position designates
1401 an element, and returns False otherwise. @Redundant[In particular, Has_Element
1402 returns False if the cursor designates a root node or equals No_Element.]]}
1403
1404 @begin{Honest}
1405 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1],ARef=[AI05-0136-1]}
1406 @ChgAdded{Version=[3],Text=[This function might not detect cursors that
1407 designate deleted elements; such cursors are invalid (see below) and the
1408 result of calling Has_Element with an invalid cursor is unspecified (but
1409 not erroneous).]}
1410 @end{Honest}
1411
1412 @begin{Example}
1413 @ChgRef{Version=[5],Kind=[Added]}
1414 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} @AdaSubDefn{Has_Element} (Container : Tree; Position : Cursor)
1415 @key{return} Boolean
1416 @key[with] Nonblocking, Global => (@key[null], @key[use null]);]}
1417 @end{Example}
1418
1419 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
1420 @ChgAdded{Version=[5],Type=[Trailing],Text=[Returns True if Position designates
1421 an element in Container, and returns False otherwise. @Redundant[In particular, Has_Element
1422 returns False if the cursor designates a root node or equals No_Element.]]}
1423
1424
1425 @begin{Example}
1426 @ChgRef{Version=[3],Kind=[AddedNormal]}
1427 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Equal_Subtree (Left_Position : Cursor;
1428 Right_Position: Cursor) @key{return} Boolean;]}
1429 @end{Example}
1430
1431 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1],ARef=[AI05-0264-1]}
1432 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Left_Position or Right_Position
1433 equals No_Element, propagates Constraint_Error. If the number of child nodes
1434 of the element designated by Left_Position is different from the number of
1435 child nodes of the element designated by Right_Position, the function
1436 returns False. If Left_Position designates a root node and Right_Position does
1437 not, the function returns False. If Right_Position designates a root
1438 node and Left_Position does not, the function returns False. Unless both
1439 cursors designate a root node, the elements are compared using the generic
1440 formal equality operator. If the result of the element comparison is False,
1441 the function returns
1442 False. Otherwise, it calls Equal_Subtree on a cursor designating each child
1443 element of the element designated by Left_Position and a cursor designating
1444 the corresponding child element of the element designated by Right_Position.
1445 If any such call returns False, the function returns False; otherwise, it
1446 returns True. Any exception raised during the evaluation of element equality
1447 is propagated.]}
1448
1449 @begin{Ramification}
1450 @ChgRef{Version=[3],Kind=[AddedNormal]}
1451 @ChgAdded{Version=[3],Text=[Left_Position and Right_Position do not need to
1452 be from the same tree.]}
1453 @end{Ramification}
1454
1455 @begin{ImplNote}
1456 @ChgRef{Version=[3],Kind=[AddedNormal]}
1457 @ChgAdded{Version=[3],Text=[This wording describes the canonical semantics.
1458 However, the order and number of calls on the formal equality function
1459 is unspecified for all of the operations that use it in this package, so an
1460 implementation can call it as many or as few times as it needs to get the
1461 correct answer. Similarly, a global rule (see the introduction of
1462 @RefSecNum{Predefined Language Environment})
1463 says that language-defined routines are not affected by overriding of other
1464 language-defined routines. This means that no reasonable program can tell
1465 how many times Equal_Subtree is called, and thus an implementation can call
1466 it as many or as few times as it needs to get the correct answer.
1467 Specifically, there is no requirement to call the formal equality or
1468 Equal_Subtree additional times once the answer has been determined.]}
1469 @end{ImplNote}
1470
1471 @begin{Example}
1472 @ChgRef{Version=[3],Kind=[AddedNormal]}
1473 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} "=" (Left, Right : Tree) @key{return} Boolean;]}
1474 @end{Example}
1475
1476 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0262-1]}
1477 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Left and Right denote the same
1478 tree object, then the function returns True. Otherwise, it calls Equal_Subtree
1479 with cursors designating the root nodes of Left and Right; the result is
1480 returned. Any exception raised during the evaluation of Equal_Subtree is
1481 propagated.]}
1482
1483 @begin{ImplNote}
1484 @ChgRef{Version=[3],Kind=[AddedNormal]}
1485 @ChgAdded{Version=[3],Text=[Similar considerations apply here as apply to
1486 Equal_Subtree. The actual number of calls performed is unspecified.]}
1487 @end{ImplNote}
1488
1489
1490 @begin{Example}
1491 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
1492 @ChgAdded{Version=[5],Text=[@key{function} Same_Object (Left, Right : Tree) @key{return} Boolean
1493 @key[with] Nonblocking, Global => (@key[null], @key[use null]);]}
1494 @end{Example}
1495
1496 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
1497 @ChgAdded{Version=[5],Type=[Trailing],Text=[Returns True if Left and Right
1498 denote the same tree object, and returns False otherwise.]}
1499
1500 @begin{ImplNote}
1501 @ChgRef{Version=[5],Kind=[AddedNormal]}
1502 @ChgAdded{Version=[5],Text=[This can be implemented by comparing object
1503 addresses or identifiers (if available). The elements stored in the
1504 containers should not be compared.]}
1505 @end{ImplNote}
1506
1507 @begin{Example}
1508 @ChgRef{Version=[5],Kind=[Added]}
1509 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Tampering_With_Cursors_Prohibited
1510 (Container : Tree) @key{return} Boolean
1511 @key[with] Nonblocking, Global => (@key[null], @key[use null]);]}
1512 @end{Example}
1513
1514 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
1515 @ChgAdded{Version=[5],Type=[Trailing],Text=[Returns True if tampering with
1516 cursors or tampering with elements is currently prohibited for Container, and
1517 returns False otherwise.]}
1518
1519 @begin{Reason}
1520 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
1521 @ChgAdded{Version=[5],Text=[Prohibiting tampering with elements also
1522 needs to prohibit tampering with cursors, as deleting an element is similar
1523 to replacing it.]}
1524 @end{Reason}
1525
1526 @begin{ImplNote}
1527 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
1528 @ChgAdded{Version=[5],Text=[Various contracts elsewhere in this specification
1529 require that this function is implemented with synchronized data. Moreover,
1530 it is possible for tampering to be prohibited by multiple operations
1531 (sequentiually or in parallel). Therefore, tampering needs to be
1532 implemented with an atomic or protected counter. The counter is initialized
1533 to zero, and is incremented when tampering is prohibited, and decremented
1534 when leaving an area that prohibited tampering. Function
1535 Tampering_With_Cursors_Prohibited returns True if the counter is nonzero.
1536 (Note that any case where the result is not well-defined for one task
1537 is incorrect use of shared variables and would be erroneous by the rules
1538 of @RefSecNum{Shared Variables}, so no special protection is needed to
1539 read the counter.)]}
1540 @end{ImplNote}
1541
1542 @begin{Example}
1543 @ChgRef{Version=[5],Kind=[Added]}
1544 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Tampering_With_Elements_Prohibited
1545 (Container : Tree) @key{return} Boolean
1546 @key[with] Nonblocking, Global => (@key[null], @key[use null]);]}
1547 @end{Example}
1548
1549 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
1550 @ChgAdded{Version=[5],Type=[Trailing],Text=[Always returns False@Redundant[,
1551 regardless of whether tampering with elements is prohibited].]}
1552
1553 @begin{Reason}
1554 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
1555 @ChgAdded{Version=[5],Text=[A definite element cannot
1556 change size, so we allow operations that tamper with elements even when
1557 tampering with elements is prohibited. That's not true for the indefinite
1558 containers, which is why this kind of tampering exists.]}
1559 @end{Reason}
1560
1561 @ChgNote{Moved this item to put it in the order it is declared.}
1562 @begin{Example}
1563 @ChgRef{Version=[5],Kind=[Added]}
1564 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Is_Empty (Container : Tree) @key{return} Boolean
1565 @key[with] Nonblocking, Global => (@key[null], @key[use null]),
1566 Post => Is_Empty'Result = (Node_Count (Container) = 1);]}
1567 @end{Example}
1568
1569 @ChgRef{Version=[5],Kind=[Added],ARef=[AI05-0136-1],ARef=[AI12-0112-1]}
1570 @ChgAdded{Version=[5],Type=[Trailing],Text=[Returns True
1571 if Container is empty.]}
1572
1573 @begin{Ramification}
1574 @ChgRef{Version=[5],Kind=[AddedNormal]}
1575 @ChgAdded{Version=[5],Text=[An empty tree contains just the root node.]}
1576 @end{Ramification}
1577
1578 @begin{Example}
1579 @ChgRef{Version=[3],Kind=[AddedNormal]}
1580 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1581 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Node_Count (Container : Tree) @key{return} Count_Type@Chg{Version=[5],New=[
1582 @key[with] Nonblocking, Global => (@key[null], @key[use null])],Old=[]};]}
1583 @end{Example}
1584
1585 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1586 @ChgAdded{Version=[3],Type=[Trailing],Text=[Node_Count returns the number of
1587 nodes in Container.]}
1588
1589 @begin{Ramification}
1590 @ChgRef{Version=[3],Kind=[AddedNormal]}
1591 @ChgAdded{Version=[3],Text=[Since all tree objects have a root node, this
1592 can never return a value of 0. Node_Count (Some_Tree) should always equal
1593 Subtree_Node_Count (Root (Some_Tree)).]}
1594 @end{Ramification}
1595
1596 @begin{Example}
1597 @ChgRef{Version=[3],Kind=[AddedNormal]}
1598 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1599 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Subtree_Node_Count (Position : Cursor) @key{return} Count_Type@Chg{Version=[5],New=[
1600 @key[with] Nonblocking, Global => (@key[in all], @key[use null])],Old=[]};]}
1601 @end{Example}
1602
1603 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
1604 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position is No_Element,
1605 Subtree_Node_Count returns 0; otherwise, Subtree_Node_Count returns the number of
1606 nodes in the subtree that is rooted by Position.]}
1607
1608 @begin{Example}
1609 @ChgRef{Version=[3],Kind=[AddedNormal]}
1610 @ChgRef{Version=[5],Kind=[Revised]}
1611 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} @Chg{Version=[5],New=[Subtree_Node_Count],Old=[Is_Empty]} (Container : Tree@Chg{Version=[5],New=[; Position : Cursor)
1612 ],Old=[) ]}@key{return} @Chg{Version=[5],New=[Count_Type
1613 @key[with] Pre => Meaningful_For (Container, Position) @key[or else raise] Program_Error,
1614 Nonblocking, Global => (@key[null], @key[use null])],Old=[Boolean]};]}
1615 @end{Example}
1616
1617 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1618 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1619 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[If Position
1620 is No_Element, Subtree_Node_Count returns 0; otherwise, Subtree_Node_Count
1621 returns the number of nodes in the subtree of Container that is rooted by
1622 Position],Old=[Equivalent to Node_Count (Container) = 1]}.]}
1623
1624 @begin{Ramification}
1625 @ChgRef{Version=[3],Kind=[AddedNormal]}
1626 @ChgRef{Version=[5],Kind=[Deleted],ARef=[AI12-0112-1]}
1627 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[An empty tree contains just the root node.]}]}
1628 @end{Ramification}
1629
1630 @begin{Reason}
1631 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
1632 @ChgAdded{Version=[5],Text=[We raise Program_Error if Position belongs to
1633 some other container because we have promised to read only the container
1634 passed to this function. Determining the answer requires reading the
1635 container that Position belongs to, which we've promised not
1636 to do if it is not Container. We don't make this check for functions like
1637 Has_Element and Is_Root
1638 which do not require reading another container to determine the answer,
1639 but we do make it for most functions.]}
1640 @end{Reason}
1641
1642 @begin{Example}
1643 @ChgRef{Version=[3],Kind=[AddedNormal]}
1644 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1645 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Depth (Position : Cursor) @key{return} Count_Type@Chg{Version=[5],New=[
1646 @key{with} Nonblocking, Global => (@key{in all}, @key{use null})],Old=[]};]}
1647 @end{Example}
1648
1649 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
1650 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position equals No_Element,
1651 Depth returns 0; otherwise, Depth returns the number of ancestor nodes of the
1652 node designated by Position (including the node itself).]}
1653
1654 @begin{Ramification}
1655 @ChgRef{Version=[3],Kind=[AddedNormal]}
1656 @ChgAdded{Version=[3],Text=[Depth (Root (Some_Tree)) = 1.]}
1657 @end{Ramification}
1658
1659 @begin{Example}
1660 @ChgRef{Version=[5],Kind=[Added]}
1661 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Depth (Container : Tree; Position : Cursor)
1662 @key{return} Count_Type
1663 @key{with} Pre => Meaningful_For (Container, Position) @key{or else raise} Program_Error,
1664 Nonblocking, Global => (@key{null}, @key{use null});]}
1665 @end{Example}
1666
1667 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
1668 @ChgAdded{Version=[5],Type=[Trailing],Text=[If Position equals No_Element,
1669 Depth returns 0; otherwise, Depth returns the number of ancestor nodes of the
1670 node of Container designated by Position (including the node itself).]}
1671
1672 @begin{Example}
1673 @ChgRef{Version=[3],Kind=[AddedNormal]}
1674 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1675 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Is_Root (Position : Cursor) @key{return} Boolean@Chg{Version=[5],New=[
1676 @key{with} Nonblocking, Global => (@key{in all}, @key{use null})],Old=[]};]}
1677 @end{Example}
1678
1679 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
1680 @ChgAdded{Version=[3],Type=[Trailing],Text=[Is_Root returns True if the
1681 Position designates the root node of some tree; and returns False otherwise.]}
1682
1683 @begin{Example}
1684 @ChgRef{Version=[5],Kind=[Added]}
1685 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Is_Root (Container : Tree; Position : Cursor)
1686 @key{return} Boolean
1687 @key{with} Nonblocking, Global => (@key{null}, @key{use null});]}
1688 @end{Example}
1689
1690 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
1691 @ChgAdded{Version=[5],Type=[Trailing],Text=[Is_Root returns True if the
1692 Position designates the root node of Container; and returns False otherwise.]}
1693
1694 @begin{Ramification}
1695 @ChgRef{Version=[5],Kind=[AddedNormal]}
1696 @ChgAdded{Version=[5],Text=[The two parameter Is_Root returns False even
1697 if Position is the root of some other tree than Container.]}
1698 @end{Ramification}
1699
1700 @begin{Example}
1701 @ChgRef{Version=[3],Kind=[AddedNormal]}
1702 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1703 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Is_Leaf (Position : Cursor) @key{return} Boolean@Chg{Version=[5],New=[
1704 @key{with} Nonblocking, Global => (@key{in all}, @key{use null})],Old=[]};]}
1705 @end{Example}
1706
1707 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1708 @ChgAdded{Version=[3],Type=[Trailing],Text=[Is_Leaf returns True if Position
1709 designates a node that does not have any child nodes; and returns False
1710 otherwise.]}
1711
1712 @begin{Ramification}
1713 @ChgRef{Version=[3],Kind=[AddedNormal]}
1714 @ChgAdded{Version=[3],Text=[Is_Leaf returns False if passed No_Element,
1715 since No_Element does not designate a node. Is_Leaf can be passed a cursor
1716 that designates the root node; Is_Leaf will return True if passed the root
1717 node of an empty tree.]}
1718 @end{Ramification}
1719
1720 @begin{Example}
1721 @ChgRef{Version=[5],Kind=[Added]}
1722 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Is_Leaf (Container : Tree; Position : Cursor)
1723 @key{return} Boolean
1724 @key{with} Pre => Meaningful_For (Container, Position) @key{or else raise} Program_Error,
1725 Nonblocking, Global => (@key{null}, @key{use null});]}
1726 @end{Example}
1727
1728 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
1729 @ChgAdded{Version=[5],Type=[Trailing],Text=[Is_Leaf returns True if Position
1730 designates a node in Container that does not have any child nodes; and
1731 returns False otherwise.]}
1732
1733 @begin{Example}
1734 @ChgRef{Version=[5],Kind=[Added]}
1735 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Is_Ancestor_Of (Container : Tree; Position : Cursor)
1736 Parent : Cursor;
1737 Position : Cursor) @key{return} Boolean
1738 @key{with} Pre => (Meaningful_For (Container, Position)
1739 @key{or else raise} Program_Error) @key{and then}
1740 (Meaningful_For (Container, Parent)
1741 @key{or else raise} Program_Error),
1742 Nonblocking, Global => (@key{null}, @key{use null});]}
1743 @end{Example}
1744
1745 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
1746 @ChgAdded{Version=[5],Type=[Trailing],Text=[Is_Ancestor_Of returns True if
1747 Parent designates an ancestor node of Position (including Position itself),
1748 and returns False otherwise.]}
1749
1750 @begin{Example}
1751 @ChgRef{Version=[3],Kind=[AddedNormal]}
1752 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1753 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Root (Container : Tree) @key{return} Cursor@Chg{Version=[5],New=[
1754 @key[with] Nonblocking, Global => (@key[null], @key[use null]),
1755 Post => Root'Result /= No_Element @key[and then]
1756 @key[not] Has_Element (Container, Root'Result)],Old=[]};]}
1757 @end{Example}
1758
1759 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1760 @ChgAdded{Version=[3],Type=[Trailing],Text=[Root returns a cursor that
1761 designates the root node of Container.]}
1762
1763 @begin{Ramification}
1764 @ChgRef{Version=[3],Kind=[AddedNormal]}
1765 @ChgAdded{Version=[3],Text=[There is always a root node, even in an empty
1766 container, so this function never returns No_Element.]}
1767 @end{Ramification}
1768
1769 @begin{Example}
1770 @ChgRef{Version=[3],Kind=[AddedNormal]}
1771 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1772 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Clear (Container : @key{in out} Tree)@Chg{Version=[5],New=[
1773 @key[with] Pre => @key[not] Tampering_With_Cursors_Prohibited (Container)
1774 @key[or else raise] Program_Error,
1775 Post => Node_Count (Container) = 1],Old=[]};]}
1776 @end{Example}
1777
1778 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1779 @ChgAdded{Version=[3],Type=[Trailing],Text=[Removes all the elements from
1780 Container.]}
1781
1782 @begin{Ramification}
1783 @ChgRef{Version=[3],Kind=[AddedNormal]}
1784 @ChgAdded{Version=[3],Text=[The root node is not removed; all trees have a
1785 root node.]}
1786 @end{Ramification}
1787
1788 @begin{Example}
1789 @ChgRef{Version=[3],Kind=[AddedNormal]}
1790 @ChgRef{Version=[5],Kind=[Revised]}
1791 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Element (Position : Cursor) @key{return} Element_Type@Chg{Version=[5],New=[
1792 @key{with} Pre => (Position /= No_Element @key{or else}
1793 @key{raise} Constraint_Error) @key{and then}
1794 (Has_Element (Position) @key{or else raise} Program_Error),
1795 Nonblocking => Element_Type'Nonblocking,
1796 Global => (@key{in all}, @key{use} Element_Type)],Old=[]};]}
1797 @end{Example}
1798
1799 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1800 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1801 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
1802 Position equals No_Element, then Constraint_Error is propagated; if Position
1803 designates the root node of a tree, then Program_Error is propagated.
1804 Otherwise, ]}Element returns the element designated by Position.]}
1805
1806 @begin{Ramification}
1807 @ChgRef{Version=[3],Kind=[AddedNormal]}
1808 @ChgAdded{Version=[3],Text=[The root node does not contain an element, so
1809 that value cannot be read or written.]}
1810 @end{Ramification}
1811
1812 @begin{Example}
1813 @ChgRef{Version=[5],Kind=[Added]}
1814 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Element (Container : Tree;
1815 Position : Cursor) @key{return} Element_Type
1816 @key{with} Pre => (Position /= No_Element @key{or else}
1817 @key{raise} Constraint_Error) @key{and then}
1818 (Has_Element (Container, Position) @key{or else raise} Program_Error),
1819 Nonblocking => Element_Type'Nonblocking,
1820 Global => (@key{null}, @key{use} Element_Type);]}
1821 @end{Example}
1822
1823 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
1824 @ChgAdded{Version=[5],Type=[Trailing],Text=[Element returns the element
1825 designated by Position in Container.]}
1826
1827 @begin{Example}
1828 @ChgRef{Version=[3],Kind=[AddedNormal]}
1829 @ChgRef{Version=[5],Kind=[Revised]}
1830 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Replace_Element (Container : @key{in out} Tree;
1831 Position : @key{in} Cursor;
1832 New_item : @key{in} Element_Type)@Chg{Version=[5],New=[
1833 @key{with} Pre => (@key{not} Tampering_With_Elements_Prohibited (Container)
1834 @key{or else raise} Program_Error) @key{and then}
1835 (Position /= No_Element
1836 @key{or else raise} Constraint_Error) @key{and then}
1837 (Has_Element (Container, Position) @key{or else raise} Program_Error)],Old=[]};]}
1838 @end{Example}
1839
1840 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0264-1]}
1841 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1],ARef=[AI12-0196-1]}
1842 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
1843 Position equals No_Element,
1844 then Constraint_Error is propagated; if Position does not designate an element
1845 in Container (including if it designates the root node), then Program_Error is
1846 propagated. Otherwise, ]}Replace_Element assigns the value New_Item to the
1847 element designated by
1848 Position.@Chg{Version=[5],New=[ For the purposes of
1849 determining whether the parameters overlap in a call to Replace_Element, the
1850 Container parameter is not considered to overlap with any object
1851 @Redundant[(including itself)].],Old=[]}]}
1852
1853 @begin{Example}
1854 @ChgRef{Version=[3],Kind=[AddedNormal]}
1855 @ChgRef{Version=[5],Kind=[Revised]}
1856 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Query_Element
1857 (Position : @key{in} Cursor;
1858 Process : @key{not null access procedure} (Element : @key{in} Element_Type))@Chg{Version=[5],New=[
1859 @key{with} Pre => (Position /= No_Element
1860 @key{or else raise} Constraint_Error) @key{and then}
1861 (Has_Element (Position)
1862 @key{or else raise} Program_Error),
1863 Global => @key{in all}],Old=[]};]}
1864 @end{Example}
1865
1866 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0265-1]}
1867 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1868 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
1869 Position equals No_Element,
1870 then Constraint_Error is propagated; if Position designates the root node of a
1871 tree, then Program_Error is propagated. Otherwise, ]}Query_Element calls
1872 Process.@key{all} with the element designated by Position as the argument.
1873 Tampering with the elements of the tree that contains the element designated
1874 by Position is prohibited during the execution of the call on
1875 Process.@key{all}. Any exception raised by Process.@key{all} is propagated.]}
1876
1877 @begin{Example}
1878 @ChgRef{Version=[5],Kind=[Added]}
1879 @ChgAdded{Version=[5],Text=[@key{procedure} Query_Element
1880 (Container : @key{in} Tree;
1881 Position : @key{in} Cursor;
1882 Process : @key{not null access procedure} (Element : @key{in} Element_Type))
1883 @key{with} Pre => (Position /= No_Element
1884 @key{or else raise} Constraint_Error) @key{and then}
1885 (Has_Element (Container, Position)
1886 @key{or else raise} Program_Error);]}
1887 @end{Example}
1888
1889 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
1890 @ChgAdded{Version=[5],Type=[Trailing],Text=[Query_Element calls Process.@key{all}
1891 with the element designated by Position as the
1892 argument. Tampering with the elements of Container
1893 is prohibited during the execution of the call on
1894 Process.@key{all}. Any exception raised by Process.@key{all} is propagated.]}
1895
1896 @begin{Example}
1897 @ChgRef{Version=[3],Kind=[AddedNormal]}
1898 @ChgRef{Version=[5],Kind=[Revised]}
1899 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Update_Element
1900 (Container : @key{in out} Tree;
1901 Position : @key{in} Cursor;
1902 Process : @key{not null access procedure}
1903 (Element : @key{in out} Element_Type))@Chg{Version=[5],New=[
1904 @key{with} Pre => (Position /= No_Element @key{or else raise} Constraint_Error) @key{and then}
1905 (Has_Element (Container, Position) @key{or else raise} Program_Error)],Old=[]};]}
1906 @end{Example}
1907
1908 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0264-1],ARef=[AI05-0265-1]}
1909 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1910 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
1911 Position equals No_Element,
1912 then Constraint_Error is propagated; if Position does not designate an element
1913 in Container (including if it designates the root node), then Program_Error is
1914 propagated. Otherwise, ]}Update_Element calls Process.@key{all} with the element
1915 designated by Position as the argument. Tampering with the elements of
1916 Container is prohibited during the execution of the call on Process.@key{all}.
1917 Any exception raised by Process.@key{all} is propagated.]}
1918
1919 @ChgRef{Version=[3],Kind=[AddedNormal]}
1920 @ChgAdded{Version=[3],Text=[If Element_Type is unconstrained and definite,
1921 then the actual Element parameter of Process.@key{all} shall be
1922 unconstrained.]}
1923
1924 @begin{Ramification}
1925 @ChgRef{Version=[3],Kind=[AddedNormal]}
1926 @ChgAdded{Version=[3],Text=[This means that the elements cannot be directly
1927 allocated from the heap; it must be possible to change the discriminants of
1928 the element in place.]}
1929 @end{Ramification}
1930
1931 @begin{Example}
1932 @ChgRef{Version=[3],Kind=[AddedNormal]}
1933 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1934 @ChgAdded{Version=[3],Text=[@key[type] Constant_Reference_Type
1935 (Element : @key[not null access constant] Element_Type) @key[is private]
1936 @key[with] Implicit_Dereference => Element@Chg{Version=[5],New=[,
1937 Nonblocking, Global => @key[in out synchronized],
1938 Default_Initial_Condition => (@key[raise] Program_Error)],Old=[]};]}
1939
1940 @ChgRef{Version=[3],Kind=[AddedNormal]}
1941 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1942 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[type] Reference_Type (Element : @key[not null access] Element_Type) @key[is private]
1943 @key[with] Implicit_Dereference => Element@Chg{Version=[5],New=[,
1944 Nonblocking, Global => @key[in out synchronized],
1945 Default_Initial_Condition => (@key[raise] Program_Error)],Old=[]};]}
1946 @end{Example}
1947
1948 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
1949 @ChgAdded{Version=[3],Type=[Trailing],Text=[The types Constant_Reference_Type
1950 and Reference_Type need finalization.@PDefn2{Term=<needs finalization>,Sec=<language-defined type>}]}
1951
1952 @ChgRef{Version=[3],Kind=[AddedNormal]}
1953 @ChgRef{Version=[5],Kind=[Deleted],ARef=[AI12-0112-1]}
1954 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[The default
1955 initialization of an object of type
1956 Constant_Reference_Type or Reference_Type propagates Program_Error.]}]}
1957
1958 @begin{Reason}
1959 @ChgRef{Version=[3],Kind=[AddedNormal]}
1960 @ChgAdded{Version=[3],Text=[It is expected that Reference_Type (and
1961 Constant_Reference_Type) will be a controlled type, for which finalization
1962 will have some action to terminate the tampering check for the associated
1963 container. If the object is created by default, however, there is no
1964 associated container. Since this is useless, and supporting this case would
1965 take extra work, we define it to raise an exception.]}
1966 @end{Reason}
1967
1968 @begin{Example}
1969 @ChgRef{Version=[3],Kind=[AddedNormal]}
1970 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1971 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Constant_Reference (Container : @key[aliased in] Tree;
1972 Position : @key[in] Cursor)
1973 @key[return] Constant_Reference_Type@Chg{Version=[5],New=[
1974 @key[with] Pre => (Position /= No_Element @key[or else]
1975 @key[raise] Constraint_Error) @key[and then]
1976 (Has_Element (Container, Position) @key[or else raise] Program_Error),
1977 Post => Tampering_With_Cursors_Prohibited (Container),
1978 Nonblocking, Global => (@key[null], @key[use null])],Old=[]};]}
1979 @end{Example}
1980
1981 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0269-1]}
1982 @ChgAdded{Version=[3],Type=[Trailing],Text=[This function (combined with the
1983 Constant_Indexing and Implicit_Dereference aspects) provides a convenient way
1984 to gain read access to an individual element of a tree given a
1985 cursor.]}
1986
1987 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0265-1]}
1988 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
1989 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
1990 Position equals No_Element, then
1991 Constraint_Error is propagated; if Position does not designate an element in
1992 Container, then Program_Error is propagated. Otherwise, ]}Constant_Reference
1993 returns an object whose discriminant is an access value that designates the
1994 element designated by Position. Tampering with the elements of Container
1995 is prohibited while the object returned by Constant_Reference exists
1996 and has not been finalized.]}
1997
1998 @begin{Example}
1999 @ChgRef{Version=[3],Kind=[AddedNormal]}
2000 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2001 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Reference (Container : @key[aliased in out] Tree;
2002 Position : @key[in] Cursor)
2003 @key[return] Reference_Type@Chg{Version=[5],New=[
2004 @key[with] Pre => (Position /= No_Element @key[or else]
2005 @key[raise] Constraint_Error) @key[and then]
2006 (Has_Element (Container, Position) @key[or else raise] Program_Error),
2007 Post => Tampering_With_Cursors_Prohibited (Container),
2008 Nonblocking, Global => (@key[null], @key[use null])],Old=[]};]}
2009 @end{Example}
2010
2011 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0269-1]}
2012 @ChgAdded{Version=[3],Type=[Trailing],Text=[This function (combined with the
2013 Variable_Indexing and Implicit_Dereference aspects) provides a convenient way
2014 to gain read and write access to an individual element of a tree
2015 given a cursor.]}
2016
2017 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0265-1]}
2018 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2019 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[If
2020 Position equals No_Element, then Constraint_Error is propagated;
2021 if Position does not designate an element in Container, then
2022 Program_Error is propagated. ]}Otherwise, Reference returns an
2023 object whose discriminant is an access value that designates the element
2024 designated by Position. Tampering with the elements
2025 of Container is prohibited while the object returned by Reference exists
2026 and has not been finalized.]}
2027
2028 @begin{Example}
2029 @ChgRef{Version=[3],Kind=[AddedNormal]}
2030 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2031 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Assign (Target : @key{in out} Tree; Source : @key{in} Tree)@Chg{Version=[5],New=[
2032 @key[with] Pre => @key[not] Tampering_With_Cursors_Prohibited (Target)
2033 @key[or else raise] Program_Error,
2034 Post => Node_Count (Source) = Node_Count (Target)],Old=[]};]}
2035 @end{Example}
2036
2037 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
2038 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Target denotes the same object
2039 as Source, the operation has no effect. Otherwise, the elements of Source are
2040 copied to Target as for an @nt{assignment_statement} assigning Source to
2041 Target.]}
2042
2043 @begin{Ramification}
2044 @ChgRef{Version=[3],Kind=[AddedNormal]}
2045 @ChgAdded{Version=[3],Text=[Each element in Target has a
2046 parent element that corresponds to the parent element of the Source element,
2047 and has child elements that correspond to the child elements of the Source
2048 element.]}
2049 @end{Ramification}
2050 @begin{Discussion}
2051 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
2052 @ChgAdded{Version=[3],Text=[This routine exists for compatibility with the
2053 bounded tree container. For an unbounded tree, @exam{Assign(A, B)} and
2054 @exam{A := B} behave identically. For a bounded tree, := will raise an
2055 exception if the container capacities are different, while Assign will
2056 not raise an exception if there is enough room in the target.]}
2057 @end{Discussion}
2058
2059 @begin{Example}
2060 @ChgRef{Version=[3],Kind=[AddedNormal]}
2061 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2062 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Copy (Source : Tree) @key[return] Tree@Chg{Version=[5],New=[
2063 @key[with] Post =>
2064 Node_Count (Copy'Result) = Node_Count (Source) @key[and then]
2065 @key[not] Tampering_With_Elements_Prohibited (Copy'Result) @key[and then]
2066 @key[not] Tampering_With_Cursors_Prohibited (Copy'Result)],Old=[]};]}
2067 @end{Example}
2068
2069 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
2070 @ChgAdded{Version=[3],Type=[Trailing],Text=[Returns a tree with the same
2071 structure as Source and whose elements are initialized from the corresponding
2072 elements of Source.]}
2073
2074 @begin{Example}
2075 @ChgRef{Version=[3],Kind=[AddedNormal]}
2076 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2077 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Move (Target : @key{in out} Tree;
2078 Source : @key{in out} Tree)@Chg{Version=[5],New=[
2079 @key{with} Pre => (@key{not} Tampering_With_Cursors_Prohibited (Target)
2080 @key{or else raise} Program_Error) @key{and then}
2081 (@key{not} Tampering_With_Cursors_Prohibited (Source)
2082 @key{or else raise} Program_Error),
2083 Post =>
2084 (@key{if} Same_Object (Target, Source) @key{then} True
2085 @key{else}
2086 Node_Count (Target) = Node_Count (Source'Old) @key{and then}
2087 Node_Count (Source) = 1)],Old=[]};]}
2088 @end{Example}
2089
2090 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
2091 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Target denotes the same object
2092 as Source, then the operation has no effect. Otherwise, Move first calls Clear
2093 (Target). Then, the nodes other than the root node in Source are moved to
2094 Target (in the same positions). After Move completes, Node_Count (Target) is
2095 the number of nodes originally in Source, and Node_Count (Source) is 1.]}
2096
2097 @begin{Example}
2098 @ChgRef{Version=[3],Kind=[AddedNormal]}
2099 @ChgRef{Version=[5],Kind=[Revised]}
2100 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Delete_Leaf (Container : @key{in out} Tree;
2101 Position : @key{in out} Cursor)@Chg{Version=[5],New=[
2102 @key{with} Pre => (@key{if} Tampering_With_Cursors_Prohibited (Container)
2103 @key{then raise} Program_Error) @key{and then}
2104 (Position /= No_Element
2105 @key{or else raise} Constraint_Error) @key{and then}
2106 (Has_Element (Container, Position)
2107 @key{or else raise} Program_Error) @key{and then}
2108 (Is_Leaf (Container, Position)
2109 @key{or else raise} Constraint_Error),
2110 Post =>
2111 Node_Count (Container)'Old = Node_Count (Container) + 1 @key{and then}
2112 Position = No_Element],Old=[]};]}
2113 @end{Example}
2114
2115 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
2116 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2117 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
2118 Position equals No_Element,
2119 then Constraint_Error is propagated; if Position does not designate an element
2120 in Container (including if it designates the root node), then Program_Error is
2121 propagated. If the element designated by position has any child elements, then
2122 Constraint_Error is propagated. Otherwise, ]}Delete_Leaf removes (from Container)
2123 the element designated by Position@Chg{Version=[5],New=[, and],Old=[. Finally,]}
2124 Position is set to No_Element.]}
2125
2126 @begin{Ramification}
2127 @ChgRef{Version=[3],Kind=[AddedNormal]}
2128 @ChgAdded{Version=[3],Text=[The check on Position
2129 checks that the cursor does not belong to some other Container. This check
2130 implies that a reference to the container is included in the cursor value.
2131 This wording is not meant to require detection of dangling cursors; such
2132 cursors are defined to be invalid, which means that execution is erroneous,
2133 and any result is allowed (including not raising an exception).]}
2134
2135 @ChgRef{Version=[3],Kind=[AddedNormal]}
2136 @ChgAdded{Version=[3],Text=[The root node cannot be deleted.]}
2137 @end{Ramification}
2138
2139 @begin{Example}
2140 @ChgRef{Version=[3],Kind=[AddedNormal]}
2141 @ChgRef{Version=[5],Kind=[Revised]}
2142 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Delete_Subtree (Container : @key{in out} Tree;
2143 Position : @key{in out} Cursor)@Chg{Version=[5],New=[
2144 @key{with} Pre => (@key{if} Tampering_With_Cursors_Prohibited (Container)
2145 @key{then raise} Program_Error) @key{and then}
2146 (Position /= No_Element
2147 @key{or else raise} Constraint_Error) @key{and then}
2148 (Has_Element (Container, Position)
2149 @key{or else raise} Program_Error),
2150 Post => Node_Count (Container)'Old = Node_Count (Container) +
2151 Subtree_Node_Count (Container, Position)'Old @key{and then}
2152 Position = No_Element],Old=[]};]}
2153 @end{Example}
2154
2155 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0264-1],ARef=[AI05-0269-1]}
2156 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2157 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
2158 Position equals No_Element,
2159 then Constraint_Error is propagated. If Position does not designate an element
2160 in Container (including if it designates the root node), then Program_Error is
2161 propagated. Otherwise, ]}Delete_Subtree removes (from Container) the subtree
2162 designated by Position (that is, all descendants of the node designated
2163 by Position including the node itself), and Position is set to No_Element.]}
2164
2165 @begin{Ramification}
2166 @ChgRef{Version=[3],Kind=[AddedNormal]}
2167 @ChgAdded{Version=[3],Text=[The root node cannot be deleted. To delete the
2168 entire contents of the tree, call Clear(Container).]}
2169 @end{Ramification}
2170
2171 @begin{Example}
2172 @ChgRef{Version=[3],Kind=[AddedNormal]}
2173 @ChgRef{Version=[5],Kind=[Revised]}
2174 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Swap (Container : @key{in out} Tree;
2175 I, J : @key{in} Cursor)@Chg{Version=[5],New=[
2176 @key{with} Pre => (@key{not} Tampering_With_Cursors_Prohibited (Container)
2177 @key{or else raise} Program_Error) @key{and then}
2178 (I /= No_Element @key{or else} Constraint_Error) @key{and then}
2179 (J /= No_Element @key{or else} Constraint_Error) @key{and then}
2180 (Has_Element (Container, I)
2181 @key{or else raise} Program_Error) @key{and then}
2182 (Has_Element (Container, J)
2183 @key{or else raise} Program_Error)],Old=[]};]}
2184 @end{Example}
2185
2186 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
2187 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2188 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
2189 either I or J equals
2190 No_Element, then Constraint_Error is propagated. If either I or J do not
2191 designate an element in Container (including if either designates the root
2192 node), then Program_Error is propagated. Otherwise, ]}Swap exchanges the values
2193 of the elements designated by I and J.]}
2194
2195 @begin{Ramification}
2196 @ChgRef{Version=[3],Kind=[AddedNormal]}
2197 @ChgAdded{Version=[3],Text=[After a call to Swap, I designates the element
2198 value previously designated by J, and J designates the element value
2199 previously designated by I. The position of the elements do not change; for
2200 instance, the parent node and the first child node of I are unchanged by the
2201 operation.]}
2202
2203 @ChgRef{Version=[3],Kind=[AddedNormal]}
2204 @ChgAdded{Version=[3],Text=[The root nodes do not contain element values, so
2205 they cannot be swapped.]}
2206 @end{Ramification}
2207
2208 @begin{Honest}
2209 @ChgRef{Version=[3],Kind=[AddedNormal]}
2210 @ChgAdded{Version=[3],Text=[The implementation is not required to actually
2211 copy the elements if it can do the swap some other way. But it is allowed to
2212 copy the elements if needed.]}
2213 @end{Honest}
2214
2215 @begin{Example}
2216 @ChgRef{Version=[3],Kind=[AddedNormal]}
2217 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2218 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Find (Container : Tree;
2219 Item : Element_Type)
2220 @key{return} Cursor@Chg{Version=[5],New=[
2221 @key{with} Post => (@key{if} Find'Result = No_Element @key{then} True
2222 @key{else} Has_Element (Container, Find'Result))],Old=[]};]}
2223 @end{Example}
2224
2225 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0262-1]}
2226 @ChgAdded{Version=[3],Type=[Trailing],Text=[Find searches the elements of
2227 Container for an element equal to Item (using the generic formal equality
2228 operator). The search starts at the root node. The search traverses the tree
2229 in a depth-first order. If no equal element is found, then Find returns
2230 No_Element. Otherwise, it returns a cursor designating the first equal element
2231 encountered.]}
2232
2233 @begin{Example}
2234 @ChgRef{Version=[3],Kind=[AddedNormal]}
2235 @ChgRef{Version=[5],Kind=[Revised]}
2236 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Find_In_Subtree (Position : Cursor;
2237 Item : Element_Type)
2238 @key{return} Cursor@Chg{Version=[5],New=[
2239 @key{with} Pre => Position /= No_Element @key{or else raise} Constraint_Error,
2240 Post => (@key{if} Find_In_Subtree'Result = No_Element @key{then} True
2241 @key{else} Has_Element (Find_In_Subtree'Result)),
2242 Global => @key{in all}],Old=[]};]}
2243 @end{Example}
2244
2245 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1]}
2246 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2247 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
2248 Position equals No_Element,
2249 then Constraint_Error is propagated. ]}Find_In_Subtree searches
2250 the subtree rooted by Position for an element equal to Item (using the
2251 generic formal equality operator). The search starts at the element designated
2252 by Position. The search traverses the subtree in a depth-first
2253 order. If no equal element is found, then Find returns No_Element. Otherwise,
2254 it returns a cursor designating the first equal element encountered.]}
2255
2256 @begin{Ramification}
2257 @ChgRef{Version=[3],Kind=[AddedNormal]}
2258 @ChgAdded{Version=[3],Text=[Find_In_Subtree does not check any siblings of
2259 the element designated by Position. The root node does not contain an
2260 element, and therefore it can never be returned, but it can be explicitly
2261 passed to Position.]}
2262 @end{Ramification}
2263
2264 @begin{Example}
2265 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
2266 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Find_In_Subtree (Container : Tree;
2267 Position : Cursor;
2268 Item : Element_Type)
2269 @key{return} Cursor
2270 @key{with} Pre => (Position = No_Element
2271 @key{or else raise} Constraint_Error) @key{and then}
2272 (Meaningful_For (Container, Position)
2273 @key{or else raise} Program_Error),
2274 Post => (@key{if} Find_In_Subtree'Result = No_Element @key{then} True
2275 @key{else} Has_Element (Container, Find_In_Subtree'Result));]}
2276 @end{Example}
2277
2278 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
2279 @ChgAdded{Version=[5],Type=[Trailing],Text=[Find_In_Subtree searches the
2280 subtree of Container rooted by Position for an element equal to Item (using
2281 the generic formal equality operator). The search starts at the element
2282 designated by Position. The search traverses the subtree in a depth-first
2283 order. If no equal element is found, then Find returns No_Element. Otherwise,
2284 it returns a cursor designating the first equal element encountered.]}
2285
2286 @begin{Example}
2287 @ChgRef{Version=[3],Kind=[AddedNormal]}
2288 @ChgRef{Version=[5],Kind=[Revised]}
2289 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Ancestor_Find (Position : Cursor;
2290 Item : Element_Type)
2291 @key{return} Cursor@Chg{Version=[5],New=[
2292 @key{with} Pre => Position /= No_Element @key{or else raise} Constraint_Error,
2293 Post => (@key{if} Ancestor_Find'Result = No_Element @key{then} True
2294 @key{else} Has_Element (Container, Ancestor_Find'Result)),
2295 Global => @key{in all}],Old=[]};]}
2296 @end{Example}
2297
2298 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
2299 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2300 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
2301 Position equals No_Element,
2302 then Constraint_Error is propagated. Otherwise, ]}Ancestor_Find searches
2303 for an element equal to Item (using the generic formal equality operator). The
2304 search starts at the node designated by Position, and checks each ancestor
2305 proceeding toward the root of the subtree. If no equal element is found, then
2306 Ancestor_Find returns No_Element. Otherwise, it returns a cursor designating
2307 the first equal element encountered.]}
2308 @begin{Ramification}
2309 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0248-1]}
2310 @ChgAdded{Version=[3],Text=[No_Element is returned if Position is the root
2311 node.]}
2312 @end{Ramification}
2313
2314 @begin{Example}
2315 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
2316 @ChgAdded{Version=[5],Text=[@key{function} Ancestor_Find (Container : Tree;
2317 Position : Cursor;
2318 Item : Element_Type)
2319 @key{return} Cursor@Chg{Version=[5],New=[
2320 @key{with} Pre => (Position = No_Element
2321 @key{or else raise} Constraint_Error) @key{and then}
2322 (Meaningful_For (Container, Position)
2323 @key{or else raise} Program_Error),
2324 Post => (@key{if} Ancestor_Find'Result = No_Element @key{then} True
2325 @key{else} Has_Element (Container, Ancestor_Find'Result))],Old=[]};]}
2326 @end{Example}
2327
2328 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
2329 @ChgAdded{Version=[5],Type=[Trailing],Text=[Ancestor_Find searches
2330 for an element equal to Item (using the generic formal equality operator). The
2331 search starts at the node designated by Position in Container, and checks each
2332 ancestor proceeding toward the root of the subtree. If no equal element is
2333 found, then Ancestor_Find returns No_Element. Otherwise, it returns a cursor
2334 designating the first equal element encountered.]}
2335
2336 @begin{Example}
2337 @ChgRef{Version=[3],Kind=[AddedNormal]}
2338 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Contains (Container : Tree;
2339 Item : Element_Type) @key{return} Boolean;]}
2340 @end{Example}
2341
2342 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
2343 @ChgAdded{Version=[3],Type=[Trailing],Text=[Equivalent to Find (Container, Item) /= No_Element.]}
2344
2345 @begin{Example}
2346 @ChgRef{Version=[3],Kind=[AddedNormal]}
2347 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2348 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Iterate
2349 (Container : @key{in} Tree;
2350 Process : @key{not null access procedure} (Position : @key{in} Cursor))@Chg{Version=[5],New=[
2351 @key{with} Allows_Exit],Old=[]};]}
2352 @end{Example}
2353
2354 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0265-1]}
2355 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0069-1]}
2356 @ChgAdded{Version=[3],Type=[Trailing],Text=[Iterate calls Process.@key{all}
2357 with a cursor that designates each element in Container, starting
2358 @Chg{Version=[4],New=[from],Old=[with]} the
2359 root node and proceeding in a depth-first order. Tampering with the cursors
2360 of Container is prohibited during the execution of a call on Process.@key{all}.
2361 Any exception raised by Process.@key{all} is propagated.]}
2362
2363 @begin{Ramification}
2364 @ChgRef{Version=[3],Kind=[AddedNormal]}
2365 @ChgAdded{Version=[3],Text=[Process is not called with the root node, which
2366 does not have an associated element.]}
2367 @end{Ramification}
2368
2369 @begin{ImplNote}
2370 @ChgRef{Version=[3],Kind=[AddedNormal]}
2371 @ChgAdded{Version=[3],Text=[The purpose of the tamper with cursors check is
2372 to prevent erroneous execution from the Position parameter of
2373 Process.@key{all} becoming invalid. This check takes place when the
2374 operations that tamper with the cursors of the container are called. The
2375 check cannot be made later (say in the body of Iterate), because that could
2376 cause the Position cursor to be invalid and potentially cause execution to
2377 become erroneous @em defeating the purpose of the check.]}
2378
2379 @ChgRef{Version=[3],Kind=[AddedNormal]}
2380 @ChgAdded{Version=[3],Text=[See Iterate for vectors
2381 (@RefSecNum{The Generic Package Containers.Vectors}) for a suggested
2382 implementation of the check.]}
2383 @end{ImplNote}
2384
2385 @begin{Example}
2386 @ChgRef{Version=[3],Kind=[AddedNormal]}
2387 @ChgRef{Version=[5],Kind=[Revised]}
2388 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Iterate_Subtree
2389 (Position : @key{in} Cursor;
2390 Process : @key{not null access procedure} (Position : @key{in} Cursor))@Chg{Version=[5],New=[
2391 @key{with} Allows_Exit,
2392 Pre => Position /= No_Element @key{or else raise} Constraint_Error,
2393 Global => (@key{in all}, @key{use null})],Old=[]};]}
2394 @end{Example}
2395
2396 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0265-1]}
2397 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0069-1]}
2398 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2399 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
2400 Position equals No_Element,
2401 then Constraint_Error is propagated. Otherwise, ]}Iterate_Subtree calls
2402 Process.@key{all}
2403 with a cursor that designates each element in the subtree rooted by the node
2404 designated by Position, starting
2405 @Chg{Version=[4],New=[from],Old=[with]} the node designated by Position and
2406 proceeding in a depth-first order.
2407 Tampering with the cursors of the tree that contains the element
2408 designated by Position
2409 is prohibited during the execution of a call on Process.@key{all}.
2410 Any exception raised by Process.@key{all} is propagated.]}
2411
2412 @begin{Ramification}
2413 @ChgRef{Version=[3],Kind=[AddedNormal]}
2414 @ChgAdded{Version=[3],Text=[Position can be passed a cursor designating the
2415 root node; in that case, Process is not called with the root node, which
2416 does not have an associated element.]}
2417 @end{Ramification}
2418
2419 @begin{Example}
2420 @ChgRef{Version=[5],Kind=[Added]}
2421 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{procedure} Iterate_Subtree
2422 (Container : @key{in} Tree;
2423 Position : @key{in} Cursor;
2424 Process : @key{not null access procedure} (Position : @key{in} Cursor))
2425 @key{with} Allows_Exit,
2426 Pre => (Position /= No_Element
2427 @key{or else raise} Constraint_Error) @key{and then}
2428 (Meaningful_For (Container, Position)
2429 @key{or else raise} Program_Error);]}
2430 @end{Example}
2431
2432 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
2433 @ChgAdded{Version=[5],Type=[Trailing],Text=[Iterate_Subtree calls
2434 Process.@key{all}
2435 with a cursor that designates each element in the subtree rooted by the node
2436 designated by Position in Container, starting
2437 from the node designated by Position and
2438 proceeding in a depth-first order.
2439 Tampering with the cursors of the tree that contains the element
2440 designated by Position
2441 is prohibited during the execution of a call on Process.@key{all}.
2442 Any exception raised by Process.@key{all} is propagated.]}
2443
2444 @begin{Example}
2445 @ChgRef{Version=[3],Kind=[AddedNormal]}
2446 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2447 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Iterate (Container : @key{in} Tree)
2448 @key{return} Tree_Iterator_Interfaces.@Chg{Version=[5],New=[Parallel_Iterator],Old=[Forward_Iterator]}'Class@Chg{Version=[5],New=[
2449 @key{with} Post => Tampering_With_Cursors_Prohibited (Container)],Old=[]};]}
2450 @end{Example}
2451
2452 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0265-1],ARef=[AI05-0269-1]}
2453 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0069-1]}
2454 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0266-1]}
2455 @ChgAdded{Version=[3],Type=[Trailing],Text=[Iterate returns
2456 an iterator object (see @RefSecNum{User-Defined Iterator Types}) that will
2457 generate a value for a loop parameter (see @RefSecNum{Generalized Loop Iteration})
2458 designating each @Chg{Version=[4],New=[element],Old=[node]} in Container, starting
2459 @Chg{Version=[4],New=[from],Old=[with]} the root node and proceeding in a depth-first
2460 order@Chg{Version=[5],New=[ when used as a forward iterator,
2461 and processing all nodes concurrently when used as a parallel
2462 iterator],Old=[]}.
2463 Tampering with the cursors of Container is prohibited while the iterator
2464 object exists (in particular, in the
2465 @nt{sequence_of_statements} of the @nt{loop_statement} whose
2466 @nt{iterator_specification} denotes this object). The iterator object needs
2467 finalization.]}
2468
2469 @begin{Discussion}
2470 @ChgRef{Version=[3],Kind=[AddedNormal]}
2471 @ChgAdded{Version=[3],Type=[Leading],Text=[Exits are allowed from the loops
2472 created using the iterator objects. In particular, to stop the iteration at a
2473 particular cursor, just add]}
2474 @begin{Example}
2475 @ChgRef{Version=[3],Kind=[AddedNormal]}
2476 @ChgAdded{Version=[3],Text=[@key[exit when] Cur = Stop;]}
2477 @end{Example}
2478 @ChgRef{Version=[3],Kind=[AddedNormal]}
2479 @ChgAdded{Version=[3],Type=[Trailing],Text=[in the body of the loop (assuming
2480 that @exam{Cur} is the loop parameter and @exam{Stop} is the cursor that you
2481 want to stop at).]}
2482 @end{Discussion}
2483
2484 @begin{Example}
2485 @ChgRef{Version=[3],Kind=[AddedNormal]}
2486 @ChgRef{Version=[5],Kind=[Revised]}
2487 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Iterate_Subtree (Position : @key{in} Cursor)
2488 @key{return} Tree_Iterator_Interfaces.@Chg{Version=[5],New=[Parallel_Iterator],Old=[Forward_Iterator]}'Class@Chg{Version=[5],New=[
2489 @key{with} Pre => Position /= No_Element @key{or else raise} Constraint_Error,
2490 Global => (@key{in all}, @key{use null})],Old=[]};]}
2491 @end{Example}
2492
2493 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0265-1],ARef=[AI05-0269-1]}
2494 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0069-1]}
2495 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1],ARef=[AI12-0266-1]}
2496 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
2497 Position equals No_Element,
2498 then Constraint_Error is propagated. Otherwise, ]}Iterate_Subtree returns
2499 an iterator object (see @RefSecNum{User-Defined Iterator Types}) that will
2500 generate a value for a loop parameter (see @RefSecNum{Generalized Loop Iteration})
2501 designating each element in the subtree rooted by the node designated by Position,
2502 starting @Chg{Version=[4],New=[from],Old=[with]} the
2503 node designated by Position and proceeding in a depth-first
2504 order@Chg{Version=[5],New=[ when used as a forward iterator,
2505 and processing all nodes in the subtree concurrently when used
2506 as a parallel iterator],Old=[]}.@Chg{Version=[5],New=[],Old=[ If Position
2507 equals No_Element, then Constraint_Error is propagated.]}
2508 Tampering with the cursors of the container that contains the node
2509 designated by Position is prohibited while the iterator object exists
2510 (in particular, in the
2511 @nt{sequence_of_statements} of the @nt{loop_statement} whose
2512 @nt{iterator_specification} denotes this object). The iterator object
2513 needs finalization.]}
2514
2515 @begin{Example}
2516 @ChgRef{Version=[5],Kind=[Added]}
2517 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Iterate_Subtree (Container : @key{in} Tree; Position : @key{in} Cursor)
2518 @key{return} Tree_Iterator_Interfaces.Parallel_Iterator'Class
2519 @key{with} Pre => (Position /= No_Element
2520 @key{or else raise} Constraint_Error) @key{and then}
2521 (Meaningful_For (Container, Position)
2522 @key{or else raise} Program_Error),
2523 Post => Tampering_With_Cursors_Prohibited (Container);]}
2524 @end{Example}
2525
2526 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
2527 @ChgAdded{Version=[5],Type=[Trailing],Text=[Iterate_Subtree returns
2528 an iterator object (see @RefSecNum{User-Defined Iterator Types}) that will
2529 generate a value for a loop parameter (see @RefSecNum{Generalized Loop Iteration})
2530 designating each element in the subtree rooted by the node designated by
2531 Position in Container, starting from the
2532 node designated by Position and proceeding in a depth-first
2533 order@Chg{Version=[5],New=[ when used as a forward iterator,
2534 and processing all nodes in the subtree concurrently when used
2535 as a parallel iterator],Old=[]}.
2536 Tampering with the cursors of the container that contains the node
2537 designated by Position is prohibited while the iterator object exists
2538 (in particular, in the
2539 @nt{sequence_of_statements} of the @nt{loop_statement} whose
2540 @nt{iterator_specification} denotes this object). The iterator object
2541 needs finalization.]}
2542
2543 @begin{Example}
2544 @ChgRef{Version=[3],Kind=[AddedNormal]}
2545 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2546 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Child_Count (Parent : Cursor) @key{return} Count_Type@Chg{Version=[5],New=[
2547 @key{with} Post => (@key{if} Parent = No_Element @key{then} Child_Count'Result = 0
2548 @key{else} True),
2549 Nonblocking, Global => (@key{in all}, @key{use null})],Old=[]};]}
2550 @end{Example}
2551
2552 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
2553 @ChgAdded{Version=[3],Type=[Trailing],Text=[Child_Count returns the number of
2554 child nodes of the node designated by Parent.]}
2555
2556 @begin{Example}
2557 @ChgRef{Version=[5],Kind=[Added]}
2558 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Child_Count (Container : Tree; Parent : Cursor)
2559 @key{return} Count_Type
2560 @key{with} Pre => Meaningful_For (Container, Parent) @key{or else raise} Program_Error,
2561 Post => (@key{if} Parent = No_Element @key{then} Child_Count'Result = 0
2562 @key{else} True),
2563 Nonblocking, Global => (@key{null}, @key{use null});]}
2564 @end{Example}
2565
2566 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
2567 @ChgAdded{Version=[5],Type=[Trailing],Text=[Child_Count returns the number of
2568 child nodes of the node designated by Parent in Container.]}
2569
2570 @begin{Example}
2571 @ChgRef{Version=[3],Kind=[AddedNormal]}
2572 @ChgRef{Version=[5],Kind=[Revised]}
2573 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Child_Depth (Parent, Child : Cursor) @key{return} Count_Type@Chg{Version=[5],New=[
2574 @key{with} Pre => (Parent /= No_Element @key{and then} Child /= No_Element)
2575 @key{or else raise} Constraint_Error,
2576 Nonblocking, Global => (@key{in all}, @key{use null})],Old=[]};]}
2577 @end{Example}
2578
2579 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0262-1]}
2580 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2581 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
2582 Child or Parent is equal to
2583 No_Element, then Constraint_Error is propagated. Otherwise, ]}Child_Depth
2584 returns the number of ancestor nodes of Child (including Child itself), up to
2585 but not including Parent; Program_Error is propagated if Parent
2586 is not an ancestor of Child.]}
2587
2588 @begin{Ramification}
2589 @ChgRef{Version=[3],Kind=[AddedNormal]}
2590 @ChgAdded{Version=[3],Text=[Program_Error is propagated if Parent and Child
2591 are nodes in different containers.]}
2592
2593 @ChgRef{Version=[3],Kind=[AddedNormal]}
2594 @ChgAdded{Version=[3],Text=[Child_Depth (Root (Some_Tree), Child) + 1 =
2595 Depth (Child) as the root is not counted.]}
2596 @end{Ramification}
2597
2598 @begin{Example}
2599 @ChgRef{Version=[5],Kind=[Added]}
2600 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Child_Depth (Container : Tree; Parent, Child : Cursor)
2601 @key{return} Count_Type
2602 @key{with} Pre => ((Parent /= No_Element @key{and then} Child /= No_Element)
2603 @key{or else raise} Constraint_Error) @key{and then}
2604 (Meaningful_For (Container, Parent)
2605 @key{or else raise} Program_Error) @key{and then}
2606 (Meaningful_For (Container, Child)
2607 @key{or else raise} Program_Error),
2608 Nonblocking, Global => (@key{null}, @key{use null});]}
2609 @end{Example}
2610
2611 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
2612 @ChgAdded{Version=[5],Type=[Trailing],Text=[Child_Depth
2613 returns the number of ancestor nodes of Child within Container (including
2614 Child itself), up to but not including Parent; Program_Error is propagated
2615 if Parent is not an ancestor of Child.]}
2616
2617 @begin{Example}
2618 @ChgRef{Version=[3],Kind=[AddedNormal]}
2619 @ChgRef{Version=[5],Kind=[Revised]}
2620 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Insert_Child (Container : @key{in out} Tree;
2621 Parent : @key{in} Cursor;
2622 Before : @key{in} Cursor;
2623 New_Item : @key{in} Element_Type;
2624 Count : @key{in} Count_Type := 1)@Chg{Version=[5],New=[
2625 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Container)
2626 @key{or else raise} Program_Error) @key{and then}
2627 (Parent /= No_Element
2628 @key{or else raise} Constraint_Error) @key{and then}
2629 (Meaningful_For (Container, Parent)
2630 @key{or else raise} Program_Error) @key{and then}
2631 (Meaningful_For (Container, Before)
2632 @key{or else raise} Program_Error) @key{and then}
2633 (Before = No_Element @key{or else}
2634 Container.Parent (Before) = Parent
2635 @key{or else raise} Constraint_Error),
2636 Post => Node_Count (Container) =
2637 Node_Count (Container)'Old + Count],Old=[]};]}
2638 @end{Example}
2639
2640 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1]}
2641 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2642 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
2643 Parent equals No_Element, then
2644 Constraint_Error is propagated. If Parent does not designate a node in
2645 Container, then Program_Error is propagated. If Before is not equal to
2646 No_Element, and does not designate a node in Container, then Program_Error is
2647 propagated. If Before is not equal to No_Element, and
2648 Parent does not designate the parent node of the node designated by Before,
2649 then Constraint_Error is propagated.
2650 Otherwise, ]}Insert_Child allocates Count nodes containing copies of New_Item
2651 and inserts them as children of Parent. If Parent already has child nodes, then
2652 the new nodes are inserted prior to the node designated by Before, or, if
2653 Before equals No_Element, the new nodes are inserted after the last existing
2654 child node of Parent. Any exception raised during allocation of internal
2655 storage is propagated, and Container is not modified.]}
2656
2657 @begin{Example}
2658 @ChgRef{Version=[3],Kind=[AddedNormal]}
2659 @ChgRef{Version=[5],Kind=[Revised]}
2660 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Insert_Child (Container : @key{in out} Tree;
2661 Parent : @key{in} Cursor;
2662 Before : @key{in} Cursor;
2663 New_Item : @key{in} Element_Type;
2664 Position : @key{out} Cursor;
2665 Count : @key{in} Count_Type := 1)@Chg{Version=[5],New=[
2666 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Container)
2667 @key{or else raise} Program_Error) @key{and then}
2668 (Parent /= No_Element
2669 @key{or else raise} Constraint_Error) @key{and then}
2670 (Meaningful_For (Container, Parent)
2671 @key{or else raise} Program_Error) @key{and then}
2672 (Meaningful_For (Container, Before)
2673 @key{or else raise} Program_Error) @key{and then}
2674 (Before = No_Element @key{or else}
2675 Container.Parent (Before) = Parent
2676 @key{or else raise} Constraint_Error),
2677 Post => (Node_Count (Container) =
2678 Node_Count (Container)'Old + Count) @key{and then}
2679 Has_Element (Container, Position)],Old=[]};]}
2680 @end{Example}
2681
2682 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0257-1],ARef=[AI05-0262-1]}
2683 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2684 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
2685 Parent equals No_Element, then
2686 Constraint_Error is propagated. If Parent does not designate a node in
2687 Container, then Program_Error is propagated. If Before is not equal to
2688 No_Element, and does not designate a node in Container, then Program_Error is
2689 propagated. If Before is not equal to No_Element, and
2690 Parent does not designate the parent node of the node designated by Before,
2691 then Constraint_Error is propagated.
2692 Otherwise, ]}Insert_Child allocates Count nodes containing copies of New_Item
2693 and inserts them as children of Parent. If Parent already has child nodes, then
2694 the new nodes are inserted prior to the node designated by Before, or, if
2695 Before equals No_Element, the new nodes are inserted after the last existing
2696 child node of Parent. Position designates the first newly-inserted node, or if
2697 Count equals 0, then Position is assigned the value of Before. Any exception
2698 raised during allocation of internal storage is propagated, and Container is
2699 not modified.]}
2700
2701 @begin{Example}
2702 @ChgRef{Version=[3],Kind=[AddedNormal]}
2703 @ChgRef{Version=[5],Kind=[Revised]}
2704 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Insert_Child (Container : @key{in out} Tree;
2705 Parent : @key{in} Cursor;
2706 Before : @key{in} Cursor;
2707 Position : @key{out} Cursor;
2708 Count : @key{in} Count_Type := 1)@Chg{Version=[5],New=[
2709 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Container)
2710 @key{or else raise} Program_Error) @key{and then}
2711 (Parent /= No_Element
2712 @key{or else raise} Constraint_Error) @key{and then}
2713 (Meaningful_For (Container, Parent)
2714 @key{or else raise} Program_Error) @key{and then}
2715 (Meaningful_For (Container, Before)
2716 @key{or else raise} Program_Error) @key{and then}
2717 (Before = No_Element @key{or else}
2718 Container.Parent (Before) = Parent
2719 @key{or else raise} Constraint_Error),
2720 Post => (Node_Count (Container) =
2721 Node_Count (Container)'Old + Count) @key{and then}
2722 Has_Element (Container, Position)],Old=[]};]}
2723 @end{Example}
2724
2725 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0257-1],ARef=[AI05-0262-1],ARef=[AI05-0264-1]}
2726 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2727 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
2728 Parent equals No_Element, then
2729 Constraint_Error is propagated. If Parent does not designate a node in
2730 Container, then Program_Error is propagated. If Before is not equal to
2731 No_Element, and does not designate a node in Container, then Program_Error is
2732 propagated. If Before is not equal to No_Element, and
2733 Parent does not designate the parent node of the node designated by Before,
2734 then Constraint_Error is propagated.
2735 Otherwise, ]}Insert_Child allocates Count nodes, the elements contained in the
2736 new nodes are initialized by default (see @RefSecNum{Object Declarations}),
2737 and the new nodes are inserted as children of Parent. If Parent already has
2738 child nodes, then the new nodes are inserted prior to the node designated by
2739 Before, or, if Before equals No_Element, the new nodes are inserted after the
2740 last existing child node of Parent. Position designates the first
2741 newly-inserted node, or if Count equals 0, then Position is assigned the value
2742 of Before. Any exception raised during allocation of internal storage is
2743 propagated, and Container is not modified.]}
2744
2745 @begin{Example}
2746 @ChgRef{Version=[3],Kind=[AddedNormal]}
2747 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2748 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Prepend_Child (Container : @key{in out} Tree;
2749 Parent : @key{in} Cursor;
2750 New_Item : @key{in} Element_Type;
2751 Count : @key{in} Count_Type := 1)@Chg{Version=[5],New=[
2752 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Container)
2753 @key{or else raise} Program_Error) @key{and then}
2754 (Parent /= No_Element
2755 @key{or else raise} Constraint_Error) @key{and then}
2756 (Meaningful_For (Container, Parent)
2757 @key{or else raise} Program_Error),
2758 Post => Node_Count (Container) =
2759 Node_Count (Container)'Old + Count],Old=[]};]}
2760 @end{Example}
2761
2762 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
2763 @ChgAdded{Version=[3],Type=[Trailing],Text=[Equivalent to Insert_Child
2764 (Container, Parent, First_Child (Container, Parent), New_Item, Count).]}
2765
2766 @begin{Example}
2767 @ChgRef{Version=[3],Kind=[AddedNormal]}
2768 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2769 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Append_Child (Container : @key{in out} Tree;
2770 Parent : @key{in} Cursor;
2771 New_Item : @key{in} Element_Type;
2772 Count : @key{in} Count_Type := 1)@Chg{Version=[5],New=[
2773 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Container)
2774 @key{or else raise} Program_Error) @key{and then}
2775 (Parent /= No_Element
2776 @key{or else raise} Constraint_Error) @key{and then}
2777 (Meaningful_For (Container, Parent)
2778 @key{or else raise} Program_Error),
2779 Post => Node_Count (Container) =
2780 Node_Count (Container)'Old + Count],Old=[]};]}
2781 @end{Example}
2782
2783 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0269-1]}
2784 @ChgAdded{Version=[3],Type=[Trailing],Text=[Equivalent to Insert_Child
2785 (Container, Parent, No_Element, New_Item, Count).]}
2786
2787 @begin{Example}
2788 @ChgRef{Version=[3],Kind=[AddedNormal]}
2789 @ChgRef{Version=[5],Kind=[Revised]}
2790 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Delete_Children (Container : @key{in out} Tree;
2791 Parent : @key{in} Cursor)@Chg{Version=[5],New=[
2792 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Container)
2793 @key{or else raise} Program_Error) @key{and then}
2794 (Parent /= No_Element
2795 @key{or else raise} Constraint_Error) @key{and then}
2796 (Meaningful_For (Container, Parent)
2797 @key{or else raise} Program_Error),
2798 Post => (Node_Count (Container) = Node_Count (Container)'Old -
2799 Child_Count (Container, Parent)'Old) @key{and then}
2800 Child_Count (Container, Parent) = 0],Old=[]};]}
2801 @end{Example}
2802
2803 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
2804 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2805 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
2806 Parent equals No_Element, then
2807 Constraint_Error is propagated. If Parent does not designate a node in
2808 Container, Program_Error is propagated. Otherwise, ]}Delete_Children removes
2809 (from Container) all of the descendants of Parent other than Parent itself.]}
2810
2811 @begin{Discussion}
2812 @ChgRef{Version=[3],Kind=[AddedNormal]}
2813 @ChgAdded{Version=[3],Text=[This routine deletes all of the child subtrees
2814 of Parent at once. Use Delete_Subtree to delete an individual subtree.]}
2815 @end{Discussion}
2816
2817 @begin{Example}
2818 @ChgRef{Version=[3],Kind=[AddedNormal]}
2819 @ChgRef{Version=[5],Kind=[Revised]}
2820 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Copy_Subtree (Target : @key{in out} Tree;
2821 Parent : @key{in} Cursor;
2822 Before : @key{in} Cursor;
2823 Source : @key{in} Cursor)@Chg{Version=[5],New=[
2824 @key{with} Pre => (@key{not} Tampering_With_Cursors_Prohibited (Target)
2825 @key{or else raise} Program_Error) @key{and then}
2826 (Parent /= No_Element
2827 @key{or else raise} Constraint_Error) @key{and then}
2828 (Meaningful_For (Target, Parent)
2829 @key{or else raise} Program_Error) @key{and then}
2830 (Meaningful_For (Target, Before)
2831 @key{or else raise} Program_Error) @key{and then}
2832 (Before = No_Element @key{or else}
2833 Target.Parent (Before) = Parent
2834 @key{or else raise} Constraint_Error) @key{and then}
2835 (@key{not} Is_Root (Source)
2836 @key{or else raise} Constraint_Error),
2837 Post => Node_Count (Target) =
2838 Node_Count (Target)'Old + Subtree_Node_Count (Source),
2839 Global => @key{in all}],Old=[]};]}
2840 @end{Example}
2841
2842 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1]}
2843 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2844 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
2845 Parent equals No_Element, then
2846 Constraint_Error is propagated. If Parent does not designate a node in Target,
2847 then Program_Error is propagated. If Before is not equal to No_Element, and
2848 does not designate a node in Target, then Program_Error is propagated. If
2849 Before is not equal to No_Element, and
2850 Parent does not designate the parent node of the node designated by Before,
2851 then Constraint_Error is propagated. If Source designates a root node,
2852 then Constraint_Error is propagated. ]}If Source is equal to No_Element, then
2853 the operation has no effect. Otherwise, the subtree rooted by Source (which
2854 can be from any tree; it does not have to be a subtree of Target) is copied
2855 (new nodes are allocated to create a new subtree with the same structure as
2856 the Source subtree, with each element initialized from the corresponding
2857 element of the Source subtree) and inserted into Target as a child of Parent.
2858 If Parent already has child nodes, then the new nodes are inserted prior to the
2859 node designated by Before, or, if Before equals No_Element, the new nodes are
2860 inserted after the last existing child node of Parent. The parent of the newly
2861 created subtree is set to Parent, and the overall count of Target is
2862 incremented by Subtree_Node_Count (Source). Any exception raised during allocation
2863 of internal storage is propagated, and Container is not modified.]}
2864
2865 @begin{Discussion}
2866 @ChgRef{Version=[3],Kind=[AddedNormal]}
2867 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
2868 @ChgAdded{Version=[3],Text=[We only need one routine here, as the source
2869 object is not modified, so we can use the same routine for both copying
2870 within and between containers.@Chg{Version=[5],New=[ However, that requires
2871 a contract that allows reading of any container of the correct type, so
2872 we provide two other routines wuth more restrictive contracts.],Old=[]}]}
2873 @end{Discussion}
2874
2875 @begin{Ramification}
2876 @ChgRef{Version=[3],Kind=[AddedNormal]}
2877 @ChgAdded{Version=[3],Text=[We do not allow copying a subtree that includes
2878 a root node, as that would require inserting a node with no value in the
2879 middle of the target tree. To copy an entire tree to another tree object,
2880 use Copy.]}
2881 @end{Ramification}
2882
2883 @begin{Example}
2884 @ChgRef{Version=[5],Kind=[Added]}
2885 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{procedure} Copy_Local_Subtree (Target : @key{in out} Tree;
2886 Parent : @key{in} Cursor;
2887 Before : @key{in} Cursor;
2888 Source : @key{in} Cursor)
2889 @key{with} Pre => (@key{not} Tampering_With_Cursors_Prohibited (Target)
2890 @key{or else raise} Program_Error) @key{and then}
2891 (Parent /= No_Element
2892 @key{or else raise} Constraint_Error) @key{and then}
2893 (Meaningful_For (Target, Parent)
2894 @key{or else raise} Program_Error) @key{and then}
2895 (Meaningful_For (Target, Before)
2896 @key{or else raise} Program_Error) @key{and then}
2897 (Before = No_Element @key{or else}
2898 Target.Parent (Before) = Parent
2899 @key{or else raise} Constraint_Error) @key{and then}
2900 (Meaningful_For (Target, Source)
2901 @key{or else raise} Program_Error) @key{and then}
2902 (@key{not} Is_Root (Source)
2903 @key{or else raise} Constraint_Error),
2904 Post => Node_Count (Target) = Node_Count (Target)'Old +
2905 Subtree_Node_Count (Target, Source);]}
2906 @end{Example}
2907
2908 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
2909 @ChgAdded{Version=[5],Type=[Trailing],Text=[If Source is equal to No_Element, then
2910 the operation has no effect. Otherwise, the subtree rooted by Source in Target
2911 is copied (new nodes are allocated to create a new subtree with the same
2912 structure as the Source subtree, with each element initialized from the
2913 corresponding element of the Source subtree) and inserted into Target as a
2914 child of Parent. If Parent already has child nodes, then the new nodes are
2915 inserted prior to the node designated by Before, or, if Before equals
2916 No_Element, the new nodes are inserted after the last existing child node of
2917 Parent. The parent of the newly created subtree is set to Parent. Any
2918 exception raised during allocation of internal storage is propagated, and
2919 Container is not modified.]}
2920
2921 @begin{Example}
2922 @ChgRef{Version=[5],Kind=[Added]}
2923 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{procedure} Copy_Subtree (Target : @key{in out} Tree;
2924 Parent : @key{in} Cursor;
2925 Before : @key{in} Cursor;
2926 Source : @key{in} Tree;
2927 Subtree : @key{in} Cursor)
2928 @key{with} Pre => (@key{not} Tampering_With_Cursors_Prohibited (Target)
2929 @key{or else raise} Program_Error) @key{and then}
2930 (Parent /= No_Element
2931 @key{or else raise} Constraint_Error) @key{and then}
2932 (Meaningful_For (Target, Parent)
2933 @key{or else raise} Program_Error) @key{and then}
2934 (Meaningful_For (Target, Before)
2935 @key{or else raise} Program_Error) @key{and then}
2936 (Before = No_Element @key{or else}
2937 Target.Parent (Before) = Parent
2938 @key{or else raise} Constraint_Error) @key{and then}
2939 (Meaningful_For (Source, Subtree)
2940 @key{or else raise} Program_Error) @key{and then}
2941 (@key{not} Is_Root (Source, Subtree)
2942 @key{or else raise} Constraint_Error),
2943 Post => Node_Count (Target) = Node_Count (Target)'Old +
2944 Subtree_Node_Count (Source, Subtree);]}
2945 @end{Example}
2946
2947 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
2948 @ChgAdded{Version=[5],Type=[Trailing],Text=[If Subtree is equal to No_Element, then
2949 the operation has no effect. Otherwise, the subtree rooted by Subtree in
2950 Source is copied (new nodes are allocated to create a new subtree with the same
2951 structure as the Subtree, with each element initialized from the
2952 corresponding element of the Subtree) and inserted into Target as a
2953 child of Parent. If Parent already has child nodes, then the new nodes are
2954 inserted prior to the node designated by Before, or, if Before equals
2955 No_Element, the new nodes are inserted after the last existing child node of
2956 Parent. The parent of the newly created subtree is set to Parent. Any
2957 exception raised during allocation of internal storage is propagated, and
2958 Container is not modified.]}
2959
2960 @begin{Example}
2961 @ChgRef{Version=[3],Kind=[AddedNormal]}
2962 @ChgRef{Version=[5],Kind=[Revised]}
2963 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Splice_Subtree (Target : @key{in out} Tree;
2964 Parent : @key{in} Cursor;
2965 Before : @key{in} Cursor;
2966 Source : @key{in out} Tree;
2967 Position : @key{in out} Cursor)@Chg{Version=[5],New=[
2968 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Target)
2969 @key{or else raise} Program_Error) @key{and then}
2970 (@key{not} Tampering_With_Cursors_Prohibited (Source)
2971 @key{or else raise} Program_Error) @key{and then}
2972 (Parent /= No_Element
2973 @key{or else raise} Constraint_Error) @key{and then}
2974 (Meaningful_For (Target, Parent)
2975 @key{or else raise} Program_Error) @key{and then}
2976 (Meaningful_For (Target, Before)
2977 @key{or else raise} Program_Error) @key{and then}
2978 (Before = No_Element @key{or else}
2979 Target.Parent (Before) /= Parent
2980 @key{or else raise} Constraint_Error) @key{and then}
2981 (Position /= No_Element
2982 @key{or else raise} Constraint_Error) @key{and then}
2983 (Has_Element (Source, Position)
2984 @key{or else raise} Program_Error) @key{and then}
2985 (Same_Object (Source, Target) @key{or else}
2986 Position = Before @key{or else}
2987 Is_Ancestor_Of (Target, Position, Parent)
2988 @key{or else raise} Constraint_Error),
2989 Post => (@key{declare}
2990 Org_Sub_Count @key{renames}
2991 Subtree_Node_Count (Source, Position)'Old;
2992 Org_Target_Count @key{renames} Node_Count (Target)'Old;
2993 @key{begin}
2994 (@key{if not} Same_Object (Target, Source) @key{then}
2995 Node_Count (Target) = Org_Target_Count +
2996 Org_Sub_Count @key{and then}
2997 Node_Count (Source) = Node_Count (Source)'Old -
2998 Org_Sub_Count @key{and then}
2999 Has_Element (Target, Position)
3000 @key{else}
3001 Target.Parent (Position) = Parent @key{and then}
3002 Node_Count (Target) = Org_Target_Count))],Old=[]};]}
3003 @end{Example}
3004
3005 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1],ARef=[AI05-0269-1]}
3006 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
3007 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
3008 Parent equals No_Element, then
3009 Constraint_Error is propagated. If Parent does not designate a node in Target,
3010 then Program_Error is propagated. If Before is not equal to No_Element, and
3011 does not designate a node in Target, then Program_Error is propagated. If
3012 Before is not equal to No_Element, and
3013 Parent does not designate the parent node of the node designated by Before,
3014 then Constraint_Error is propagated. If Position equals No_Element,
3015 Constraint_Error is propagated. If Position does not designate a node in
3016 Source or designates a root node, then Program_Error is propagated.
3017 ]}If Source denotes the same object as Target, then:
3018 if Position equals Before there is no effect; @Chg{Version=[5],New=[],Old=[if
3019 Position designates an
3020 ancestor of Parent (including Parent itself), Constraint_Error is propagated;]}
3021 otherwise, the subtree rooted by the element designated by Position is
3022 moved to be a child of Parent. If Parent already has child nodes, then the
3023 moved nodes are inserted prior to the node designated by Before, or, if Before
3024 equals No_Element, the moved nodes are inserted after the last existing child
3025 node of Parent. In each of these cases, Position and the count of Target are
3026 unchanged, and the parent of the element designated by Position is set to
3027 Parent.]}
3028
3029 @begin{Reason}
3030 @ChgRef{Version=[3],Kind=[AddedNormal]}
3031 @ChgAdded{Version=[3],Text=[We can't allow moving the subtree of Position to
3032 a proper descendant node of the subtree, as the descendant node will be part of the
3033 subtree being moved. The result would be a circularly linked tree, or one
3034 with inaccessible nodes. Thus we have to check Position against Parent, even
3035 though such a check is @i<O>(Depth(Source)).]}
3036 @end{Reason}
3037
3038 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
3039 @ChgAdded{Version=[3],Text=[Otherwise (if Source does not denote the same
3040 object as Target), the subtree designated by Position is removed from Source
3041 and moved to Target. The subtree is inserted as a child of Parent. If Parent
3042 already has child nodes, then the moved nodes are inserted prior to the node
3043 designated by Before, or, if Before equals No_Element, the moved nodes are
3044 inserted after the last existing child node of Parent. In each of these cases,
3045 the count of Target is incremented by Subtree_Node_Count (Position), and the
3046 count of Source is decremented by Subtree_Node_Count (Position), Position is
3047 updated to represent an element in Target.]}
3048
3049 @begin{Ramification}
3050 @ChgRef{Version=[3],Kind=[AddedNormal]}
3051 @ChgAdded{Version=[3],Text=[If Source is the same as Target, and Position =
3052 Before, or Next_Sibling(Position) = Before, Splice_Subtree has no effect, as
3053 the subtree does not have to move to meet the postcondition.]}
3054
3055 @ChgRef{Version=[3],Kind=[AddedNormal]}
3056 @ChgAdded{Version=[3],Text=[We do not allow splicing a subtree that includes
3057 a root node, as that would require inserting a node with no value in the
3058 middle of the target tree. Splice the children of the root node instead.]}
3059
3060 @ChgRef{Version=[3],Kind=[AddedNormal]}
3061 @ChgAdded{Version=[3],Text=[For this reason there is no operation to splice
3062 an entire tree, as that would necessarily involve splicing a root node.]}
3063 @end{Ramification}
3064
3065 @begin{Example}
3066 @ChgRef{Version=[3],Kind=[AddedNormal]}
3067 @ChgRef{Version=[5],Kind=[Revised]}
3068 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Splice_Subtree (Container: @key{in out} Tree;
3069 Parent : @key{in} Cursor;
3070 Before : @key{in} Cursor;
3071 Position : @key{in} Cursor)@Chg{Version=[5],New=[
3072 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Container)
3073 @key{or else raise} Program_Error) @key{and then}
3074 (Parent /= No_Element
3075 @key{or else raise} Constraint_Error) @key{and then}
3076 (Meaningful_For (Container, Parent)
3077 @key{or else raise} Program_Error) @key{and then}
3078 (Meaningful_For (Container, Before)
3079 @key{or else raise} Program_Error) @key{and then}
3080 (Before = No_Element @key{or else}
3081 Container.Parent (Before) /= Parent
3082 @key{or else raise} Constraint_Error) @key{and then}
3083 (Position /= No_Element
3084 @key{or else raise} Constraint_Error) @key{and then}
3085 (Has_Element (Container, Position)
3086 @key{or else raise} Program_Error) @key{and then}
3087 (Position = Before @key{or else}
3088 Is_Ancestor_Of (Container, Position, Parent)
3089 @key{or else raise} Constraint_Error),
3090 Post => (Node_Count (Container) =
3091 Node_Count (Container)'Old @key{and then}
3092 Container.Parent (Position) = Parent)],Old=[]};]}
3093 @end{Example}
3094
3095 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1],ARef=[AI05-0269-1]}
3096 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
3097 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
3098 Parent equals No_Element, then
3099 Constraint_Error is propagated. If Parent does not designate a node in
3100 Container, then Program_Error is propagated. If Before is not equal to
3101 No_Element, and does not designate a node in Container, then Program_Error is
3102 propagated. If Before is not equal to No_Element, and
3103 Parent does not designate the parent node of the node designated by Before,
3104 then Constraint_Error is propagated. If Position
3105 equals No_Element, Constraint_Error is propagated. If Position does not
3106 designate a node in Container or designates a root node, then Program_Error is
3107 propagated.]} If Position equals Before, there is no effect.
3108 @Chg{Version=[5],New=[],Old=[If Position
3109 designates an ancestor of Parent (including Parent itself), Constraint_Error is
3110 propagated. ]}Otherwise, the subtree rooted by the element designated by
3111 Position is moved to be a child of Parent. If Parent already has child nodes,
3112 then the moved nodes are inserted prior to the node designated by Before, or,
3113 if Before equals No_Element, the moved nodes are inserted after the last
3114 existing child node of Parent. The parent of the element designated by
3115 Position is set to Parent.]}
3116
3117 @begin{Reason}
3118 @ChgRef{Version=[3],Kind=[AddedNormal]}
3119 @ChgAdded{Version=[3],Text=[We can't allow moving the subtree of Position to
3120 a proper descendant node of the subtree, as the descendant node will be part of the
3121 subtree being moved.]}
3122 @end{Reason}
3123
3124
3125 @begin{Example}
3126 @ChgRef{Version=[3],Kind=[AddedNormal]}
3127 @ChgRef{Version=[5],Kind=[Revised]}
3128 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Splice_Children (Target : @key{in out} Tree;
3129 Target_Parent : @key{in} Cursor;
3130 Before : @key{in} Cursor;
3131 Source : @key{in out} Tree;
3132 Source_Parent : @key{in} Cursor)@Chg{Version=[5],New=[
3133 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Target)
3134 @key{or else raise} Program_Error) @key{and then}
3135 (@key{not} Tampering_With_Cursors_Prohibited (Source)
3136 @key{or else raise} Program_Error) @key{and then}
3137 (Target_Parent /= No_Element
3138 @key{or else raise} Constraint_Error) @key{and then}
3139 (Meaningful_For (Target, Target_Parent)
3140 @key{or else raise} Program_Error) @key{and then}
3141 (Meaningful_For (Target, Before)
3142 @key{or else raise} Program_Error) @key{and then}
3143 (Source_Parent /= No_Element
3144 @key{or else raise} Constraint_Error) @key{and then}
3145 (Meaningful_For (Source, Source_Parent)
3146 @key{or else raise} Program_Error) @key{and then}
3147 (Before = No_Element @key{or else}
3148 Parent (Target, Before) /= Target_Parent
3149 @key{or else raise} Constraint_Error) @key{and then}
3150 (Same_Object (Target, Source) @key{or else}
3151 Target_Parent = Source_Parent @key{or else}
3152 Is_Ancestor_Of (Target, Source_Parent, Target_Parent)
3153 @key{or else raise} Constraint_Error),
3154 Post => (@key{declare}
3155 Org_Child_Count @key{renames}
3156 Child_Count (Source, Source_Parent)'Old;
3157 Org_Target_Count @key{renames} Node_Count (Target)'Old;
3158 @key{begin}
3159 (@key{if not} Same_Object (Target, Source) @key{then}
3160 Node_Count (Target) = Org_Target_Count +
3161 Org_Child_Count @key{and then}
3162 Node_Count (Source) = Node_Count (Source)'Old -
3163 Org_Child_Count
3164 @key{else}
3165 Node_Count (Target) = Org_Target_Count))],Old=[]};]}
3166 @end{Example}
3167
3168 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0262-1]}
3169 @ChgRef{Version=[5],Kind=[Deleted],ARef=[AI12-0112-1]}
3170 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
3171 Target_Parent equals
3172 No_Element, then Constraint_Error is propagated. If Target_Parent does not
3173 designate a node in Target, then Program_Error is propagated. If Before is not
3174 equal to No_Element, and does not designate an element in Target, then
3175 Program_Error is propagated. If Source_Parent equals No_Element, then
3176 Constraint_Error is propagated. If Source_Parent does not designate a node in
3177 Source, then Program_Error is propagated. If Before is not equal to
3178 No_Element, and Target_Parent does not designate the parent node of the
3179 node designated by Before, then Constraint_Error is propagated.]}]}
3180
3181 @ChgRef{Version=[3],Kind=[AddedNormal]}
3182 @ChgAdded{Version=[3],Type=[Leading],Text=[If Source denotes the same object as Target, then:]}
3183
3184 @begin{Itemize}
3185 @ChgRef{Version=[3],Kind=[AddedNormal]}
3186 @ChgAdded{Version=[3],Text=[if Target_Parent equals Source_Parent there is
3187 no effect; else]}
3188
3189 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0269-1]}
3190 @ChgRef{Version=[5],Kind=[Deleted],ARef=[AI12-0112-1]}
3191 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[if Source_Parent
3192 is an ancestor of Target_Parent other than Target_Parent itself, then
3193 Constraint_Error is propagated; else]}]}
3194
3195 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0269-1]}
3196 @ChgAdded{Version=[3],Text=[the child elements (and the further descendants) of
3197 Source_Parent are moved to be child elements of Target_Parent. If
3198 Target_Parent already has child elements, then the moved elements are
3199 inserted prior to the node designated by Before, or, if Before equals
3200 No_Element, the moved elements are inserted after the last existing child
3201 node of Target_Parent. The parent of each moved child element is set to
3202 Target_Parent.]}
3203 @end{Itemize}
3204
3205 @begin{Reason}
3206 @ChgRef{Version=[3],Kind=[AddedNormal]}
3207 @ChgAdded{Version=[3],Text=[We can't allow moving the children of
3208 Source_Parent to a proper descendant node, as the descendant node will be
3209 part of one of the subtrees being moved.]}
3210 @end{Reason}
3211
3212 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0269-1]}
3213 @ChgAdded{Version=[3],Text=[Otherwise (if Source does not denote the same
3214 object as Target), the child elements (and the further descendants) of Source_Parent
3215 are removed from Source and moved to Target. The child elements are inserted
3216 as children of Target_Parent. If Target_Parent already has child elements, then
3217 the moved elements are inserted prior to the node designated by Before, or, if
3218 Before equals No_Element, the moved elements are inserted after the last
3219 existing child node of Target_Parent. In each of these cases, the overall
3220 count of Target is incremented by Subtree_Node_Count (Source_Parent)-1, and
3221 the overall count of Source is decremented by Subtree_Node_Count
3222 (Source_Parent)-1.]}
3223
3224 @begin{Ramification}
3225 @ChgRef{Version=[3],Kind=[AddedNormal]}
3226 @ChgAdded{Version=[3],Text=[The node designated by Source_Parent is not
3227 moved, thus we never need to update Source_Parent.]}
3228
3229 @ChgRef{Version=[3],Kind=[AddedNormal]}
3230 @ChgAdded{Version=[3],Text=[Move (Target, Source) could be written
3231 Splice_Children (Target, Target.Root, No_Element, Source, Source.Root);]}
3232 @end{Ramification}
3233
3234 @begin{Example}
3235 @ChgRef{Version=[3],Kind=[AddedNormal]}
3236 @ChgRef{Version=[5],Kind=[Revised]}
3237 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Splice_Children (Container : @key{in out} Tree;
3238 Target_Parent : @key{in} Cursor;
3239 Before : @key{in} Cursor;
3240 Source_Parent : @key{in} Cursor)@Chg{Version=[5],New=[
3241 @key{with} Pre =>(@key{not} Tampering_With_Cursors_Prohibited (Container)
3242 @key{or else raise} Program_Error) @key{and then}
3243 (Target_Parent /= No_Element
3244 @key{or else raise} Constraint_Error) @key{and then}
3245 (Meaningful_For (Container, Target_Parent)
3246 @key{or else raise} Program_Error) @key{and then}
3247 (Meaningful_For (Container, Before)
3248 @key{or else raise} Program_Error) @key{and then}
3249 (Source_Parent /= No_Element
3250 @key{or else raise} Constraint_Error) @key{and then}
3251 (Meaningful_For (Container, Source_Parent)
3252 @key{or else raise} Program_Error) @key{and then}
3253 (Before = No_Element @key{or else}
3254 Parent (Container, Before) /= Target_Parent
3255 @key{or else raise} Constraint_Error) @key{and then}
3256 (Target_Parent = Source_Parent @key{or else}
3257 Is_Ancestor_Of (Container, Source_Parent, Target_Parent)
3258 @key{or else raise} Constraint_Error),
3259 Post => Node_Count (Container) = Node_Count (Container)'Old],Old=[]};]}
3260 @end{Example}
3261
3262 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1],ARef=[AI05-0264-1],ARef=[AI05-0269-1]}
3263 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
3264 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
3265 Target_Parent equals
3266 No_Element, then Constraint_Error is propagated. If Target_Parent does not
3267 designate a node in Container, then Program_Error is propagated. If Before is
3268 not equal to No_Element, and does not designate an element in Container, then
3269 Program_Error is propagated. If Source_Parent equals No_Element, then
3270 Constraint_Error is propagated. If Source_Parent does not designate a node in
3271 Container, then Program_Error is propagated. If Before is not equal to
3272 No_Element, and Target_Parent does not designate the parent node of the
3273 node designated by Before, then Constraint_Error is propagated.]}
3274 If Target_Parent equals Source_Parent there is
3275 no effect. @Chg{Version=[5],New=[],Old=[If Source_Parent is an ancestor
3276 of Target_Parent other than Target_Parent itself, then
3277 Constraint_Error is propagated. ]}Otherwise, the child elements (and the further
3278 descendants) of Source_Parent are moved to be child elements of Target_Parent.
3279 If Target_Parent already has child elements, then the moved elements are
3280 inserted prior to the node designated by Before, or, if Before equals
3281 No_Element, the moved elements are inserted after the last existing child node
3282 of Target_Parent. The parent of each moved child element is set to
3283 Target_Parent.]}
3284
3285 @begin{Example}
3286 @ChgRef{Version=[3],Kind=[AddedNormal]}
3287 @ChgRef{Version=[5],Kind=[Revised]}
3288 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Parent (Position : Cursor) @key{return} Cursor@Chg{Version=[5],New=[
3289 @key{with} Nonblocking, Global => (@key{in all}, @key{use null}),
3290 Post => (@key{if} Position = No_Element @key{or else}
3291 Is_Root (Position) @key{then} Parent'Result = No_Element
3292 @key{else} True)],Old=[]};]}
3293 @end{Example}
3294
3295 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
3296 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
3297 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[Returns],Old=[If
3298 Position is equal to No_Element
3299 or designates a root node, No_Element is returned. Otherwise,]} a cursor
3300 designating the parent node of the node designated by
3301 Position@Chg{Version=[5],New=[],Old=[ is returned]}.]}
3302
3303 @begin{Example}
3304 @ChgRef{Version=[5],Kind=[Added]}
3305 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Parent (Container : Tree;
3306 Position : Cursor) @key{return} Cursor
3307 @key{with} Nonblocking, Global => (@key{null}, @key{use null}),
3308 Pre => Meaningful_For (Container, Position) @key{or else raise} Program_Error,
3309 Post => (@key{if} Position = No_Element @key{or else}
3310 Is_Root (Container, Position)
3311 @key{then} Parent'Result = No_Element
3312 @key{else} Has_Element (Container, Parent'Result));]}
3313 @end{Example}
3314
3315 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
3316 @ChgAdded{Version=[5],Type=[Trailing],Text=[Returns a cursor
3317 designating the parent node of the node designated by
3318 Position in Container.]}
3319
3320 @begin{Example}
3321 @ChgRef{Version=[3],Kind=[AddedNormal]}
3322 @ChgRef{Version=[5],Kind=[Revised]}
3323 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} First_Child (Parent : Cursor) @key{return} Cursor@Chg{Version=[5],New=[
3324 @key{with} Nonblocking, Global => (@key{in all}, @key{use null}),
3325 Pre => Parent /= No_Element @key{or else raise} Constraint_Error],Old=[]};]}
3326 @end{Example}
3327
3328 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
3329 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
3330 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
3331 Parent is equal to No_Element,
3332 then Constraint_Error is propagated. Otherwise, ]}First_Child returns a cursor
3333 designating the first child node of the node designated by Parent; if there is
3334 no such node, No_Element is returned.]}
3335
3336 @begin{Example}
3337 @ChgRef{Version=[5],Kind=[Added]}
3338 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} First_Child (Container : Tree;
3339 Parent : Cursor) @key{return} Cursor
3340 @key{with} Nonblocking, Global => (@key{null}, @key{use null}),
3341 Pre => (Parent /= No_Element
3342 @key{or else raise} Constraint_Error) @key{and then}
3343 (Meaningful_For (Container, Parent)
3344 @key{or else raise} Program_Error),
3345 Post => First_Child'Result = No_Element @key{or else}
3346 Has_Element (Container, First_Child'Result);]}
3347 @end{Example}
3348
3349 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
3350 @ChgAdded{Version=[5],Type=[Trailing],Text=[First_Child returns a cursor
3351 designating the first child node of the node designated by Parent in Container;
3352 if there is no such node, No_Element is returned.]}
3353
3354 @begin{Example}
3355 @ChgRef{Version=[3],Kind=[AddedNormal]}
3356 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
3357 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} First_Child_Element (Parent : Cursor) @key{return} Element_Type@Chg{Version=[5],New=[
3358 @key{with} Nonblocking => Element_Type'Nonblocking,
3359 Global => (@key{in all}, @key{use} Element_Type),
3360 Pre => (Parent /= No_Element @key{and then}
3361 Last_Child (Parent) /= No_Element)
3362 @key{or else raise} Constraint_Error],Old=[]};]}
3363 @end{Example}
3364
3365 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
3366 @ChgAdded{Version=[3],Type=[Trailing],Text=[Equivalent to Element (First_Child (Parent)).]}
3367
3368 @begin{Example}
3369 @ChgRef{Version=[5],Kind=[Added]}
3370 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} First_Child_Element (Container : Tree;
3371 Parent : Cursor) @key{return} Element_Type
3372 @key{with} Nonblocking => Element_Type'Nonblocking,
3373 Global => (@key{null}, @key{use} Element_Type),
3374 Pre => (Parent /= No_Element
3375 @key{or else raise} Constraint_Error) @key{and then}
3376 (Meaningful_For (Container, Parent)
3377 @key{or else raise} Program_Error) @key{and then}
3378 (First_Child (Container, Parent) /= No_Element
3379 @key{or else raise} Constraint_Error);]}
3380 @end{Example}
3381
3382 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
3383 @ChgAdded{Version=[5],Type=[Trailing],Text=[Equivalent to
3384 Element (Container, First_Child (Container, Parent)).]}
3385
3386 @begin{Example}
3387 @ChgRef{Version=[3],Kind=[AddedNormal]}
3388 @ChgRef{Version=[5],Kind=[Revised]}
3389 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Last_Child (Parent : Cursor) @key{return} Cursor@Chg{Version=[5],New=[
3390 @key{with} Nonblocking, Global => (@key{in all}, @key{use null}),
3391 Pre => Parent /= No_Element @key{or else raise} Constraint_Error],Old=[]};]}
3392 @end{Example}
3393
3394 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
3395 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
3396 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
3397 Parent is equal to No_Element,
3398 then Constraint_Error is propagated. Otherwise, ]}Last_Child returns a cursor
3399 designating the last child node of the node designated by Parent; if there is
3400 no such node, No_Element is returned.]}
3401
3402 @begin{Example}
3403 @ChgRef{Version=[5],Kind=[Added]}
3404 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Last_Child (Container : Tree;
3405 Parent : Cursor) @key{return} Cursor
3406 @key{with} Nonblocking, Global => (@key{null}, @key{use null}),
3407 Pre => (Parent /= No_Element
3408 @key{or else raise} Constraint_Error) @key{and then}
3409 (Meaningful_For (Container, Parent)
3410 @key{or else raise} Program_Error),
3411 Post => Last_Child'Result = No_Element @key{or else}
3412 Has_Element (Container, Last_Child'Result);]}
3413 @end{Example}
3414
3415 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
3416 @ChgAdded{Version=[5],Type=[Trailing],Text=[Last_Child returns a cursor
3417 designating the last child node of the node designated by Parent in Container;
3418 if there is no such node, No_Element is returned.]}
3419
3420 @begin{Example}
3421 @ChgRef{Version=[3],Kind=[AddedNormal]}
3422 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
3423 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Last_Child_Element (Parent : Cursor) @key{return} Element_Type@Chg{Version=[5],New=[
3424 @key{with} Nonblocking => Element_Type'Nonblocking,
3425 Global => (@key{in all}, @key{use} Element_Type),
3426 Pre => (Parent /= No_Element @key{and then}
3427 Last_Child (Parent) /= No_Element)
3428 @key{or else raise} Constraint_Error],Old=[]};]}
3429 @end{Example}
3430
3431 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
3432 @ChgAdded{Version=[3],Type=[Trailing],Text=[Equivalent to Element (Last_Child (Parent)).]}
3433
3434 @begin{Example}
3435 @ChgRef{Version=[5],Kind=[Added]}
3436 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Last_Child_Element (Container : Tree;
3437 Parent : Cursor) @key{return} Element_Type
3438 @key{with} Nonblocking => Element_Type'Nonblocking,
3439 Global => (@key{null}, @key{use} Element_Type),
3440 Pre => (Parent /= No_Element
3441 @key{or else raise} Constraint_Error) @key{and then}
3442 (Meaningful_For (Container, Parent)
3443 @key{or else raise} Program_Error) @key{and then}
3444 (Last_Child (Container, Parent) /= No_Element
3445 @key{or else raise} Constraint_Error);]}
3446 @end{Example}
3447
3448 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
3449 @ChgAdded{Version=[5],Type=[Trailing],Text=[Equivalent to
3450 Element (Container, Last_Child (Container, Parent)).]}
3451
3452 @begin{Example}
3453 @ChgRef{Version=[3],Kind=[AddedNormal]}
3454 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
3455 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Next_Sibling (Position : Cursor) @key{return} Cursor@Chg{Version=[5],New=[
3456 @key{with} Nonblocking, Global => (@key{in all}, @key{use null}),
3457 Post => (@key{if} Position = No_Element
3458 @key{then} Next_Sibling'Result = No_Element
3459 @key{else} True)],Old=[]};]}
3460 @end{Example}
3461
3462 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
3463 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position equals No_Element or
3464 designates the last child node of its parent, then Next_Sibling returns the
3465 value No_Element. Otherwise, it returns a cursor that designates the successor
3466 (with the same parent) of the node designated by Position.]}
3467
3468 @begin{Example}
3469 @ChgRef{Version=[5],Kind=[Added]}
3470 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Next_Sibling (Container : Tree;
3471 Position : Cursor) @key{return} Cursor
3472 @key{with} Nonblocking, Global => (@key{null}, @key{use null}),
3473 Pre => Meaningful_For (Container, Position)
3474 @key{or else raise} Program_Error,
3475 Post => (@key{if} Next_Sibling'Result = No_Element @key{then}
3476 Position = No_Element @key{or else}
3477 Is_Root (Container, Position) @key{or else}
3478 Last_Child (Container, Parent (Container, Position))
3479 = Position
3480 @key{else} Has_Element (Container, Next_Sibling'Result));]}
3481 @end{Example}
3482
3483 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
3484 @ChgAdded{Version=[5],Type=[Trailing],Text=[Next_Sibling returns a cursor that
3485 designates the successor (with the same parent) of the node designated by
3486 Position in Container.]}
3487
3488 @begin{Example}
3489 @ChgRef{Version=[3],Kind=[AddedNormal]}
3490 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
3491 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Previous_Sibling (Position : @key{in out} Cursor)@Chg{Version=[5],New=[
3492 @key{with} Nonblocking, Global => (@key{in all}, @key{use null}),
3493 Post => (@key{if} Position = No_Element
3494 @key{then} Previous_Sibling'Result = No_Element
3495 @key{else} True)],Old=[]};]}
3496 @end{Example}
3497
3498 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
3499 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position equals No_Element or
3500 designates the first child node of its parent, then Previous_Sibling returns
3501 the value No_Element. Otherwise, it returns a cursor that designates the
3502 predecessor (with the same parent) of the node designated by Position.]}
3503
3504 @begin{Example}
3505 @ChgRef{Version=[5],Kind=[Added]}
3506 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Previous_Sibling (Container : Tree;
3507 Position : Cursor) @key{return} Cursor
3508 @key{with} Nonblocking, Global => (@key{null}, @key{use null}),
3509 Pre => Meaningful_For (Container, Position)
3510 @key{or else raise} Program_Error,
3511 Post => (@key{if} Previous_Sibling'Result = No_Element @key{then}
3512 Position = No_Element @key{or else}
3513 Is_Root (Container, Position) @key{or else}
3514 First_Child (Container, Parent (Container, Position))
3515 = Position
3516 @key{else} Has_Element (Container, Previous_Sibling'Result));]}
3517 @end{Example}
3518
3519 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
3520 @ChgAdded{Version=[5],Type=[Trailing],Text=[Previous_Sibling returns a cursor
3521 that designates the predecessor (with the same parent) of the node designated
3522 by Position in Container.]}
3523
3524 @begin{Example}
3525 @ChgRef{Version=[3],Kind=[AddedNormal]}
3526 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
3527 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Next_Sibling (Position : @key{in out} Cursor)@Chg{Version=[5],New=[
3528 @key{with} Nonblocking, Global => (@key{in all}, @key{use null})],Old=[]};]}
3529 @end{Example}
3530
3531 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
3532 @ChgAdded{Version=[3],Type=[Trailing],Text=[Equivalent to Position := Next_Sibling (Position);]}
3533
3534 @begin{Example}
3535 @ChgRef{Version=[5],Kind=[Added]}
3536 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{procedure} Next_Sibling (Container : @key{in} Tree;
3537 Position : @key{in out} Cursor)
3538 @key{with} Nonblocking, Global => (@key{null}, @key{use null}),
3539 Pre => Meaningful_For (Container, Position)
3540 @key{or else raise} Program_Error,
3541 Post => (@key{if} Position /= No_Element
3542 @key{then} Has_Element (Container, Position));]}
3543 @end{Example}
3544
3545 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
3546 @ChgAdded{Version=[5],Type=[Trailing],Text=[Equivalent to Position := Next_Sibling (Container, Position);]}
3547
3548 @begin{Example}
3549 @ChgRef{Version=[3],Kind=[AddedNormal]}
3550 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
3551 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Previous_Sibling (Position : @key{in out} Cursor)@Chg{Version=[5],New=[
3552 @key{with} Nonblocking, Global => (@key{in all}, @key{use null})],Old=[]};]}
3553 @end{Example}
3554
3555 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
3556 @ChgAdded{Version=[3],Type=[Trailing],Text=[Equivalent to Position := Previous_Sibling (Position);]}
3557
3558 @begin{Example}
3559 @ChgRef{Version=[5],Kind=[Added]}
3560 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{procedure} Previous_Sibling (Container : @key{in} Tree;
3561 Position : @key{in out} Cursor)
3562 @key{with} Nonblocking, Global => (@key{null}, @key{use null}),
3563 Pre => Meaningful_For (Container, Position)
3564 @key{or else raise} Program_Error,
3565 Post => (@key{if} Position /= No_Element
3566 @key{then} Has_Element (Container, Position);]}
3567 @end{Example}
3568
3569 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
3570 @ChgAdded{Version=[5],Type=[Trailing],Text=[Equivalent to Position := Previous_Sibling (Container, Position);]}
3571
3572 @begin{Example}
3573 @ChgRef{Version=[3],Kind=[AddedNormal]}
3574 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
3575 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Iterate_Children
3576 (Parent : @key{in} Cursor;
3577 Process : @key{not null access procedure} (Position : @key{in} Cursor))@Chg{Version=[5],New=[
3578 @key{with} Allows_Exit,
3579 Pre => Parent /= No_Element @key{or else raise} Constraint_Error,
3580 Global => (@key{in all}, @key{use null})],Old=[]};]}
3581 @end{Example}
3582
3583 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
3584 @ChgRef{Version=[5],Kind=[Deleted],ARef=[AI12-0112-1]}
3585 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
3586 Parent equals No_Element, then Constraint_Error is propagated.]}]}
3587
3588 @ChgRef{Version=[3],Kind=[AddedNormal]}
3589 @ChgAdded{Version=[3],Text=[Iterate_Children calls Process.@key{all} with a
3590 cursor that designates each child node of Parent, starting with the first child
3591 node and moving the cursor as per the Next_Sibling function.]}
3592
3593 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
3594 @ChgAdded{Version=[3],Text=[Tampering with the cursors of the tree containing
3595 Parent is prohibited during the execution of a call on Process.@key{all}.
3596 Any exception raised by Process.@key{all} is propagated.]}
3597
3598 @begin{Example}
3599 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
3600 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{procedure} Iterate_Children
3601 (Container : @key{in} Tree;
3602 Parent : @key{in} Cursor;
3603 Process : @key{not null access procedure} (Position : @key{in} Cursor))
3604 @key{with} Allows_Exit,
3605 Pre => (Parent /= No_Element
3606 @key{or else raise} Constraint_Error) @key{and then}
3607 (Meaningful_For (Container, Parent)
3608 @key{or else raise} Program_Error);]}
3609 @end{Example}
3610
3611 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
3612 @ChgAdded{Version=[5],Text=[Iterate_Children calls Process.@key{all} with a
3613 cursor that designates each child node of Container and Parent, starting with
3614 the first child node and moving the cursor as per the Next_Sibling function.]}
3615
3616 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
3617 @ChgAdded{Version=[5],Text=[Tampering with the cursors of the tree containing
3618 Parent is prohibited during the execution of a call on Process.@key{all}.
3619 Any exception raised by Process.@key{all} is propagated.]}
3620
3621 @begin{Example}
3622 @ChgRef{Version=[3],Kind=[AddedNormal]}
3623 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
3624 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Reverse_Iterate_Children
3625 (Parent : @key{in} Cursor;
3626 Process : @key{not null access procedure} (Position : @key{in} Cursor))@Chg{Version=[5],New=[
3627 @key{with} Allows_Exit,
3628 Pre => Parent /= No_Element @key{or else raise} Constraint_Error,
3629 Global => (@key{in all}, @key{use null})],Old=[]};]}
3630 @end{Example}
3631
3632 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
3633 @ChgRef{Version=[5],Kind=[Deleted],ARef=[AI12-0112-1]}
3634 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
3635 Parent equals No_Element, then Constraint_Error is propagated.]}]}
3636
3637 @ChgRef{Version=[3],Kind=[AddedNormal]}
3638 @ChgAdded{Version=[3],Text=[Reverse_Iterate_Children calls Process.@key{all}
3639 with a cursor that designates each child node of Parent, starting with the last
3640 child node and moving the cursor as per the Previous_Sibling function.]}
3641
3642 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
3643 @ChgAdded{Version=[3],Text=[Tampering with the cursors of the tree containing
3644 Parent is prohibited during the execution of a call on Process.@key{all}.
3645 Any exception raised by Process.@key{all} is propagated.]}
3646
3647 @begin{Example}
3648 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
3649 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{procedure} Reverse_Iterate_Children
3650 (Container : @key{in} Tree;
3651 Parent : @key{in} Cursor;
3652 Process : @key{not null access procedure} (Position : @key{in} Cursor))
3653 @key{with} Allows_Exit,
3654 Pre => (Parent /= No_Element
3655 @key{or else raise} Constraint_Error) @key{and then}
3656 (Meaningful_For (Container, Parent)
3657 @key{or else raise} Program_Error);]}
3658 @end{Example}
3659
3660 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
3661 @ChgAdded{Version=[5],Text=[Reverse_Iterate_Children calls Process.@key{all} with a
3662 cursor that designates each child node of Container and Parent, starting with
3663 the last child node and moving the cursor as per the Previous_Sibling
3664 function.]}
3665
3666 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
3667 @ChgAdded{Version=[5],Text=[Tampering with the cursors of the tree containing
3668 Parent is prohibited during the execution of a call on Process.@key{all}.
3669 Any exception raised by Process.@key{all} is propagated.]}
3670
3671 @begin{Example}
3672 @ChgRef{Version=[3],Kind=[AddedNormal]}
3673 @ChgRef{Version=[5],Kind=[Revised]}
3674 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Iterate_Children (Container : @key{in} Tree; Parent : @key{in} Cursor)
3675 @key{return} Tree_Iterator_Interfaces.@Chg{Version=[5],New=[Parallel_Reversible_Iterator],Old=[Reversible_Iterator]}'Class@Chg{Version=[5],New=[
3676 @key{with} Pre => (Parent /= No_Element
3677 @key{or else raise} Constraint_Error) @key{and then}
3678 (Meaningful_For (Container, Parent)
3679 @key{or else raise} Program_Error),
3680 Post => Tampering_With_Cursors_Prohibited (Container)],Old=[]};]}
3681 @end{Example}
3682
3683 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0265-1]}
3684 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1],ARef=[AI12-0266-1]}
3685 @ChgAdded{Version=[3],Type=[Trailing],Text=[Iterate_Children returns
3686 @Chg{Version=[5],New=[an],Old=[a reversible]} iterator object
3687 (see @RefSecNum{User-Defined Iterator Types}) that will generate
3688 a value for a loop parameter (see @RefSecNum{Generalized Loop Iteration})
3689 designating each child node of Parent. @Chg{Version=[5],New=[When],Old=[If
3690 Parent equals No_Element, then
3691 Constraint_Error is propagated. If Parent does not designate a node in
3692 Container, then Program_Error is propagated. Otherwise, when]} used as a forward
3693 iterator, the nodes are designated starting with the first child node and moving
3694 the cursor as per the function Next_Sibling; when used as a reverse iterator,
3695 the nodes are designated starting with the last child node and moving the cursor
3696 as per the function Previous_Sibling@Chg{Version=[5],New=[; when used as a
3697 parallel iterator, processing all child nodes concurrently],Old=[]}.
3698 Tampering with the cursors of Container is
3699 prohibited while the iterator object exists (in particular, in the
3700 @nt{sequence_of_statements} of the @nt{loop_statement} whose
3701 @nt{iterator_specification} denotes this object). The iterator object needs
3702 finalization.]}
3703
3704 @end{DescribeCode}
3705
3706 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0111-1]}
3707 @ChgAdded{Version=[5],Text=[The nested package Multiway_Trees.Stable
3708 provides a type Stable.tree that represents
3709 a @i<stable> tree,@Defn2{Term=(stable),Sec=(tree)} which is one that
3710 cannot grow and shrink. Such a tree can be created by calling the
3711 Copy function, or by establishing a
3712 @i<stabilized view> of a regular tree.@Defn2{Term=[stabilized view],Sec=[tree]}]}
3713
3714 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0111-1]}
3715 @ChgAdded{Version=[5],Type=[Leading],Text=[The subprograms of package
3716 Containers.Multiway_Trees that have a parameter or result of type tree
3717 are included in the nested package Stable with the same specification, except
3718 that the following are omitted:]}
3719
3720 @begin{Indent}
3721 @ChgRef{Version=[5],Kind=[Added]}
3722 @ChgAdded{Version=[5],Text=[Tampering_With_Cursors_Prohibited,
3723 Tampering_With_Elements_Prohibited, Assign, Move,
3724 Clear, Delete_Leaf, Insert_Child, Delete_Children, Delete_Subtree,
3725 Copy_Subtree, Copy_Local_Subtree, Splice_Subtree, and Splice_Children]}
3726 @end{Indent}
3727
3728 @begin{Ramification}
3729 @ChgRef{Version=[5],Kind=[Added]}
3730 @ChgAdded{Version=[5],Text=[The names Tree and Cursor mean the types
3731 declared in the nested package in these subprogram specifications.]}
3732 @end{Ramification}
3733 @begin{Reason}
3734 @ChgRef{Version=[5],Kind=[Added]}
3735 @ChgAdded{Version=[5],Text=[The omitted routines are those that tamper with
3736 cursors or elements (or test that state). The model is that it is
3737 impossible to tamper with cursors or elements of a stable view since no
3738 such operations are included. Thus tampering checks are not needed for
3739 a stable view, and we omit the operations associated with those checks.]}
3740 @end{Reason}
3741
3742 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0111-1]}
3743 @ChgAdded{Version=[5],Text=[The operations of this package are equivalent
3744 to those for regular trees, except that the calls to
3745 Tampering_With_Cursors_Prohibited and
3746 Tampering_With_Elements_Prohibited that occur in preconditions are replaced
3747 by False, and any that occur in postconditions are replaced by True.]}
3748
3749 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0111-1]}
3750 @ChgAdded{Version=[5],Text=[If a stable tree is declared with the Base
3751 discriminant designating a pre-existing regular tree, the stable tree
3752 represents a stabilized view of the underlying regular tree, and any operation
3753 on the stable tree is reflected on the underlying regular tree. While a
3754 stabilized view exists, any operation that tampers with elements performed on
3755 the underlying tree is prohibited. The finalization of a stable tree that
3756 provides such a view removes this restriction on the underlying regular tree
3757 @Redundant[(though some other restriction might exist due to other concurrent
3758 iterations or stabilized views)].]}
3759
3760 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0111-1]}
3761 @ChgAdded{Version=[5],Text=[If a stable tree is declared without specifying
3762 Base, the object must be initialized. The initializing expression of the stable
3763 tree, @Redundant[typically a call on Copy], determines the Node_Count
3764 of the tree. The Node_Count of a stable tree never changes after
3765 initialization.]}
3766
3767 @end{StaticSem}
3768
3769 @begin{Bounded}
3770
3771 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
3772 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
3773 It is a bounded error for the actual function associated with a generic formal
3774 subprogram, when called as part of an operation of this package, to tamper with
3775 elements of any Tree parameter of the operation. Either Program_Error is raised,
3776 or the operation works as defined on the value of the Tree either prior to, or
3777 subsequent to, some or all of the modifications to the
3778 Tree.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}]}
3779
3780 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
3781 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
3782 It is a bounded error to call any subprogram declared in the visible part of
3783 Containers.Multiway_Trees when the associated container has been finalized. If
3784 the operation takes Container as an @key[in out] parameter, then it raises
3785 Constraint_Error or Program_Error. Otherwise, the operation either proceeds as
3786 it would for an empty container, or it raises
3787 Constraint_Error@Defn2{Term=[Constraint_Error],Sec=(raised by detection of a bounded error)}
3788 or Program_Error.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}]}
3789 @end{Bounded}
3790
3791 @begin{Erron}
3792 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
3793 @ChgAdded{Version=[3],Type=[Leading],Keepnext=[T],Text=[A Cursor
3794 value is @i<invalid> if any of the following have occurred since
3795 it was created:@Defn2{Term=[invalid cursor],Sec=[of a tree]}
3796 @PDefn2{Term=[cursor],Sec=[invalid]}]}
3797 @begin{Itemize}
3798
3799 @ChgRef{Version=[3],Kind=[AddedNormal]}
3800 @ChgAdded{Version=[3],Text=[The tree that contains the element it designates has
3801 been finalized;]}
3802
3803 @ChgRef{Version=[3],Kind=[AddedNormal]}
3804 @ChgAdded{Version=[3],Text=[The tree that contains the element it designates has
3805 been used as the Source or Target of a call to Move;]}
3806
3807 @ChgRef{Version=[3],Kind=[AddedNormal]}
3808 @ChgAdded{Version=[3],Text=[The tree that contains the element it designates has
3809 been used as the Target of a call to Assign or the target of an
3810 @nt{assignment_statement};]}
3811
3812 @ChgRef{Version=[3],Kind=[AddedNormal]}
3813 @ChgAdded{Version=[3],Text=[The element it designates has been removed from the
3814 tree that previously contained the element.]}
3815 @begin{Reason}
3816 @ChgRef{Version=[3],Kind=[AddedNormal]}
3817 @ChgAdded{Version=[3],Text=[We talk about which tree the element was removed
3818 from in order to handle splicing nodes from one tree to another. The node
3819 still exists, but any cursors that designate it in the original tree are now
3820 invalid. This bullet covers removals caused by calls to Clear, Delete_Leaf,
3821 Delete_Subtree, Delete_Children, Splice_Children, and Splice_Subtree.]}
3822 @end{Reason}
3823
3824 @end{Itemize}
3825
3826 @ChgRef{Version=[3],Kind=[AddedNormal]}
3827 @ChgAdded{Version=[3],Text=[The result of "=" or Has_Element is unspecified if
3828 it is called with an invalid cursor parameter.@PDefn{unspecified} Execution is
3829 erroneous if any other subprogram declared in Containers.Multiway_Trees is
3830 called with an invalid cursor parameter.]}
3831
3832 @begin{Discussion}
3833 @ChgRef{Version=[3],Kind=[AddedNormal]}
3834 @ChgAdded{Version=[3],Text=[The list above is intended to be exhaustive. In
3835 other cases, a cursor value continues to designate its original element (or
3836 the root node). For instance, cursor values survive the insertion and deletion
3837 of other nodes.]}
3838
3839 @ChgRef{Version=[3],Kind=[AddedNormal]}
3840 @ChgAdded{Version=[3],Text=[While it is possible to check for these cases, in
3841 many cases the overhead necessary to make the check is substantial in time or
3842 space. Implementations are encouraged to check for as many of these cases as
3843 possible and raise Program_Error if detected.]}
3844 @end{Discussion}
3845
3846 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
3847 @ChgAdded{Version=[3],Text=[Execution is erroneous if the tree associated with
3848 the result of a call to Reference or Constant_Reference is finalized before the
3849 result object returned by the call to Reference or Constant_Reference is
3850 finalized.]}
3851 @begin{Reason}
3852 @ChgRef{Version=[3],Kind=[AddedNormal]}
3853 @ChgAdded{Version=[3],Text=[Each object of Reference_Type and
3854 Constant_Reference_Type probably contains some reference to the originating
3855 container. If that container is prematurely finalized (which is only possible
3856 via Unchecked_Deallocation, as accessibility checks prevent passing a
3857 container to Reference that will not live as long as the result), the
3858 finalization of the object of Reference_Type will try to access a nonexistent
3859 object. This is a normal case of a dangling pointer created by
3860 Unchecked_Deallocation; we have to explicitly mention it here as the pointer
3861 in question is not visible in the specification of the type. (This is the same
3862 reason we have to say this for invalid cursors.)]}
3863 @end{Reason}
3864 @end{Erron}
3865
3866 @begin{ImplReq}
3867
3868 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
3869 @ChgAdded{Version=[3],Text=[No storage associated with a multiway tree object
3870 shall be lost upon assignment or scope exit.]}
3871
3872 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0262-1]}
3873 @ChgAdded{Version=[3],Text=[The execution of an @nt{assignment_statement} for
3874 a tree shall have the effect of copying the elements from the source tree
3875 object to the target tree object and changing the node count of the target
3876 object to that of the source object.]}
3877
3878 @begin{ImplNote}
3879 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0298-1]}
3880 @ChgAdded{Version=[3],Text=[An assignment of a Tree is a @lquotes@;deep@rquotes
3881 copy; that is the elements are copied as well the data structures.
3882 We say @lquotes@;effect of@rquotes in order to allow the implementation to
3883 avoid copying elements immediately if it wishes. For instance, an
3884 implementation that avoided copying until one of the containers is modified
3885 would be allowed. (Note that this implementation would
3886 require care, see @RefSecNum{The Generic Package Containers.Vectors} for more.)]}
3887 @end{ImplNote}
3888 @end{ImplReq}
3889
3890 @begin{ImplAdvice}
3891
3892 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
3893 @ChgAdded{Version=[3],Text=[Containers.Multiway_Trees should be implemented
3894 similarly to a multiway tree. In particular, if @i{N} is the overall number of nodes
3895 for a particular tree, then the worst-case time complexity of Element, Parent,
3896 First_Child, Last_Child, Next_Sibling, Previous_Sibling,
3897 Insert_Child with Count=1, and Delete should be @i{O}(log @i{N}).]}
3898 @ChgImplAdvice{Version=[3],Kind=[AddedNormal],Text=[@ChgAdded{Version=[3],
3899 Text=[The worst-case time complexity of the Element, Parent,
3900 First_Child, Last_Child, Next_Sibling, Previous_Sibling,
3901 Insert_Child with Count=1, and Delete
3902 operations of Containers.Multiway_Trees should be @i{O}(log @i<N>).]}]}
3903
3904 @begin{Reason}
3905 @ChgRef{Version=[3],Kind=[AddedNormal]}
3906 @ChgAdded{Version=[3],Text=[We do not mean to overly constrain implementation
3907 strategies here. However, it is important for portability that the performance
3908 of large containers has roughly the same factors on different implementations.
3909 If a program is moved to an implementation that takes @i{O}(@i<N>) time to access
3910 elements, that program could be unusable when the trees are large. We allow
3911 @i{O}(log @i<N>) access because the proportionality constant and caching effects are
3912 likely to be larger than the log factor, and we don't want to discourage
3913 innovative implementations.]}
3914 @end{Reason}
3915
3916 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
3917 @ChgAdded{Version=[3],Text=[Move should not copy elements, and should minimize
3918 copying of internal data structures.]}
3919 @ChgImplAdvice{Version=[3],Kind=[AddedNormal],Text=[@ChgAdded{Version=[3],
3920 Text=[Containers.Multiway_Trees.Move should not copy elements, and should
3921 minimize copying of internal data structures.]}]}
3922
3923 @begin{ImplNote}
3924 @ChgRef{Version=[3],Kind=[AddedNormal]}
3925 @ChgAdded{Version=[3],Text=[Usually that can be accomplished simply by
3926 moving the pointer(s) to the internal data structures from the Source
3927 container to the Target container.]}
3928 @end{ImplNote}
3929
3930 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
3931 @ChgAdded{Version=[3],Text=[If an exception is propagated from a tree
3932 operation, no storage should be lost, nor any elements removed from a tree
3933 unless specified by the operation.]}
3934 @ChgImplAdvice{Version=[3],Kind=[AddedNormal],Text=[@ChgAdded{Version=[3],
3935 Text=[If an exception is propagated from a tree
3936 operation, no storage should be lost, nor any elements removed from a tree
3937 unless specified by the operation.]}]}
3938
3939 @begin{Reason}
3940 @ChgRef{Version=[3],Kind=[AddedNormal]}
3941 @ChgAdded{Version=[3],Text=[This is important so that programs can recover
3942 from errors. But we don't want to require heroic efforts, so we just require
3943 documentation of cases where this can't be accomplished.]}
3944 @end{Reason}
3945 @end{ImplAdvice}
3946
3947 @begin{Extend2005}
3948 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0257-1],ARef=[AI05-0265-1],ARef=[AI05-0269-1]}
3949 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
3950 The generic package Containers.Multiway_Trees is new.]}
3951 @end{Extend2005}
3952
3953 @begin{Inconsistent2012}
3954 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
3955 @ChgAdded{Version=[5],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
3956 Tampering with elements is now defined to be equivalent to tampering with
3957 cursors for regular containers. If a program requires tampering detection
3958 to work, it might fail in Ada 202x. Needless to say, this shouldn't happen
3959 outside of test programs. See @Inconsistent2012Title in
3960 @RefSecNum{The Generic Package Containers.Vectors} for more details.]}
3961 @end{Inconsistent2012}
3962
3963 @begin{Incompatible2012}
3964 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1],ARef=[AI12-0112-1]}
3965 @ChgAdded{Version=[5],Text=[@Defn{incompatibilities with Ada 2012}A number of
3966 new subprograms, types, and even a nested package were to
3967 Containers.Multiway_Trees to better support contracts and stable views. If an
3968 instance of Containers.Hashed_Maps
3969 is referenced in a @nt{use_clause}, and an entity @i<E> with the same
3970 @nt{defining_identifier} as a new entity in Containers.Hashed_Maps is
3971 defined in a package that is also referenced in a @nt{use_clause}, the
3972 entity @i<E> may no longer be use-visible, resulting in errors. This should
3973 be rare and is easily fixed if it does occur.]}
3974 @end{Incompatible2012}
3975
3976 @begin{Extend2012}
3977 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0196-1]}
3978 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}@b{Correction:}
3979 Replace_Element is now defined such that it can be used
3980 concurrently so long as it operates on different elements. This allows
3981 some container operations to be used in parallel without separate
3982 synchronization.]}
3983
3984 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0266-1]}
3985 @ChgAdded{Version=[5],Text=[Most iterators can now return parallel
3986 iterators, to be used in parallel constructs.]}
3987 @end{Extend2012}
3988
3989 @begin{DiffWord2012}
3990 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0069-1]}
3991 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Fixed the function Iterate
3992 so it is clear that the root node is never visited.]}
3993
3994 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0078-1]}
3995 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> The definition of @i<node> is
3996 clarified so that it it doesn't appear to say all nodes have an element.]}
3997
3998 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0110-1]}
3999 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified that tampering checks
4000 precede all other checks made by a subprogram (but come after those associated
4001 with the call).]}
4002
4003 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
4004 @ChgAdded{Version=[5],Text=[Added contracts to this container. This includes
4005 describing some of the semantics with pre- and postconditions, rather than
4006 English text. Note that the preconditions can be Suppressed (see
4007 @RefSecNum{Suppressing Checks}).]}
4008 @end{DiffWord2012}
4009
4010
4011 @LabeledAddedSubclause{Version=[2],Name=[The Generic Package Containers.Indefinite_Vectors]}
4012
4013 @begin{Intro}
4014 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4015 @ChgAdded{Version=[2],Text=[The language-defined generic package
4016 Containers.Indefinite_Vectors provides a private type Vector and a set of
4017 operations. It provides the same operations as the package Containers.Vectors
4018 (see @RefSecNum{The Generic Package Containers.Vectors}), with the difference that
4019 the generic formal Element_Type is indefinite.]}
4020 @end{Intro}
4021
4022 @begin{StaticSem}
4023
4024 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4025 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
4026 @ChgAdded{Version=[2],Type=[Leading],Text=[The declaration
4027 of the generic library package
4028 Containers.Indefinite_Vectors@ChildUnit{Parent=[Ada.Containers],Child=[Indefinite_Vectors]}
4029 has the same contents @Chg{Version=[3],New=[and semantics ],Old=[]}as
4030 Containers.Vectors except:]}
4031
4032 @begin{Itemize}
4033 @ChgRef{Version=[2],Kind=[AddedNormal]}
4034 @ChgAdded{Version=[2],Text=[The generic formal Element_Type is indefinite.]}
4035
4036 @ChgRef{Version=[2],Kind=[AddedNormal]}
4037 @ChgAdded{Version=[2],Keepnext=[T],Type=[Leading],Text=[The procedures with
4038 the profiles:]}
4039 @begin{Example}
4040 @ChgRef{Version=[2],Kind=[AddedNormal]}
4041 @ChgAdded{Version=[2],Noprefix=[T],Keepnext=[F],Type=[Leading],Text=[@key{procedure} Insert (Container : @key{in out} Vector;
4042 Before : @key{in} Extended_Index;
4043 Count : @key{in} Count_Type := 1);]}
4044
4045 @ChgRef{Version=[2],Kind=[AddedNormal]}
4046 @ChgAdded{Version=[2],Noprefix=[T],Keepnext=[T],Type=[Leading],Text=[@key{procedure} Insert (Container : @key{in out} Vector;
4047 Before : @key{in} Cursor;
4048 Position : @key{out} Cursor;
4049 Count : @key{in} Count_Type := 1);]}
4050 @end{Example}
4051 @ChgRef{Version=[2],Kind=[AddedNormal]}
4052 @ChgAdded{Version=[2],Noprefix=[T],Text=[are omitted.]}
4053
4054 @begin{Discussion}
4055 @ChgRef{Version=[2],Kind=[AddedNormal]}
4056 @ChgAdded{Version=[2],Text=[These procedures are omitted because there is no
4057 way to create a default-initialized object of an indefinite type. Note that
4058 Insert_Space can be used instead of this routine in most cases. Omitting
4059 the routine completely allows any problems to be diagnosed by
4060 the compiler when converting from a definite to indefinite vector.]}
4061 @end{Discussion}
4062
4063 @ChgRef{Version=[2],Kind=[AddedNormal]}
4064 @ChgAdded{Version=[2],Text=[The actual Element parameter of access subprogram Process
4065 of Update_Element may be constrained even if Element_Type is unconstrained.]}
4066
4067 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
4068 @ChgAdded{Version=[4],Text=[The operations "&", Append, Insert, Prepend,
4069 Replace_Element, and To_Vector that have a formal parameter of type
4070 Element_Type perform indefinite insertion (see @RefSecNum{Containers}).]}
4071
4072 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1],ARef=[AI12-0112-1]}
4073 @ChgAdded{Version=[5],Type=[Leading],Text=[The description of
4074 Tampering_With_Elements_Prohibited is replaced by:]}
4075
4076 @begin{Indent}
4077 @ChgRef{Version=[5],Kind=[AddedNormal]}
4078 @ChgAdded{Version=[5],Text=[Returns True if tampering with elements is
4079 prohibited for Container, and False otherwise.]}
4080 @end{Indent}
4081 @begin{Reason}
4082 @ChgRef{Version=[5],Kind=[AddedNormal]}
4083 @ChgAdded{Version=[5],Text=[Complete replacement of an element can cause its
4084 memory to be deallocated while another operation is holding onto a
4085 reference to it. That can't be allowed. However, a simple modification of
4086 (part of) an element is not a problem, so Update_Element does not cause a
4087 problem.]}
4088 @end{Reason}
4089
4090 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1],ARef=[AI12-0112-1]}
4091 @ChgAdded{Version=[5],Text=[Tampering_With_Cursors_Prohibited is replaced by
4092 Tampering_With_Elements_Prohibited in the postcondition for the operations
4093 Reference and Constant_Reference.]}
4094
4095 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
4096 @ChgAdded{Version=[5],Text=[The operations Replace_Element,
4097 Reverse_Elements, and Swap, and the nested generic unit Generic_Sorting are
4098 omitted from the nested package Stable.]}
4099
4100 @end{Itemize}
4101 @end{StaticSem}
4102
4103 @begin{Extend95}
4104 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4105 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
4106 The generic package Containers.Indefinite_Vectors is new.]}
4107 @end{Extend95}
4108
4109 @begin{Inconsistent2012}
4110 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
4111 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
4112 Defined some routines to @ldquote@;perform indefinite insertion@rdquote.
4113 This could mean that some calls to those routines would now raise
4114 Program_Error where they previously worked. However, this is extremely
4115 unlikely, as it would require that the package was not implemented in Ada
4116 (an Ada @nt{allocator} would raise Program_Error in these circumstances), and
4117 that a program inserted a more nested tagged type (or access discriminant)
4118 into a container, and then used that object before its type or discriminant
4119 went out of scope. All known implementations are implemented in Ada, so we
4120 believe there is no practical incompatibility. As such, we
4121 mention this only for completeness.]}
4122
4123 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
4124 @ChgAdded{Version=[5],Text=[Defined the Iterator_View aspect, so that the
4125 stable view is used for container element iterators. This means that tampering
4126 with elements is prohibited during the entire loop, rather than tampering
4127 with cursors being prohibited during the loop, and tampering with elements
4128 being prohibited only during the lifetimes of references to the loop
4129 parameter. Thus, if a container element iterator does an operation that
4130 tampers with elements on the iterated container, that operation will fail a
4131 tampering check in Ada 202x (and thus raise Program_Error), while it would
4132 have worked in Ada 2012 so long as the loop parameter is not involved.
4133 We believe this to be a dubious loop structure that should be rare. Note
4134 that this issue only occurs for the indefinite container form, the regular
4135 and bounded containers allow such operations at ay time in Ada 202x.]}
4136
4137 @end{Inconsistent2012}
4138
4139
4140 @LabeledAddedSubclause{Version=[2],Name=[The Generic Package Containers.Indefinite_Doubly_Linked_Lists]}
4141
4142 @begin{Intro}
4143 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4144 @ChgAdded{Version=[2],Text=[The language-defined generic package Containers.Indefinite_Doubly_Linked_Lists
4145 provides private types List and Cursor, and a set of operations for each
4146 type. It provides the same operations as the package
4147 Containers.Doubly_Linked_Lists
4148 (see @RefSecNum{The Generic Package Containers.Doubly_Linked_Lists}),
4149 with the difference that the generic formal Element_Type is indefinite.]}
4150 @end{Intro}
4151
4152 @begin{StaticSem}
4153
4154 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4155 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
4156 @ChgAdded{Version=[2],Type=[Leading],Text=[The declaration of
4157 the generic library package
4158 Containers.@!Indefinite_@!Doubly_@!Linked_@!Lists@ChildUnit{Parent=[Ada.Containers],Child=[Indefinite_Doubly_Linked_Lists]}
4159 has the same contents @Chg{Version=[3],New=[and semantics ],Old=[]}as
4160 Containers.@!Doubly_@!Linked_@!Lists except:]}
4161
4162 @begin{Itemize}
4163 @ChgRef{Version=[2],Kind=[AddedNormal]}
4164 @ChgAdded{Version=[2],Text=[The generic formal Element_Type is indefinite.]}
4165
4166 @ChgRef{Version=[2],Kind=[AddedNormal]}
4167 @ChgAdded{Version=[2],Keepnext=[T],Type=[Leading],Text=[The procedure with
4168 the profile:]}
4169 @begin{Example}
4170 @ChgRef{Version=[2],Kind=[AddedNormal]}
4171 @ChgAdded{Version=[2],Noprefix=[T],Keepnext=[T],Type=[Leading],Text=[@key{procedure} Insert (Container : @key{in out} List;
4172 Before : @key{in} Cursor;
4173 Position : @key{out} Cursor;
4174 Count : @key{in} Count_Type := 1);]}
4175 @end{Example}
4176 @ChgRef{Version=[2],Kind=[AddedNormal]}
4177 @ChgAdded{Version=[2],Noprefix=[T],Text=[is omitted.]}
4178
4179 @begin{Discussion}
4180 @ChgRef{Version=[2],Kind=[AddedNormal]}
4181 @ChgAdded{Version=[2],Text=[This procedure is omitted because there is no way
4182 to create a default-initialized object of an indefinite type. We considered
4183 having this routine insert an empty element similar to the empty elements of
4184 a vector, but rejected this possibility because the semantics are fairly
4185 complex and very different from the existing definite container. That would
4186 make it more error-prone to convert a container from a definite type to an
4187 indefinite type; by omitting the routine completely, any problems will be
4188 diagnosed by the compiler.]}
4189 @end{Discussion}
4190
4191 @ChgRef{Version=[2],Kind=[AddedNormal]}
4192 @ChgAdded{Version=[2],Text=[The actual Element parameter of access subprogram Process
4193 of Update_Element may be constrained even if Element_Type is unconstrained.]}
4194
4195 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
4196 @ChgAdded{Version=[4],Text=[The operations Append, Insert, Prepend, and
4197 Replace_Element that have a formal parameter of type Element_Type perform
4198 indefinite insertion (see @RefSecNum{Containers}).]}
4199
4200 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1],ARef=[AI12-0112-1]}
4201 @ChgAdded{Version=[5],Type=[Leading],Text=[The description of
4202 Tampering_With_Elements_Prohibited is replaced by:]}
4203
4204 @begin{Indent}
4205 @ChgRef{Version=[5],Kind=[AddedNormal]}
4206 @ChgAdded{Version=[5],Text=[Returns True if tampering with elements is
4207 prohibited for Container, and False otherwise.]}
4208 @end{Indent}
4209 @begin{Reason}
4210 @ChgRef{Version=[5],Kind=[AddedNormal]}
4211 @ChgAdded{Version=[5],Text=[Complete replacement of an element can cause its
4212 memory to be deallocated while another operation is holding onto a
4213 reference to it. That can't be allowed. However, a simple modification of
4214 (part of) an element is not a problem.]}
4215 @end{Reason}
4216
4217 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1],ARef=[AI12-0112-1]}
4218 @ChgAdded{Version=[5],Text=[Tampering_With_Cursors_Prohibited is replaced by
4219 Tampering_With_Elements_Prohibited in the postcondition for the operations
4220 Reference and Constant_Reference.]}
4221
4222 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
4223 @ChgAdded{Version=[5],Text=[The operations Replace_Element and Swap are
4224 omitted from the nested package Stable.]}
4225
4226 @end{Itemize}
4227 @end{StaticSem}
4228
4229 @begin{Extend95}
4230 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4231 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
4232 The generic package Containers.Indefinite_Doubly_Linked_Lists is new.]}
4233 @end{Extend95}
4234
4235 @begin{Inconsistent2012}
4236 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
4237 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
4238 Defined some routines to @ldquote@;perform indefinite insertion@rdquote.
4239 This could mean that some calls to those routines would now raise
4240 Program_Error where they previously worked. However, this is extremely
4241 unlikely; see @Inconsistent2012Title in
4242 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
4243
4244 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
4245 @ChgAdded{Version=[5],Text=[Defined the Iterator_View aspect, so that the
4246 stable view is used for container element iterators. This leads to a rare
4247 situation where Program_Error will be raised in Ada 202x for code that
4248 would have worked in Ada 2012. See @Inconsistent2012Title in
4249 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
4250 @end{Inconsistent2012}
4251
4252
4253 @LabeledAddedSubclause{Version=[2],Name=[The Generic Package Containers.Indefinite_Hashed_Maps]}
4254
4255 @begin{Intro}
4256 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4257 @ChgAdded{Version=[2],Text=[The language-defined generic package Containers.Indefinite_Hashed_Maps provides
4258 a map with the same operations as the package Containers.Hashed_Maps
4259 (see @RefSecNum{The Generic Package Containers.Hashed_Maps}),
4260 with the difference that the generic formal types Key_Type and Element_Type are
4261 indefinite.]}
4262 @end{Intro}
4263
4264 @begin{StaticSem}
4265
4266 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4267 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
4268 @ChgAdded{Version=[2],Type=[Leading],Text=[The declaration of
4269 the generic library package
4270 Containers.Indefinite_Hashed_Maps@ChildUnit{Parent=[Ada.Containers],Child=[Indefinite_Hashed_Maps]}
4271 has the same contents @Chg{Version=[3],New=[and semantics ],Old=[]}as
4272 Containers.Hashed_Maps except:]}
4273
4274 @begin{Itemize}
4275 @ChgRef{Version=[2],Kind=[AddedNormal]}
4276 @ChgAdded{Version=[2],Text=[The generic formal Key_Type is indefinite.]}
4277
4278 @ChgRef{Version=[2],Kind=[AddedNormal]}
4279 @ChgAdded{Version=[2],Text=[The generic formal Element_Type is indefinite.]}
4280
4281 @ChgRef{Version=[2],Kind=[AddedNormal]}
4282 @ChgAdded{Version=[2],Keepnext=[T],Type=[Leading],Text=[The procedure with
4283 the profile:]}
4284 @begin{Example}
4285 @ChgRef{Version=[2],Kind=[AddedNormal]}
4286 @ChgAdded{Version=[2],Noprefix=[T],Keepnext=[T],Type=[Leading],Text=[@key{procedure} Insert (Container : @key{in out} Map;
4287 Key : @key{in} Key_Type;
4288 Position : @key{out} Cursor;
4289 Inserted : @key{out} Boolean);]}
4290 @end{Example}
4291 @ChgRef{Version=[2],Kind=[AddedNormal]}
4292 @ChgAdded{Version=[2],Noprefix=[T],Text=[is omitted.]}
4293
4294 @begin{Discussion}
4295 @ChgRef{Version=[2],Kind=[AddedNormal]}
4296 @ChgAdded{Version=[2],Text=[This procedure is omitted because there is no way
4297 to create a default-initialized object of an indefinite type. We considered
4298 having this routine insert an empty element similar to the empty elements of
4299 a vector, but rejected this possibility because the semantics are fairly
4300 complex and very different from the existing case. That would make it more
4301 error-prone to convert a container from a definite type to an indefinite
4302 type; by omitting the routine completely, any problems will be diagnosed by
4303 the compiler.]}
4304 @end{Discussion}
4305
4306 @ChgRef{Version=[2],Kind=[AddedNormal]}
4307 @ChgAdded{Version=[2],Text=[The actual Element parameter of access subprogram Process
4308 of Update_Element may be constrained even if Element_Type is unconstrained.]}
4309
4310 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
4311 @ChgAdded{Version=[4],Text=[The operations Include, Insert, Replace, and
4312 Replace_Element that have a formal parameter of type Element_Type perform
4313 indefinite insertion (see @RefSecNum{Containers}).]}
4314 @begin{Discussion}
4315 @ChgRef{Version=[4],Kind=[AddedNormal]}
4316 @ChgAdded{Version=[4],Text=[Some of the named operations also have a formal
4317 of the indefinite formal type Key_Type and perform indefinite insertion using
4318 that value, but it is sufficient to mention the formal of type Element_Type
4319 to cover those.]}
4320 @end{Discussion}
4321
4322 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1],ARef=[AI12-0112-1]}
4323 @ChgAdded{Version=[5],Type=[Leading],Text=[The description of
4324 Tampering_With_Elements_Prohibited is replaced by:]}
4325
4326 @begin{Indent}
4327 @ChgRef{Version=[5],Kind=[AddedNormal]}
4328 @ChgAdded{Version=[5],Text=[Returns True if tampering with elements is
4329 prohibited for Container, and False otherwise.]}
4330 @end{Indent}
4331 @begin{Reason}
4332 @ChgRef{Version=[5],Kind=[AddedNormal]}
4333 @ChgAdded{Version=[5],Text=[Complete replacement of an element can cause its
4334 memory to be deallocated while another operation is holding onto a
4335 reference to it. That can't be allowed. However, a simple modification of
4336 (part of) an element is not a problem.]}
4337 @end{Reason}
4338
4339 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1],ARef=[AI12-0112-1]}
4340 @ChgAdded{Version=[5],Text=[Tampering_With_Cursors_Prohibited is replaced by
4341 Tampering_With_Elements_Prohibited in the postcondition for the operations
4342 Reference and Constant_Reference.]}
4343
4344 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
4345 @ChgAdded{Version=[5],Text=[The operations Replace and Replace_Element are
4346 omitted from the nested package Stable.]}
4347
4348 @end{Itemize}
4349 @end{StaticSem}
4350
4351 @begin{Extend95}
4352 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4353 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
4354 The generic package Containers.Indefinite_Hashed_Maps is new.]}
4355 @end{Extend95}
4356
4357 @begin{Inconsistent2012}
4358 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
4359 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
4360 Defined some routines to @ldquote@;perform indefinite insertion@rdquote.
4361 This could mean that some calls to those routines would now raise
4362 Program_Error where they previously worked. However, this is extremely
4363 unlikely; see @Inconsistent2012Title in
4364 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
4365
4366 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
4367 @ChgAdded{Version=[5],Text=[Defined the Iterator_View aspect, so that the
4368 stable view is used for container element iterators. This leads to a rare
4369 situation where Program_Error will be raised in Ada 202x for code that
4370 would have worked in Ada 2012. See @Inconsistent2012Title in
4371 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
4372 @end{Inconsistent2012}
4373
4374
4375 @LabeledAddedSubclause{Version=[2],Name=[The Generic Package Containers.Indefinite_Ordered_Maps]}
4376
4377 @begin{Intro}
4378 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4379 @ChgAdded{Version=[2],Text=[The language-defined generic package Containers.Indefinite_Ordered_Maps
4380 provides a map with the same operations as the package Containers.Ordered_Maps
4381 (see @RefSecNum{The Generic Package Containers.Ordered_Maps}), with the difference that
4382 the generic formal types Key_Type and Element_Type are indefinite.]}
4383 @end{Intro}
4384
4385 @begin{StaticSem}
4386
4387 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4388 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
4389 @ChgAdded{Version=[2],Type=[Leading],Text=[The declaration of
4390 the generic library package
4391 Containers.Indefinite_Ordered_Maps@ChildUnit{Parent=[Ada.Containers],Child=[Indefinite_Ordered_Maps]}
4392 has the same contents @Chg{Version=[3],New=[and semantics ],Old=[]}as
4393 Containers.Ordered_Maps except:]}
4394
4395 @begin{Itemize}
4396 @ChgRef{Version=[2],Kind=[AddedNormal]}
4397 @ChgAdded{Version=[2],Text=[The generic formal Key_Type is indefinite.]}
4398
4399 @ChgRef{Version=[2],Kind=[AddedNormal]}
4400 @ChgAdded{Version=[2],Text=[The generic formal Element_Type is indefinite.]}
4401
4402 @ChgRef{Version=[2],Kind=[AddedNormal]}
4403 @ChgAdded{Version=[2],Keepnext=[T],Type=[Leading],Text=[The procedure with
4404 the profile:]}
4405 @begin{Example}
4406 @ChgRef{Version=[2],Kind=[AddedNormal]}
4407 @ChgAdded{Version=[2],Noprefix=[T],Keepnext=[T],Type=[Leading],Text=[@key{procedure} Insert (Container : @key{in out} Map;
4408 Key : @key{in} Key_Type;
4409 Position : @key{out} Cursor;
4410 Inserted : @key{out} Boolean);]}
4411 @end{Example}
4412 @ChgRef{Version=[2],Kind=[AddedNormal]}
4413 @ChgAdded{Version=[2],Noprefix=[T],Text=[is omitted.]}
4414
4415 @begin{Discussion}
4416 @ChgRef{Version=[2],Kind=[AddedNormal]}
4417 @ChgAdded{Version=[2],Text=[This procedure is omitted because there is no way
4418 to create a default-initialized object of an indefinite type. We considered
4419 having this routine insert an empty element similar to the empty elements of
4420 a vector, but rejected this possibility because the semantics are fairly
4421 complex and very different from the existing case. That would make it more
4422 error-prone to convert a container from a definite type to an indefinite
4423 type; by omitting the routine completely, any problems will be diagnosed by
4424 the compiler.]}
4425 @end{Discussion}
4426
4427 @ChgRef{Version=[2],Kind=[AddedNormal]}
4428 @ChgAdded{Version=[2],Text=[The actual Element parameter of access subprogram Process
4429 of Update_Element may be constrained even if Element_Type is unconstrained.]}
4430
4431 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
4432 @ChgAdded{Version=[4],Text=[The operations Include, Insert, Replace, and
4433 Replace_Element that have a formal parameter of type Element_Type perform
4434 indefinite insertion (see @RefSecNum{Containers}).]}
4435 @begin{Discussion}
4436 @ChgRef{Version=[4],Kind=[AddedNormal]}
4437 @ChgAdded{Version=[4],Text=[Some of the named operations also have a formal
4438 of the indefinite formal type Key_Type and perform indefinite insertion using
4439 that value, but it is sufficient to mention the formal of type Element_Type
4440 to cover those.]}
4441 @end{Discussion}
4442
4443 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1],ARef=[AI12-0112-1]}
4444 @ChgAdded{Version=[5],Type=[Leading],Text=[The description of
4445 Tampering_With_Elements_Prohibited is replaced by:]}
4446
4447 @begin{Indent}
4448 @ChgRef{Version=[5],Kind=[AddedNormal]}
4449 @ChgAdded{Version=[5],Text=[Returns True if tampering with elements is
4450 prohibited for Container, and False otherwise.]}
4451 @end{Indent}
4452 @begin{Reason}
4453 @ChgRef{Version=[5],Kind=[AddedNormal]}
4454 @ChgAdded{Version=[5],Text=[Complete replacement of an element can cause its
4455 memory to be deallocated while another operation is holding onto a
4456 reference to it. That can't be allowed. However, a simple modification of
4457 (part of) an element is not a problem.]}
4458 @end{Reason}
4459
4460 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1],ARef=[AI12-0112-1]}
4461 @ChgAdded{Version=[5],Text=[Tampering_With_Cursors_Prohibited is replaced by
4462 Tampering_With_Elements_Prohibited in the postcondition for the operations
4463 Reference and Constant_Reference.]}
4464
4465 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
4466 @ChgAdded{Version=[5],Text=[The operations Replace and Replace_Element are
4467 omitted from the nested package Stable.]}
4468
4469 @end{Itemize}
4470 @end{StaticSem}
4471
4472 @begin{Extend95}
4473 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4474 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
4475 The generic package Containers.Indefinite_Ordered_Maps is new.]}
4476 @end{Extend95}
4477
4478 @begin{Inconsistent2012}
4479 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
4480 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
4481 Defined some routines to @ldquote@;perform indefinite insertion@rdquote.
4482 This could mean that some calls to those routines would now raise
4483 Program_Error where they previously worked. However, this is extremely
4484 unlikely; see @Inconsistent2012Title in
4485 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
4486
4487 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
4488 @ChgAdded{Version=[5],Text=[Defined the Iterator_View aspect, so that the
4489 stable view is used for container element iterators. This leads to a rare
4490 situation where Program_Error will be raised in Ada 202x for code that
4491 would have worked in Ada 2012. See @Inconsistent2012Title in
4492 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
4493 @end{Inconsistent2012}
4494
4495
4496 @LabeledAddedSubclause{Version=[2],Name=[The Generic Package Containers.Indefinite_Hashed_Sets]}
4497
4498 @begin{Intro}
4499 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4500 @ChgAdded{Version=[2],Text=[The language-defined generic package
4501 Containers.Indefinite_Hashed_Sets provides a set with the same operations as
4502 the package Containers.Hashed_Sets
4503 (see @RefSecNum{The Generic Package Containers.Hashed_Sets}), with the difference
4504 that the generic formal type Element_Type is indefinite.]}
4505 @end{Intro}
4506
4507 @begin{StaticSem}
4508
4509 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4510 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
4511 @ChgAdded{Version=[2],Type=[Leading],Text=[The declaration
4512 of the generic library package
4513 Containers.Indefinite_Hashed_Sets@ChildUnit{Parent=[Ada.Containers],Child=[Indefinite_Hashed_Sets]}
4514 has the same contents @Chg{Version=[3],New=[and semantics ],Old=[]}as
4515 Containers.Hashed_Sets except:]}
4516
4517 @begin{Itemize}
4518 @ChgRef{Version=[2],Kind=[AddedNormal]}
4519 @ChgAdded{Version=[2],Text=[The generic formal Element_Type is indefinite.]}
4520
4521 @ChgRef{Version=[2],Kind=[AddedNormal]}
4522 @ChgAdded{Version=[2],Text=[The actual Element parameter of access subprogram Process
4523 of Update_@!Element_@!Preserving_Key may be constrained even if Element_Type is
4524 unconstrained.]}
4525
4526 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
4527 @ChgAdded{Version=[4],Text=[The operations Include, Insert, Replace,
4528 Replace_Element, and To_Set that have a formal parameter of type Element_Type
4529 perform indefinite insertion (see @RefSecNum{Containers}).]}
4530 @begin{Ramification}
4531 @ChgRef{Version=[4],Kind=[AddedNormal]}
4532 @ChgAdded{Version=[4],Text=[This includes the procedure Replace declared in
4533 the nested generic package Generic_Keys, as well as the routines declared
4534 directly in the Containers.Indefinite_Hashed_Sets package.]}
4535 @end{Ramification}
4536
4537 @begin{Discussion}
4538 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
4539 @ChgAdded{Version=[5],Text=[Unlike the other containers, a Hashed_Set has no
4540 operations that tamper with elements without tampering with cursors.
4541 Modifying the contents of a element of a set can change its position in the
4542 set, so those operations tamper with cursors.]}
4543
4544 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
4545 @ChgAdded{Version=[5],Text=[Because of this characteristic, this subclause
4546 is missing the rules that other indefinite containers have modifying the
4547 definition and use of Tampering_with_Elements, and the definition of the
4548 Stable subpackaage is the same as the definite version.]}
4549 @end{Discussion}
4550
4551 @end{Itemize}
4552 @end{StaticSem}
4553
4554 @begin{Extend95}
4555 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4556 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
4557 The generic package Containers.Indefinite_Hashed_Sets is new.]}
4558 @end{Extend95}
4559
4560 @begin{Inconsistent2012}
4561 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
4562 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
4563 Defined some routines to @ldquote@;perform indefinite insertion@rdquote.
4564 This could mean that some calls to those routines would now raise
4565 Program_Error where they previously worked. However, this is extremely
4566 unlikely; see @Inconsistent2012Title in
4567 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
4568 @end{Inconsistent2012}
4569
4570
4571 @LabeledAddedSubclause{Version=[2],Name=[The Generic Package Containers.Indefinite_Ordered_Sets]}
4572
4573 @begin{Intro}
4574 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4575 @ChgAdded{Version=[2],Text=[The language-defined generic package
4576 Containers.Indefinite_Ordered_Sets provides a set with the same operations as
4577 the package Containers.Ordered_Sets
4578 (see @RefSecNum{The Generic Package Containers.Ordered_Sets}), with the difference
4579 that the generic formal type Element_Type is indefinite.]}
4580 @end{Intro}
4581
4582 @begin{StaticSem}
4583
4584 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4585 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
4586 @ChgAdded{Version=[2],Type=[Leading],Text=[The declaration
4587 of the generic library package
4588 Containers.Indefinite_Ordered_Sets@ChildUnit{Parent=[Ada.Containers],Child=[Indefinite_Ordered_Sets]}
4589 has the same contents @Chg{Version=[3],New=[and semantics ],Old=[]}as
4590 Containers.Ordered_Sets except:]}
4591
4592 @begin{Itemize}
4593 @ChgRef{Version=[2],Kind=[AddedNormal]}
4594 @ChgAdded{Version=[2],Text=[The generic formal Element_Type is indefinite.]}
4595
4596 @ChgRef{Version=[2],Kind=[AddedNormal]}
4597 @ChgAdded{Version=[2],Text=[The actual Element parameter of access subprogram Process
4598 of Update_@!Element_@!Preserving_Key may be constrained even if Element_Type is
4599 unconstrained.]}
4600
4601 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
4602 @ChgAdded{Version=[4],Text=[The operations Include, Insert, Replace,
4603 Replace_Element, and To_Set that have a formal parameter of type Element_Type
4604 perform indefinite insertion (see @RefSecNum{Containers}).]}
4605 @begin{Ramification}
4606 @ChgRef{Version=[4],Kind=[AddedNormal]}
4607 @ChgAdded{Version=[4],Text=[This includes the procedure Replace declared in
4608 the nested generic package Generic_Keys, as well as the routines declared
4609 directly in the Containers.Indefinite_Ordered_Sets package.]}
4610 @end{Ramification}
4611
4612 @begin{Discussion}
4613 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
4614 @ChgAdded{Version=[5],Text=[Unlike the other containers, a Ordered_Set has no
4615 operations that tamper with elements without tampering with cursors.
4616 Modifying the contents of a element of a set can change its position in the
4617 set, so those operations tamper with cursors.]}
4618
4619 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
4620 @ChgAdded{Version=[5],Text=[Because of this characteristic, this subclause
4621 is missing the rules that other indefinite containers have modifying the
4622 definition and use of Tampering_with_Elements, and the definition of the
4623 Stable subpackaage is the same as the definite version.]}
4624 @end{Discussion}
4625
4626 @end{Itemize}
4627 @end{StaticSem}
4628
4629 @begin{Extend95}
4630 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4631 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
4632 The generic package Containers.Indefinite_Ordered_Sets is new.]}
4633 @end{Extend95}
4634
4635 @begin{Inconsistent2012}
4636 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
4637 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
4638 Defined some routines to @ldquote@;perform indefinite insertion@rdquote.
4639 This could mean that some calls to those routines would now raise
4640 Program_Error where they previously worked. However, this is extremely
4641 unlikely; see @Inconsistent2012Title in
4642 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
4643 @end{Inconsistent2012}
4644
4645
4646 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Indefinite_Multiway_Trees]}
4647
4648 @begin{Intro}
4649 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
4650 @ChgAdded{Version=[3],Text=[The language-defined generic package
4651 Containers.Indefinite_Multiway_Trees
4652 provides a multiway tree with the same operations as the package
4653 Containers.Multiway_Trees (see @RefSecNum{The Generic Package Containers.Multiway_Trees}),
4654 with the difference that the generic formal Element_Type is indefinite.]}
4655 @end{Intro}
4656
4657 @begin{StaticSem}
4658
4659 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
4660 @ChgAdded{Version=[3],Type=[Leading],Text=[The declaration
4661 of the generic library package
4662 Containers.Indefinite_Multiway_Trees@ChildUnit{Parent=[Ada.Containers],Child=[Indefinite_Multiway_Trees]}
4663 has the same contents and semantics as
4664 Containers.Multiway_Trees except:]}
4665
4666 @begin{Itemize}
4667 @ChgRef{Version=[3],Kind=[AddedNormal]}
4668 @ChgAdded{Version=[3],Text=[The generic formal Element_Type is indefinite.]}
4669
4670 @ChgRef{Version=[3],Kind=[AddedNormal]}
4671 @ChgAdded{Version=[3],Keepnext=[T],Type=[Leading],Text=[The procedure with
4672 the profile:]}
4673 @begin{Example}
4674 @ChgRef{Version=[3],Kind=[AddedNormal]}
4675 @ChgAdded{Version=[3],Noprefix=[T],Keepnext=[T],Type=[Leading],Text=[@key{procedure} Insert_Child (Container : @key{in out} Tree;
4676 Parent : @key{in} Cursor;
4677 Before : @key{in} Cursor;
4678 Position : @key{out} Cursor;
4679 Count : @key{in} Count_Type := 1);]}
4680 @end{Example}
4681 @ChgRef{Version=[3],Kind=[AddedNormal]}
4682 @ChgAdded{Version=[3],Noprefix=[T],Text=[is omitted.]}
4683
4684 @begin{Discussion}
4685 @ChgRef{Version=[3],Kind=[AddedNormal]}
4686 @ChgAdded{Version=[3],Text=[This procedure is omitted because there is no way to create a
4687 default-initialized object of an indefinite type. We considered having this
4688 routine insert an empty element similar to the empty elements of a vector, but
4689 rejected this possibility because the semantics are fairly complex and very
4690 different from the existing case. That would make it more error-prone to convert
4691 a container from a definite type to an indefinite type; by omitting the routine
4692 completely, any problems will be diagnosed by the compiler.]}
4693 @end{Discussion}
4694
4695 @ChgRef{Version=[3],Kind=[AddedNormal]}
4696 @ChgAdded{Version=[3],Text=[The actual Element parameter of access subprogram
4697 Process of Update_Element may be constrained even if Element_Type is
4698 unconstrained.]}
4699
4700 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
4701 @ChgAdded{Version=[4],Text=[The operations Append_Child, Insert_Child,
4702 Prepend_Child, and Replace_Element that have a formal parameter of type
4703 Element_Type perform indefinite insertion (see @RefSecNum{Containers}).]}
4704
4705 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1],ARef=[AI12-0112-1]}
4706 @ChgAdded{Version=[5],Type=[Leading],Text=[The description of
4707 Tampering_With_Elements_Prohibited is replaced by:]}
4708
4709 @begin{Indent}
4710 @ChgRef{Version=[5],Kind=[AddedNormal]}
4711 @ChgAdded{Version=[5],Text=[Returns True if tampering with elements is
4712 prohibited for Container, and False otherwise.]}
4713 @end{Indent}
4714 @begin{Reason}
4715 @ChgRef{Version=[5],Kind=[AddedNormal]}
4716 @ChgAdded{Version=[5],Text=[Complete replacement of an element can cause its
4717 memory to be deallocated while another operation is holding onto a
4718 reference to it. That can't be allowed. However, a simple modification of
4719 (part of) an element is not a problem.]}
4720 @end{Reason}
4721
4722 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1],ARef=[AI12-0112-1]}
4723 @ChgAdded{Version=[5],Text=[Tampering_With_Cursors_Prohibited is replaced by
4724 Tampering_With_Elements_Prohibited in the postcondition for the operations
4725 Reference and Constant_Reference.]}
4726
4727 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
4728 @ChgAdded{Version=[5],Text=[The operations Replace_Element and Swap are
4729 omitted from the nested package Stable.]}
4730
4731 @end{Itemize}
4732 @end{StaticSem}
4733
4734 @begin{Extend2005}
4735 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
4736 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
4737 The generic package Containers.Indefinite_Multiway_Trees is new.]}
4738 @end{Extend2005}
4739
4740 @begin{Inconsistent2012}
4741 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
4742 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
4743 Defined some routines to @ldquote@;perform indefinite insertion@rdquote.
4744 This could mean that some calls to those routines would now raise
4745 Program_Error where they previously worked. However, this is extremely
4746 unlikely; see @Inconsistent2012Title in
4747 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
4748
4749 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
4750 @ChgAdded{Version=[5],Text=[Defined the Iterator_View aspect, so that the
4751 stable view is used for container element iterators. This leads to a rare
4752 situation where Program_Error will be raised in Ada 202x for code that
4753 would have worked in Ada 2012. See @Inconsistent2012Title in
4754 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
4755 @end{Inconsistent2012}
4756
4757
4758 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Indefinite_Holders]}
4759
4760 @begin{Intro}
4761 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
4762 @ChgAdded{Version=[3],Text=[The language-defined generic package
4763 Containers.Indefinite_Holders provides a private type Holder and a set of
4764 operations for that type. A holder container holds a single element of an
4765 indefinite type.]}
4766
4767 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
4768 @ChgAdded{Version=[3],Text=[A holder container allows the declaration of an
4769 object that can be used like an uninitialized variable or component of an
4770 indefinite type.]}
4771
4772 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
4773 @ChgAdded{Version=[3],Text=[A holder container may be @i{empty}.
4774 An empty holder does not contain an element.@Defn{empty holder}]}
4775 @end{Intro}
4776
4777 @begin{StaticSem}
4778
4779 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
4780 @ChgAdded{Version=[3],KeepNext=[T],Type=[Leading],Text=[The generic library
4781 package Containers.Indefinite_Holders has the following declaration:]}
4782 @begin{Example}
4783 @ChgRef{Version=[3],Kind=[AddedNormal],Aref=[AI05-0069-1],Aref=[AI05-0084-1]}
4784 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
4785 @ChgAdded{Version=[3],Text=[@key[generic]
4786 @key[type] Element_Type (<>) @key[is private];
4787 @key[with function] "=" (Left, Right : Element_Type) @key[return] Boolean @key[is] <>;
4788 @key[package] Ada.Containers.Indefinite_Holders@Chg{Version=[5],New=[
4789 @key[with] Preelaborate, Remote_Types,
4790 Nonblocking, Global => @key[null]],Old=[]}@key[is]@ChildUnit{Parent=[Ada.Containers],Child=[Indefinite_Holders]}@Chg{Version=[5],New=[],Old=[
4791 @key[pragma] Preelaborate(Indefinite_Holders);
4792 @key[pragma] Remote_Types(Indefinite_Holders);]}]}
4793
4794 @begin{Discussion}
4795 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
4796 @ChgAdded{Version=[5],Text=[For discussion on the reasons and meaning of
4797 the specifications of the Global and Nonblocking aspects in this generic
4798 package, see the notes on the equivalent operations in the specification
4799 of the Containers.Vectors package (see
4800 @RefSecNum{The Generic Package Containers.Vectors}).]}
4801 @end{Discussion}
4802
4803 @ChgRef{Version=[3],Kind=[AddedNormal]}
4804 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
4805 @ChgAdded{Version=[3],Text=[ @key[type] @AdaTypeDefn{Holder} @key[is tagged private] @Chg{Version=[5],New=[
4806 @key[with] Stable_Properties => (Is_Empty,
4807 Tampering_With_The_Element_Prohibited),
4808 Default_Initial_Condition => Is_Empty (Holder)],Old=[]};
4809 @key[pragma] Preelaborable_Initialization (Holder);]}
4810
4811 @ChgRef{Version=[3],Kind=[AddedNormal]}
4812 @ChgAdded{Version=[3],Text=[ @AdaObjDefn{Empty_Holder} : @key[constant] Holder;]}
4813
4814 @ChgRef{Version=[5],Kind=[Added],Aref=[AI12-0112-1]}
4815 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Equal_Element} (Left, Right : Element_Type) @key[return] Boolean
4816 @key[renames] "=";]}
4817
4818 @ChgRef{Version=[3],Kind=[AddedNormal]}
4819 @ChgAdded{Version=[3],Text=[ @key[function] "=" (Left, Right : Holder) @key[return] Boolean;]}
4820
4821 @ChgRef{Version=[5],Kind=[Added],Aref=[AI12-0112-1]}
4822 @ChgAdded{Version=[5],Text=[ @key[function] @AdaSubDefn{Tampering_With_The_Element_Prohibited}
4823 (Container : Holder) @key[return] Boolean
4824 @key[with] Nonblocking, Global => (@key[null], @key[use null]);]}
4825
4826 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0339-1]}
4827 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Empty} @key{return} Holder
4828 @key[is] (Empty_Holder)
4829 @key[with] Post =>
4830 @key[not] Tampering_With_The_Element_Prohibited (Empty'Result)
4831 @key[and then] Is_Empty (Empty'Result);]}
4832
4833 @ChgRef{Version=[3],Kind=[AddedNormal]}
4834 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
4835 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{To_Holder} (New_Item : Element_Type) @key[return] Holder@Chg{Version=[5],New=[
4836 @key[with] Post => @key[not] Is_Empty (To_Holder'Result)],Old=[]};]}
4837
4838 @ChgRef{Version=[3],Kind=[AddedNormal]}
4839 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
4840 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Is_Empty} (Container : Holder) @key[return] Boolean@Chg{Version=[5],New=[
4841 @key[with] Global => (@key[null], @key[use null])],Old=[]};]}
4842
4843 @ChgRef{Version=[3],Kind=[AddedNormal]}
4844 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
4845 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Clear} (Container : @key[in out] Holder)@Chg{Version=[5],New=[
4846 @key[with] Pre => @key[not] Tampering_With_The_Element_Prohibited (Container)
4847 @key[or else raise] Program_Error,
4848 Post => Is_Empty (Container)],Old=[]};]}
4849
4850 @ChgRef{Version=[3],Kind=[AddedNormal]}
4851 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
4852 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Element} (Container : Holder) @key[return] Element_Type@Chg{Version=[5],New=[
4853 @key[with] Pre => @key[not] Is_Empty (Container) @key[or else raise] Constraint_Error,
4854 Global => (@key[null], @key[use] Element_Type)],Old=[]};]}
4855
4856 @ChgRef{Version=[3],Kind=[AddedNormal]}
4857 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
4858 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Replace_Element} (Container : @key[in out] Holder;
4859 New_Item : @key[in] Element_Type)@Chg{Version=[5],New=[
4860 @key[with] Pre => @key[not] Tampering_With_The_Element_Prohibited (Container)
4861 @key[or else raise] Program_Error,
4862 Post => @key[not] Is_Empty (Container)],Old=[]};]}
4863
4864 @ChgRef{Version=[3],Kind=[AddedNormal]}
4865 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
4866 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Query_Element}
4867 (Container : @key[in] Holder;
4868 Process : @key[not null access procedure] (Element : @key[in] Element_Type))@Chg{Version=[5],New=[
4869 @key[with] Pre => @key[not] Is_Empty (Container) @key[or else raise] Constraint_Error],Old=[]};]}
4870
4871 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0248-1]}
4872 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
4873 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Update_Element}
4874 (Container : @key[in out] Holder;
4875 Process : @key[not null access procedure] (Element : @key[in out] Element_Type))@Chg{Version=[5],New=[
4876 @key[with] Pre => @key[not] Is_Empty (Container) @key[or else raise] Constraint_Error],Old=[]};]}
4877
4878 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
4879 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
4880 @ChgAdded{Version=[3],Text=[ @key[type] @AdaTypeDefn{Constant_Reference_Type}
4881 (Element : @key[not null access constant] Element_Type) @key[is private]
4882 @key[with] Implicit_Dereference => Element@Chg{Version=[5],New=[,
4883 Nonblocking, Global => @key[in out synchronized],
4884 Default_Initial_Condition => (@key[raise] Program_Error)],Old=[]};]}
4885
4886 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
4887 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
4888 @ChgAdded{Version=[3],Text=[ @key[type] @AdaTypeDefn{Reference_Type}
4889 (Element : @key[not null access] Element_Type) @key[is private]
4890 @key[with] Implicit_Dereference => Element@Chg{Version=[5],New=[,
4891 Nonblocking, Global => @key[in out synchronized],
4892 Default_Initial_Condition => (@key[raise] Program_Error)],Old=[]};]}
4893
4894 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
4895 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
4896 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Constant_Reference} (Container : @key[aliased in] Holder)
4897 @key[return] Constant_Reference_Type@Chg{Version=[5],New=[
4898 @key[with] Pre => @key[not] Is_Empty (Container) @key[or else raise] Constraint_Error,
4899 Post => Tampering_With_The_Element_Prohibited (Container),
4900 Nonblocking, Global => (@key[null], @key[use null])],Old=[]};]}
4901
4902 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
4903 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
4904 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Reference} (Container : @key[aliased in out] Holder)
4905 @key[return] Reference_Type@Chg{Version=[5],New=[
4906 @key[with] Pre => @key[not] Is_Empty (Container) @key[or else raise] Constraint_Error,
4907 Post => Tampering_With_The_Element_Prohibited (Container),
4908 Nonblocking, Global => (@key[null], @key[use null])],Old=[]};]}
4909
4910 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
4911 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
4912 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Assign} (Target : @key[in out] Holder; Source : @key[in] Holder)@Chg{Version=[5],New=[
4913 @key[with] Post => (Is_Empty (Source) = Is_Empty (Target))],Old=[]};]}
4914
4915 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
4916 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
4917 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Copy} (Source : Holder) @key[return] Holder@Chg{Version=[5],New=[
4918 @key[with] Post => (Is_Empty (Source) = Is_Empty (Copy'Result))],Old=[]};]}
4919
4920 @ChgRef{Version=[3],Kind=[AddedNormal]}
4921 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
4922 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Move} (Target : @key[in out] Holder; Source : @key[in out] Holder)@Chg{Version=[5],New=[
4923 @key[with] Pre => (@key[not] Tampering_With_The_Element_Prohibited (Target)
4924 @key[or else raise] Program_Error) @key[and then]
4925 (@key[not] Tampering_With_The_Element_Prohibited (Source)
4926 @key[or else raise] Program_Error),
4927 Post => (@key[if] Target /= Source @key[then]
4928 Is_Empty (Source) @key[and then] (@key[not] Is_Empty (Target)))],Old=[]};]}
4929
4930 @ChgRef{Version=[5],Kind=[Added]}
4931 @ChgAdded{Version=[5],KeepNext=[T],Text=[ @key[procedure] @AdaSubDefn{Swap} (Left, Right : @key[in out] Holder)
4932 @key[with] Pre => (@key[not] Tampering_With_The_Element_Prohibited (Left)
4933 @key[or else raise] Program_Error) @key[and then]
4934 (@key[not] Tampering_With_The_Element_Prohibited (Right)
4935 @key[or else raise] Program_Error),
4936 Post => Is_Empty (Left) = Is_Empty (Right)'Old @key[and then]
4937 Is_Empty (Right) = Is_Empty (Left)'Old;]}
4938
4939 @ChgRef{Version=[3],Kind=[AddedNormal]}
4940 @ChgAdded{Version=[3],Text=[@key{private}]}
4941
4942 @ChgRef{Version=[3],Kind=[AddedNormal]}
4943 @ChgAdded{Version=[3],Text=[ ... -- @Examcom[not specified by the language]]}
4944
4945 @ChgRef{Version=[3],Kind=[AddedNormal]}
4946 @ChgAdded{Version=[3],Text=[@key{end} Ada.Containers.Indefinite_Holders;]}
4947
4948 @end{Example}
4949
4950 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
4951 @ChgAdded{Version=[3],Text=[The actual function for the generic formal
4952 function "=" on Element_Type values is expected to define a reflexive and
4953 symmetric relationship and return the same result value each time it is called
4954 with a particular pair of values. If it behaves in some other manner, the
4955 function "=" on holder values returns an unspecified value. The exact arguments
4956 and number of calls of this generic formal function by the function "=" on
4957 holder values are unspecified.]}
4958
4959 @begin{Ramification}
4960 @ChgRef{Version=[3],Kind=[AddedNormal]}
4961 @ChgAdded{Version=[3],Text=[If the actual function for "=" is not symmetric
4962 and consistent, the result returned by any of the functions defined to use
4963 "=" cannot be predicted. The implementation is not required to protect
4964 against "=" raising an exception, or returning random results, or any other
4965 "bad" behavior. And it can call "=" in whatever manner makes sense. But
4966 note that only the results of the function "=" is unspecified; other
4967 subprograms are not allowed to break if "=" is bad.]}
4968 @end{Ramification}
4969
4970 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
4971 @ChgAdded{Version=[3],Text=[The type Holder is used to represent holder
4972 containers. The type Holder needs finalization@PDefn2{Term=<needs finalization>,
4973 Sec=<language-defined type>}
4974 (see @RefSecNum{Assignment and Finalization}).]}
4975
4976 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
4977 @ChgAdded{Version=[3],Text=[Empty_Holder represents an empty holder object. If
4978 an object of type Holder is not otherwise initialized, it is initialized to the
4979 same value as Empty_Holder.]}
4980
4981 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0262-1]}
4982 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
4983 @ChgAdded{Version=[3],Text=[@Redundant[Some operations
4984 @Chg{Version=[5],New=[],Old=[of this generic package have access-to-subprogram
4985 parameters. To
4986 ensure such operations are well-defined, they guard against certain actions by
4987 the designated subprogram. In particular, some operations]} check for
4988 @ldquote@;tampering with the element@rdquote of a container because they depend
4989 @Defn2{Term=[tamper with elements],Sec=[of a holder]}on the element
4990 of the container not being replaced.]@Chg{Version=[5],New=[When
4991 tampering with the element is @i<prohibited>@Defn2{Term=[prohibited],Sec=[tampering with a holder]}
4992 @Defn2{Term=[tampering],Sec=[prohibited for a holder]}for a particular
4993 holder object @i<H>, Program_Error is propagated by the finalization of
4994 @i<H>@Redundant[, as well as by a call that passes @i<H> to certain of the
4995 operations of this package, as indicated by the precondition of such an
4996 operation].],Old=[]}]}
4997
4998 @begin{NotIso}
4999 @ChgAdded{Version=[5],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs
5000 30 through 35 are removed as preconditions now describe these rules.>}]}@Comment{This
5001 message should be deleted if the paragraphs are ever renumbered.}
5002 @end{NotIso}
5003
5004 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0262-1]}
5005 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg],ARef=[AI12-0112-1]}
5006 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[@Defn2{Term=[tamper with elements],Sec=[of a holder]}
5007 A subprogram is said to @i{tamper with the element} of a
5008 holder object @i<H> if:]}]}
5009
5010 @begin{Itemize}
5011 @ChgRef{Version=[3],Kind=[AddedNormal]}
5012 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
5013 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[It clears the element
5014 contained by @i<H>, that is, it calls the Clear procedure with @i<H> as
5015 a parameter;]}]}
5016
5017 @ChgRef{Version=[3],Kind=[AddedNormal]}
5018 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
5019 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[It replaces the
5020 element contained by @i<H>, that is,
5021 it calls the Replace_Element procedure with @i<H> as a parameter;]}]}
5022
5023 @ChgRef{Version=[3],Kind=[AddedNormal]}
5024 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
5025 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[It calls the Move procedure with @i<H> as a parameter;]}]}
5026
5027 @ChgRef{Version=[3],Kind=[AddedNormal]}
5028 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
5029 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[It finalizes @i<H>.]}]}
5030
5031 @begin{Reason}
5032 @ChgRef{Version=[3],Kind=[AddedNormal]}
5033 @ChgAdded{Version=[3],Text=[Complete replacement of an element can cause its
5034 memory to be deallocated while another operation is holding onto a reference
5035 to it. That can't be allowed. However, a simple modification of (part of) an
5036 element is not a problem, so Update_Element does not cause a problem.]}
5037 @end{Reason}
5038 @end{Itemize}
5039
5040 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
5041 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0110-1]}
5042 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg],ARef=[AI12-0112-1]}
5043 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[@Defn2{Term=[prohibited],Sec=[tampering with a holder]}
5044 @Defn2{Term=[tampering],Sec=[prohibited for a holder]}
5045 When tampering with the element is @i<prohibited> for a particular holder object
5046 @i<H>, Program_Error is propagated by a call of any language-defined subprogram
5047 that is defined to tamper with the element of @i<H>, leaving @i<H>
5048 unmodified.@Chg{Version=[4],New=[ These checks are made before any other
5049 defined behavior of the body of the language-defined subprogram.],Old=[]}]}]}
5050
5051 @begin{DescribeCode}
5052
5053 @begin{Example}
5054 @ChgRef{Version=[3],Kind=[AddedNormal]}
5055 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} "=" (Left, Right : Holder) @key{return} Boolean;]}
5056 @end{Example}
5057
5058 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
5059 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Left and Right denote the same
5060 holder object, then the function returns True. Otherwise, it compares the
5061 element contained in Left to the element contained in Right using the
5062 generic formal equality operator, returning the result of that operation. Any
5063 exception raised during the evaluation of element equality is propagated.]}
5064
5065 @begin{ImplNote}
5066 @ChgRef{Version=[3],Kind=[AddedNormal]}
5067 @ChgAdded{Version=[3],Text=[This wording describes the canonical semantics.
5068 However, the order and number of calls on the formal equality @key[function]
5069 is unspecified, so an implementation need not call the equality function
5070 if the correct answer can be determined without doing so.]}
5071 @end{ImplNote}
5072
5073 @begin{Example}
5074 @ChgRef{Version=[5],Kind=[Added],Aref=[AI12-0112-1]}
5075 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key[function] Tampering_With_The_Element_Prohibited
5076 (Container : Holder) @key[return] Boolean
5077 @key[with] Nonblocking, Global => (@key[null], @key[use null]);]}
5078 @end{Example}
5079
5080 @ChgRef{Version=[5],Kind=[Added],Aref=[AI12-0112-1]}
5081 @ChgAdded{Version=[5],Type=[Trailing],Text=[Returns True if tampering with the
5082 element is currently prohibited for Container, and
5083 returns False otherwise.]}
5084
5085 @begin{Example}
5086 @ChgRef{Version=[3],Kind=[AddedNormal]}
5087 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5088 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] To_Holder (New_Item : Element_Type) @key[return] Holder@Chg{Version=[5],New=[
5089 @key[with] Post => @key[not] Is_Empty (To_Holder'Result)],Old=[]};]}
5090 @end{Example}
5091
5092 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
5093 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0035-1]}
5094 @ChgAdded{Version=[3],Type=[Trailing],Text=[Returns a nonempty holder
5095 containing an element initialized to New_Item.@Chg{Version=[4],New=[
5096 To_Holder performs indefinite insertion (see @RefSecNum{Containers}).],Old=[]}]}
5097
5098 @begin{Example}
5099 @ChgRef{Version=[3],Kind=[AddedNormal]}
5100 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5101 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Is_Empty (Container : Holder) @key[return] Boolean@Chg{Version=[5],New=[
5102 @key[with] Global => (@key[null], @key[use null])],Old=[]};]}
5103 @end{Example}
5104
5105 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
5106 @ChgAdded{Version=[3],Type=[Trailing],Text=[Returns True if Container is
5107 empty, and False if it contains an element.]}
5108
5109 @begin{Example}
5110 @ChgRef{Version=[3],Kind=[AddedNormal]}
5111 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5112 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[procedure] Clear (Container : @key[in out] Holder)@Chg{Version=[5],New=[
5113 @key[with] Pre => @key[not] Tampering_With_The_Element_Prohibited (Container)
5114 @key[or else raise] Program_Error,
5115 Post => Is_Empty (Container)],Old=[]};]}
5116 @end{Example}
5117
5118 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
5119 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5120 @ChgAdded{Version=[3],Type=[Trailing],Text=[Removes the element from
5121 Container.@Chg{Version=[5],New=[],Old=[ Container is empty after a
5122 successful Clear operation.]}]}
5123
5124 @begin{Example}
5125 @ChgRef{Version=[3],Kind=[AddedNormal]}
5126 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5127 @ChgAdded{Version=[3],Text=[@key[function] Element (Container : Holder) @key[return] Element_Type@Chg{Version=[5],New=[
5128 @key[with] Pre => @key[not] Is_Empty (Container) @key[or else raise] Constraint_Error,
5129 Global => (@key[null], @key[use] Element_Type)],Old=[]};]}
5130 @end{Example}
5131
5132 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
5133 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5134 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[Returns],Old=[If
5135 Container is empty, Constraint_Error is propagated. Otherwise, returns]} the
5136 element stored in Container.]}
5137
5138 @begin{Example}
5139 @ChgRef{Version=[3],Kind=[AddedNormal]}
5140 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5141 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[procedure] Replace_Element (Container : @key[in out] Holder;
5142 New_Item : @key[in] Element_Type)@Chg{Version=[5],New=[
5143 @key[with] Pre => @key[not] Tampering_With_The_Element_Prohibited (Container)
5144 @key[or else raise] Program_Error,
5145 Post => @key[not] Is_Empty (Container)],Old=[]};]}
5146 @end{Example}
5147
5148 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
5149 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0035-1]}
5150 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5151 @ChgAdded{Version=[3],Type=[Trailing],Text=[Replace_Element assigns the value
5152 New_Item into Container, replacing any preexisting content of
5153 Container@Chg{Version=[4],New=[; Replace_Element performs indefinite insertion
5154 (see @RefSecNum{Containers})],Old=[]}.@Chg{Version=[5],New=[],Old=[ Container
5155 is not empty after a successful call to Replace_Element.]}]}
5156
5157 @begin{Example}
5158 @ChgRef{Version=[3],Kind=[AddedNormal]}
5159 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5160 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[procedure] Query_Element
5161 (Container : @key[in] Holder;
5162 Process : @key[not null access procedure] (Element : @key[in] Element_Type))@Chg{Version=[5],New=[
5163 @key[with] Pre => @key[not] Is_Empty (Container) @key[or else raise] Constraint_Error,
5164 Global => (@key[null], @key[use null])],Old=[]};]}
5165 @end{Example}
5166
5167 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0262-1],ARef=[AI05-0265-1]}
5168 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5169 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
5170 Container is empty, Constraint_Error is propagated. Otherwise, ]}Query_Element
5171 calls Process.@key[all] with the contained element as the argument.
5172 Tampering with the element
5173 of Container is prohibited during the execution of the call on
5174 Process.@key[all]. Any exception raised by Process.@key[all] is propagated.]}
5175
5176 @begin{ImplNote}
5177 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
5178 @ChgAdded{Version=[3],Text=[The @ldquote@;tamper with the element@rdquote
5179 check is intended to prevent the Element parameter of Process from being
5180 replaced or deleted outside of Process. The check prevents data loss (if
5181 Element_Type is passed by copy) or erroneous execution (if Element_Type is an
5182 unconstrained type).]}
5183 @end{ImplNote}
5184
5185 @begin{Example}
5186 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0248-1]}
5187 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5188 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[procedure] Update_Element
5189 (Container : @key[in out] Holder;
5190 Process : @key[not null access procedure] (Element : @key[in out] Element_Type))@Chg{Version=[5],New=[
5191 @key[with] Pre => @key[not] Is_Empty (Container) @key[or else raise] Constraint_Error],Old=[]};]}
5192 @end{Example}
5193
5194 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0262-1],ARef=[AI05-0265-1]}
5195 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5196 @ChgAdded{Version=[3],Type=[Trailing],Text=[@Chg{Version=[5],New=[],Old=[If
5197 Container is empty, Constraint_Error is propagated. Otherwise, ]}Update_Element
5198 calls Process.@key[all] with the contained element as the argument.
5199 Tampering with the element of Container is prohibited during the execution
5200 of the call on Process.@key[all].
5201 Any exception raised by Process.@key[all] is propagated.]}
5202
5203 @begin{ImplNote}
5204 @ChgRef{Version=[3],Kind=[AddedNormal]}
5205 @ChgAdded{Version=[3],Text=[The Element parameter of Process.@key[all] may be
5206 constrained even if Element_Type is unconstrained.]}
5207 @end{ImplNote}
5208
5209 @begin{Example}
5210 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5211 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5212 @ChgAdded{Version=[3],Text=[@key[type] Constant_Reference_Type
5213 (Element : @key[not null access constant] Element_Type) @key[is private]
5214 @key[with] Implicit_Dereference => Element@Chg{Version=[5],New=[,
5215 Nonblocking, Global => @key[in out synchronized],
5216 Default_Initial_Condition => (@key[raise] Program_Error)],Old=[]};]}
5217
5218 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5219 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5220 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[type] Reference_Type (Element : @key[not null access] Element_Type) @key[is private]
5221 @key[with] Implicit_Dereference => Element@Chg{Version=[5],New=[,
5222 Nonblocking, Global => @key[in out synchronized],
5223 Default_Initial_Condition => (@key[raise] Program_Error)],Old=[]};]}
5224 @end{Example}
5225
5226 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5227 @ChgAdded{Version=[3],Type=[Trailing],Text=[The types Constant_Reference_Type
5228 and Reference_Type
5229 need finalization.@PDefn2{Term=<needs finalization>,Sec=<language-defined type>}]}
5230
5231 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5232 @ChgRef{Version=[5],Kind=[Deleted],Aref=[AI12-0112-1]}
5233 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[The default
5234 initialization of an object of type
5235 Constant_Reference_Type or Reference_Type propagates Program_Error.]}]}
5236
5237 @begin{Reason}
5238 @ChgRef{Version=[3],Kind=[AddedNormal]}
5239 @ChgAdded{Version=[3],Text=[It is expected that Reference_Type (and
5240 Constant_Reference_Type) will be a controlled type, for which finalization
5241 will have some action to terminate the tampering check for the associated
5242 container. If the object is created by default, however, there is no
5243 associated container. Since this is useless, and supporting this case would
5244 take extra work, we define it to raise an exception.]}
5245 @end{Reason}
5246
5247 @begin{Example}
5248 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5249 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5250 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Constant_Reference (Container : @key[aliased in] Holder)
5251 @key[return] Constant_Reference_Type@Chg{Version=[5],New=[
5252 @key[with] Pre => @key[not] Is_Empty (Container) @key[or else raise] Constraint_Error,
5253 Post => Tampering_With_The_Element_Prohibited (Container),
5254 Nonblocking, Global => (@key[null], @key[use null])],Old=[]};]}
5255 @end{Example}
5256
5257 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5258 @ChgAdded{Version=[3],Type=[Trailing],Text=[This function (combined with the
5259 Implicit_Dereference aspect) provides a convenient way to gain read access to
5260 the contained element of a holder container.]}
5261
5262 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0262-1],ARef=[AI05-0265-1]}
5263 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5264 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[If Container is
5265 empty, Constraint_Error is propagated. Otherwise, ]}Constant_Reference
5266 returns an object whose discriminant
5267 is an access value that designates the contained element. Tampering with the
5268 element of Container is prohibited while the object returned by
5269 Constant_Reference exists and has not been finalized.]}
5270
5271 @begin{Example}
5272 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5273 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5274 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Reference (Container : @key[aliased in out] Holder)
5275 @key[return] Reference_Type@Chg{Version=[5],New=[
5276 @key[with] Pre => @key[not] Is_Empty (Container) @key[or else raise] Constraint_Error,
5277 Post => Tampering_With_The_Element_Prohibited (Container),
5278 Nonblocking, Global => (@key[null], @key[use null])],Old=[]};]}
5279 @end{Example}
5280
5281 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5282 @ChgAdded{Version=[3],Type=[Trailing],Text=[This function (combined with the
5283 Implicit_Dereference aspects) provides a convenient way to gain read and write
5284 access to the contained element of a holder container.]}
5285
5286 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0262-1],ARef=[AI05-0265-1]}
5287 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5288 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[If Container is
5289 empty, Constraint_Error is propagated. Otherwise, ]}Reference returns
5290 an object whose discriminant is an
5291 access value that designates the contained element. Tampering with the
5292 element of Container is prohibited while the object returned by
5293 Reference exists and has not been finalized.]}
5294
5295 @begin{Example}
5296 @ChgRef{Version=[3],Kind=[AddedNormal]}
5297 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5298 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[procedure] Assign (Target : @key[in out] Holder; Source : @key[in] Holder)@Chg{Version=[5],New=[
5299 @key[with] Post => (Is_Empty (Source) = Is_Empty (Target))],Old=[]};]}
5300 @end{Example}
5301
5302 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
5303 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Target denotes the same object as
5304 Source, the operation has no effect. If Source is empty, Clear (Target) is
5305 called. Otherwise, Replace_Element (Target, Element (Source)) is called.]}
5306 @begin{Discussion}
5307 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
5308 @ChgAdded{Version=[3],Text=[This routine exists for compatibility with the
5309 other containers. For a holder, @exam{Assign(A, B)} and
5310 @exam{A := B} behave effectively the same. (Assign Clears the Target, while
5311 := finalizes the Target, but these should have similar effects.)]}
5312 @end{Discussion}
5313
5314 @begin{Example}
5315 @ChgRef{Version=[3],Kind=[AddedNormal]}
5316 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5317 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Copy (Source : Holder) @key[return] Holder@Chg{Version=[5],New=[
5318 @key[with] Post => (Is_Empty (Source) = Is_Empty (Copy'Result))],Old=[]};]}
5319 @end{Example}
5320
5321 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
5322 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Source is empty, returns an empty
5323 holder container; otherwise, returns To_Holder (Element (Source)).]}
5324
5325 @begin{Example}
5326 @ChgRef{Version=[3],Kind=[AddedNormal]}
5327 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5328 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[procedure] Move (Target : @key[in out] Holder; Source : @key[in out] Holder)@Chg{Version=[5],New=[
5329 @key[with] Pre => (@key[not] Tampering_With_The_Element_Prohibited (Target)
5330 @key[or else raise] Program_Error) @key[and then]
5331 (@key[not] Tampering_With_The_Element_Prohibited (Source)
5332 @key[or else raise] Program_Error),
5333 Post => (@key[if] Target /= Source @key[then]
5334 Is_Empty (Source) @key[and then] (@key[not] Is_Empty (Target)))],Old=[]};]}
5335 @end{Example}
5336
5337 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0248-1]}
5338 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0112-1]}
5339 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Target denotes the same object
5340 as Source, then the operation has no effect. Otherwise, the element contained
5341 by Source (if any) is removed from Source and inserted into Target, replacing
5342 any preexisting content.@Chg{Version=[5],New=[],Old=[ Source is empty after a
5343 successful call to Move.]}]}
5344
5345 @begin{Example}
5346 @ChgRef{Version=[5],Kind=[Added]}
5347 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key[procedure] Swap (Left, Right : @key[in out] Holder)
5348 @key[with] Pre => (@key[not] Tampering_With_The_Element_Prohibited (Left)
5349 @key[or else raise] Program_Error) @key[and then]
5350 (@key[not] Tampering_With_The_Element_Prohibited (Right)
5351 @key[or else raise] Program_Error),
5352 Post => Is_Empty (Left) = Is_Empty (Right)'Old @key[and then]
5353 Is_Empty (Right) = Is_Empty (Left)'Old;]}
5354 @end{Example}
5355
5356 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0350-1]}
5357 @ChgAdded{Version=[5],Type=[Trailing],Text=[If Left denotes the same object as
5358 Right, then the operation has no effect. Otherwise, operation exchanges the
5359 elements (if any) contained by Left and Right.]}
5360
5361 @end{DescribeCode}
5362
5363 @end{StaticSem}
5364
5365 @begin{Bounded}
5366
5367 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0022-1],ARef=[AI05-0069-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1]}
5368 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
5369 It is a bounded error for the actual function associated with a
5370 generic formal subprogram, when called as part of an operation of
5371 this package, to tamper with the element of any Holder parameter of the
5372 operation. Either Program_Error is raised, or the operation works as
5373 defined on the value of the Holder either prior to, or subsequent to,
5374 some or all of the modifications to the
5375 Holder.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}]}
5376
5377 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0027-1],ARef=[AI05-0069-1]}
5378 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
5379 It is a bounded error to call any subprogram declared in the visible part
5380 of Containers.Indefinite_Holders when the associated container has been
5381 finalized. If the operation takes Container as an @key[in out] parameter,
5382 then it raises Constraint_Error or Program_Error. Otherwise, the operation
5383 either proceeds as it would for an empty container, or it raises
5384 Constraint_Error or@Defn2{Term=[Constraint_Error],Sec=(raised by detection of a bounded error)}
5385 Program_Error.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}]}
5386 @end{Bounded}
5387
5388 @begin{Erron}
5389 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0269-1]}
5390 @ChgAdded{Version=[3],Text=[Execution is erroneous if the holder container
5391 associated with the result of a call to Reference or Constant_Reference is
5392 finalized before the result object returned by the call to Reference or
5393 Constant_Reference is finalized.@PDefn2{Term=(erroneous execution),Sec=(cause)}]}
5394
5395 @begin{Reason}
5396 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5397 @ChgAdded{Version=[3],Text=[Each object of Reference_Type and
5398 Constant_Reference_Type probably contains some reference to the originating
5399 container. If that container is prematurely finalized (which is only possible
5400 via Unchecked_Deallocation, as accessibility checks prevent passing a
5401 container to Reference that will not live as long as the result), the
5402 finalization of the object of Reference_Type will try to access a nonexistent
5403 object. This is a normal case of a dangling pointer created by
5404 Unchecked_Deallocation; we have to explicitly mention it here as the pointer
5405 in question is not visible in the specification of the type. (This is the same
5406 reason we have to say this for invalid cursors.)]}
5407 @end{Reason}
5408 @end{Erron}
5409
5410 @begin{ImplReq}
5411
5412 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
5413 @ChgAdded{Version=[3],Text=[No storage associated with a holder object shall be
5414 lost upon assignment or scope exit.]}
5415
5416 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0269-1]}
5417 @ChgAdded{Version=[3],Text=[The execution of an @nt{assignment_statement}
5418 for a holder container shall have the effect of copying the element (if any)
5419 from the source holder object to the target holder object.]}
5420
5421 @begin{ImplNote}
5422 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0298-1]}
5423 @ChgAdded{Version=[3],Text=[An assignment of a holder container is a
5424 @ldquote@;deep@rdquote copy; that is the element is copied as well as any
5425 data structures. We say @ldquote@;effect of@rdquote in order to allow the
5426 implementation to avoid copying the element immediately if it wishes. For
5427 instance, an implementation that avoided copying until one of the containers
5428 is modified would be allowed. (Note that this implementation would
5429 require care, see @RefSecNum{The Generic Package Containers.Vectors} for more.)]}
5430 @end{ImplNote}
5431 @end{ImplReq}
5432
5433 @begin{ImplAdvice}
5434
5435 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0269-1]}
5436 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0350-1]}
5437 @ChgAdded{Version=[3],Text=[Move @Chg{Version=[5],New=[ and Swap],Old=[]} should not
5438 copy @Chg{Version=[5],New=[any elements],Old=[the element]}, and should
5439 minimize copying of internal data structures.]}
5440 @ChgImplAdvice{Version=[5],Kind=[Added],
5441 InitialVersion=[3],Text=[@ChgAdded{Version=[3],
5442 Text=[@Chg{Version=[5],New=[Move and Swap in ],Old=[]}Containers.Indefinite_Holders@Chg{Version=[5],New=[],Old=[.Move]}
5443 should not copy @Chg{Version=[5],New=[any elements],Old=[the element]}, and
5444 should minimize copying of internal data structures.]}]}
5445
5446 @begin{ImplNote}
5447 @ChgRef{Version=[3],Kind=[AddedNormal]}
5448 @ChgRef{Version=[5],Kind=[Revised],Aref=[AI12-0350-1]}
5449 @ChgAdded{Version=[3],Text=[Usually that can be accomplished simply by moving
5450 the pointer(s) to the internal data structures@Chg{Version=[5],New=[
5451 appropriately],Old=[ from the Source holder to the
5452 Target holder]}.]}
5453 @end{ImplNote}
5454
5455 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0269-1]}
5456 @ChgAdded{Version=[3],Text=[If an exception is propagated from a holder
5457 operation, no storage should be lost, nor should the element be removed from a
5458 holder container unless specified by the operation.]}
5459 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
5460 Text=[If an exception is propagated from a holder
5461 operation, no storage should be lost, nor should the element be removed from a
5462 holder container unless specified by the operation.]}]}
5463
5464 @begin{Reason}
5465 @ChgRef{Version=[3],Kind=[AddedNormal]}
5466 @ChgAdded{Version=[3],Text=[This is important so that programs can recover
5467 from errors. But we don't want to require heroic efforts, so we just require
5468 documentation of cases where this can't be accomplished.]}
5469 @end{Reason}
5470 @end{ImplAdvice}
5471
5472 @begin{Extend2005}
5473 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0084-1],ARef=[AI05-0265-1]}
5474 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic package
5475 Containers.Indefinite_Holders is new.]}
5476 @end{Extend2005}
5477
5478 @begin{Inconsistent2012}
5479 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
5480 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
5481 Defined some routines to @ldquote@;perform indefinite insertion@rdquote.
5482 This could mean that some calls to those routines would now raise
5483 Program_Error where they previously worked. However, this is extremely
5484 unlikely; see @Inconsistent2012Title in
5485 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
5486 @end{Inconsistent2012}
5487
5488 @begin{Incompatible2012}
5489 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1],ARef=[AI12-0112-1],ARef=[AI12-0350-1]}
5490 @ChgAdded{Version=[5],Text=[@Defn{incompatibilities with Ada 2012}A number of
5491 new subprograms and types were added to
5492 Containers.Indefinite_Holders to better support contracts and provide
5493 additional functionality. If an instance of Containers.Indefinite_Holders
5494 is referenced in a @nt{use_clause}, and an entity @i<E> with the same
5495 @nt{defining_identifier} as a new entity in Containers.Hashed_Maps is
5496 defined in a package that is also referenced in a @nt{use_clause}, the
5497 entity @i<E> may no longer be use-visible, resulting in errors. This should
5498 be rare and is easily fixed if it does occur.]}
5499 @end{Incompatible2012}
5500
5501 @begin{DiffWord2012}
5502 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0110-1]}
5503 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified that tampering checks
5504 precede all other checks made by a subprogram (but come after those associated
5505 with the call).]}
5506
5507 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
5508 @ChgAdded{Version=[5],Text=[Added contracts to this container. This includes
5509 describing some of the semantics with pre- and postconditions, rather than
5510 English text. Note that the preconditions can be Suppressed (see
5511 @RefSecNum{Suppressing Checks}).]}
5512 @end{DiffWord2012}
5513
5514
5515 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Vectors]}
5516
5517 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
5518 @ChgAdded{Version=[3],Text=[The language-defined generic package
5519 Containers.Bounded_Vectors@ChildUnit{Parent=[Ada.Containers],Child=[Bounded_Vectors]}
5520 provides a private type Vector and a set of
5521 operations. It provides the same operations as the package Containers.Vectors
5522 (see @RefSecNum{The Generic Package Containers.Vectors}), with the difference that the
5523 maximum storage is bounded.]}
5524
5525 @begin{StaticSem}
5526
5527 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
5528 @ChgAdded{Version=[3],Type=[Leading],Text=[The declaration of the generic
5529 library package Containers.Bounded_Vectors has the same contents and semantics
5530 as Containers.Vectors except:]}
5531
5532 @begin{Itemize}
5533 @ChgRef{Version=[3],Kind=[AddedNormal]}
5534 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
5535 @ChgAdded{Version=[3],Text=[The
5536 @Chg{Version=[5],New=[aspect],Old=[@nt{pragma}]} Preelaborate is replaced
5537 with @Chg{Version=[5],New=[aspect],Old=[@nt{pragma}]} Pure.]}
5538
5539 @ChgRef{Version=[3],Kind=[AddedNormal]}
5540 @ChgAdded{Version=[3],Type=[Leading],Text=[The type Vector is declared with a
5541 discriminant that specifies the capacity:]}
5542 @begin{Example}
5543 @ChgRef{Version=[3],Kind=[AddedNormal]}
5544 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
5545 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key{type} Vector (Capacity : Count_Type) @key[is tagged private]@Chg{Version=[5],New=[...],Old=[;]}]}
5546 @end{Example}
5547
5548 @ChgRef{Version=[3],Kind=[AddedNormal]}
5549 @ChgAdded{Version=[3],Text=[The type Vector needs finalization if and only if
5550 type Element_Type needs finalization.]}
5551
5552 @begin{ImplNote}
5553 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5554 @ChgAdded{Version=[3],Text=[The type Vector cannot depend on package
5555 Ada.Finalization unless the element type depends on that package.
5556 The objects returned from the Iterator and Reference functions probably do
5557 depend on package Ada.Finalization. Restricted environments may need to
5558 avoid use of those functions and their associated types.]}
5559 @end{ImplNote}
5560
5561 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
5562 @ChgAdded{Version=[5],Text=[Capacity is omitted from the Stable_Properties
5563 of type Vector.]}
5564
5565 @begin{Reason}
5566 @ChgRef{Version=[5],Kind=[AddedNormal]}
5567 @ChgAdded{Version=[5],Text=[The capacity is a discriminant here, so it can't
5568 be changed by most routines; thus including it in the stable properties
5569 adds no information.]}
5570 @end{Reason}
5571
5572 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0339-1]}
5573 @ChgAdded{Version=[5],Type=[Leading],Text=[In function Empty, the
5574 postcondition is altered to:]}
5575
5576 @begin{Example}
5577 @ChgRef{Version=[5],Kind=[Added]}
5578 @ChgAdded{Version=[5],Noprefix=[T],Text=[ Post =>
5579 Empty'Result.Capacity = Capacity @key[and then]
5580 @key[not] Tampering_With_Elements_Prohibited (Empty'Result) @key[and then]
5581 @key[not] Tampering_With_Cursors_Prohibited (Empty'Result) @key[and then]
5582 Length (Empty'Result) = 0;]}
5583 @end{Example}
5584
5585 @ChgRef{Version=[3],Kind=[AddedNormal]}
5586 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
5587 @ChgAdded{Version=[5],Type=[Leading],Text=[]}@Comment{Conditional leading format.}
5588 @ChgAdded{Version=[3],Text=[In function Copy, @Chg{Version=[5],New=[the
5589 postcondition is altered to:],Old=[if the Capacity parameter is
5590 equal to or greater than the length of Source, the vector capacity exactly equals
5591 the value of the Capacity parameter.]}]}
5592 @begin{Example}
5593 @ChgRef{Version=[5],Kind=[Added]}
5594 @ChgAdded{Version=[5],Noprefix=[T],Text=[ Post => Length (Copy'Result) = Length (Source) @key[and then]
5595 (@key[if] Capacity > Length (Source) @key[then]
5596 Copy'Result.Capacity = Capacity
5597 @key[else] Copy'Result.Capacity >= Length (Source));]}
5598 @end{Example}
5599
5600 @ChgRef{Version=[3],Kind=[AddedNormal]}
5601 @ChgAdded{Version=[3],Type=[Leading],Text=[The description of Reserve_Capacity
5602 is replaced with:]}
5603
5604 @begin{Example}
5605 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
5606 @ChgAdded{Version=[5],Noprefix=[T],Text=[ @key[procedure] Reserve_Capacity (Container : @key[in out] Vector;
5607 Capacity : @key[in] Count_Type)
5608 @key[with] Pre => Capacity <= Container.Capacity @key[or else raise] Capacity_Error;]}
5609 @end{Example}
5610
5611 @begin{Indent}
5612 @ChgRef{Version=[3],Kind=[AddedNormal]}
5613 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
5614 @ChgAdded{Version=[3],NoPrefix=[T],Text=[@Chg{Version=[5],New=[This],Old=[If the specified Capacity is larger
5615 than the capacity of Container, then Reserve_Capacity propagates Capacity_Error.
5616 Otherwise, the]} operation has no effect@Chg{Version=[5],New=[,
5617 @Redundant[other than checking the precondition]],Old=[]}.]}
5618 @end{Indent}
5619
5620 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
5621 @ChgAdded{Version=[5],Text=[The portion of the postcondition checking the
5622 capacity is omitted from subprograms Set_Length, Assign, Insert,
5623 Insert_Space, Prepend, Append, and Delete.]}
5624
5625 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
5626 @ChgAdded{Version=[5],Type=[Leading],Text=[For procedures Insert,
5627 Insert_Space, Prepend, and Append, the part of the precondition reading:]}
5628
5629 @begin{Example}
5630 @ChgRef{Version=[5],Kind=[Added]}
5631 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (<@examcom{some length}> <= Maximum_Length - <@examcom{some other length}>
5632 @key[or else raise] Constraint_Error)]}
5633 @end{Example}
5634
5635 @ChgRef{Version=[5],Kind=[Added]}
5636 @ChgAdded{Version=[5],Type=[Leading],Noprefix=[T],Text=[is replaced by:]}
5637
5638 @begin{Example}
5639 @ChgRef{Version=[5],Kind=[Added]}
5640 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (<@examcom{some length}> <= Maximum_Length - <@examcom{some other length}>
5641 @key[or else raise] Constraint_Error) @key[and then]
5642 (<@examcom{some length}> <= Container.Capacity - <@examcom{some other length}>
5643 @key[or else raise] Capacity_Error)]}
5644 @end{Example}
5645
5646
5647 @end{Itemize}
5648 @end{StaticSem}
5649
5650 @begin{Bounded}
5651 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0160-1],ARef=[AI05-0265-1]}
5652 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
5653 It is a bounded error to assign from a bounded vector object while tampering
5654 with elements @Redundant[or cursors] of that object is prohibited. Either
5655 Program_Error is raised by the assignment, execution proceeds with the target
5656 object prohibiting tampering with elements @Redundant[or cursors], or execution
5657 proceeds normally.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}]}
5658 @begin{TheProof}
5659 @ChgRef{Version=[3],Kind=[AddedNormal]}
5660 @ChgAdded{Version=[3],Text=[Tampering with elements includes tampering
5661 with cursors, so we only really need to talk about tampering with elements
5662 here; we mention cursors for clarity.]}
5663 @end{TheProof}
5664 @end{Bounded}
5665
5666 @begin{Erron}
5667 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
5668 @ChgAdded{Version=[3],Text=[When a bounded vector object @i<V> is
5669 finalized, if tampering with cursors is prohibited for @i<V> other than due
5670 to an assignment from another vector, then execution is erroneous.
5671 @PDefn2{Term=(erroneous execution),Sec=(cause)}]}
5672
5673 @begin{Reason}
5674 @ChgRef{Version=[3],Kind=[AddedNormal]}
5675 @ChgAdded{Version=[3],Text=[This is a tampering event, but since the
5676 implementation is not allowed to use Ada.Finalization, it is not possible in a
5677 pure Ada implementation to detect this error. (There is no Finalize routine
5678 that will be called that could make the check.) Since the check probably
5679 cannot be made, the bad effects that could occur (such as an iterator going
5680 into an infinite loop or accessing a nonexistent element) cannot be prevented
5681 and we have to allow anything. We do allow re-assigning an object that only
5682 prohibits tampering because it was copied from another object as that cannot
5683 cause any negative effects.]}
5684 @end{Reason}
5685 @end{Erron}
5686
5687 @begin{ImplReq}
5688 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0264-1]}
5689 @ChgAdded{Version=[3],Type=[Leading],Text=[For each instance of
5690 Containers.Vectors and each instance of Containers.Bounded_Vectors,
5691 if the two instances meet the following conditions,
5692 then the output generated by
5693 the Vector'Output or Vector'Write subprograms of either instance
5694 shall be readable by the Vector'Input
5695 or Vector'Read of the other instance, respectively:]}
5696
5697 @begin{Itemize}
5698 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0248-1]}
5699 @ChgAdded{Version=[3],Text=[the Element_Type parameters of the two instances
5700 are statically matching subtypes of the same type; and]}
5701
5702 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
5703 @ChgAdded{Version=[3],Text=[the output generated by Element_Type'Output or
5704 Element_Type'Write is readable by Element_Type'Input or Element_Type'Read,
5705 respectively (where Element_Type denotes the type of the two actual
5706 Element_Type parameters); and]}
5707
5708 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
5709 @ChgAdded{Version=[3],Text=[the preceding two conditions also hold for the
5710 Index_Type parameters of the instances.]}
5711 @end{Itemize}
5712 @end{ImplReq}
5713
5714 @begin{ImplAdvice}
5715 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
5716 @ChgAdded{Version=[3],Text=[Bounded vector objects should be implemented without
5717 implicit pointers or dynamic allocation.]}
5718 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
5719 Text=[Bounded vector objects should be implemented without
5720 implicit pointers or dynamic allocation.]}]}
5721
5722 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
5723 @ChgAdded{Version=[3],Text=[The implementation advice for procedure Move to
5724 minimize copying does not apply.]}
5725 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
5726 Text=[The implementation advice for procedure Move to
5727 minimize copying does not apply to bounded vectors.]}]}
5728
5729 @end{ImplAdvice}
5730
5731 @begin{Extend2005}
5732 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0160-1],ARef=[AI05-0184-1]}
5733 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic package
5734 Containers.Bounded_Vectors is new.]}
5735 @end{Extend2005}
5736
5737 @begin{Inconsistent2012}
5738 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
5739 @ChgAdded{Version=[5],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
5740 Tampering with elements is now defined to be equivalent to tampering with
5741 cursors for bounded containers. If a program requires tampering detection
5742 to work, it might fail in Ada 202x. Needless to say, this shouldn't happen
5743 outside of test programs. See @Inconsistent2012Title in
5744 @RefSecNum{The Generic Package Containers.Vectors} for more details.]}
5745 @end{Inconsistent2012}
5746
5747
5748
5749 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Doubly_Linked_Lists]}
5750
5751 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
5752 @ChgAdded{Version=[3],Text=[The language-defined generic package
5753 Containers.Bounded_Doubly_Linked_Lists@ChildUnit{Parent=[Ada.Containers],Child=[Bounded_Doubly_Linked_Lists]}
5754 provides a private type List
5755 and a set of operations. It provides the same operations as the
5756 package Containers.Doubly_Linked_Lists
5757 (see @RefSecNum{The Generic Package Containers.Doubly_Linked_Lists}), with the
5758 difference that the maximum storage is bounded.]}
5759
5760 @begin{StaticSem}
5761
5762 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
5763 @ChgAdded{Version=[3],Type=[Leading],Text=[The declaration of the generic
5764 library package Containers.Bounded_Doubly_Linked_Lists has the same contents and semantics
5765 as Containers.Doubly_Linked_Lists except:]}
5766
5767 @begin{Itemize}
5768 @ChgRef{Version=[3],Kind=[AddedNormal]}
5769 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
5770 @ChgAdded{Version=[3],Text=[The
5771 @Chg{Version=[5],New=[aspect],Old=[@nt{pragma}]} Preelaborate is replaced
5772 with @Chg{Version=[5],New=[aspect],Old=[@nt{pragma}]} Pure.]}
5773
5774 @ChgRef{Version=[3],Kind=[AddedNormal]}
5775 @ChgAdded{Version=[3],Type=[Leading],Text=[The type List is declared with a
5776 discriminant that specifies the capacity (maximum number of elements)
5777 as follows:]}
5778 @begin{Example}
5779 @ChgRef{Version=[3],Kind=[AddedNormal]}
5780 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
5781 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key{type} List (Capacity : Count_Type) @key[is tagged private]@Chg{Version=[5],New=[...],Old=[;]}]}
5782 @end{Example}
5783
5784 @ChgRef{Version=[3],Kind=[AddedNormal]}
5785 @ChgAdded{Version=[3],Text=[The type List needs finalization if and only if
5786 type Element_Type needs finalization.]}
5787
5788 @begin{ImplNote}
5789 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5790 @ChgAdded{Version=[3],Text=[The type List cannot depend on package
5791 Ada.Finalization unless the element type depends on that package.
5792 The objects returned from the Iterator and Reference functions probably do
5793 depend on package Ada.Finalization. Restricted environments may need to
5794 avoid use of those functions and their associated types.]}
5795 @end{ImplNote}
5796
5797 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0339-1]}
5798 @ChgAdded{Version=[5],Type=[Leading],Text=[The function Empty is replaced by:]}
5799
5800 @begin{Example}
5801 @ChgRef{Version=[5],Kind=[Added]}
5802 @ChgAdded{Version=[5],Noprefix=[T],Text=[ @key[function] Empty (Capacity : Count_Type := @RI{implementation-defined})
5803 @key[return] List
5804 @key[with] Post =>
5805 Empty'Result.Capacity = Capacity @key[and then]
5806 @key[not] Tampering_With_Elements_Prohibited (Empty'Result) @key[and then]
5807 @key[not] Tampering_With_Cursors_Prohibited (Empty'Result) @key[and then]
5808 Length (Empty'Result) = 0;]}
5809 @end{Example}
5810
5811 @ChgRef{Version=[3],Kind=[AddedNormal]}
5812 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
5813 @ChgAdded{Version=[5],Type=[Leading],Text=[]}@Comment{Conditional leading format.}
5814 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[For procedures Insert,
5815 Prepend, Append, Merge, and the three-parameter Splice whose parameter
5816 Source has type List, the part of the precondition reading:],Old=[The
5817 allocation of internal storage includes a check that the capacity is not
5818 exceeded, and Capacity_Error is raised if this check fails.]}]}
5819
5820 @begin{Example}
5821 @ChgRef{Version=[5],Kind=[Added]}
5822 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (<@examcom{some length}> <= Count_Type'Last - <@examcom{some other length}>
5823 @key[or else raise] Constraint_Error)]}
5824 @end{Example}
5825
5826 @ChgRef{Version=[5],Kind=[Added]}
5827 @ChgAdded{Version=[5],Type=[Leading],Noprefix=[T],Text=[is replaced by:]}
5828
5829 @begin{Example}
5830 @ChgRef{Version=[5],Kind=[Added]}
5831 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (<@examcom{some length}> <= Count_Type'Last - <@examcom{some other length}>
5832 @key[or else raise] Constraint_Error) @key[and then]
5833 (<@examcom{some length}> <= Container.Capacity - <@examcom{some other length}>
5834 @key[or else raise] Capacity_Error)]}
5835 @end{Example}
5836
5837 @ChgRef{Version=[3],Kind=[AddedNormal]}
5838 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
5839 @ChgAdded{Version=[5],Type=[Leading],Text=[]}@Comment{Conditional leading format.}
5840 @ChgAdded{Version=[3],Text=[In procedure Assign, @Chg{Version=[5],New=[the
5841 precondition is altered to:],Old=[if Source length is greater
5842 than Target capacity, then Capacity_Error is
5843 propagated.]}]}
5844 @begin{Example}
5845 @ChgRef{Version=[5],Kind=[Added]}
5846 @ChgAdded{Version=[5],Noprefix=[T],Text=[ Pre => (@key{not} Tampering_With_Cursors_Prohibited (Target)
5847 @key{or else raise} Program_Error) @key{and then}
5848 (Length (Source) <= Target.Capacity
5849 @key{or else raise} Capacity_Error),]}
5850 @end{Example}
5851
5852 @ChgRef{Version=[3],Kind=[AddedNormal]}
5853 @ChgAdded{Version=[3],Type=[Leading],Text=[The function Copy is replaced with:]}
5854 @begin{Example}
5855 @ChgRef{Version=[3],Kind=[AddedNormal]}
5856 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
5857 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[function] @AdaSubDefn{Copy} (Source : List; Capacity : Count_Type := 0)
5858 @key[return] List@Chg{Version=[5],New=[
5859 @key[with] Pre => Capacity = 0 @key[or else] Capacity >= Length (Source)
5860 @key[or else raise] Capacity_Error,
5861 Post => Length (Copy'Result) = Length (Source) @key[and then]
5862 @key[not] Tampering_With_Elements_Prohibited (Copy'Result) @key[and then]
5863 @key[not] Tampering_With_Cursors_Prohibited (Copy'Result) @key[and then]
5864 Copy'Result.Capacity = (@key[if] Capacity = 0 @key[then]
5865 Length (Source) @key[else] Capacity)],Old=[]};]}
5866 @end{Example}
5867 @begin{Indent}
5868 @ChgRef{Version=[3],Kind=[AddedNormal]}
5869 @ChgRef{Version=[5],Kind=[Revised]}
5870 @ChgAdded{Version=[3],Noprefix=[T],Text=[@Chg{Version=[5],New=[Returns a
5871 list whose elements have the same values as the elements of Source.],Old=[If
5872 Capacity is 0, then the list capacity is the length of
5873 Source; if Capacity is equal to or greater than the length of Source,
5874 the list capacity equals the value of the Capacity parameter;
5875 otherwise, the operation propagates Capacity_Error]}.]}
5876 @end{Indent}
5877
5878 @ChgRef{Version=[3],Kind=[AddedNormal]}
5879 @ChgRef{Version=[5],Kind=[Deleted],ARef=[AI12-0112-1]}
5880 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[],Old=[In the
5881 three-parameter procedure Splice whose
5882 Source has type List, if the sum of the length of Target and the length
5883 of Source is greater than the capacity of Target, then Splice propagates
5884 Capacity_Error.]}]}
5885
5886 @ChgRef{Version=[3],Kind=[AddedNormal]}
5887 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
5888 @ChgAdded{Version=[5],Type=[Leading],Text=[]}@Comment{Conditional leading format.}
5889 @ChgAdded{Version=[3],Text=[In the four-parameter procedure Splice,
5890 @Chg{Version=[5],New=[the precondition is altered to:],Old=[if
5891 the length of Target equals the capacity of Target, then Splice
5892 propagates Capacity_Error.]}]}
5893 @begin{Example}
5894 @ChgRef{Version=[5],Kind=[Added]}
5895 @ChgAdded{Version=[5],Noprefix=[T],Text=[ Pre => (@key{if} Tampering_With_Cursors_Prohibited (Target)
5896 @key{then raise} Program_Error
5897 @key{elsif} Tampering_With_Cursors_Prohibited (Source)
5898 @key{then raise} Program_Error
5899 @key{elsif} Position = No_Element
5900 @key{then raise} Constraint_Error
5901 @key{elsif not} Has_Element (Source, Position)
5902 @key{then raise} Program_Error
5903 @key{elsif} Before /= No_Element @key{and then}
5904 @key{not} Has_Element (Target, Before)
5905 @key{then raise} Program_Error
5906 @key{elsif} Same_Object (Target, Source) @key{then} True
5907 @key{elsif} Length (Target) = Count_Type'Last
5908 @key{then raise} Constraint_Error
5909 @key{elsif} Length (Target) = Target.Capacity
5910 @key{then raise} Capacity_Error),]}
5911 @end{Example}
5912
5913 @end{Itemize}
5914 @end{StaticSem}
5915
5916 @begin{Bounded}
5917 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0160-1],ARef=[AI05-0265-1]}
5918 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
5919 It is a bounded error to assign from a bounded list object while tampering
5920 with elements @Redundant[or cursors] of that object is prohibited. Either
5921 Program_Error is raised by the assignment, execution proceeds with the target
5922 object prohibiting tampering with elements @Redundant[or cursors], or execution
5923 proceeds normally.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}]}
5924 @begin{TheProof}
5925 @ChgRef{Version=[3],Kind=[AddedNormal]}
5926 @ChgAdded{Version=[3],Text=[Tampering with elements includes tampering
5927 with cursors, so we only really need to talk about tampering with elements
5928 here; we mention cursors for clarity.]}
5929 @end{TheProof}
5930 @end{Bounded}
5931
5932 @begin{Erron}
5933 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
5934 @ChgAdded{Version=[3],Text=[When a bounded list object @i<L> is
5935 finalized, if tampering with cursors is prohibited for @i<L> other than due
5936 to an assignment from another list, then execution is erroneous.
5937 @PDefn2{Term=(erroneous execution),Sec=(cause)}]}
5938
5939 @begin{Reason}
5940 @ChgRef{Version=[3],Kind=[AddedNormal]}
5941 @ChgAdded{Version=[3],Text=[This is a tampering event, but since the
5942 implementation is not allowed to use Ada.Finalization, it is not possible in a
5943 pure Ada implementation to detect this error. (There is no Finalize routine
5944 that will be called that could make the check.) Since the check probably
5945 cannot be made, the bad effects that could occur (such as an iterator going
5946 into an infinite loop or accessing a nonexistent element) cannot be prevented
5947 and we have to allow anything. We do allow re-assigning an object that only
5948 prohibits tampering because it was copied from another object as that cannot
5949 cause any negative effects.]}
5950 @end{Reason}
5951 @end{Erron}
5952
5953
5954 @begin{ImplReq}
5955 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0264-1]}
5956 @ChgAdded{Version=[3],Type=[Leading],Text=[For each instance of
5957 Containers.Doubly_Linked_Lists and each instance of
5958 Containers.Bounded_Doubly_Linked_Lists,
5959 if the two instances meet the following conditions,
5960 then the output generated by
5961 the List'Output or List'Write subprograms of either instance
5962 shall be readable by the List'Input
5963 or List'Read of the other instance, respectively:]}
5964
5965 @begin{Itemize}
5966 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0248-1]}
5967 @ChgAdded{Version=[3],Text=[the Element_Type parameters of the two instances
5968 are statically matching subtypes of the same type; and]}
5969
5970 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
5971 @ChgAdded{Version=[3],Text=[the output generated by Element_Type'Output or
5972 Element_Type'Write is readable by Element_Type'Input or Element_Type'Read,
5973 respectively (where Element_Type denotes the type of the two actual
5974 Element_Type parameters).]}
5975 @end{Itemize}
5976 @end{ImplReq}
5977
5978 @begin{ImplAdvice}
5979 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
5980 @ChgAdded{Version=[3],Text=[Bounded list objects should be implemented without
5981 implicit pointers or dynamic allocation.]}
5982 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
5983 Text=[Bounded list objects should be implemented without
5984 implicit pointers or dynamic allocation.]}]}
5985
5986 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
5987 @ChgAdded{Version=[3],Text=[The implementation advice for procedure Move to
5988 minimize copying does not apply.]}
5989 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
5990 Text=[The implementation advice for procedure Move to
5991 minimize copying does not apply to bounded lists.]}]}
5992
5993 @end{ImplAdvice}
5994
5995 @begin{Extend2005}
5996 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0160-1],ARef=[AI05-0184-1]}
5997 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic package
5998 Containers.Bounded_Doubly_Linked_Lists is new.]}
5999 @end{Extend2005}
6000
6001 @begin{Inconsistent2012}
6002 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
6003 @ChgAdded{Version=[5],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
6004 Tampering with elements is now defined to be equivalent to tampering with
6005 cursors for bounded containers. If a program requires tampering detection
6006 to work, it might fail in Ada 202x. Needless to say, this shouldn't happen
6007 outside of test programs. See @Inconsistent2012Title in
6008 @RefSecNum{The Generic Package Containers.Vectors} for more details.]}
6009 @end{Inconsistent2012}
6010
6011
6012
6013 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Hashed_Maps]}
6014
6015 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
6016 @ChgAdded{Version=[3],Text=[The language-defined generic package
6017 Containers.Bounded_Hashed_Maps@ChildUnit{Parent=[Ada.Containers],Child=[Bounded_Hashed_Maps]}
6018 provides a private type Map
6019 and a set of operations. It provides the same operations as the
6020 package Containers.Hashed_Maps
6021 (see @RefSecNum{The Generic Package Containers.Hashed_Maps}), with the
6022 difference that the maximum storage is bounded.]}
6023
6024 @begin{StaticSem}
6025
6026 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
6027 @ChgAdded{Version=[3],Type=[Leading],Text=[The declaration of the generic
6028 library package Containers.Bounded_Hashed_Maps has the same contents and semantics
6029 as Containers.Hashed_Maps except:]}
6030
6031 @begin{Itemize}
6032 @ChgRef{Version=[3],Kind=[AddedNormal]}
6033 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6034 @ChgAdded{Version=[3],Text=[The
6035 @Chg{Version=[5],New=[aspect],Old=[@nt{pragma}]} Preelaborate is replaced
6036 with @Chg{Version=[5],New=[aspect],Old=[@nt{pragma}]} Pure.]}
6037
6038 @ChgRef{Version=[3],Kind=[AddedNormal]}
6039 @ChgAdded{Version=[3],Type=[Leading],Text=[The type Map is declared with
6040 discriminants that specify both the capacity (number of elements) and
6041 modulus (number of distinct hash values) of the hash table as follows:]}
6042 @begin{Example}
6043 @ChgRef{Version=[3],Kind=[AddedNormal]}
6044 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6045 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[type] Map (Capacity : Count_Type;
6046 Modulus : Hash_Type) @key[is tagged private]@Chg{Version=[5],New=[...],Old=[;]}]}
6047 @end{Example}
6048
6049 @ChgRef{Version=[3],Kind=[AddedNormal]}
6050 @ChgAdded{Version=[3],Text=[The type Map needs finalization if and only if type
6051 Key_Type or type Element_Type needs finalization.]}
6052
6053 @begin{ImplNote}
6054 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
6055 @ChgAdded{Version=[3],Text=[The type Map cannot depend on package
6056 Ada.Finalization unless the element or key type depends on that package.
6057 The objects returned from the Iterator and Reference functions probably do
6058 depend on package Ada.Finalization. Restricted environments may need to
6059 avoid use of those functions and their associated types.]}
6060 @end{ImplNote}
6061
6062 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0339-1]}
6063 @ChgAdded{Version=[5],Type=[Leading],Text=[In function Empty, the
6064 postcondition is altered to:]}
6065
6066 @begin{Example}
6067 @ChgRef{Version=[5],Kind=[Added]}
6068 @ChgAdded{Version=[5],Noprefix=[T],Text=[ Post =>
6069 Empty'Result.Capacity = Capacity @key[and then]
6070 Empty'Result.Modulus = Default_Modulus (Capacity) @key[and then]
6071 @key[not] Tampering_With_Elements_Prohibited (Empty'Result) @key[and then]
6072 @key[not] Tampering_With_Cursors_Prohibited (Empty'Result) @key[and then]
6073 Length (Empty'Result) = 0;]}
6074 @end{Example}
6075
6076 @ChgRef{Version=[3],Kind=[AddedNormal]}
6077 @ChgAdded{Version=[3],Type=[Leading],Text=[The description of Reserve_Capacity
6078 is replaced with:]}
6079
6080 @begin{Example}
6081 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
6082 @ChgAdded{Version=[5],Noprefix=[T],Text=[ @key[procedure] Reserve_Capacity (Container : @key[in out] Map;
6083 Capacity : @key[in] Count_Type)
6084 @key[with] Pre => Capacity <= Container.Capacity @key[or else raise] Capacity_Error;]}
6085 @end{Example}
6086
6087 @begin{Indent}
6088 @ChgRef{Version=[3],Kind=[AddedNormal]}
6089 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6090 @ChgAdded{Version=[3],NoPrefix=[T],Text=[@Chg{Version=[5],New=[This],Old=[If the specified Capacity is larger
6091 than the capacity of Container, then Reserve_Capacity propagates Capacity_Error.
6092 Otherwise, the]} operation has no effect@Chg{Version=[5],New=[,
6093 @Redundant[other than checking the precondition]],Old=[]}.]}
6094 @end{Indent}
6095
6096 @ChgRef{Version=[3],Kind=[AddedNormal]}
6097 @ChgAdded{Version=[3],Type=[Leading],Text=[An additional operation is added immediately following Reserve_Capacity:]}
6098 @begin{Example}
6099 @ChgRef{Version=[3],Kind=[AddedNormal]}
6100 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[function] @AdaSubDefn{Default_Modulus} (Capacity : Count_Type) @key[return] Hash_Type;]}
6101 @end{Example}
6102 @begin{Indent}
6103 @ChgRef{Version=[3],Kind=[AddedNormal]}
6104 @ChgAdded{Version=[3],Noprefix=[T],Text=[Default_Modulus returns an
6105 implementation-defined value for the number of distinct hash values to be
6106 used for the given capacity (maximum number of elements).]}
6107 @end{Indent}
6108
6109 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
6110 @ChgAdded{Version=[5],Type=[Leading],Text=[For procedures Insert
6111 and Include, the part of the precondition reading:]}
6112
6113 @begin{Example}
6114 @ChgRef{Version=[5],Kind=[Added]}
6115 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (<@examcom{some length}> <= Count_Type'Last - <@examcom{some other length}>
6116 @key[or else raise] Constraint_Error)]}
6117 @end{Example}
6118
6119 @ChgRef{Version=[5],Kind=[Added]}
6120 @ChgAdded{Version=[5],Type=[Leading],Noprefix=[T],Text=[is replaced by:]}
6121
6122 @begin{Example}
6123 @ChgRef{Version=[5],Kind=[Added]}
6124 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (<@examcom{some length}> <= Count_Type'Last - <@examcom{some other length}>
6125 @key[or else raise] Constraint_Error) @key[and then]
6126 (<@examcom{some length}> > Container.Capacity - <@examcom{some other length}>
6127 @key[or else raise] Capacity_Error)]}
6128 @end{Example}
6129
6130 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
6131 @ChgAdded{Version=[5],Type=[Leading],Text=[In procedure Assign,
6132 the precondition is altered to:]}
6133 @begin{Example}
6134 @ChgRef{Version=[5],Kind=[Added]}
6135 @ChgAdded{Version=[5],Noprefix=[T],Text=[ Pre => (@key{not} Tampering_With_Cursors_Prohibited (Target)
6136 @key{or else raise} Program_Error) @key{and then}
6137 (Length (Source) <= Target.Capacity
6138 @key{or else raise} Capacity_Error),]}
6139 @end{Example}
6140
6141 @ChgRef{Version=[3],Kind=[AddedNormal]}
6142 @ChgAdded{Version=[3],Type=[Leading],Text=[The function Copy is replaced with:]}
6143 @begin{Example}
6144 @ChgRef{Version=[3],Kind=[AddedNormal]}
6145 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6146 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[function] @AdaSubDefn{Copy} (Source : Map;
6147 Capacity : Count_Type := 0;
6148 Modulus : Hash_Type := 0) @key[return] Map@Chg{Version=[5],New=[
6149 @key[with] Pre => Capacity = 0 @key[or else] Capacity >= Length (Source)
6150 @key[or else raise] Capacity_Error,
6151 Post => Length (Copy'Result) = Length (Source) @key[and then]
6152 @key[not] Tampering_With_Elements_Prohibited (Copy'Result) @key[and then]
6153 @key[not] Tampering_With_Cursors_Prohibited (Copy'Result) @key[and then]
6154 Copy'Result.Capacity = (@key[if] Capacity = 0 @key[then]
6155 Length (Source) @key[else] Capacity) @key[and then]
6156 Copy'Result.Modulus = (@key[if] Modulus = 0 @key[then]
6157 Default_Modulus (Capacity) @key[else] Modulus)],Old=[]};]}
6158 @end{Example}
6159
6160 @begin{Indent}
6161 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0264-1]}
6162 @ChgRef{Version=[5],Kind=[Revised]}
6163 @ChgAdded{Version=[3],Noprefix=[T],Text=[Returns a map with key/element pairs initialized from the values
6164 in Source.@Chg{Version=[5],New=[],Old=[ If Capacity is 0, then the map
6165 capacity is the length of Source; if Capacity is equal to or greater than
6166 the length of Source, the map capacity is the value of the Capacity
6167 parameter; otherwise, the operation propagates Capacity_Error. If
6168 the Modulus argument is 0, then the map modulus is the value
6169 returned by a call to Default_Modulus with the map capacity as its
6170 argument; otherwise, the map modulus is the value of the Modulus parameter.]}]}
6171 @end{Indent}
6172
6173 @end{Itemize}
6174 @end{StaticSem}
6175
6176 @begin{Bounded}
6177 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0160-1],ARef=[AI05-0265-1]}
6178 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
6179 It is a bounded error to assign from a bounded map object while tampering
6180 with elements @Redundant[or cursors] of that object is prohibited. Either
6181 Program_Error is raised by the assignment, execution proceeds with the target
6182 object prohibiting tampering with elements @Redundant[or cursors], or execution
6183 proceeds normally.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}]}
6184 @begin{TheProof}
6185 @ChgRef{Version=[3],Kind=[AddedNormal]}
6186 @ChgAdded{Version=[3],Text=[Tampering with elements includes tampering
6187 with cursors, so we only really need to talk about tampering with elements
6188 here; we mention cursors for clarity.]}
6189 @end{TheProof}
6190 @end{Bounded}
6191
6192 @begin{Erron}
6193 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
6194 @ChgAdded{Version=[3],Text=[When a bounded map object @i<M> is
6195 finalized, if tampering with cursors is prohibited for @i<M> other than due
6196 to an assignment from another map, then execution is erroneous.
6197 @PDefn2{Term=(erroneous execution),Sec=(cause)}]}
6198
6199 @begin{Reason}
6200 @ChgRef{Version=[3],Kind=[AddedNormal]}
6201 @ChgAdded{Version=[3],Text=[This is a tampering event, but since the
6202 implementation is not allowed to use Ada.Finalization, it is not possible in a
6203 pure Ada implementation to detect this error. (There is no Finalize routine
6204 that will be called that could make the check.) Since the check probably
6205 cannot be made, the bad effects that could occur (such as an iterator going
6206 into an infinite loop or accessing a nonexistent element) cannot be prevented
6207 and we have to allow anything. We do allow re-assigning an object that only
6208 prohibits tampering because it was copied from another object as that cannot
6209 cause any negative effects.]}
6210 @end{Reason}
6211 @end{Erron}
6212
6213 @begin{ImplReq}
6214 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0264-1]}
6215 @ChgAdded{Version=[3],Type=[Leading],Text=[For each instance of
6216 Containers.Hashed_Maps and each instance of Containers.Bounded_Hashed_Maps,
6217 if the two instances meet the following conditions,
6218 then the output generated by
6219 the Map'Output or Map'Write subprograms of either instance
6220 shall be readable by the Map'Input
6221 or Map'Read of the other instance, respectively:]}
6222
6223 @begin{Itemize}
6224 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0248-1]}
6225 @ChgAdded{Version=[3],Text=[the Element_Type parameters of the two instances
6226 are statically matching subtypes of the same type; and]}
6227
6228 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
6229 @ChgAdded{Version=[3],Text=[the output generated by Element_Type'Output or
6230 Element_Type'Write is readable by Element_Type'Input or Element_Type'Read,
6231 respectively (where Element_Type denotes the type of the two actual
6232 Element_Type parameters); and]}
6233
6234 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
6235 @ChgAdded{Version=[3],Text=[the preceding two conditions also hold for the
6236 Key_Type parameters of the instances.]}
6237 @end{Itemize}
6238 @end{ImplReq}
6239
6240 @begin{ImplAdvice}
6241 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0269-1]}
6242 @ChgAdded{Version=[3],Text=[Bounded hashed map objects should be implemented without
6243 implicit pointers or dynamic allocation.]}
6244 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
6245 Text=[Bounded hashed map objects should be implemented without
6246 implicit pointers or dynamic allocation.]}]}
6247
6248 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
6249 @ChgAdded{Version=[3],Text=[The implementation advice for procedure Move to
6250 minimize copying does not apply.]}
6251 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
6252 Text=[The implementation advice for procedure Move to
6253 minimize copying does not apply to bounded hashed maps.]}]}
6254
6255 @end{ImplAdvice}
6256
6257 @begin{Extend2005}
6258 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0160-1],ARef=[AI05-0184-1]}
6259 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic package
6260 Containers.Bounded_Hashed_Maps is new.]}
6261 @end{Extend2005}
6262
6263 @begin{Inconsistent2012}
6264 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
6265 @ChgAdded{Version=[5],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
6266 Tampering with elements is now defined to be equivalent to tampering with
6267 cursors for bounded containers. If a program requires tampering detection
6268 to work, it might fail in Ada 202x. Needless to say, this shouldn't happen
6269 outside of test programs. See @Inconsistent2012Title in
6270 @RefSecNum{The Generic Package Containers.Vectors} for more details.]}
6271 @end{Inconsistent2012}
6272
6273
6274 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Ordered_Maps]}
6275
6276 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
6277 @ChgAdded{Version=[3],Text=[The language-defined generic package
6278 Containers.Bounded_Ordered_Maps@ChildUnit{Parent=[Ada.Containers],Child=[Bounded_Ordered_Maps]}
6279 provides a private type Map and a set of operations. It provides the same
6280 operations as the package Containers.Ordered_Maps (see
6281 @RefSecNum{The Generic Package Containers.Ordered_Maps}), with the difference
6282 that the maximum storage is bounded.]}
6283
6284 @begin{StaticSem}
6285
6286 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
6287 @ChgAdded{Version=[3],Type=[Leading],Text=[The declaration of the generic
6288 library package Containers.Bounded_Ordered_Maps has the same contents and semantics
6289 as Containers.Ordered_Maps except:]}
6290
6291 @begin{Itemize}
6292 @ChgRef{Version=[3],Kind=[AddedNormal]}
6293 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6294 @ChgAdded{Version=[3],Text=[The
6295 @Chg{Version=[5],New=[aspect],Old=[@nt{pragma}]} Preelaborate is replaced
6296 with @Chg{Version=[5],New=[aspect],Old=[@nt{pragma}]} Pure.]}
6297
6298 @ChgRef{Version=[3],Kind=[AddedNormal]}
6299 @ChgAdded{Version=[3],Type=[Leading],Text=[The type Map is declared with a
6300 discriminant that specifies the capacity (maximum number of elements)
6301 as follows:]}
6302 @begin{Example}
6303 @ChgRef{Version=[3],Kind=[AddedNormal]}
6304 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6305 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[type] Map (Capacity : Count_Type) @key[is tagged private]@Chg{Version=[5],New=[...],Old=[;]}]}
6306 @end{Example}
6307
6308 @ChgRef{Version=[3],Kind=[AddedNormal]}
6309 @ChgAdded{Version=[3],Text=[The type Map needs finalization if and only if
6310 type Key_Type or type Element_Type needs finalization.]}
6311
6312 @begin{ImplNote}
6313 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
6314 @ChgAdded{Version=[3],Text=[The type Map cannot depend on package
6315 Ada.Finalization unless the element type depends on that package.
6316 The objects returned from the Iterator and Reference functions probably do
6317 depend on package Ada.Finalization. Restricted environments may need to
6318 avoid use of those functions and their associated types.]}
6319 @end{ImplNote}
6320
6321 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0339-1]}
6322 @ChgAdded{Version=[5],Type=[Leading],Text=[The function Empty is replaced by:]}
6323
6324 @begin{Example}
6325 @ChgRef{Version=[5],Kind=[Added]}
6326 @ChgAdded{Version=[5],Noprefix=[T],Text=[ @key[function] Empty (Capacity : Count_Type := @RI{implementation-defined})
6327 @key[return] Map
6328 @key[with] Post =>
6329 Empty'Result.Capacity = Capacity @key[and then]
6330 @key[not] Tampering_With_Elements_Prohibited (Empty'Result) @key[and then]
6331 @key[not] Tampering_With_Cursors_Prohibited (Empty'Result) @key[and then]
6332 Length (Empty'Result) = 0;]}
6333 @end{Example}
6334
6335 @ChgRef{Version=[3],Kind=[AddedNormal]}
6336 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6337 @ChgAdded{Version=[5],Type=[Leading],Text=[]}@Comment{Conditional leading format.}
6338 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[For procedures Insert
6339 and Include, the part of the precondition reading:],Old=[The
6340 allocation of internal storage includes a check that the capacity is not
6341 exceeded, and Capacity_Error is raised if this check fails.]}]}
6342
6343 @begin{Example}
6344 @ChgRef{Version=[5],Kind=[Added]}
6345 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (@key[if] <@examcom{some length}> > Count_Type'Last - <@examcom{some other length}>
6346 @key[then raise] Constraint_Error)]}
6347 @end{Example}
6348
6349 @ChgRef{Version=[5],Kind=[Added]}
6350 @ChgAdded{Version=[5],Type=[Leading],Noprefix=[T],Text=[is replaced by:]}
6351
6352 @begin{Example}
6353 @ChgRef{Version=[5],Kind=[Added]}
6354 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (@key[if] <@examcom{some length}> > Count_Type'Last - <@examcom{some other length}>
6355 @key[then raise] Constraint_Error
6356 @key[elsif] <@examcom{some length}> > Container.Capacity - <@examcom{some other length}>
6357 @key[then raise] Capacity_Error)]}
6358 @end{Example}
6359
6360
6361 @ChgRef{Version=[3],Kind=[AddedNormal]}
6362 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6363 @ChgAdded{Version=[5],Type=[Leading],Text=[]}@Comment{Conditional leading format.}
6364 @ChgAdded{Version=[3],Text=[In procedure Assign, @Chg{Version=[5],New=[the
6365 precondition is altered to:],Old=[if Source length is greater
6366 than Target capacity, then Capacity_Error is propagated.]}]}
6367
6368 @begin{Example}
6369 @ChgRef{Version=[5],Kind=[Added]}
6370 @ChgAdded{Version=[5],Noprefix=[T],Text=[ Pre => (@key{not} Tampering_With_Cursors_Prohibited (Target)
6371 @key{or else raise} Program_Error) @key{and then}
6372 (Length (Source) <= Target.Capacity
6373 @key{or else raise} Capacity_Error),]}
6374 @end{Example}
6375
6376 @ChgRef{Version=[3],Kind=[AddedNormal]}
6377 @ChgAdded{Version=[3],Type=[Leading],Text=[The function Copy is replaced with:]}
6378 @begin{Example}
6379 @ChgRef{Version=[3],Kind=[AddedNormal]}
6380 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6381 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[function] @AdaSubDefn{Copy} (Source : Map;
6382 Capacity : Count_Type := 0) @key[return] Map@Chg{Version=[5],New=[
6383 @key[with] Pre => Capacity = 0 @key[or else] Capacity >= Length (Source)
6384 @key[or else raise] Capacity_Error,
6385 Post => Length (Copy'Result) = Length (Source) @key[and then]
6386 @key[not] Tampering_With_Elements_Prohibited (Copy'Result) @key[and then]
6387 @key[not] Tampering_With_Cursors_Prohibited (Copy'Result) @key[and then]
6388 Copy'Result.Capacity = (@key[if] Capacity = 0 @key[then]
6389 Length (Source) @key[else] Capacity)],Old=[]};]}
6390
6391 @end{Example}
6392 @begin{Indent}
6393 @ChgRef{Version=[3],Kind=[AddedNormal]}
6394 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6395 @ChgAdded{Version=[3],Noprefix=[T],Text=[Returns a map with key/element pairs
6396 initialized from the values in Source.@Chg{Version=[5],New=[],Old=[ If
6397 Capacity is 0, then the map
6398 capacity is the length of Source; if Capacity is equal to or greater than
6399 the length of Source, the map capacity is the specified value; otherwise, the
6400 operation propagates Capacity_Error.]}]}
6401 @end{Indent}
6402
6403 @end{Itemize}
6404 @end{StaticSem}
6405
6406 @begin{Bounded}
6407 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0160-1],ARef=[AI05-0265-1]}
6408 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
6409 It is a bounded error to assign from a bounded map object while tampering
6410 with elements @Redundant[or cursors] of that object is prohibited. Either
6411 Program_Error is raised by the assignment, execution proceeds with the target
6412 object prohibiting tampering with elements @Redundant[or cursors], or execution
6413 proceeds normally.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}]}
6414 @begin{TheProof}
6415 @ChgRef{Version=[3],Kind=[AddedNormal]}
6416 @ChgAdded{Version=[3],Text=[Tampering with elements includes tampering
6417 with cursors, so we only really need to talk about tampering with elements
6418 here; we mention cursors for clarity.]}
6419 @end{TheProof}
6420 @end{Bounded}
6421
6422 @begin{Erron}
6423 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
6424 @ChgAdded{Version=[3],Text=[When a bounded map object @i<M> is
6425 finalized, if tampering with cursors is prohibited for @i<M> other than due
6426 to an assignment from another map, then execution is erroneous.
6427 @PDefn2{Term=(erroneous execution),Sec=(cause)}]}
6428
6429 @begin{Reason}
6430 @ChgRef{Version=[3],Kind=[AddedNormal]}
6431 @ChgAdded{Version=[3],Text=[This is a tampering event, but since the
6432 implementation is not allowed to use Ada.Finalization, it is not possible in a
6433 pure Ada implementation to detect this error. (There is no Finalize routine
6434 that will be called that could make the check.) Since the check probably
6435 cannot be made, the bad effects that could occur (such as an iterator going
6436 into an infinite loop or accessing a nonexistent element) cannot be prevented
6437 and we have to allow anything. We do allow re-assigning an object that only
6438 prohibits tampering because it was copied from another object as that cannot
6439 cause any negative effects.]}
6440 @end{Reason}
6441 @end{Erron}
6442
6443 @begin{ImplReq}
6444 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0264-1]}
6445 @ChgAdded{Version=[3],Type=[Leading],Text=[For each instance of
6446 Containers.Ordered_Maps and each instance of Containers.Bounded_Ordered_Maps,
6447 if the two instances meet the following conditions,
6448 then the output generated by
6449 the Map'Output or Map'Write subprograms of either instance
6450 shall be readable by the Map'Input
6451 or Map'Read of the other instance, respectively:]}
6452
6453 @begin{Itemize}
6454 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0248-1]}
6455 @ChgAdded{Version=[3],Text=[the Element_Type parameters of the two instances
6456 are statically matching subtypes of the same type; and]}
6457
6458 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
6459 @ChgAdded{Version=[3],Text=[the output generated by Element_Type'Output or
6460 Element_Type'Write is readable by Element_Type'Input or Element_Type'Read,
6461 respectively (where Element_Type denotes the type of the two actual
6462 Element_Type parameters); and]}
6463
6464 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
6465 @ChgAdded{Version=[3],Text=[the preceding two conditions also hold for the
6466 Key_Type parameters of the instances.]}
6467 @end{Itemize}
6468 @end{ImplReq}
6469
6470 @begin{ImplAdvice}
6471 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0269-1]}
6472 @ChgAdded{Version=[3],Text=[Bounded ordered map objects should be implemented
6473 without implicit pointers or dynamic allocation.]}
6474 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
6475 Text=[Bounded ordered map objects should be implemented without
6476 implicit pointers or dynamic allocation.]}]}
6477
6478 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
6479 @ChgAdded{Version=[3],Text=[The implementation advice for procedure Move to
6480 minimize copying does not apply.]}
6481 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
6482 Text=[The implementation advice for procedure Move to
6483 minimize copying does not apply to bounded ordered maps.]}]}
6484
6485 @end{ImplAdvice}
6486
6487 @begin{Extend2005}
6488 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0160-1],ARef=[AI05-0184-1]}
6489 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic package
6490 Containers.Bounded_Ordered_Maps is new.]}
6491 @end{Extend2005}
6492
6493 @begin{Inconsistent2012}
6494 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
6495 @ChgAdded{Version=[5],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
6496 Tampering with elements is now defined to be equivalent to tampering with
6497 cursors for bounded containers. If a program requires tampering detection
6498 to work, it might fail in Ada 202x. Needless to say, this shouldn't happen
6499 outside of test programs. See @Inconsistent2012Title in
6500 @RefSecNum{The Generic Package Containers.Vectors} for more details.]}
6501 @end{Inconsistent2012}
6502
6503
6504 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Hashed_Sets]}
6505
6506 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
6507 @ChgAdded{Version=[3],Text=[The language-defined generic package
6508 Containers.Bounded_Hashed_Sets@ChildUnit{Parent=[Ada.Containers],Child=[Bounded_Hashed_Sets]}
6509 provides a private type Set and a set of operations. It provides the same
6510 operations as the package Containers.Hashed_Sets
6511 (see @RefSecNum{The Generic Package Containers.Hashed_Sets}), with the
6512 difference that the maximum storage is bounded.]}
6513
6514 @begin{StaticSem}
6515
6516 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
6517 @ChgAdded{Version=[3],Type=[Leading],Text=[The declaration of the generic
6518 library package Containers.Bounded_Hashed_Sets has the same contents and semantics
6519 as Containers.Hashed_Sets except:]}
6520
6521 @begin{Itemize}
6522 @ChgRef{Version=[3],Kind=[AddedNormal]}
6523 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6524 @ChgAdded{Version=[3],Text=[The
6525 @Chg{Version=[5],New=[aspect],Old=[@nt{pragma}]} Preelaborate is replaced
6526 with @Chg{Version=[5],New=[aspect],Old=[@nt{pragma}]} Pure.]}
6527
6528 @ChgRef{Version=[3],Kind=[AddedNormal]}
6529 @ChgAdded{Version=[3],Type=[Leading],Text=[The type Set is declared with
6530 discriminants that specify both the capacity (number of elements) and
6531 modulus (number of distinct hash values) of the hash table as follows:]}
6532 @begin{Example}
6533 @ChgRef{Version=[3],Kind=[AddedNormal]}
6534 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6535 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[type] Set (Capacity : Count_Type;
6536 Modulus : Hash_Type) @key[is tagged private]@Chg{Version=[5],New=[...],Old=[;]}]}
6537 @end{Example}
6538
6539 @ChgRef{Version=[3],Kind=[AddedNormal]}
6540 @ChgAdded{Version=[3],Text=[The type Set needs finalization if and only if
6541 type Element_Type needs finalization.]}
6542
6543 @begin{ImplNote}
6544 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
6545 @ChgAdded{Version=[3],Text=[The type Set cannot depend on package
6546 Ada.Finalization unless the element or key type depends on that package.
6547 The objects returned from the Iterator and Reference functions probably do
6548 depend on package Ada.Finalization. Restricted environments may need to
6549 avoid use of those functions and their associated types.]}
6550 @end{ImplNote}
6551
6552 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0339-1]}
6553 @ChgAdded{Version=[5],Type=[Leading],Text=[In function Empty, the
6554 postcondition is altered to:]}
6555
6556 @begin{Example}
6557 @ChgRef{Version=[5],Kind=[Added]}
6558 @ChgAdded{Version=[5],Noprefix=[T],Text=[ Post =>
6559 Empty'Result.Capacity = Capacity @key[and then]
6560 Empty'Result.Modulus = Default_Modulus (Capacity) @key[and then]
6561 @key[not] Tampering_With_Cursors_Prohibited (Empty'Result) @key[and then]
6562 Length (Empty'Result) = 0;]}
6563 @end{Example}
6564
6565 @ChgRef{Version=[3],Kind=[AddedNormal]}
6566 @ChgAdded{Version=[3],Type=[Leading],Text=[The description of Reserve_Capacity
6567 is replaced with:]}
6568 @begin{Example}
6569 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
6570 @ChgAdded{Version=[5],Noprefix=[T],Text=[ @key[procedure] Reserve_Capacity (Container : @key[in out] Set;
6571 Capacity : @key[in] Count_Type)
6572 @key[with] Pre => Capacity <= Container.Capacity @key[or else raise] Capacity_Error;]}
6573 @end{Example}
6574
6575 @begin{Indent}
6576 @ChgRef{Version=[3],Kind=[AddedNormal]}
6577 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6578 @ChgAdded{Version=[3],NoPrefix=[T],Text=[@Chg{Version=[5],New=[This],Old=[If the specified Capacity is larger
6579 than the capacity of Container, then Reserve_Capacity propagates Capacity_Error.
6580 Otherwise, the]} operation has no effect@Chg{Version=[5],New=[,
6581 @Redundant[other than checking the precondition]],Old=[]}.]}
6582 @end{Indent}
6583
6584 @ChgRef{Version=[3],Kind=[AddedNormal]}
6585 @ChgAdded{Version=[3],Type=[Leading],Text=[An additional operation is added immediately following Reserve_Capacity:]}
6586 @begin{Example}
6587 @ChgRef{Version=[3],Kind=[AddedNormal]}
6588 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[function] @AdaSubDefn{Default_Modulus} (Capacity : Count_Type) @key[return] Hash_Type;]}
6589 @end{Example}
6590 @begin{Indent}
6591 @ChgRef{Version=[3],Kind=[AddedNormal]}
6592 @ChgAdded{Version=[3],Noprefix=[T],Text=[Default_Modulus returns an
6593 implementation-defined value for the number of distinct hash values to be
6594 used for the given capacity (maximum number of elements).]}
6595 @end{Indent}
6596
6597 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
6598 @ChgAdded{Version=[5],Type=[Leading],Text=[For procedures Insert
6599 and Include, the part of the precondition reading:]}
6600
6601 @begin{Example}
6602 @ChgRef{Version=[5],Kind=[Added]}
6603 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (<@examcom{some length}> <= Count_Type'Last - <@examcom{some other length}>
6604 @key[or else raise] Constraint_Error)]}
6605 @end{Example}
6606
6607 @ChgRef{Version=[5],Kind=[Added]}
6608 @ChgAdded{Version=[5],Type=[Leading],Noprefix=[T],Text=[is replaced by:]}
6609
6610 @begin{Example}
6611 @ChgRef{Version=[5],Kind=[Added]}
6612 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (<@examcom{some length}> <= Count_Type'Last - <@examcom{some other length}>
6613 @key[or else raise] Constraint_Error) @key[and then]
6614 (<@examcom{some length}> <= Container.Capacity - <@examcom{some other length}>
6615 @key[or else raise] Capacity_Error)]}
6616 @end{Example}
6617
6618 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
6619 @ChgAdded{Version=[5],Type=[Leading],Text=[In procedure Assign,
6620 the precondition is altered to:]}
6621 @begin{Example}
6622 @ChgRef{Version=[5],Kind=[Added]}
6623 @ChgAdded{Version=[5],Noprefix=[T],Text=[ Pre => (@key{not} Tampering_With_Cursors_Prohibited (Target)
6624 @key{or else raise} Program_Error) @key{and then}
6625 (Length (Source) <= Target.Capacity
6626 @key{or else raise} Capacity_Error),]}
6627 @end{Example}
6628
6629 @ChgRef{Version=[3],Kind=[AddedNormal]}
6630 @ChgAdded{Version=[3],Type=[Leading],Text=[The function Copy is replaced with:]}
6631 @begin{Example}
6632 @ChgRef{Version=[3],Kind=[AddedNormal]}
6633 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6634 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[function] @AdaSubDefn{Copy} (Source : Set;
6635 Capacity : Count_Type := 0;
6636 Modulus : Hash_Type := 0) @key[return] Map@Chg{Version=[5],New=[
6637 @key[with] Pre => Capacity = 0 @key[or else] Capacity >= Length (Source)
6638 @key[or else raise] Capacity_Error,
6639 Post => Length (Copy'Result) = Length (Source) @key[and then]
6640 @key[not] Tampering_With_Cursors_Prohibited (Copy'Result) @key[and then]
6641 Copy'Result.Capacity = (@key[if] Capacity = 0 @key[then]
6642 Length (Source) @key[else] Capacity) @key[and then]
6643 Copy'Result.Modulus = (@key[if] Modulus = 0 @key[then]
6644 Default_Modulus (Capacity) @key[else] Modulus)],Old=[]};]}
6645 @end{Example}
6646
6647 @begin{Indent}
6648 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0264-1]}
6649 @ChgRef{Version=[5],Kind=[Revised]}
6650 @ChgAdded{Version=[3],Noprefix=[T],Text=[Returns a set with key/element pairs initialized from the values
6651 in Source.@Chg{Version=[5],New=[],Old=[ If Capacity is 0, then the set
6652 capacity is the length of Source; if Capacity is equal to or greater than
6653 the length of Source, the set capacity is the value of the Capacity
6654 parameter; otherwise, the operation propagates Capacity_Error. If
6655 the Modulus argument is 0, then the set modulus is the value
6656 returned by a call to Default_Modulus with the set capacity as its
6657 argument; otherwise, the set modulus is the value of the Modulus parameter.]}]}
6658 @end{Indent}
6659
6660 @end{Itemize}
6661 @end{StaticSem}
6662
6663 @begin{Bounded}
6664 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0160-1],ARef=[AI05-0265-1]}
6665 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
6666 It is a bounded error to assign from a bounded set object while tampering
6667 with elements @Redundant[or cursors] of that object is prohibited. Either
6668 Program_Error is raised by the assignment, execution proceeds with the target
6669 object prohibiting tampering with elements @Redundant[or cursors], or execution
6670 proceeds normally.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}]}
6671 @begin{TheProof}
6672 @ChgRef{Version=[3],Kind=[AddedNormal]}
6673 @ChgAdded{Version=[3],Text=[Tampering with elements includes tampering
6674 with cursors, so we only really need to talk about tampering with elements
6675 here; we mention cursors for clarity.]}
6676 @end{TheProof}
6677 @end{Bounded}
6678
6679 @begin{Erron}
6680 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
6681 @ChgAdded{Version=[3],Text=[When a bounded set object @i<S> is
6682 finalized, if tampering with cursors is prohibited for @i<S> other than due
6683 to an assignment from another set, then execution is erroneous.
6684 @PDefn2{Term=(erroneous execution),Sec=(cause)}]}
6685
6686 @begin{Reason}
6687 @ChgRef{Version=[3],Kind=[AddedNormal]}
6688 @ChgAdded{Version=[3],Text=[This is a tampering event, but since the
6689 implementation is not allowed to use Ada.Finalization, it is not possible in a
6690 pure Ada implementation to detect this error. (There is no Finalize routine
6691 that will be called that could make the check.) Since the check probably
6692 cannot be made, the bad effects that could occur (such as an iterator going
6693 into an infinite loop or accessing a nonexistent element) cannot be prevented
6694 and we have to allow anything. We do allow re-assigning an object that only
6695 prohibits tampering because it was copied from another object as that cannot
6696 cause any negative effects.]}
6697 @end{Reason}
6698 @end{Erron}
6699
6700 @begin{ImplReq}
6701 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0264-1]}
6702 @ChgAdded{Version=[3],Type=[Leading],Text=[For each instance of
6703 Containers.Hashed_Sets and each instance of Containers.Bounded_Hashed_Sets,
6704 if the two instances meet the following conditions,
6705 then the output generated by
6706 the Set'Output or Set'Write subprograms of either instance
6707 shall be readable by the Set'Input
6708 or Set'Read of the other instance, respectively:]}
6709
6710 @begin{Itemize}
6711 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0248-1]}
6712 @ChgAdded{Version=[3],Text=[the Element_Type parameters of the two instances
6713 are statically matching subtypes of the same type; and]}
6714
6715 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
6716 @ChgAdded{Version=[3],Text=[the output generated by Element_Type'Output or
6717 Element_Type'Write is readable by Element_Type'Input or Element_Type'Read,
6718 respectively (where Element_Type denotes the type of the two actual
6719 Element_Type parameters).]}
6720 @end{Itemize}
6721 @end{ImplReq}
6722
6723 @begin{ImplAdvice}
6724 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0269-1]}
6725 @ChgAdded{Version=[3],Text=[Bounded hashed set objects should be implemented
6726 without implicit pointers or dynamic allocation.]}
6727 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
6728 Text=[Bounded hashed set objects should be implemented without
6729 implicit pointers or dynamic allocation.]}]}
6730
6731 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
6732 @ChgAdded{Version=[3],Text=[The implementation advice for procedure Move to
6733 minimize copying does not apply.]}
6734 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
6735 Text=[The implementation advice for procedure Move to
6736 minimize copying does not apply to bounded hashed sets.]}]}
6737
6738 @end{ImplAdvice}
6739
6740 @begin{Extend2005}
6741 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0160-1],ARef=[AI05-0184-1]}
6742 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic package
6743 Containers.Bounded_Hashed_Sets is new.]}
6744 @end{Extend2005}
6745
6746
6747 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Ordered_Sets]}
6748
6749 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
6750 @ChgAdded{Version=[3],Text=[The language-defined generic package
6751 Containers.Bounded_Ordered_Sets@ChildUnit{Parent=[Ada.Containers],Child=[Bounded_Ordered_Sets]}
6752 provides a private type Set and a set of operations. It provides the same
6753 operations as the package Containers.Ordered_Sets
6754 (see @RefSecNum{The Generic Package Containers.Ordered_Sets}), with the
6755 difference that the maximum storage is bounded.]}
6756
6757 @begin{StaticSem}
6758
6759 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
6760 @ChgAdded{Version=[3],Type=[Leading],Text=[The declaration of the generic
6761 library package Containers.Bounded_Ordered_Sets has the same contents and semantics
6762 as Containers.Ordered_Sets except:]}
6763
6764 @begin{Itemize}
6765 @ChgRef{Version=[3],Kind=[AddedNormal]}
6766 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6767 @ChgAdded{Version=[3],Text=[The
6768 @Chg{Version=[5],New=[aspect],Old=[@nt{pragma}]} Preelaborate is replaced
6769 with @Chg{Version=[5],New=[aspect],Old=[@nt{pragma}]} Pure.]}
6770
6771 @ChgRef{Version=[3],Kind=[AddedNormal]}
6772 @ChgAdded{Version=[3],Type=[Leading],Text=[The type Set is declared with a
6773 discriminant that specifies the capacity (maximum number of elements)
6774 as follows:]}
6775 @begin{Example}
6776 @ChgRef{Version=[3],Kind=[AddedNormal]}
6777 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6778 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key{type} Set (Capacity : Count_Type) @key[is tagged private]@Chg{Version=[5],New=[...],Old=[;]}]}
6779 @end{Example}
6780
6781 @ChgRef{Version=[3],Kind=[AddedNormal]}
6782 @ChgAdded{Version=[3],Text=[The type Set needs finalization if and only if
6783 type Element_Type needs finalization.]}
6784
6785 @begin{ImplNote}
6786 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
6787 @ChgAdded{Version=[3],Text=[The type Set cannot depend on package
6788 Ada.Finalization unless the element type depends on that package. The
6789 objects returned from the Iterator and Reference functions probably do
6790 depend on package Ada.Finalization. Restricted environments may need to
6791 avoid use of those functions and their associated types.]}
6792 @end{ImplNote}
6793
6794 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0339-1]}
6795 @ChgAdded{Version=[5],Type=[Leading],Text=[The function Empty is replaced by:]}
6796
6797 @begin{Example}
6798 @ChgRef{Version=[5],Kind=[Added]}
6799 @ChgAdded{Version=[5],Noprefix=[T],Text=[ @key[function] Empty (Capacity : Count_Type := @RI{implementation-defined})
6800 @key[return] Set
6801 @key[with] Post =>
6802 Empty'Result.Capacity = Capacity @key[and then]
6803 @key[not] Tampering_With_Cursors_Prohibited (Empty'Result) @key[and then]
6804 Length (Empty'Result) = 0;]}
6805 @end{Example}
6806
6807 @ChgRef{Version=[3],Kind=[AddedNormal]}
6808 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6809 @ChgAdded{Version=[5],Type=[Leading],Text=[]}@Comment{Conditional leading format.}
6810 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[For procedures Insert
6811 and Include, the part of the precondition reading:],Old=[If Insert (or Include) adds an element, a check is
6812 made that the capacity is not exceeded, and Capacity_Error is raised
6813 if this check fails.]}]}
6814
6815 @begin{Example}
6816 @ChgRef{Version=[5],Kind=[Added]}
6817 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (<@examcom{some length}> <= Count_Type'Last - <@examcom{some other length}>
6818 @key[or else raise] Constraint_Error)]}
6819 @end{Example}
6820
6821 @ChgRef{Version=[5],Kind=[Added]}
6822 @ChgAdded{Version=[5],Type=[Leading],Noprefix=[T],Text=[is replaced by:]}
6823
6824 @begin{Example}
6825 @ChgRef{Version=[5],Kind=[Added]}
6826 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (<@examcom{some length}> <= Count_Type'Last - <@examcom{some other length}>
6827 @key[or else raise] Constraint_Error) @key[and then]
6828 (<@examcom{some length}> <= Container.Capacity - <@examcom{some other length}>
6829 @key[or else raise] Capacity_Error)]}
6830 @end{Example}
6831
6832
6833 @ChgRef{Version=[3],Kind=[AddedNormal]}
6834 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6835 @ChgAdded{Version=[5],Type=[Leading],Text=[]}@Comment{Conditional leading format.}
6836 @ChgAdded{Version=[3],Text=[In procedure Assign, @Chg{Version=[5],New=[the
6837 precondition is altered to:],Old=[if Source length is greater
6838 than Target capacity, then Capacity_Error is propagated.]}]}
6839
6840 @begin{Example}
6841 @ChgRef{Version=[5],Kind=[Added]}
6842 @ChgAdded{Version=[5],Noprefix=[T],Text=[ Pre => (@key{not} Tampering_With_Cursors_Prohibited (Target)
6843 @key{or else raise} Program_Error) @key{and then}
6844 (Length (Source) <= Target.Capacity
6845 @key{or else raise} Capacity_Error),]}
6846 @end{Example}
6847
6848 @ChgRef{Version=[3],Kind=[AddedNormal]}
6849 @ChgAdded{Version=[3],Type=[Leading],Text=[The function Copy is replaced with:]}
6850 @begin{Example}
6851 @ChgRef{Version=[3],Kind=[AddedNormal]}
6852 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6853 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[function] @AdaSubDefn{Copy} (Source : Set;
6854 Capacity : Count_Type := 0) @key[return] Map@Chg{Version=[5],New=[
6855 @key[with] Pre => Capacity = 0 @key[or else] Capacity >= Length (Source)
6856 @key[or else raise] Capacity_Error,
6857 Post => Length (Copy'Result) = Length (Source) @key[and then]
6858 @key[not] Tampering_With_Cursors_Prohibited (Copy'Result) @key[and then]
6859 Copy'Result.Capacity = (@key[if] Capacity = 0 @key[then]
6860 Length (Source) @key[else] Capacity)],Old=[]};]}
6861
6862 @end{Example}
6863 @begin{Indent}
6864 @ChgRef{Version=[3],Kind=[AddedNormal]}
6865 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6866 @ChgAdded{Version=[3],Noprefix=[T],Text=[Returns a set with key/element pairs
6867 initialized from the values in Source.@Chg{Version=[5],New=[],Old=[ If
6868 Capacity is 0, then the set
6869 capacity is the length of Source; if Capacity is equal to or greater than
6870 the length of Source, the set capacity is the specified value; otherwise, the
6871 operation propagates Capacity_Error.]}]}
6872 @end{Indent}
6873
6874 @end{Itemize}
6875 @end{StaticSem}
6876
6877 @begin{Bounded}
6878 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0160-1],ARef=[AI05-0265-1]}
6879 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
6880 It is a bounded error to assign from a bounded set object while tampering
6881 with elements @Redundant[or cursors] of that object is prohibited. Either
6882 Program_Error is raised by the assignment, execution proceeds with the target
6883 object prohibiting tampering with elements @Redundant[or cursors], or execution
6884 proceeds normally.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}]}
6885 @begin{TheProof}
6886 @ChgRef{Version=[3],Kind=[AddedNormal]}
6887 @ChgAdded{Version=[3],Text=[Tampering with elements includes tampering
6888 with cursors, so we only really need to talk about tampering with elements
6889 here; we mention cursors for clarity.]}
6890 @end{TheProof}
6891 @end{Bounded}
6892
6893 @begin{Erron}
6894 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
6895 @ChgAdded{Version=[3],Text=[When a bounded set object @i<S> is
6896 finalized, if tampering with cursors is prohibited for @i<S> other than due
6897 to an assignment from another set, then execution is erroneous.
6898 @PDefn2{Term=(erroneous execution),Sec=(cause)}]}
6899
6900 @begin{Reason}
6901 @ChgRef{Version=[3],Kind=[AddedNormal]}
6902 @ChgAdded{Version=[3],Text=[This is a tampering event, but since the
6903 implementation is not allowed to use Ada.Finalization, it is not possible in a
6904 pure Ada implementation to detect this error. (There is no Finalize routine
6905 that will be called that could make the check.) Since the check probably
6906 cannot be made, the bad effects that could occur (such as an iterator going
6907 into an infinite loop or accessing a nonexistent element) cannot be prevented
6908 and we have to allow anything. We do allow re-assigning an object that only
6909 prohibits tampering because it was copied from another object as that cannot
6910 cause any negative effects.]}
6911 @end{Reason}
6912 @end{Erron}
6913
6914 @begin{ImplReq}
6915 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0264-1]}
6916 @ChgAdded{Version=[3],Type=[Leading],Text=[For each instance of
6917 Containers.Ordered_Sets and each instance of Containers.Bounded_Ordered_Sets,
6918 if the two instances meet the following conditions,
6919 then the output generated by
6920 the Set'Output or Set'Write subprograms of either instance
6921 shall be readable by the Set'Input
6922 or Set'Read of the other instance, respectively:]}
6923
6924 @begin{Itemize}
6925 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0248-1]}
6926 @ChgAdded{Version=[3],Text=[the Element_Type parameters of the two instances
6927 are statically matching subtypes of the same type; and]}
6928
6929 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
6930 @ChgAdded{Version=[3],Text=[the output generated by Element_Type'Output or
6931 Element_Type'Write is readable by Element_Type'Input or Element_Type'Read,
6932 respectively (where Element_Type denotes the type of the two actual
6933 Element_Type parameters).]}
6934 @end{Itemize}
6935 @end{ImplReq}
6936
6937 @begin{ImplAdvice}
6938 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0269-1]}
6939 @ChgAdded{Version=[3],Text=[Bounded ordered set objects should be implemented
6940 without implicit pointers or dynamic allocation.]}
6941 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
6942 Text=[Bounded ordered set objects should be implemented without
6943 implicit pointers or dynamic allocation.]}]}
6944
6945 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
6946 @ChgAdded{Version=[3],Text=[The implementation advice for procedure Move to
6947 minimize copying does not apply.]}
6948 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
6949 Text=[The implementation advice for procedure Move to
6950 minimize copying does not apply to bounded ordered sets.]}]}
6951
6952 @end{ImplAdvice}
6953
6954 @begin{Extend2005}
6955 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0160-1],ARef=[AI05-0184-1]}
6956 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic package
6957 Containers.Bounded_Ordered_Sets is new.]}
6958 @end{Extend2005}
6959
6960
6961 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Multiway_Trees]}
6962
6963 @begin{Intro}
6964 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
6965 @ChgAdded{Version=[3],Text=[The language-defined generic package
6966 Containers.Bounded_Multiway_Trees@ChildUnit{Parent=[Ada.Containers],Child=[Bounded_Multiway_Trees]}
6967 provides a private type Tree and a set of operations. It provides the same
6968 operations as the package Containers.Multiway_Trees (see
6969 @RefSecNum{The Generic Package Containers.Multiway_Trees}), with the difference
6970 that the maximum storage is bounded.]}
6971
6972 @end{Intro}
6973
6974 @begin{StaticSem}
6975
6976 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
6977 @ChgAdded{Version=[3],Type=[Leading],Text=[The declaration of the generic
6978 library package Containers.Bounded_Multiway_Trees has the same contents and
6979 semantics as Containers.Multiway_Trees except:]}
6980
6981 @begin{Itemize}
6982 @ChgRef{Version=[3],Kind=[AddedNormal]}
6983 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6984 @ChgAdded{Version=[3],Text=[The
6985 @Chg{Version=[5],New=[aspect],Old=[@nt{pragma}]} Preelaborate is replaced
6986 with @Chg{Version=[5],New=[aspect],Old=[@nt{pragma}]} Pure.]}
6987
6988 @ChgRef{Version=[3],Kind=[AddedNormal]}
6989 @ChgAdded{Version=[3],Type=[Leading],Text=[The type Tree is declared with a
6990 discriminant that specifies the capacity (maximum number of elements)
6991 as follows:]}
6992 @begin{Example}
6993 @ChgRef{Version=[3],Kind=[AddedNormal]}
6994 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
6995 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key{type} Tree (Capacity : Count_Type) @key[is tagged private]@Chg{Version=[5],New=[...],Old=[;]}]}
6996 @end{Example}
6997
6998 @ChgRef{Version=[3],Kind=[AddedNormal]}
6999 @ChgAdded{Version=[3],Text=[The type Tree needs finalization if and only if
7000 type Element_Type needs finalization.]}
7001
7002 @begin{ImplNote}
7003 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
7004 @ChgAdded{Version=[3],Text=[The type Tree cannot depend on package
7005 Ada.Finalization unless the element type depends on that package. The
7006 objects returned from the Iterator and Reference functions probably do
7007 depend on package Ada.Finalization. Restricted environments may need to
7008 avoid use of those functions and their associated types.]}
7009 @end{ImplNote}
7010
7011 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0339-1]}
7012 @ChgAdded{Version=[5],Type=[Leading],Text=[The function Empty is replaced by:]}
7013
7014 @begin{Example}
7015 @ChgRef{Version=[5],Kind=[Added]}
7016 @ChgAdded{Version=[5],Noprefix=[T],Text=[ @key[function] Empty (Capacity : Count_Type := @RI{implementation-defined})
7017 @key[return] Tree
7018 @key[with] Post =>
7019 Empty'Result.Capacity = Capacity @key[and then]
7020 @key[not] Tampering_With_Elements_Prohibited (Empty'Result) @key[and then]
7021 @key[not] Tampering_With_Cursors_Prohibited (Empty'Result) @key[and then]
7022 Node_Count (Empty'Result) = 1;]}
7023 @end{Example}
7024
7025 @ChgRef{Version=[3],Kind=[AddedNormal]}
7026 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7027 @ChgAdded{Version=[5],Type=[Leading],Text=[]}@Comment{Conditional leading format.}
7028 @ChgAdded{Version=[3],Text=[@Chg{Version=[5],New=[For procedures Insert_Child,
7029 Prepend_Child, and Append_Child, the initial subexpression of the precondition
7030 is replaced with:],Old=[The
7031 allocation of internal storage includes a check that the capacity is not
7032 exceeded, and Capacity_Error is raised if this check fails.]}]}
7033
7034 @begin{Example}
7035 @ChgRef{Version=[5],Kind=[Added]}
7036 @ChgAdded{Version=[5],Noprefix=[T],Text=[ @key{with} Pre => (@key{not} Tampering_With_Cursors_Prohibited (Container)
7037 @key{or else raise} Program_Error) @key{and then}
7038 (Node_Count (Container) - 1 <= Container.Capacity - Count
7039 @key[or else raise] Capacity_Error)]}
7040 @end{Example}
7041
7042 @ChgRef{Version=[3],Kind=[AddedNormal]}
7043 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7044 @ChgAdded{Version=[5],Type=[Leading],Text=[]}@Comment{Conditional leading format.}
7045 @ChgAdded{Version=[3],Text=[In procedure Assign, @Chg{Version=[5],New=[the
7046 precondition is altered to:],Old=[if Source length is greater
7047 than Target capacity, then Capacity_Error is
7048 propagated.]}]}
7049 @begin{Example}
7050 @ChgRef{Version=[5],Kind=[Added]}
7051 @ChgAdded{Version=[5],Noprefix=[T],Text=[ Pre => (@key{not} Tampering_With_Cursors_Prohibited (Target)
7052 @key{or else raise} Program_Error) @key{and then}
7053 (Node_Count (Source) - 1 <= Target.Capacity
7054 @key{or else raise} Capacity_Error),]}
7055 @end{Example}
7056
7057 @ChgRef{Version=[3],Kind=[AddedNormal]}
7058 @ChgAdded{Version=[3],Type=[Leading],Text=[Function Copy is declared as follows:]}
7059 @begin{Example}
7060 @ChgRef{Version=[3],Kind=[AddedNormal]}
7061 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0056-1]}
7062 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key{function} Copy (Source : Tree; Capacity : Count_Type := 0)
7063 @key{return} @Chg{Version=[4],New=[Tree],Old=[List]}@Chg{Version=[5],New=[
7064 @key[with] Pre => Capacity = 0 @key[or else] Capacity >= Node_Count (Source) - 1
7065 @key[or else raise] Capacity_Error,
7066 Post => Node_Count (Copy'Result) = Node_Count (Source) @key[and then]
7067 @key[not] Tampering_With_Elements_Prohibited (Copy'Result) @key[and then]
7068 @key[not] Tampering_With_Cursors_Prohibited (Copy'Result) @key[and then]
7069 Copy'Result.Capacity = (@key[if] Capacity = 0 @key[then]
7070 Node_Count (Source) - 1 @key[else] Capacity)],Old=[]};]}
7071 @end{Example}
7072 @begin{Indent}
7073 @ChgRef{Version=[3],Kind=[AddedNormal]}
7074 @ChgRef{Version=[5],Kind=[Revised]}
7075 @ChgAdded{Version=[3],Noprefix=[T],Text=[@Chg{Version=[5],New=[Returns a
7076 list whose elements have the same values as the elements of Source.],Old=[If
7077 Capacity is 0, then the tree
7078 capacity is the count of Source; if Capacity is equal to or greater than
7079 Source.Count, the tree capacity equals the value of the Capacity parameter;
7080 otherwise, the operation propagates Capacity_Error.]}]}
7081 @end{Indent}
7082
7083 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
7084 @ChgAdded{Version=[5],Type=[Leading],Text=[In the four-parameter procedure
7085 Copy_Subtree, the last @key{or else} of the precondition is replaced by:]}
7086
7087 @begin{Example}
7088 @ChgRef{Version=[5],Kind=[Added]}
7089 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (@key{not} Is_Root (Source)
7090 @key{or else raise} Constraint_Error) @key{and then}
7091 (Node_Count (Target) - 1 + Subtree_Node_Count (Source) <= Target.Capacity
7092 @key{or else raise} Capacity_Error),]}
7093 @end{Example}
7094
7095 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
7096 @ChgAdded{Version=[5],Type=[Leading],Text=[In the five-parameter procedure
7097 Copy_Subtree, the last @key{or else} of the precondition is replaced by:]}
7098
7099 @begin{Example}
7100 @ChgRef{Version=[5],Kind=[Added]}
7101 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (@key{not} Is_Root (Source, Subtree)
7102 @key{or else raise} Constraint_Error) @key{and then}
7103 (Node_Count (Target) - 1 +
7104 Subtree_Node_Count (Source, Subtree) <= Target.Capacity
7105 @key{or else raise} Capacity_Error),]}
7106 @end{Example}
7107
7108 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
7109 @ChgAdded{Version=[5],Type=[Leading],Text=[In Copy_Local_Subtree,
7110 the last @key{or else} of the precondition is replaced by:]}
7111
7112 @begin{Example}
7113 @ChgRef{Version=[5],Kind=[Added]}
7114 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (@key{not} Is_Root (Source, Subtree)
7115 @key{or else raise} Constraint_Error) @key{and then}
7116 (Node_Count (Target) - 1 +
7117 Subtree_Node_Count (Target, Source) <= Target.Capacity
7118 @key{or else raise} Capacity_Error),]}
7119 @end{Example}
7120
7121 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
7122 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7123 @ChgAdded{Version=[5],Type=[Leading],Text=[]}@Comment{Conditional leading format.}
7124 @ChgAdded{Version=[3],Text=[In the five-parameter procedure Splice_Subtree,
7125 @Chg{Version=[5],New=[the penultimate @key{or else} of the precondition
7126 is replaced by:],Old=[if
7127 Source is not the same object as Target, and if the sum of Target.Count and
7128 Subtree_Node_Count (Position) is greater than Target.Capacity, then
7129 Splice_Subtree propagates Capacity_Error.]}]}
7130
7131 @begin{Example}
7132 @ChgRef{Version=[5],Kind=[Added]}
7133 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (Has_Element (Source, Position)
7134 @key{or else raise} Program_Error) @key{and then}
7135 (Same_Object (Target, Source) @key{or else}
7136 Node_Count (Target) - 1 +
7137 Subtree_Node_Count (Source, Position) <= Target.Capacity
7138 @key{or else raise} Capacity_Error) @key{and then}]}
7139 @end{Example}
7140
7141 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
7142 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7143 @ChgAdded{Version=[5],Type=[Leading],Text=[]}@Comment{Conditional leading format.}
7144 @ChgAdded{Version=[3],Text=[In the five-parameter procedure Splice_Children,
7145 @Chg{Version=[5],New=[the penultimate @key{elsif} of the precondition
7146 is replaced by:],Old=[if
7147 Source is not the same object as Target, and if the sum of Target.Count
7148 and Subtree_Node_Count (Source_Parent)-1 is greater than Target.Capacity,
7149 then Splice_Children propagates Capacity_Error.]}]}
7150
7151 @begin{Example}
7152 @ChgRef{Version=[5],Kind=[Added]}
7153 @ChgAdded{Version=[5],Noprefix=[T],Text=[ (Before = No_Element @key{or else}
7154 Parent (Target, Before) /= Target_Parent
7155 @key{or else raise} Constraint_Error) @key{and then}
7156 (Same_Object (Target, Source) @key{or else}
7157 Node_Count (Target) - 1 +
7158 Child_Count (Source, Source_Parent) <= Target.Capacity
7159 @key{or else raise} Capacity_Error) @key{and then}]}
7160 @end{Example}
7161
7162 @end{Itemize}
7163 @end{StaticSem}
7164
7165 @begin{Bounded}
7166 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0160-1],ARef=[AI05-0265-1]}
7167 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
7168 It is a bounded error to assign from a bounded tree object while tampering
7169 with elements @Redundant[or cursors] of that object is prohibited. Either
7170 Program_Error is raised by the assignment, execution proceeds with the target
7171 object prohibiting tampering with elements @Redundant[or cursors], or execution
7172 proceeds normally.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}]}
7173 @begin{TheProof}
7174 @ChgRef{Version=[3],Kind=[AddedNormal]}
7175 @ChgAdded{Version=[3],Text=[Tampering with elements includes tampering
7176 with cursors, so we only really need to talk about tampering with elements
7177 here; we mention cursors for clarity.]}
7178 @end{TheProof}
7179 @end{Bounded}
7180
7181 @begin{Erron}
7182 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
7183 @ChgAdded{Version=[3],Text=[When a bounded tree object @i<T> is
7184 finalized, if tampering with cursors is prohibited for @i<T> other than due
7185 to an assignment from another tree, then execution is erroneous.
7186 @PDefn2{Term=(erroneous execution),Sec=(cause)}]}
7187
7188 @begin{Reason}
7189 @ChgRef{Version=[3],Kind=[AddedNormal]}
7190 @ChgAdded{Version=[3],Text=[This is a tampering event, but since the
7191 implementation is not allowed to use Ada.Finalization, it is not possible in a
7192 pure Ada implementation to detect this error. (There is no Finalize routine
7193 that will be called that could make the check.) Since the check probably
7194 cannot be made, the bad effects that could occur (such as an iterator going
7195 into an infinite loop or accessing a nonexistent element) cannot be prevented
7196 and we have to allow anything. We do allow re-assigning an object that only
7197 prohibits tampering because it was copied from another object as that cannot
7198 cause any negative effects.]}
7199 @end{Reason}
7200 @end{Erron}
7201
7202 @begin{ImplReq}
7203 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0264-1]}
7204 @ChgAdded{Version=[3],Type=[Leading],Text=[For each instance of
7205 Containers.Multiway_Trees and each instance of Containers.Bounded_Multiway_Trees,
7206 if the two instances meet the following conditions,
7207 then the output generated by
7208 the Tree'Output or Tree'Write subprograms of either instance
7209 shall be readable by the Tree'Input
7210 or Tree'Read of the other instance, respectively:]}
7211
7212 @begin{Itemize}
7213 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0248-1]}
7214 @ChgAdded{Version=[3],Text=[the Element_Type parameters of the two instances
7215 are statically matching subtypes of the same type; and]}
7216
7217 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
7218 @ChgAdded{Version=[3],Text=[the output generated by Element_Type'Output or
7219 Element_Type'Write is readable by Element_Type'Input or Element_Type'Read,
7220 respectively (where Element_Type denotes the type of the two actual
7221 Element_Type parameters).]}
7222 @end{Itemize}
7223 @end{ImplReq}
7224
7225 @begin{ImplAdvice}
7226 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
7227 @ChgAdded{Version=[3],Text=[Bounded tree objects should be implemented without
7228 implicit pointers or dynamic allocation.]}
7229 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
7230 Text=[Bounded tree objects should be implemented without
7231 implicit pointers or dynamic allocation.]}]}
7232
7233 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
7234 @ChgAdded{Version=[3],Text=[The implementation advice for procedure Move to
7235 minimize copying does not apply.]}
7236 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
7237 Text=[The implementation advice for procedure Move to
7238 minimize copying does not apply to bounded trees.]}]}
7239 @end{ImplAdvice}
7240
7241
7242 @begin{Extend2005}
7243 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0184-1]}
7244 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
7245 The generic package Containers.Bounded_Multiway_Trees is new.]}
7246 @end{Extend2005}
7247
7248 @begin{Inconsistent2012}
7249 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0111-1]}
7250 @ChgAdded{Version=[5],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
7251 Tampering with elements is now defined to be equivalent to tampering with
7252 cursors for bounded containers. If a program requires tampering detection
7253 to work, it might fail in Ada 202x. Needless to say, this shouldn't happen
7254 outside of test programs. See @Inconsistent2012Title in
7255 @RefSecNum{The Generic Package Containers.Vectors} for more details.]}
7256 @end{Inconsistent2012}
7257
7258
7259 @RMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
7260 @LabeledAddedSubclause{Version=[2],Name=[Array Sorting]}
7261
7262 @begin{Intro}
7263 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
7264 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0001-1]}
7265 @ChgAdded{Version=[2],Text=[The language-defined generic procedures
7266 Containers.@!Generic_@!Array_Sort@Chg{Version=[3],New=[,],Old=[ and]}
7267 Containers.@!Generic_@!Constrained_@!Array_Sort@Chg{Version=[3],New=[, and
7268 Containers.@!Generic_Sort],Old=[]}
7269 provide sorting on arbitrary array types.]}
7270 @end{Intro}
7271
7272 @begin{StaticSem}
7273
7274 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
7275 @ChgAdded{Version=[2],KeepNext=[T],Type=[Leading],Text=[The generic library
7276 procedure Containers.Generic_Array_Sort has the following declaration:]}
7277 @begin{Example}
7278 @ChgRef{Version=[2],Kind=[AddedNormal]}
7279 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7280 @ChgAdded{Version=[2],Text=[@key{generic}
7281 @key{type} Index_Type @key{is} (<>);
7282 @key{type} Element_Type @key{is private};
7283 @key{type} Array_Type @key{is array} (Index_Type @key{range} <>) @key{of} Element_Type;
7284 @key{with function} "<" (Left, Right : Element_Type)
7285 @key{return} Boolean @key{is} <>;
7286 @key{procedure} Ada.Containers.Generic_Array_Sort (Container : @key{in out} Array_Type)@Chg{Version=[5],New=[],Old=[;]}@SubChildUnit{Parent=[Ada.Containers],Child=[Generic_Array_Sort]}@Chg{Version=[5],New=[
7287 @key{with} Pure,
7288 Nonblocking, Global => @key[null]],Old=[@key{pragma} Pure(Ada.Containers.Generic_Array_Sort)]};]}
7289 @end{Example}
7290
7291 @begin{Discussion}
7292 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
7293 @ChgAdded{Version=[5],Text=[Global => @key[null] means
7294 that the only global side-effects allowed are associated with the actual
7295 generic parameters. Similarly, when Nonblocking is set to True for
7296 a generic unit, the only blocking allowed is that
7297 associated with the actual generic parameters.]}
7298 @end{Discussion}
7299
7300 @begin{DescribeCode}
7301 @ChgRef{Version=[2],Kind=[AddedNormal]}
7302 @ChgAdded{Version=[2],Text=[Reorders the elements of Container such that the elements are
7303 sorted smallest first as determined by the generic formal "<" operator
7304 provided. Any exception raised during evaluation of "<" is propagated.]}
7305
7306 @ChgRef{Version=[2],Kind=[AddedNormal]}
7307 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0044-1],ARef=[AI05-0262-1]}
7308 @ChgAdded{Version=[2],Text=[The actual function for the generic formal function
7309 "<" of Generic_Array_Sort is expected to return the same value each time it is
7310 called with a particular pair of element values. It should define a strict
7311 @Chg{Version=[3],New=[weak ],Old=[]}ordering relationship@Chg{Version=[3],
7312 New=[ (see @RefSecNum{Containers})],Old=[, that is, be irreflexive, asymmetric,
7313 and transitive]}; it
7314 should not modify Container. If the actual for "<" behaves in some other
7315 manner, the behavior of the instance of Generic_Array_Sort is unspecified.
7316 @Chg{Version=[3],New=[The number of],Old=[How many]}
7317 times Generic_Array_Sort calls "<" is unspecified.@PDefn{unspecified}]}
7318
7319 @begin{Ramification}
7320 @ChgRef{Version=[2],Kind=[AddedNormal]}
7321 @ChgAdded{Version=[2],Text=[This implies swapping the elements, usually
7322 including an intermediate copy. This of course means that the elements will be
7323 copied. Since the elements are nonlimited, this usually will not be a problem.
7324 Note that there is Implementation Advice below that the implementation should
7325 use a sort that minimizes copying of elements.]}
7326
7327 @ChgRef{Version=[2],Kind=[AddedNormal]}
7328 @ChgAdded{Version=[2],Text=[The sort is not required to be stable (and the fast
7329 algorithm required will not be stable). If a stable sort is needed, the user
7330 can include the original location of the element as an extra "sort key". We
7331 considered requiring the implementation to do that, but it is mostly extra
7332 overhead -- usually there is something already in the element that provides the
7333 needed stability.]}
7334 @end{Ramification}
7335
7336 @end{DescribeCode}
7337
7338 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
7339 @ChgAdded{Version=[2],KeepNext=[T],Type=[Leading],Text=[The generic library
7340 procedure Containers.@!Generic_@!Constrained_@!Array_Sort has the following
7341 declaration:]}
7342 @begin{Example}
7343 @ChgRef{Version=[2],Kind=[AddedNormal]}
7344 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7345 @ChgAdded{Version=[2],Text=[@key{generic}
7346 @key{type} Index_Type @key{is} (<>);
7347 @key{type} Element_Type @key{is private};
7348 @key{type} Array_Type @key{is array} (Index_Type) @key{of} Element_Type;
7349 @key{with function} "<" (Left, Right : Element_Type)
7350 @key{return} Boolean @key{is} <>;
7351 @key{procedure} Ada.Containers.Generic_Constrained_Array_Sort@SubChildUnit{Parent=[Ada.Containers],Child=[Generic_Constrained_Array_Sort]}
7352 (Container : @key{in out} Array_Type)@Chg{Version=[5],New=[
7353 @key{with} Pure,
7354 Nonblocking, Global => @key[null]],Old=[@key{pragma} Pure(Ada.Containers.Generic_Constrained_Array_Sort)]};]}
7355 @end{Example}
7356
7357 @begin{Discussion}
7358 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
7359 @ChgAdded{Version=[5],Text=[Global => @key[null] means
7360 that the only global side-effects allowed are associated with the actual
7361 generic parameters. Similarly, when Nonblocking is set to True for
7362 a generic unit, the only blocking allowed is that
7363 associated with the actual generic parameters.]}
7364 @end{Discussion}
7365
7366 @begin{DescribeCode}
7367 @ChgRef{Version=[2],Kind=[AddedNormal]}
7368 @ChgAdded{Version=[2],Text=[Reorders the elements of Container such that the
7369 elements are sorted smallest first as determined by the generic formal "<"
7370 operator provided. Any exception raised during evaluation of "<" is
7371 propagated.]}
7372
7373 @ChgRef{Version=[2],Kind=[AddedNormal]}
7374 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0044-1],ARef=[AI05-0262-1]}
7375 @ChgAdded{Version=[2],Text=[The actual function for the generic formal function
7376 "<" of Generic_Constrained_Array_Sort is expected to return the same value each
7377 time it is called with a particular pair of element values. It should define a
7378 strict @Chg{Version=[3],New=[weak ],Old=[]}ordering relationship@Chg{Version=[3],
7379 New=[ (see @RefSecNum{Containers})],Old=[, that is, be irreflexive, asymmetric,
7380 and transitive]}; it should not modify Container. If the actual for "<" behaves in
7381 some other manner, the behavior of the instance of
7382 Generic_Constrained_Array_Sort is unspecified. @Chg{Version=[3],New=[The number
7383 of],Old=[How many]} times Generic_Constrained_Array_Sort calls "<" is
7384 unspecified.@PDefn{unspecified}]}
7385
7386 @end{DescribeCode}
7387
7388 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0001-1]}
7389 @ChgAdded{Version=[3],KeepNext=[T],Type=[Leading],Text=[The generic library
7390 procedure Containers.@!Generic_@!Sort has the following declaration:]}
7391 @begin{Example}
7392 @ChgRef{Version=[3],Kind=[Added]}
7393 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0056-1]}
7394 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0112-1]}
7395 @ChgAdded{Version=[3],Text=[@key{generic}
7396 @key{type} Index_Type @key{is} (<>);
7397 @key{with function} Before (Left, Right : Index_Type) @key{return} Boolean;
7398 @key{with procedure} Swap (Left, Right : @Chg{Version=[4],New=[@key[in] ],Old=[]}Index_Type);
7399 @key{procedure} Ada.Containers.Generic_Sort@SubChildUnit{Parent=[Ada.Containers],Child=[Generic_Sort]}
7400 (First, Last : Index_Type'Base)@Chg{Version=[5],New=[
7401 @key{with} Pure, Nonblocking, Global => @key[null]],Old=[@key{pragma} Pure(Ada.Containers.Generic_Sort)]};]}
7402 @end{Example}
7403
7404 @begin{Discussion}
7405 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
7406 @ChgAdded{Version=[5],Text=[Global => @key[null] means
7407 that the only global side-effects allowed are associated with the actual
7408 generic parameters. Similarly, when Nonblocking is set to True for
7409 a generic unit, the only blocking allowed is that
7410 associated with the actual generic parameters.]}
7411 @end{Discussion}
7412
7413 @begin{DescribeCode}
7414 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0001-1],ARef=[AI05-0248-1]}
7415 @ChgAdded{Version=[3],Text=[Reorders the elements of an indexable structure,
7416 over the range First .. Last, such that the elements are sorted in the ordering
7417 determined by the generic formal function Before; Before should return True if
7418 Left is to be sorted before Right. The generic formal Before
7419 compares the elements having the given indices, and the generic formal Swap
7420 exchanges the values of the indicated elements. Any exception raised during
7421 evaluation of Before or Swap is propagated.]}
7422
7423 @ChgRef{Version=[3],Kind=[Added]}
7424 @ChgAdded{Version=[3],Text=[The actual function for the generic formal function Before of
7425 Generic_Sort is expected to return the same value each time it is
7426 called with index values that identify a particular pair of element values.
7427 It should define a strict weak ordering relationship (see @RefSecNum{Containers});
7428 it should not modify the elements. The actual function for the generic formal
7429 Swap should exchange the values of the indicated elements. If the actual for
7430 either Before or Swap behaves in some other manner, the behavior of
7431 Generic_Sort is unspecified. The number of times the Generic_Sort calls Before
7432 or Swap is unspecified.@PDefn{unspecified}]}
7433
7434 @end{DescribeCode}
7435
7436 @end{StaticSem}
7437
7438 @begin{ImplAdvice}
7439
7440 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
7441 @ChgAdded{Version=[2],Text=[
7442 The worst-case time complexity of a call on an instance of
7443 Containers.Generic_Array_Sort or
7444 Containers.Generic_Constrained_Array_Sort should be @i{O}(@i<N>**2) or better,
7445 and the average time complexity should be better
7446 than @i{O}(@i<N>**2), where @i<N> is the length of the Container parameter.]}
7447 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
7448 Text=[Containers.Generic_Array_Sort and Containers.Generic_Constrained_Array_Sort
7449 should have an average time complexity better than @i{O}(@i{N}**2) and worst case no
7450 worse than @i{O}(@i{N}**2).]}]}
7451
7452 @begin{Discussion}
7453 @ChgRef{Version=[2],Kind=[AddedNormal]}
7454 @ChgAdded{Version=[2],Text=[In other words, we're requiring the use of
7455 a sorting algorithm better than @i{O}(@i<N>**2), such as Quicksort. No bubble
7456 sorts allowed!]}
7457 @end{Discussion}
7458
7459 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
7460 @ChgAdded{Version=[2],Text=[
7461 Containers.Generic_Array_Sort and Containers.Generic_Constrained_Array_Sort
7462 should minimize copying of elements.]}
7463 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
7464 Text=[Containers.Generic_Array_Sort and Containers.Generic_Constrained_Array_Sort
7465 should minimize copying of elements.]}]}
7466
7467 @begin{Honest}
7468 @ChgRef{Version=[2],Kind=[AddedNormal]}
7469 @ChgAdded{Version=[2],Text=[We do not mean @lquotes@;absolutely minimize@rquotes@;
7470 here; we're not intending to require a single copy for each element. Rather,
7471 we want to suggest that the sorting algorithm chosen is one that does not
7472 copy items unnecessarily. Bubble sort would not meet this advice, for
7473 instance.]}
7474 @end{Honest}
7475
7476 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0248-1]}
7477 @ChgAdded{Version=[3],Text=[
7478 The worst-case time complexity of a call on an instance of
7479 Containers.Generic_Sort should be @i{O}(@i<N>**2) or better,
7480 and the average time complexity should be better
7481 than @i{O}(@i<N>**2), where @i<N> is the difference between the Last and First
7482 parameters plus 1.]}
7483 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
7484 Text=[Containers.Generic_Sort
7485 should have an average time complexity better than @i{O}(@i{N}**2) and worst case no
7486 worse than @i{O}(@i{N}**2).]}]}
7487
7488 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0248-1]}
7489 @ChgAdded{Version=[3],Text=[Containers.Generic_Sort
7490 should minimize calls to the generic formal Swap.]}
7491 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
7492 Text=[Containers.Generic_Sort should minimize calls to the generic formal Swap.]}]}
7493 @end{ImplAdvice}
7494
7495 @begin{Extend95}
7496 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
7497 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
7498 The generic procedures Containers.Generic_Array_Sort and
7499 Containers.Generic_Constrained_Array_Sort are new.]}
7500 @end{Extend95}
7501
7502 @begin{Extend2005}
7503 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0248-1]}
7504 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic
7505 procedure Containers.Generic_Sort is new.]}
7506 @end{Extend2005}
7507
7508 @begin{DiffWord2005}
7509 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0044-1]}
7510 @ChgAdded{Version=[3],Text=[@b<Correction:> Redefined "<" actuals
7511 to require a strict weak ordering; the old definition allowed
7512 indeterminant comparisons that would not have worked in a sort.]}
7513 @end{DiffWord2005}
7514
7515 @begin{DiffWord2012}
7516 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
7517 @ChgAdded{Version=[5],Text=[Added contracts to these procedures.]}
7518 @end{DiffWord2012}
7519
7520
7521 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Synchronized_Queue_Interfaces]}
7522
7523 @begin{Intro}
7524 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
7525 @ChgAdded{Version=[3],Text=[The language-defined generic package
7526 Containers.Synchronized_Queue_Interfaces provides interface type Queue, and a
7527 set of operations for that type. Interface Queue specifies a first-in, first-out
7528 queue.]}
7529 @end{Intro}
7530
7531 @begin{StaticSem}
7532 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
7533 @ChgAdded{Version=[3],KeepNext=[T],Type=[Leading],Text=[The generic library
7534 package Containers.Synchronized_Queue_Interfaces has the following declaration:]}
7535 @begin{Example}
7536 @ChgRef{Version=[3],Kind=[AddedNormal]}
7537 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7538 @ChgAdded{Version=[3],Text=[@key[generic]
7539 @key[type] Element_Type @key[is private];
7540 @key[package] Ada.Containers.Synchronized_Queue_Interfaces@Chg{Version=[5],New=[],Old=[ @key{is}]}@ChildUnit{Parent=[Ada.Containers],Child=[Synchronized_Queue_Interfaces]}@Chg{Version=[5],New=[
7541 @key[with] Pure, Nonblocking, Global => @key[null] @key[is]],Old=[
7542 @key{pragma} Pure(Synchronized_Queue_Interfaces);]}]}
7543
7544 @begin{Discussion}
7545 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
7546 @ChgAdded{Version=[5],Text=[Global => @key[null] means
7547 that the only global side-effects allowed are associated with the actual
7548 generic parameters. Similarly, when Nonblocking is set to True for
7549 a generic unit, the only blocking allowed is that
7550 associated with the actual generic parameters.]}
7551 @end{Discussion}
7552
7553 @ChgRef{Version=[3],Kind=[AddedNormal]}
7554 @ChgAdded{Version=[3],Text=[ @key[type] @AdaTypeDefn{Queue} @key[is synchronized interface];]}
7555
7556 @ChgRef{Version=[3],Kind=[AddedNormal]}
7557 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7558 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Enqueue}
7559 (Container : @key[in out] Queue;
7560 New_Item : @key[in] Element_Type) @key[is abstract]
7561 @key[with] Synchronization => By_Entry@Chg{Version=[5],New=[,
7562 Nonblocking => False,
7563 Global'Class=> @key[in out synchronized]],Old=[]};]}
7564
7565 @ChgRef{Version=[3],Kind=[AddedNormal]}
7566 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7567 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Dequeue}
7568 (Container : @key[in out] Queue;
7569 Element : @key[out] Element_Type) @key[is abstract]
7570 @key[with] Synchronization => By_Entry@Chg{Version=[5],New=[,
7571 Nonblocking => False,
7572 Global'Class=> @key[in out synchronized]],Old=[]};]}
7573
7574 @ChgRef{Version=[3],Kind=[AddedNormal]}
7575 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7576 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Current_Use} (Container : Queue) @key[return] Count_Type @key[is abstract]@Chg{Version=[5],New=[
7577 @key[with] Nonblocking, Global'Class => (@key[null], @key[use null])],Old=[]};
7578 @key[function] @AdaSubDefn{Peak_Use} (Container : Queue) @key[return] Count_Type @key[is abstract]@Chg{Version=[5],New=[
7579 @key[with] Nonblocking, Global'Class => (@key[null], @key[use null]),
7580 Post'Class => Peak_Use'Result >= Current_Use (Container)],Old=[]};]}
7581
7582 @ChgRef{Version=[3],Kind=[AddedNormal]}
7583 @ChgAdded{Version=[3],Text=[@key{end} Ada.Containers.Synchronized_Queue_Interfaces;]}
7584 @end{Example}
7585
7586 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0112-1]}
7587 @ChgAdded{Version=[5],Text=[The subprogram behavior descriptions given below
7588 are the semantics for the corresponding callable entities found in the
7589 language-defined generic packages that have a formal package named
7590 Queue_Interfaces.]}
7591
7592
7593 @begin{DescribeCode}
7594
7595 @begin{Example}
7596 @ChgRef{Version=[3],Kind=[AddedNormal]}
7597 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7598 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[procedure] Enqueue
7599 (Container : @key[in out] Queue;
7600 New_Item : @key[in] Element_Type) @key[is abstract]@Chg{Version=[5],New=[
7601 @key[with] Synchronization => By_Entry
7602 Nonblocking => False,
7603 Global'Class=> @key[in out synchronized]],Old=[]};]}
7604 @end{Example}
7605
7606 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0262-1],ARef=[AI05-0264-1]}
7607 @ChgAdded{Version=[3],Type=[Trailing],Text=[A queue type that implements this
7608 interface is allowed to have a bounded @i<capacity>@Defn2{Term=[capacity],Sec=[of a queue]}.
7609 If the queue object has a bounded
7610 capacity, and the number of existing elements equals the capacity, then Enqueue
7611 blocks until storage becomes available; otherwise, Enqueue does not block. In any
7612 case, it then copies New_Item onto the queue.]}
7613
7614 @begin{Example}
7615 @ChgRef{Version=[3],Kind=[AddedNormal]}
7616 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7617 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[procedure] Dequeue
7618 (Container : @key[in out] Queue;
7619 Element : @key[out] Element_Type) @key[is abstract]@Chg{Version=[5],New=[
7620 @key[with] Synchronization => By_Entry
7621 Nonblocking => False,
7622 Global'Class=> @key[in out synchronized]],Old=[]};]}
7623 @end{Example}
7624
7625 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0251-1]}
7626 @ChgAdded{Version=[3],Type=[Trailing],Text=[If the queue is empty, then Dequeue
7627 blocks until an item becomes available. In any case, it then assigns the
7628 element at the head of the queue to Element, and removes it from the queue.]}
7629
7630 @begin{Example}
7631 @ChgRef{Version=[3],Kind=[AddedNormal]}
7632 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7633 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Current_Use (Container : Queue) @key[return] Count_Type @key[is abstract]@Chg{Version=[5],New=[
7634 @key[with] Nonblocking, Global'Class=> (@key[null], @key[use null])],Old=[]};]}
7635 @end{Example}
7636
7637 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
7638 @ChgAdded{Version=[3],Type=[Trailing],Text=[Returns the number of elements
7639 currently in the queue.]}
7640
7641 @begin{Example}
7642 @ChgRef{Version=[3],Kind=[AddedNormal]}
7643 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7644 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Peak_Use (Container : Queue) @key[return] Count_Type @key[is abstract]@Chg{Version=[5],New=[
7645 @key[with] Nonblocking, Global'Class=> (@key[null], @key[use null]),
7646 Post'Class => Peak_Use'Result >= Current_Use (Container)],Old=[]};]}
7647 @end{Example}
7648
7649 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
7650 @ChgAdded{Version=[3],Type=[Trailing],Text=[Returns the maximum number of
7651 elements that have been in the queue at any one time.]}
7652
7653 @end{DescribeCode}
7654
7655 @end{StaticSem}
7656
7657 @begin{Notes}
7658 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0251-1]}
7659 @ChgAdded{Version=[3],Text=[Unlike other language-defined containers, there are
7660 no queues whose element types are indefinite. Elements of an indefinite type can
7661 be handled by defining the element of the queue to be a holder container (see
7662 @RefSecNum{The Generic Package Containers.Indefinite_Holders}) of the indefinite
7663 type, or to be an explicit access type that designates the indefinite type.]}
7664
7665 @begin{Reason}
7666 @ChgRef{Version=[3],Kind=[AddedNormal]}
7667 @ChgAdded{Version=[3],Text=[There are no indefinite queues, as a useful
7668 definition for Dequeue is not possible. Dequeue cannot be a function, as Ada
7669 does not have entries that are functions (thus conditional and timed calls
7670 would not be possible). Moreover, protected functions do not allow modifying
7671 the queue object (thus it doesn't work even if we decided we didn't care about
7672 conditional and timed calls). If Dequeue is an entry, then the dequeued object
7673 would have to be an @key[out] parameter and that would require the queue client to
7674 guess the tag and constraints of the value that will be dequeued (otherwise
7675 Constraint_Error would be raised), and that is rarely going to be possible.]}
7676 @end{Reason}
7677 @end{Notes}
7678
7679 @begin{Extend2005}
7680 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0251-1]}
7681 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic
7682 package Containers.Synchronized_Queue_Interfaces is new.]}
7683 @end{Extend2005}
7684
7685
7686 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Unbounded_Synchronized_Queues]}
7687
7688 @begin{StaticSem}
7689 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
7690 @ChgAdded{Version=[3],Text=[The language-defined generic package
7691 Containers.Unbounded_Synchronized_Queues provides type Queue, which implements
7692 the interface type Containers.Synchronized_Queue_Interfaces.Queue.]}
7693
7694 @begin{Example}
7695 @ChgRef{Version=[3],Kind=[AddedNormal]}
7696 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7697 @ChgAdded{Version=[3],Text=[@key[with] System;
7698 @key[with] Ada.Containers.Synchronized_Queue_Interfaces;
7699 @key[generic]
7700 @key[with package] Queue_Interfaces @key[is new] Ada.Containers.Synchronized_Queue_Interfaces (<>);
7701 Default_Ceiling : System.Any_Priority := System.Priority'Last;
7702 @key[package] Ada.Containers.Unbounded_Synchronized_Queues@Chg{Version=[5],New=[],Old=[ @key{is}]}@ChildUnit{Parent=[Ada.Containers],Child=[Unbounded_Synchronized_Queues]}@Chg{Version=[5],New=[
7703 @key[with] Preelaborate,
7704 Nonblocking, Global => @key[null] @key[is]],Old=[
7705 @key[pragma] Preelaborate(Unbounded_Synchronized_Queues);]}]}
7706
7707 @begin{Discussion}
7708 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
7709 @ChgAdded{Version=[5],Text=[For discussion on the reasons and meaning of
7710 the specifications of the Global and Nonblocking aspects of this generic
7711 package, see the notes on the specification of the Containers.Vectors
7712 package (see @RefSecNum{The Generic Package Containers.Vectors}).]}
7713 @end{Discussion}
7714
7715 @ChgRef{Version=[3],Kind=[AddedNormal]}
7716 @ChgAdded{Version=[3],Text=[ @key[package] Implementation @key[is]
7717 ... -- @Examcom[not specified by the language]
7718 @key[end] Implementation;]}
7719
7720 @ChgRef{Version=[3],Kind=[AddedNormal]}
7721 @ChgAdded{Version=[3],Text=[ @key[protected type] @AdaTypeDefn{Queue}
7722 (Ceiling : System.Any_Priority := Default_Ceiling)
7723 @key[with] Priority => Ceiling @key[is]
7724 @key[new] Queue_Interfaces.Queue @key[with]]}
7725
7726 @ChgRef{Version=[3],Kind=[AddedNormal]}
7727 @ChgAdded{Version=[3],Text=[ @key[overriding]
7728 @key[entry] @AdaSubDefn{Enqueue} (New_Item : @key[in] Queue_Interfaces.Element_Type);
7729 @key[overriding]
7730 @key[entry] @AdaSubDefn{Dequeue} (Element : @key[out] Queue_Interfaces.Element_Type);]}
7731
7732 @ChgRef{Version=[3],Kind=[AddedNormal]}
7733 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7734 @ChgAdded{Version=[3],Text=[ @key[overriding]
7735 @key[function] @AdaSubDefn{Current_Use} @key[return] Count_Type@Chg{Version=[5],New=[
7736 @key[with] Nonblocking, Global => (@key[null], @key[use null])],Old=[]};
7737 @key[overriding]
7738 @key[function] @AdaSubDefn{Peak_Use} @key[return] Count_Type@Chg{Version=[5],New=[
7739 @key[with] Nonblocking, Global => (@key[null], @key[use null])],Old=[]};]}
7740
7741 @ChgRef{Version=[3],Kind=[AddedNormal]}
7742 @ChgAdded{Version=[3],Text=[ @key[private]
7743 ... -- @Examcom[not specified by the language]
7744 @key[end] Queue;]}
7745
7746 @ChgRef{Version=[3],Kind=[AddedNormal]}
7747 @ChgAdded{Version=[3],Text=[@key{private}]}
7748
7749 @ChgRef{Version=[3],Kind=[AddedNormal]}
7750 @ChgAdded{Version=[3],Text=[ ... -- @Examcom[not specified by the language]]}
7751
7752 @ChgRef{Version=[3],Kind=[AddedNormal]}
7753 @ChgAdded{Version=[3],Text=[@key{end} Ada.Containers.Unbounded_Synchronized_Queues;]}
7754 @end{Example}
7755
7756 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
7757 @ChgAdded{Version=[3],Text=[The type Queue is used to represent task-safe
7758 queues.]}
7759
7760 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
7761 @ChgAdded{Version=[3],Text=[The capacity for instances of type Queue is
7762 unbounded.]}
7763
7764 @begin{Ramification}
7765 @ChgRef{Version=[3],Kind=[AddedNormal]}
7766 @ChgAdded{Version=[3],Text=[Enqueue never blocks; if more storage is needed
7767 for a new element, it is allocated dynamically. We don't need to explicitly
7768 specify that Queue needs finalization, because it is visibly protected.]}
7769 @end{Ramification}
7770
7771 @begin{Discussion}
7772 @ChgRef{Version=[3],Kind=[AddedNormal]}
7773 @ChgAdded{Version=[3],Text=[Nested package Implementation can be used to
7774 declare the types needed to implement the protected type Queue. This
7775 nested package is necessary as types cannot be declared in the private
7776 part of a protected type, and the types have to be declared within the
7777 generic unit in order to depend on the types imported with package
7778 Queue_Interfaces. Clients should never depend on the contents of
7779 nested package Implementation.]}
7780 @end{Discussion}
7781
7782 @end{StaticSem}
7783
7784 @begin{Extend2005}
7785 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
7786 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic
7787 package Containers.Unbounded_Synchronized_Queues is new.]}
7788 @end{Extend2005}
7789
7790
7791
7792 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Synchronized_Queues]}
7793
7794 @begin{StaticSem}
7795 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
7796 @ChgAdded{Version=[3],Text=[The language-defined generic package
7797 Containers.Bounded_Synchronized_Queues provides type Queue, which implements
7798 the interface type Containers.Synchronized_Queue_Interfaces.Queue.]}
7799
7800 @begin{Example}
7801 @ChgRef{Version=[3],Kind=[AddedNormal]}
7802 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7803 @ChgAdded{Version=[3],Text=[@key[with] System;
7804 @key[with] Ada.Containers.Synchronized_Queue_Interfaces;
7805 @key[generic]
7806 @key[with package] Queue_Interfaces @key[is new] Ada.Containers.Synchronized_Queue_Interfaces (<>);
7807 Default_Capacity : Count_Type;
7808 Default_Ceiling : System.Any_Priority := System.Priority'Last;
7809 @key[package] Ada.Containers.Bounded_Synchronized_Queues@Chg{Version=[5],New=[],Old=[ @key{is}]}@ChildUnit{Parent=[Ada.Containers],Child=[Bounded_Synchronized_Queues]}@Chg{Version=[5],New=[
7810 @key[with] Preelaborate,
7811 Nonblocking, Global => @key[null] @key[is]],Old=[
7812 @key[pragma] Preelaborate(Bounded_Synchronized_Queues);]}]}
7813
7814 @begin{Discussion}
7815 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
7816 @ChgAdded{Version=[5],Text=[For discussion on the reasons and meaning of
7817 the specifications of the Global and Nonblocking aspects of this generic
7818 package, see the notes on the specification of the Containers.Vectors
7819 package (see @RefSecNum{The Generic Package Containers.Vectors}).]}
7820 @end{Discussion}
7821
7822 @ChgRef{Version=[3],Kind=[AddedNormal]}
7823 @ChgAdded{Version=[3],Text=[ @key[package] Implementation @key[is]
7824 ... -- @Examcom[not specified by the language]
7825 @key[end] Implementation;]}
7826
7827 @ChgRef{Version=[3],Kind=[AddedNormal]}
7828 @ChgAdded{Version=[3],Text=[ @key[protected type] @AdaTypeDefn{Queue}
7829 (Capacity : Count_Type := Default_Capacity;
7830 Ceiling : System.Any_Priority := Default_Ceiling)
7831 @key[with] Priority => Ceiling @key[is]
7832 @key[new] Queue_Interfaces.Queue @key[with]]}
7833
7834 @ChgRef{Version=[3],Kind=[AddedNormal]}
7835 @ChgAdded{Version=[3],Text=[ @key[overriding]
7836 @key[entry] @AdaSubDefn{Enqueue} (New_Item : @key[in] Queue_Interfaces.Element_Type);
7837 @key[overriding]
7838 @key[entry] @AdaSubDefn{Dequeue} (Element : @key[out] Queue_Interfaces.Element_Type);]}
7839
7840 @ChgRef{Version=[3],Kind=[AddedNormal]}
7841 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7842 @ChgAdded{Version=[3],Text=[ @key[overriding]
7843 @key[function] @AdaSubDefn{Current_Use} @key[return] Count_Type@Chg{Version=[5],New=[
7844 @key[with] Nonblocking, Global => (@key[null], @key[use null])],Old=[]};
7845 @key[overriding]
7846 @key[function] @AdaSubDefn{Peak_Use} @key[return] Count_Type@Chg{Version=[5],New=[
7847 @key[with] Nonblocking, Global => (@key[null], @key[use null])],Old=[]};]}
7848
7849 @ChgRef{Version=[3],Kind=[AddedNormal]}
7850 @ChgAdded{Version=[3],Text=[ @key[private]
7851 ... -- @Examcom[not specified by the language]
7852 @key[end] Queue;]}
7853
7854 @ChgRef{Version=[3],Kind=[AddedNormal]}
7855 @ChgAdded{Version=[3],Text=[@key{private}]}
7856
7857 @ChgRef{Version=[3],Kind=[AddedNormal]}
7858 @ChgAdded{Version=[3],Text=[ ... -- @Examcom[not specified by the language]]}
7859
7860 @ChgRef{Version=[3],Kind=[AddedNormal]}
7861 @ChgAdded{Version=[3],Text=[@key{end} Ada.Containers.Bounded_Synchronized_Queues;]}
7862 @end{Example}
7863
7864 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
7865 @ChgAdded{Version=[3],Keepnext=[T],Type=[Leading],Text=[The semantics are the
7866 same as for Unbounded_Synchronized_Queues, except:]}
7867
7868 @begin{Itemize}
7869 @ChgRef{Version=[3],Kind=[AddedNormal]}
7870 @ChgAdded{Version=[3],Text=[The capacity for instances of type Queue is
7871 bounded and specified by the discriminant Capacity.]}
7872 @end{Itemize}
7873
7874 @begin{Ramification}
7875 @ChgRef{Version=[3],Kind=[AddedNormal]}
7876 @ChgAdded{Version=[3],Text=[Since this type has a bounded capacity, Enqueue
7877 might block if the queue is full.]}
7878 @end{Ramification}
7879
7880 @end{StaticSem}
7881
7882 @begin{ImplAdvice}
7883 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
7884 @ChgAdded{Version=[3],Text=[Bounded queue objects should be implemented without
7885 implicit pointers or dynamic allocation.]}
7886 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
7887 Text=[Bounded queue objects should be implemented without
7888 implicit pointers or dynamic allocation.]}]}
7889 @end{ImplAdvice}
7890
7891
7892 @begin{Extend2005}
7893 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
7894 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic
7895 package Containers.Bounded_Synchronized_Queues is new.]}
7896 @end{Extend2005}
7897
7898
7899
7900 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Unbounded_Priority_Queues]}
7901
7902 @begin{StaticSem}
7903 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
7904 @ChgAdded{Version=[3],Text=[The language-defined generic package
7905 Containers.Unbounded_Priority_Queues provides type Queue, which implements
7906 the interface type Containers.Synchronized_Queue_Interfaces.Queue.]}
7907
7908 @begin{Example}
7909 @ChgRef{Version=[3],Kind=[AddedNormal]}
7910 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7911 @ChgAdded{Version=[3],Text=[@key[with] System;
7912 @key[with] Ada.Containers.Synchronized_Queue_Interfaces;
7913 @key[generic]
7914 @key[with package] Queue_Interfaces @key[is new] Ada.Containers.Synchronized_Queue_Interfaces (<>);
7915 @key[type] Queue_Priority @key[is private];
7916 @key[with] @key[function] Get_Priority
7917 (Element : Queue_Interfaces.Element_Type) @key[return] Queue_Priority @key[is] <>;
7918 @key[with] @key[function] Before
7919 (Left, Right : Queue_Priority) @key[return] Boolean @key[is] <>;
7920 Default_Ceiling : System.Any_Priority := System.Priority'Last;
7921 @key[package] Ada.Containers.Unbounded_Priority_Queues@Chg{Version=[5],New=[],Old=[ @key{is}]}@ChildUnit{Parent=[Ada.Containers],Child=[Unbounded_Priority_Queues]}@Chg{Version=[5],New=[
7922 @key[with] Preelaborate,
7923 Nonblocking, Global => @key[null] @key[is]],Old=[
7924 @key[pragma] Preelaborate(Unbounded_Priority_Queues);]}]}
7925
7926 @begin{Discussion}
7927 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
7928 @ChgAdded{Version=[5],Text=[For discussion on the reasons and meaning of
7929 the specifications of the Global and Nonblocking aspects of this generic
7930 package, see the notes on the specification of the Containers.Vectors
7931 package (see @RefSecNum{The Generic Package Containers.Vectors}).]}
7932 @end{Discussion}
7933
7934 @ChgRef{Version=[3],Kind=[AddedNormal]}
7935 @ChgAdded{Version=[3],Text=[ @key[package] Implementation @key[is]
7936 ... -- @Examcom[not specified by the language]
7937 @key[end] Implementation;]}
7938
7939 @ChgRef{Version=[3],Kind=[AddedNormal]}
7940 @ChgAdded{Version=[3],Text=[ @key[protected type] @AdaTypeDefn{Queue}
7941 (Ceiling : System.Any_Priority := Default_Ceiling)
7942 @key[with] Priority => Ceiling @key[is]
7943 @key[new] Queue_Interfaces.Queue @key[with]]}
7944
7945 @ChgRef{Version=[3],Kind=[AddedNormal]}
7946 @ChgAdded{Version=[3],Text=[ @key[overriding]
7947 @key[entry] @AdaSubDefn{Enqueue} (New_Item : @key[in] Queue_Interfaces.Element_Type);
7948 @key[overriding]
7949 @key[entry] @AdaSubDefn{Dequeue} (Element : @key[out] Queue_Interfaces.Element_Type);]}
7950
7951 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0251-1]}
7952 @ChgAdded{Version=[3],Text=[ @key[not overriding]
7953 @key[procedure] @AdaSubDefn{Dequeue_Only_High_Priority}
7954 (At_Least : @key[in] Queue_Priority;
7955 Element : @key[in out] Queue_Interfaces.Element_Type;
7956 Success : @key[out] Boolean);]}
7957
7958 @ChgRef{Version=[3],Kind=[AddedNormal]}
7959 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
7960 @ChgAdded{Version=[3],Text=[ @key[overriding]
7961 @key[function] @AdaSubDefn{Current_Use} @key[return] Count_Type@Chg{Version=[5],New=[
7962 @key[with] Nonblocking, Global => (@key[null], @key[use null])],Old=[]};
7963 @key[overriding]
7964 @key[function] @AdaSubDefn{Peak_Use} @key[return] Count_Type@Chg{Version=[5],New=[
7965 @key[with] Nonblocking, Global => (@key[null], @key[use null])],Old=[]};]}
7966
7967 @ChgRef{Version=[3],Kind=[AddedNormal]}
7968 @ChgAdded{Version=[3],Text=[ @key[private]
7969 ... -- @Examcom[not specified by the language]
7970 @key[end] Queue;]}
7971
7972 @ChgRef{Version=[3],Kind=[AddedNormal]}
7973 @ChgAdded{Version=[3],Text=[@key{private}]}
7974
7975 @ChgRef{Version=[3],Kind=[AddedNormal]}
7976 @ChgAdded{Version=[3],Text=[ ... -- @Examcom[not specified by the language]]}
7977
7978 @ChgRef{Version=[3],Kind=[AddedNormal]}
7979 @ChgAdded{Version=[3],Text=[@key{end} Ada.Containers.Unbounded_Priority_Queues;]}
7980 @end{Example}
7981
7982 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
7983 @ChgAdded{Version=[3],Text=[The type Queue is used to represent task-safe
7984 priority queues.]}
7985
7986 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
7987 @ChgAdded{Version=[3],Text=[The capacity for instances of type Queue is
7988 unbounded.]}
7989
7990 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
7991 @ChgAdded{Version=[3],Text=[Two elements @i<E1> and @i<E2> are equivalent if
7992 Before(Get_Priority(@i<E1>), Get_Priority(@i<E2>)) and
7993 Before(Get_Priority(@i<E2>), Get_Priority(@i<E1>)) both return False.]}
7994
7995 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0248-1]}
7996 @ChgAdded{Version=[3],Text=[The actual functions for Get_Priority and Before are
7997 expected to return the same value each time they are called with the same
7998 actuals, and should not modify their actuals. Before should define a strict weak
7999 ordering relationship (see @RefSecNum{Containers}). If the actual
8000 functions behave in some other manner, the behavior of Unbounded_Priority_Queues
8001 is unspecified.]}
8002
8003 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
8004 @ChgAdded{Version=[3],Text=[Enqueue inserts an item according to the order
8005 specified by the Before function on the result of Get_Priority on the elements;
8006 Before should return True if Left is to be inserted before Right.
8007 If the queue already contains elements equivalent to New_Item, then it is
8008 inserted after the existing equivalent elements.]}
8009
8010 @begin{Ramification}
8011 @ChgRef{Version=[3],Kind=[AddedNormal]}
8012 @ChgAdded{Version=[3],Text=[Enqueue never blocks; if more storage is needed
8013 for a new element, it is allocated dynamically. We don't need to explicitly
8014 specify that Queue needs finalization, because it is visibly protected.]}
8015 @end{Ramification}
8016
8017 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0251-1],ARef=[AI05-0262-1]}
8018 @ChgAdded{Version=[3],Text=[For a call on Dequeue_Only_High_Priority, if the
8019 head of the nonempty queue is @i<E>, and the function Before(At_Least,
8020 Get_Priority(@i<E>)) returns False, then @i<E> is assigned to
8021 Element and then removed from the queue, and Success is set to True;
8022 otherwise, Success is set to False and Element is unchanged.]}
8023
8024 @begin{Ramification}
8025 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0251-1]}
8026 @ChgAdded{Version=[3],Text=[Unlike Dequeue, Dequeue_Only_High_Priority is not
8027 blocking; it always returns immediately.]}
8028 @end{Ramification}
8029
8030 @begin{Reason}
8031 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0251-1]}
8032 @ChgAdded{Version=[3],Text=[The use of Before is "backwards" so that it acts
8033 like ">=" (it is defined similarly to ">"); thus we dequeue only when it is
8034 False.]}
8035 @end{Reason}
8036
8037 @end{StaticSem}
8038
8039 @begin{Extend2005}
8040 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0251-1]}
8041 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic
8042 package Containers.Unbounded_Priority_Queues is new.]}
8043 @end{Extend2005}
8044
8045
8046 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Priority_Queues]}
8047
8048 @begin{StaticSem}
8049 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
8050 @ChgAdded{Version=[3],Text=[The language-defined generic package
8051 Containers.Bounded_Priority_Queues provides type Queue, which implements
8052 the interface type Containers.Synchronized_Queue_Interfaces.Queue.]}
8053
8054 @begin{Example}
8055 @ChgRef{Version=[3],Kind=[AddedNormal]}
8056 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
8057 @ChgAdded{Version=[3],Text=[@key[with] System;
8058 @key[with] Ada.Containers.Synchronized_Queue_Interfaces;
8059 @key[generic]
8060 @key[with package] Queue_Interfaces @key[is new] Ada.Containers.Synchronized_Queue_Interfaces (<>);
8061 @key[type] Queue_Priority @key[is private];
8062 @key[with function] Get_Priority
8063 (Element : Queue_Interfaces.Element_Type) @key[return] Queue_Priority @key[is] <>;
8064 @key[with function] Before
8065 (Left, Right : Queue_Priority) @key[return] Boolean @key[is] <>;
8066 Default_Capacity : Count_Type;
8067 Default_Ceiling : System.Any_Priority := System.Priority'Last;
8068 @key[package] Ada.Containers.Bounded_Priority_Queues@Chg{Version=[5],New=[],Old=[ @key{is}]}@ChildUnit{Parent=[Ada.Containers],Child=[Bounded_Priority_Queues]}@Chg{Version=[5],New=[
8069 @key[with] Preelaborate,
8070 Nonblocking, Global => @key[null] @key[is]],Old=[
8071 @key[pragma] Preelaborate(Bounded_Priority_Queues);]}]}
8072
8073 @begin{Discussion}
8074 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0112-1]}
8075 @ChgAdded{Version=[5],Text=[For discussion on the reasons and meaning of
8076 the specifications of the Global and Nonblocking aspects of this generic
8077 package, see the notes on the specification of the Containers.Vectors
8078 package (see @RefSecNum{The Generic Package Containers.Vectors}).]}
8079 @end{Discussion}
8080
8081 @ChgRef{Version=[3],Kind=[AddedNormal]}
8082 @ChgAdded{Version=[3],Text=[ @key[package] Implementation @key[is]
8083 ... -- @Examcom[not specified by the language]
8084 @key[end] Implementation;]}
8085
8086 @ChgRef{Version=[3],Kind=[AddedNormal]}
8087 @ChgAdded{Version=[3],Text=[ @key[protected type] @AdaTypeDefn{Queue}
8088 (Capacity : Count_Type := Default_Capacity;
8089 Ceiling : System.Any_Priority := Default_Ceiling)
8090 @key[with] Priority => Ceiling @key[is]
8091 @key[new] Queue_Interfaces.Queue @key[with]]}
8092
8093 @ChgRef{Version=[3],Kind=[AddedNormal]}
8094 @ChgAdded{Version=[3],Text=[ @key[overriding]
8095 @key[entry] @AdaSubDefn{Enqueue} (New_Item : @key[in] Queue_Interfaces.Element_Type);
8096 @key[overriding]
8097 @key[entry] @AdaSubDefn{Dequeue} (Element : @key[out] Queue_Interfaces.Element_Type);]}
8098
8099 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0251-1]}
8100 @ChgAdded{Version=[3],Text=[ @key[not overriding]
8101 @key[procedure] @AdaSubDefn{Dequeue_Only_High_Priority}
8102 (At_Least : @key[in] Queue_Priority;
8103 Element : @key[in out] Queue_Interfaces.Element_Type;
8104 Success : @key[out] Boolean);]}
8105
8106 @ChgRef{Version=[3],Kind=[AddedNormal]}
8107 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0112-1]}
8108 @ChgAdded{Version=[3],Text=[ @key[overriding]
8109 @key[function] @AdaSubDefn{Current_Use} @key[return] Count_Type@Chg{Version=[5],New=[
8110 @key[with] Nonblocking, Global => (@key[null], @key[use null])],Old=[]};
8111 @key[overriding]
8112 @key[function] @AdaSubDefn{Peak_Use} @key[return] Count_Type@Chg{Version=[5],New=[
8113 @key[with] Nonblocking, Global => (@key[null], @key[use null])],Old=[]};]}
8114
8115 @ChgRef{Version=[3],Kind=[AddedNormal]}
8116 @ChgAdded{Version=[3],Text=[ @key[private]
8117 ... -- @Examcom[not specified by the language]
8118 @key[end] Queue;]}
8119
8120 @ChgRef{Version=[3],Kind=[AddedNormal]}
8121 @ChgAdded{Version=[3],Text=[@key{private}]}
8122
8123 @ChgRef{Version=[3],Kind=[AddedNormal]}
8124 @ChgAdded{Version=[3],Text=[ ... -- @Examcom[not specified by the language]]}
8125
8126 @ChgRef{Version=[3],Kind=[AddedNormal]}
8127 @ChgAdded{Version=[3],Text=[@key{end} Ada.Containers.Bounded_Priority_Queues;]}
8128 @end{Example}
8129
8130 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
8131 @ChgAdded{Version=[3],Keepnext=[T],Type=[Leading],Text=[The semantics are the
8132 same as for Unbounded_Priority_Queues, except:]}
8133
8134 @begin{Itemize}
8135 @ChgRef{Version=[3],Kind=[AddedNormal]}
8136 @ChgAdded{Version=[3],Text=[The capacity for instances of type Queue is
8137 bounded and specified by the discriminant Capacity.]}
8138 @end{Itemize}
8139
8140 @begin{Ramification}
8141 @ChgRef{Version=[3],Kind=[AddedNormal]}
8142 @ChgAdded{Version=[3],Text=[Since this type has a bounded capacity, Enqueue
8143 might block if the queue is full.]}
8144 @end{Ramification}
8145
8146 @end{StaticSem}
8147
8148 @begin{ImplAdvice}
8149 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
8150 @ChgAdded{Version=[3],Text=[Bounded priority queue objects should be implemented without
8151 implicit pointers or dynamic allocation.]}
8152 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
8153 Text=[Bounded priority queue objects should be implemented without
8154 implicit pointers or dynamic allocation.]}]}
8155 @end{ImplAdvice}
8156
8157 @begin{Extend2005}
8158 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0251-1]}
8159 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic
8160 package Containers.Bounded_Priority_Queues is new.]}
8161 @end{Extend2005}
8162
8163
8164 @LabeledAddedSubclause{Version=[5],Name=[The Generic Package Containers.Bounded_Indefinite_Holders]}
8165
8166 @begin{Intro}
8167 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0254-1]}
8168 @ChgAdded{Version=[5],Text=[The language-defined generic package
8169 Containers.Bounded_Indefinite_Holders@ChildUnit{Parent=[Ada.Containers],Child=[Bounded_Indefinite_Holders]}
8170 provides a private type Holder and a set of operations for that type. It
8171 provides the same operations as the package Containers.Indefinite_Holders
8172 (see @RefSecNum{The Generic Package Containers.Indefinite_Holders}), with the
8173 difference that the maximum storage is bounded.]}
8174 @end{Intro}
8175
8176 @begin{StaticSem}
8177
8178 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0254-1]}
8179 @ChgAdded{Version=[5],Type=[Leading],Text=[The declaration of the generic
8180 library package Containers.Bounded_Indefinite_Holders has the same contents and
8181 semantics as Containers.Indefinite_Holders except:]}
8182
8183 @begin{Itemize}
8184
8185 @ChgRef{Version=[5],Kind=[AddedNormal]}
8186 @ChgAdded{Version=[5],Text=[The following is added to
8187 the context clause:]}
8188
8189 @begin{Example}
8190 @ChgRef{Version=[5],Kind=[AddedNormal]}
8191 @ChgAdded{Version=[5],Text=[ @key[with] System.Storage_Elements; @key[use] System.Storage_Elements;]}
8192 @end{Example}
8193
8194 @ChgRef{Version=[5],Kind=[AddedNormal]}
8195 @ChgAdded{Version=[5],Type=[Leading],Text=[An additional generic parameter
8196 follows Element_Type:]}
8197
8198 @begin{Example}
8199 @ChgRef{Version=[5],Kind=[AddedNormal]}
8200 @ChgAdded{Version=[5],Text=[ Max_Element_Size_in_Storage_Elements : Storage_Count;]}
8201 @end{Example}
8202
8203 @begin{Reason}
8204 @ChgRef{Version=[5],Kind=[AddedNormal]}
8205 @ChgAdded{Version=[5],Text=[This value is in Storage_Elements so that it can
8206 be used as a discriminant on a storage pool object in the implementation of
8207 the object; Ada doesn't allow discriminant dependent components to use
8208 formulas.]}
8209
8210 @ChgRef{Version=[5],Kind=[AddedNormal]}
8211 @ChgAdded{Version=[5],Text=[This is a generic parameter as it is a property
8212 of the Element_Type; the largest possible object of Element_Type is unlikely
8213 to be different for different containers, so making it a discriminant (as
8214 Capacity is) provides no useful capability.]}
8215 @end{Reason}
8216
8217 @ChgRef{Version=[5],Kind=[AddedNormal]}
8218 @ChgAdded{Version=[5],Type=[Leading],Text=[Add to the precondition of To_Holder
8219 and Replace_Element:]}
8220
8221 @begin{Example}
8222 @ChgRef{Version=[5],Kind=[AddedNormal]}
8223 @ChgAdded{Version=[5],Text=[ @key[and then] (New_Item'Size <=
8224 Max_Element_Size_in_Storage_Elements * System.Storage_Unit
8225 @key[or else raise] Program_Error)]}
8226 @end{Example}
8227
8228 @begin{Reason}
8229 @ChgRef{Version=[5],Kind=[AddedNormal]}
8230 @ChgAdded{Version=[5],Text=[This ensures that an object that won't fit is not
8231 inserted into the container.]}
8232 @end{Reason}
8233 @end{Itemize}
8234 @end{StaticSem}
8235
8236 @begin{Bounded}
8237 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0254-1]}
8238 @ChgAdded{Version=[5],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
8239 It is a bounded error to assign from a bounded holder object while tampering
8240 with elements of that object is prohibited. Either Program_Error is raised by
8241 the assignment, execution proceeds with the target object prohibiting tampering
8242 with elements, or execution
8243 proceeds normally.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}]}
8244 @end{Bounded}
8245
8246 @begin{ImplReq}
8247 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0254-1]}
8248 @ChgAdded{Version=[5],Type=[Leading],Text=[For each instance of
8249 Containers.Indefinite_Holders and each instance of
8250 Containers.Bounded_Indefinite_Holders, if the two instances meet the following
8251 conditions, then the output generated by the Holder'Output or Holder'Write
8252 subprograms of either instance shall be readable by the Holder'Input or
8253 Holder'Read of the other instance, respectively:]}
8254
8255 @begin{Itemize}
8256 @ChgRef{Version=[5],Kind=[AddedNormal]}
8257 @ChgAdded{Version=[5],Text=[the Element_Type parameters of the two instances
8258 are statically matching subtypes of the same type; and]}
8259
8260 @ChgRef{Version=[5],Kind=[AddedNormal]}
8261 @ChgAdded{Version=[5],Text=[the output generated by Element_Type'Output or
8262 Element_Type'Write is readable by Element_Type'Input or Element_Type'Read,
8263 respectively (where Element_Type denotes the type of the two actual
8264 Element_Type parameters).]}
8265 @end{Itemize}
8266 @end{ImplReq}
8267
8268 @begin{ImplAdvice}
8269 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0254-1]}
8270 @ChgAdded{Version=[5],Text=[Bounded holder objects should be implemented without
8271 dynamic allocation and any finalization should be trivial unless Element_Type
8272 needs finalization.]}
8273 @ChgImplAdvice{Version=[5],Kind=[Added],Text=[@ChgAdded{Version=[5],
8274 Text=[Bounded holder objects should be implemented without dynamic allocation.]}]}
8275
8276 @begin{Honest}
8277 @ChgRef{Version=[5],Kind=[AddedNormal]}
8278 @ChgAdded{Version=[5],Text=[Implementation of this container in Ada will
8279 probably require the use of a special storage pool. When we say "without
8280 dynamic allocation", we mean that this pool does not use heap memory and has
8281 a trivial finalization routine (that is, procedures Adjust and Finalize are
8282 null procedures). All storage pools are controlled, so we can't reasonably
8283 say that a bounded holder will not need finalization.]}
8284 @end{Honest}
8285
8286 @begin{ImplNote}
8287 @ChgRef{Version=[5],Kind=[AddedNormal]}
8288 @ChgAdded{Version=[5],Text=[If the implementation supports discontiguous
8289 objects that require multiple calls to Allocate in a storage pool, the
8290 storage pool will need to support such allocations. The storage pool
8291 implementation can assume that all Allocate calls occur together, and
8292 similarly for Deallocate calls, thus simplifying the pool implementation so
8293 that allocation only occurs at a high-water mark location.]}
8294 @end{ImplNote}
8295
8296 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0350-1]}
8297 @ChgAdded{Version=[5],Text=[The @ImplAdviceTitle about the Move and Swap
8298 operations is deleted for bounded holders; these operations can copy elements
8299 as needed.]}
8300
8301 @begin{Reason}
8302 @ChgRef{Version=[5],Kind=[AddedNormal]}
8303 @ChgAdded{Version=[5],Text=[The memory of a bounded indefinite holder belongs
8304 directly to the container, so it cannot be moved with the element. If the
8305 element type contains any internal pointers, moving it without calling Adjust
8306 would leave such pointers pointing to the wrong holder object. Thus, a full
8307 copy is needed, including any associated finalization and adjustments.]}
8308 @end{Reason}
8309 @end{ImplAdvice}
8310
8311 @begin{Extend2012}
8312 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0254-1]}
8313 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012} The generic
8314 package Containers.Bounded_Indefinite_Holders is new.]}
8315 @end{Extend2012}
8316
8317
8318 @LabeledAddedSubclause{Version=[3],Name=[Example of Container Use]}
8319
8320 @begin{Examples}
8321
8322 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
8323 @ChgAdded{Version=[3],Text=[The following example is an implementation of
8324 Dijkstra's shortest path algorithm in a directed graph with positive distances.
8325 The graph is represented by a map from nodes to sets of edges.]}
8326
8327 @begin{Example}
8328
8329 @ChgRef{Version=[3],Kind=[AddedNormal]}
8330 @ChgAdded{Version=[3],Text=[@key[with] Ada.Containers.Vectors;
8331 @key[with] Ada.Containers.Doubly_Linked_Lists;
8332 @key[use] Ada.Containers;
8333 @key[generic]
8334 @key[type] Node @key[is range] <>;
8335 @key[package] Shortest_Paths @key[is]
8336 @key[type] Distance @key[is new] Float @key[range] 0.0 .. Float'Last;
8337 @key[type] Edge @key[is record]
8338 To, From : Node;
8339 Length : Distance;
8340 @key[end record];]}
8341
8342 @ChgRef{Version=[3],Kind=[AddedNormal]}
8343 @ChgAdded{Version=[3],Text=[ @key[package] Node_Maps @key[is new] Vectors (Node, Node);
8344 -- @Examcom{The algorithm builds a map to indicate the node used to reach a given}
8345 -- @Examcom{node in the shortest distance.}]}
8346
8347 @ChgRef{Version=[3],Kind=[AddedNormal]}
8348 @ChgAdded{Version=[3],Text=[ @key[package] Adjacency_Lists @key[is new] Doubly_Linked_Lists (Edge);
8349 @key[use] Adjacency_Lists;]}
8350
8351 @ChgRef{Version=[3],Kind=[AddedNormal]}
8352 @ChgAdded{Version=[3],Text=[ @key[package] Graphs @key[is new] Vectors (Node, Adjacency_Lists.List);]}
8353
8354 @ChgRef{Version=[3],Kind=[AddedNormal]}
8355 @ChgAdded{Version=[3],Text=[ @key[package] Paths @key[is new] Doubly_Linked_Lists (Node);]}
8356
8357 @ChgRef{Version=[3],Kind=[AddedNormal]}
8358 @ChgAdded{Version=[3],Text=[ @key[function] Shortest_Path
8359 (G : Graphs.Vector; Source : Node; Target : Node) @key[return] Paths.List
8360 @key[with] Pre => G (Source) /= Adjacency_Lists.Empty_List;]}
8361
8362 @ChgRef{Version=[3],Kind=[AddedNormal]}
8363 @ChgAdded{Version=[3],Text=[@key[end] Shortest_Paths;]}
8364
8365 @ChgRef{Version=[3],Kind=[AddedNormal]}
8366 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0178-1]}
8367 @ChgAdded{Version=[3],Text=[@key[package body] Shortest_Paths @key[is]
8368 @key[function] Shortest_Path
8369 (G : Graphs.Vector; Source : Node; Target : Node) @key[return] Paths.List
8370 @key[is]
8371 @key[use] @Chg{Version=[5],New=[],Old=[Adjacency_Lists, ]}Node_Maps, Paths, Graphs;
8372 Reached : @key[array] (Node) @key[of] Boolean := (@key[others] => False);
8373 -- @ExamCom{The set of nodes whose shortest distance to the source is known.}]}
8374
8375 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0299-1]}
8376 @ChgAdded{Version=[3],Text=[ Reached_From : @key[array] (Node) @key[of] Node;
8377 So_Far : @key[array] (Node) @key[of] Distance := (@key[others] => Distance'Last);
8378 The_Path : Paths.List := Paths.Empty_List;
8379 Nearest_Distance : Distance;
8380 Next : Node;
8381 @key[begin]
8382 So_Far(Source) := 0.0;]}
8383
8384 @ChgRef{Version=[3],Kind=[AddedNormal]}
8385 @ChgAdded{Version=[3],Text=[ @key[while not] Reached(Target) @key[loop]
8386 Nearest_Distance := Distance'Last;]}
8387
8388 @ChgRef{Version=[3],Kind=[AddedNormal]}
8389 @ChgAdded{Version=[3],Text=[ -- @Examcom{Find closest node not reached yet, by iterating over all nodes.}
8390 -- @Examcom{A more efficient algorithm uses a priority queue for this step.}]}
8391
8392 @ChgRef{Version=[3],Kind=[AddedNormal]}
8393 @ChgAdded{Version=[3],Text=[ Next := Source;
8394 @key[for] N @key[in] Node'First .. Node'Last @key[loop]
8395 @key[if not] Reached(N)
8396 @key[and then] So_Far(N) < Nearest_Distance @key[then]
8397 Next := N;
8398 Nearest_Distance := So_Far(N);
8399 @key[end if];
8400 @key[end loop];]}
8401
8402 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0299-1]}
8403 @ChgAdded{Version=[3],Text=[ @key[if] Nearest_Distance = Distance'Last @key[then]
8404 -- @Examcom{No next node found, graph is not connected}
8405 @key[return] Paths.Empty_List;]}
8406
8407 @ChgRef{Version=[3],Kind=[AddedNormal]}
8408 @ChgAdded{Version=[3],Text=[ @key[else]
8409 Reached(Next) := True;
8410 @key[end if];]}
8411
8412 @ChgRef{Version=[3],Kind=[AddedNormal]}
8413 @ChgAdded{Version=[3],Text=[ -- @ExamCom{Update minimum distance to newly reachable nodes.}]}
8414
8415 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0299-1]}
8416 @ChgAdded{Version=[3],Text=[ @key[for] E @key[of] G (Next) @key[loop]
8417 @key[if not] Reached(E.To) @key[then]
8418 Nearest_Distance := E.Length + So_Far(Next);]}
8419
8420 @ChgRef{Version=[3],Kind=[AddedNormal]}
8421 @ChgAdded{Version=[3],Text=[ @key[if] Nearest_Distance < So_Far(E.To) @key[then]
8422 Reached_From(E.To) := Next;
8423 So_Far(E.To) := Nearest_Distance;
8424 @key[end if];
8425 @key[end if];
8426 @key[end loop];
8427 @key[end loop];]}
8428
8429 @ChgRef{Version=[3],Kind=[AddedNormal]}
8430 @ChgAdded{Version=[3],Text=[ -- @ExamCom{Rebuild path from target to source.}]}
8431
8432 @ChgRef{Version=[3],Kind=[AddedNormal]}
8433 @ChgAdded{Version=[3],Text=[ @key[declare]
8434 N : Node := Target;
8435 @key[begin]
8436 @key[while] N /= Source @key[loop]
8437 N := Reached_From(N);
8438 Prepend (The_Path, N);
8439 @key[end loop];
8440 @key[end];]}
8441
8442 @ChgRef{Version=[3],Kind=[AddedNormal]}
8443 @ChgAdded{Version=[3],Text=[ @key[return] The_Path;
8444 @key[end];
8445 @key[end] Shortest_Paths;]}
8446
8447 @end{Example}
8448
8449 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
8450 @ChgAdded{Version=[3],Type=[Leading],Text=[Note that the effect of the
8451 Constant_Indexing aspect (on type Vector) and the Implicit_Dereference aspect
8452 (on type Reference_Type) is that]}
8453
8454 @begin{Example}
8455
8456 @ChgRef{Version=[3],Kind=[AddedNormal]}
8457 @ChgAdded{Version=[3],Text=[G (Next)]}
8458
8459 @end{Example}
8460
8461 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
8462 @ChgAdded{Version=[3],Type=[Leading],Text=[is a convenient short hand for]}
8463
8464 @begin{Example}
8465
8466 @ChgRef{Version=[3],Kind=[AddedNormal]}
8467 @ChgAdded{Version=[3],Text=[G.Constant_Reference (Next).Element.@key[all]]}
8468
8469 @end{Example}
8470
8471 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
8472 @ChgAdded{Version=[3],Type=[Leading],Keepnext=[T],Text=[Similarly, the effect of the loop:]}
8473
8474 @begin{Example}
8475 @ChgRef{Version=[3],Kind=[AddedNormal]}
8476 @ChgAdded{Version=[3],Text=[@key[for] E @key[of] G (Next) @key[loop]
8477 @key[if not] Reached(E.To) @key[then]
8478 ...
8479 @key[end if];
8480 @key[end loop];]}
8481
8482 @end{Example}
8483
8484 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
8485 @ChgAdded{Version=[3],Type=[Leading],Keepnext=[T],Text=[is the same as:]}
8486
8487 @begin{Example}
8488
8489 @ChgRef{Version=[3],Kind=[AddedNormal]}
8490 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0080-1]}
8491 @ChgAdded{Version=[3],Text=[@key[for] C @key[in] G (Next).Iterate @key[loop]
8492 @key[declare]
8493 E : Edge @key[renames] G (Next)(C)@Chg{Version=[4],New=[],Old=[.@key[all]]};
8494 @key[begin]
8495 @key[if not] Reached(E.To) @key[then]
8496 ...
8497 @key[end if];
8498 @key[end];
8499 @key[end loop];]}
8500
8501 @end{Example}
8502
8503 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
8504 @ChgAdded{Version=[3],Type=[Leading],Keepnext=[T],Text=[which is the same as:]}
8505
8506 @begin{Example}
8507
8508 @ChgRef{Version=[3],Kind=[AddedNormal]}
8509 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0080-1]}
8510 @ChgAdded{Version=[3],Text=[@key[declare]
8511 L : Adjacency_Lists.List @key[renames] G (Next);
8512 C : Adjacency_Lists.Cursor := L.First;
8513 @key[begin]
8514 @key[while] Has_Element (C) @key[loop]
8515 @key[declare]
8516 E : Edge @key[renames] L(C)@Chg{Version=[4],New=[],Old=[.@key[all]]};
8517 @key[begin]
8518 @key[if not] Reached(E.To) @key[then]
8519 ...
8520 @key[end if];
8521 @key[end];
8522 C := L.Next (C);
8523 @key[end loop];
8524 @key[end];]}
8525
8526 @end{Example}
8527 @end{Examples}
8528
8529 @begin{DiffWord2005}
8530 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
8531 @ChgAdded{Version=[3],Text=[This example of container use is new.]}
8532 @end{DiffWord2005}
8533
8534
8535