Debian Codegraph @

source_2012/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.29 $ $Date: 2015/04/03 04:12:42 $ $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 @ChgAdded{Version=[3],Text=[@key{with} Ada.Iterator_Interfaces;
81 @key{generic}
82 @key{type} Element_Type @key{is private};
83 @key{with function} "=" (Left, Right : Element_Type) @key{return} Boolean @key{is} <>;
84 @key{package} Ada.Containers.Multiway_Trees @key{is}@ChildUnit{Parent=[Ada.Containers],Child=[Multiway_Trees]}
85 @key{pragma} Preelaborate(Multiway_Trees);
86 @key{pragma} Remote_Types(Multiway_Trees);]}
87
88 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0212-1]}
89 @ChgAdded{Version=[3],Text=[ @key{type} @AdaTypeDefn{Tree} @key{is tagged private}
90 @key{with} Constant_Indexing => Constant_Reference,
91 Variable_Indexing => Reference,
92 Default_Iterator => Iterate,
93 Iterator_Element => Element_Type;
94 @key{pragma} Preelaborable_Initialization(Tree);]}
95
96 @ChgRef{Version=[3],Kind=[AddedNormal]}
97 @ChgAdded{Version=[3],Text=[ @key{type} @AdaTypeDefn{Cursor} @key{is private};
98 @key{pragma} Preelaborable_Initialization(Cursor);]}
99
100 @ChgRef{Version=[3],Kind=[AddedNormal]}
101 @ChgAdded{Version=[3],Text=[ @AdaObjDefn{Empty_Tree} : @key{constant} Tree;]}
102
103 @ChgRef{Version=[3],Kind=[AddedNormal]}
104 @ChgAdded{Version=[3],Text=[ @AdaObjDefn{No_Element} : @key{constant} Cursor;]}
105
106 @ChgRef{Version=[3],Kind=[AddedNormal]}
107 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Has_Element} (Position : Cursor) @key{return} Boolean;]}
108
109 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
110 @ChgAdded{Version=[3],Text=[ @key{package} @AdaPackDefn{Tree_Iterator_Interfaces} @key{is new}
111 Ada.Iterator_Interfaces (Cursor, Has_Element);]}
112
113 @ChgRef{Version=[3],Kind=[AddedNormal]}
114 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Equal_Subtree} (Left_Position : Cursor;
115 Right_Position: Cursor) @key{return} Boolean;]}
116
117 @ChgRef{Version=[3],Kind=[AddedNormal]}
118 @ChgAdded{Version=[3],Text=[ @key{function} "=" (Left, Right : Tree) @key{return} Boolean;]}
119
120 @ChgRef{Version=[3],Kind=[AddedNormal]}
121 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Is_Empty} (Container : Tree) @key{return} Boolean;]}
122
123 @ChgRef{Version=[3],Kind=[AddedNormal]}
124 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Node_Count} (Container : Tree) @key{return} Count_Type;]}
125
126 @ChgRef{Version=[3],Kind=[AddedNormal]}
127 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Subtree_Node_Count} (Position : Cursor) @key{return} Count_Type;]}
128
129 @ChgRef{Version=[3],Kind=[AddedNormal]}
130 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Depth} (Position : Cursor) @key{return} Count_Type;]}
131
132 @ChgRef{Version=[3],Kind=[AddedNormal]}
133 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Is_Root} (Position : Cursor) @key{return} Boolean;]}
134
135 @ChgRef{Version=[3],Kind=[AddedNormal]}
136 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Is_Leaf} (Position : Cursor) @key{return} Boolean;]}
137
138 @ChgRef{Version=[3],Kind=[AddedNormal]}
139 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Root} (Container : Tree) @key{return} Cursor;]}
140
141 @ChgRef{Version=[3],Kind=[AddedNormal]}
142 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Clear} (Container : @key{in out} Tree);]}
143
144 @ChgRef{Version=[3],Kind=[AddedNormal]}
145 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Element} (Position : Cursor) @key{return} Element_Type;]}
146
147 @ChgRef{Version=[3],Kind=[AddedNormal]}
148 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Replace_Element} (Container : @key{in out} Tree;
149 Position : @key{in} Cursor;
150 New_Item : @key{in} Element_Type);]}
151
152 @ChgRef{Version=[3],Kind=[AddedNormal]}
153 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Query_Element}
154 (Position : @key{in} Cursor;
155 Process : @key{not null access procedure} (Element : @key{in} Element_Type));]}
156
157 @ChgRef{Version=[3],Kind=[AddedNormal]}
158 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Update_Element}
159 (Container : @key{in out} Tree;
160 Position : @key{in} Cursor;
161 Process : @key{not null access procedure}
162 (Element : @key{in out} Element_Type));]}
163
164 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
165 @ChgAdded{Version=[3],Text=[ @key[type] @AdaTypeDefn{Constant_Reference_Type}
166 (Element : @key[not null access constant] Element_Type) @key[is private]
167 @key[with] Implicit_Dereference => Element;]}
168
169 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
170 @ChgAdded{Version=[3],Text=[ @key[type] @AdaTypeDefn{Reference_Type} (Element : @key[not null access] Element_Type) @key[is private]
171 @key[with] Implicit_Dereference => Element;]}
172
173 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
174 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Constant_Reference} (Container : @key[aliased in] Tree;
175 Position : @key[in] Cursor)
176 @key[return] Constant_Reference_Type;]}
177
178 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
179 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Reference} (Container : @key[aliased in out] Tree;
180 Position : @key[in] Cursor)
181 @key[return] Reference_Type;]}
182
183 @ChgRef{Version=[3],Kind=[AddedNormal]}
184 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Assign} (Target : @key{in out} Tree; Source : @key{in} Tree);]}
185
186 @ChgRef{Version=[3],Kind=[AddedNormal]}
187 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Copy} (Source : Tree) @key{return} Tree;]}
188
189 @ChgRef{Version=[3],Kind=[AddedNormal]}
190 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Move} (Target : @key{in out} Tree;
191 Source : @key{in out} Tree);]}
192
193 @ChgRef{Version=[3],Kind=[AddedNormal]}
194 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Delete_Leaf} (Container : @key{in out} Tree;
195 Position : @key{in out} Cursor);]}
196
197 @ChgRef{Version=[3],Kind=[AddedNormal]}
198 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Delete_Subtree} (Container : @key{in out} Tree;
199 Position : @key{in out} Cursor);]}
200
201 @ChgRef{Version=[3],Kind=[AddedNormal]}
202 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Swap} (Container : @key{in out} Tree;
203 I, J : @key{in} Cursor);]}
204
205 @ChgRef{Version=[3],Kind=[AddedNormal]}
206 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Find} (Container : Tree;
207 Item : Element_Type)
208 @key{return} Cursor;]}
209
210 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
211 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Find_In_Subtree} (Position : Cursor;
212 Item : Element_Type)
213 @key{return} Cursor;]}
214
215 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
216 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Ancestor_Find} (Position : Cursor;
217 Item : Element_Type)
218 @key{return} Cursor;]}
219
220 @ChgRef{Version=[3],Kind=[AddedNormal]}
221 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Contains} (Container : Tree;
222 Item : Element_Type) @key{return} Boolean;]}
223
224 @ChgRef{Version=[3],Kind=[AddedNormal]}
225 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Iterate}
226 (Container : @key{in} Tree;
227 Process : @key{not null access procedure} (Position : @key{in} Cursor));]}
228
229 @ChgRef{Version=[3],Kind=[AddedNormal]}
230 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Iterate_Subtree}
231 (Position : @key{in} Cursor;
232 Process : @key{not null access procedure} (Position : @key{in} Cursor));]}
233
234 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
235 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Iterate} (Container : @key{in} Tree)
236 @key{return} Tree_Iterator_Interfaces.Forward_Iterator'Class;]}
237
238 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
239 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Iterate_Subtree} (Position : @key{in} Cursor)
240 @key{return} Tree_Iterator_Interfaces.Forward_Iterator'Class;]}
241
242 @ChgRef{Version=[3],Kind=[AddedNormal]}
243 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Child_Count} (Parent : Cursor) @key{return} Count_Type;]}
244
245 @ChgRef{Version=[3],Kind=[AddedNormal]}
246 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Child_Depth} (Parent, Child : Cursor) @key{return} Count_Type;]}
247
248 @ChgRef{Version=[3],Kind=[AddedNormal]}
249 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Insert_Child} (Container : @key{in out} Tree;
250 Parent : @key{in} Cursor;
251 Before : @key{in} Cursor;
252 New_Item : @key{in} Element_Type;
253 Count : @key{in} Count_Type := 1);]}
254
255 @ChgRef{Version=[3],Kind=[AddedNormal]}
256 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Insert_Child} (Container : @key{in out} Tree;
257 Parent : @key{in} Cursor;
258 Before : @key{in} Cursor;
259 New_Item : @key{in} Element_Type;
260 Position : @key{out} Cursor;
261 Count : @key{in} Count_Type := 1);]}
262
263 @ChgRef{Version=[3],Kind=[AddedNormal]}
264 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Insert_Child} (Container : @key{in out} Tree;
265 Parent : @key{in} Cursor;
266 Before : @key{in} Cursor;
267 Position : @key{out} Cursor;
268 Count : @key{in} Count_Type := 1);]}
269
270 @ChgRef{Version=[3],Kind=[AddedNormal]}
271 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Prepend_Child} (Container : @key{in out} Tree;
272 Parent : @key{in} Cursor;
273 New_Item : @key{in} Element_Type;
274 Count : @key{in} Count_Type := 1);]}
275
276 @ChgRef{Version=[3],Kind=[AddedNormal]}
277 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Append_Child} (Container : @key{in out} Tree;
278 Parent : @key{in} Cursor;
279 New_Item : @key{in} Element_Type;
280 Count : @key{in} Count_Type := 1);]}
281
282 @ChgRef{Version=[3],Kind=[AddedNormal]}
283 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Delete_Children} (Container : @key{in out} Tree;
284 Parent : @key{in} Cursor);]}
285
286 @ChgRef{Version=[3],Kind=[AddedNormal]}
287 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Copy_Subtree} (Target : @key{in out} Tree;
288 Parent : @key{in} Cursor;
289 Before : @key{in} Cursor;
290 Source : @key{in} Cursor);]}
291
292 @ChgRef{Version=[3],Kind=[AddedNormal]}
293 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Splice_Subtree} (Target : @key{in out} Tree;
294 Parent : @key{in} Cursor;
295 Before : @key{in} Cursor;
296 Source : @key{in out} Tree;
297 Position : @key{in out} Cursor);]}
298
299 @ChgRef{Version=[3],Kind=[AddedNormal]}
300 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Splice_Subtree} (Container: @key{in out} Tree;
301 Parent : @key{in} Cursor;
302 Before : @key{in} Cursor;
303 Position : @key{in} Cursor);]}
304
305 @ChgRef{Version=[3],Kind=[AddedNormal]}
306 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Splice_Children} (Target : @key{in out} Tree;
307 Target_Parent : @key{in} Cursor;
308 Before : @key{in} Cursor;
309 Source : @key{in out} Tree;
310 Source_Parent : @key{in} Cursor);]}
311
312 @ChgRef{Version=[3],Kind=[AddedNormal]}
313 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Splice_Children} (Container : @key{in out} Tree;
314 Target_Parent : @key{in} Cursor;
315 Before : @key{in} Cursor;
316 Source_Parent : @key{in} Cursor);]}
317
318 @ChgRef{Version=[3],Kind=[AddedNormal]}
319 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Parent} (Position : Cursor) @key{return} Cursor;]}
320
321 @ChgRef{Version=[3],Kind=[AddedNormal]}
322 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{First_Child} (Parent : Cursor) @key{return} Cursor;]}
323
324 @ChgRef{Version=[3],Kind=[AddedNormal]}
325 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{First_Child_Element} (Parent : Cursor) @key{return} Element_Type;]}
326
327 @ChgRef{Version=[3],Kind=[AddedNormal]}
328 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Last_Child} (Parent : Cursor) @key{return} Cursor;]}
329
330 @ChgRef{Version=[3],Kind=[AddedNormal]}
331 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Last_Child_Element} (Parent : Cursor) @key{return} Element_Type;]}
332
333 @ChgRef{Version=[3],Kind=[AddedNormal]}
334 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Next_Sibling} (Position : Cursor) @key{return} Cursor;]}
335
336 @ChgRef{Version=[3],Kind=[AddedNormal]}
337 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Previous_Sibling} (Position : Cursor) @key{return} Cursor;]}
338
339 @ChgRef{Version=[3],Kind=[AddedNormal]}
340 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Next_Sibling} (Position : @key{in out} Cursor);]}
341
342 @ChgRef{Version=[3],Kind=[AddedNormal]}
343 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Previous_Sibling} (Position : @key{in out} Cursor);]}
344
345 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
346 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Iterate_Children}
347 (Parent : @key{in} Cursor;
348 Process : @key{not null access procedure} (Position : @key{in} Cursor));]}
349
350 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
351 @ChgAdded{Version=[3],Text=[ @key{procedure} @AdaSubDefn{Reverse_Iterate_Children}
352 (Parent : @key{in} Cursor;
353 Process : @key{not null access procedure} (Position : @key{in} Cursor));]}
354
355 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
356 @ChgAdded{Version=[3],Text=[ @key{function} @AdaSubDefn{Iterate_Children} (Container : @key[in] Tree; Parent : @key[in] Cursor)
357 @key[return] Tree_Iterator_Interfaces.Reversible_Iterator'Class;]}
358
359 @ChgRef{Version=[3],Kind=[AddedNormal]}
360 @ChgAdded{Version=[3],Text=[@key{private}
361 ... -- @Examcom[not specified by the language]
362 @key[end] Ada.Containers.Multiway_Trees;]}
363
364 @end{Example}
365
366 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
367 @ChgAdded{Version=[3],Text=[The actual function for the generic formal function "=" on Element_Type values
368 is expected to define a reflexive and symmetric relationship and return the same
369 result value each time it is called with a particular pair of values. If it
370 behaves in some other manner, the functions Find, Reverse_Find, Equal_Subtree,
371 and "=" on tree values return an unspecified value. The exact arguments and
372 number of calls of this generic formal function by the functions Find,
373 Reverse_Find, Equal_Subtree, and "=" on tree values are unspecified.@PDefn{unspecified}]}
374
375 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
376 @ChgAdded{Version=[3],Text=[The type Tree is used to represent trees. The
377 type Tree needs finalization@PDefn2{Term=<needs finalization>,Sec=<language-defined type>}
378 (see @RefSecNum{Assignment and Finalization}).]}
379
380 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
381 @ChgAdded{Version=[3],Text=[Empty_Tree represents the empty Tree object. It
382 contains only the root node (Node_Count (Empty_Tree) returns 1). If an object of type
383 Tree is not otherwise initialized, it is initialized to the same value as
384 Empty_Tree.]}
385
386 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
387 @ChgAdded{Version=[3],Text=[No_Element represents a cursor that designates no
388 element. If an object of type Cursor is not otherwise initialized, it is
389 initialized to the same value as No_Element.]}
390
391 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
392 @ChgAdded{Version=[3],Text=[The predefined "=" operator for type Cursor returns
393 True if both cursors are No_Element, or designate the same element in the same
394 container.]}
395
396 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
397 @ChgAdded{Version=[3],Text=[Execution of the default implementation of the
398 Input, Output, Read, or Write attribute of type Cursor raises Program_Error.]}
399
400 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1]}
401 @ChgAdded{Version=[3],Text=[Tree'Write for a Tree object @i<T> writes
402 Node_Count(@i<T>) - 1 elements of the tree to the stream. It also may write
403 additional information about the tree.]}
404
405 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1]}
406 @ChgAdded{Version=[3],Text=[Tree'Read reads the representation of a tree
407 from the stream, and assigns to @i<Item> a tree with the same elements and
408 structure as was written by Tree'Write.]}
409
410 @begin{Ramification}
411 @ChgRef{Version=[3],Kind=[AddedNormal]}
412 @ChgAdded{Version=[3],Text=[Streaming more elements than the container
413 holds is wrong. For implementation implications of this rule, see the Implementation Note in
414 @RefSecNum{The Generic Package Containers.Vectors}.]}
415 @end{Ramification}
416
417
418
419 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
420 @ChgAdded{Version=[3],Text=[@Redundant[Some operations of this generic package
421 have access-to-subprogram parameters. To ensure such operations are
422 well-defined, they guard against certain actions by the designated subprogram.
423 In particular, some operations check for "tampering with cursors" of a container
424 because they depend on the set of elements of the container remaining constant,
425 and others check for "tampering with elements" of a container because they
426 depend on elements of the container not being replaced.]]}
427
428 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
429 @ChgAdded{Version=[3],Type=[Leading],Text=[@Defn2{Term=[tamper with cursors],Sec=[of a tree]}
430 A subprogram is said to
431 @i{tamper with cursors} of a tree object @i<T> if:]}
432
433 @begin{Itemize}
434 @ChgRef{Version=[3],Kind=[AddedNormal]}
435 @ChgAdded{Version=[3],Text=[it inserts or deletes elements of @i<T>, that is,
436 it calls the Clear, Delete_Leaf, Insert_Child, Delete_Children,
437 Delete_Subtree, or Copy_Subtree procedures
438 with @i<T> as a parameter; or]}
439
440 @begin{Honest}
441 @ChgRef{Version=[3],Kind=[AddedNormal]}
442 @ChgAdded{Version=[3],Text=[Operations which are defined to be equivalent to
443 a call on one of these operations also are included. Similarly, operations
444 which call one of these as part of their definition are included.]}
445 @end{Honest}
446
447 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
448 @ChgAdded{Version=[3],Text=[it reorders the elements of @i<T>, that is, it
449 calls the Splice_Subtree or Splice_Children procedures with @i<T> as a
450 parameter; or]}
451
452 @ChgRef{Version=[3],Kind=[AddedNormal]}
453 @ChgAdded{Version=[3],Text=[it finalizes @i<T>; or]}
454
455 @ChgRef{Version=[3],Kind=[AddedNormal]}
456 @ChgAdded{Version=[3],Text=[it calls Assign with @i<T> as the Target parameter; or]}
457
458 @begin{Ramification}
459 @ChgRef{Version=[3],Kind=[Added]}
460 @ChgAdded{Version=[3],Text=[We don't need to explicitly mention
461 @nt{assignment_statement}, because that finalizes the target object
462 as part of the operation, and finalization of an object is already defined
463 as tampering with cursors.]}
464 @end{Ramification}
465
466 @ChgRef{Version=[3],Kind=[AddedNormal]}
467 @ChgAdded{Version=[3],Text=[it calls the Move procedure with @i<T> as a parameter.]}
468
469 @begin{Reason}
470 @ChgRef{Version=[3],Kind=[AddedNormal]}
471 @ChgAdded{Version=[3],Text=[Swap copies elements rather than reordering
472 them, so it doesn't tamper with cursors.]}
473 @end{Reason}
474 @end{Itemize}
475
476 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
477 @ChgAdded{Version=[3],Type=[Leading],Text=[@Defn2{Term=[tamper with elements],Sec=[of a tree]}
478 A subprogram is said to
479 @i{tamper with elements} of a tree object @i<T> if:]}
480
481 @begin{Itemize}
482 @ChgRef{Version=[3],Kind=[AddedNormal]}
483 @ChgAdded{Version=[3],Text=[it tampers with cursors of @i<T>; or]}
484
485 @ChgRef{Version=[3],Kind=[AddedNormal]}
486 @ChgAdded{Version=[3],Text=[it replaces one or more elements of @i<T>, that is, it calls the Replace_Element or Swap
487 procedures with @i<T> as a parameter.]}
488
489 @begin{Reason}
490 @ChgRef{Version=[3],Kind=[AddedNormal]}
491 @ChgAdded{Version=[3],Text=[Complete replacement of an element can cause its
492 memory to be deallocated while another operation is holding onto a reference
493 to it. That can't be allowed. However, a simple modification of (part of) an
494 element is not a problem, so Update_Element does not cause a problem.]}
495 @end{Reason}
496 @begin{Ramification}
497 @ChgRef{Version=[3],Kind=[Added]}
498 @ChgAdded{Version=[3],Text=[Assign is defined in terms of Clear and Replace_Element,
499 so we don't need to mention it explicitly. Similarly, we don't need to
500 explicitly mention @nt{assignment_statement}, because that finalizes the
501 target object as part of the operation, and finalization of an object is
502 already defined as tampering with the element.]}
503 @end{Ramification}
504 @end{Itemize}
505
506 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
507 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0110-1]}
508 @ChgAdded{Version=[3],Text=[@Defn2{Term=[prohibited],Sec=[tampering with a tree]}
509 @Defn2{Term=[tampering],Sec=[prohibited for a tree]}
510 When tampering with cursors is @i<prohibited> for a particular tree object
511 @i<T>, Program_Error is propagated by a call of any language-defined subprogram
512 that is defined to tamper with the cursors of @i<T>, leaving @i<T> unmodified.
513 Similarly, when tampering with elements is @i<prohibited> for a particular tree
514 object @i<T>, Program_Error is propagated by a call of any language-defined
515 subprogram that is defined to tamper with the elements of @i<T> @Redundant[(or
516 tamper with the cursors of @i<T>)], leaving @i<T>
517 unmodified.@Chg{Version=[4],New=[ These checks are made before any other
518 defined behavior of the body of the language-defined subprogram.],Old=[]}]}
519 @begin{TheProof}
520 @ChgRef{Version=[3],Kind=[AddedNormal]}
521 @ChgAdded{Version=[3],Text=[Tampering with elements includes tampering with
522 cursors, so we mention it only from completeness in the second sentence.]}
523 @end{TheProof}
524
525 @begin{DescribeCode}
526
527 @begin{Example}
528 @ChgRef{Version=[3],Kind=[AddedNormal]}
529 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Has_Element (Position : Cursor) @key{return} Boolean;]}
530 @end{Example}
531
532 @ChgRef{Version=[3],Kind=[AddedNormal]}
533 @ChgAdded{Version=[3],Type=[Trailing],Text=[Returns True if Position designates
534 an element, and returns False otherwise. @Redundant[In particular, Has_Element
535 returns False if the cursor designates a root node or equals No_Element.]]}
536
537 @begin{Honest}
538 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1],ARef=[AI05-0136-1]}
539 @ChgAdded{Version=[3],Text=[This function might not detect cursors that
540 designate deleted elements; such cursors are invalid (see below) and the
541 result of calling Has_Element with an invalid cursor is unspecified (but
542 not erroneous).]}
543 @end{Honest}
544
545 @begin{Example}
546 @ChgRef{Version=[3],Kind=[AddedNormal]}
547 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Equal_Subtree (Left_Position : Cursor;
548 Right_Position: Cursor) @key{return} Boolean;]}
549 @end{Example}
550
551 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1],ARef=[AI05-0264-1]}
552 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Left_Position or Right_Position
553 equals No_Element, propagates Constraint_Error. If the number of child nodes
554 of the element designated by Left_Position is different from the number of
555 child nodes of the element designated by Right_Position, the function
556 returns False. If Left_Position designates a root node and Right_Position does
557 not, the function returns False. If Right_Position designates a root
558 node and Left_Position does not, the function returns False. Unless both
559 cursors designate a root node, the elements are compared using the generic
560 formal equality operator. If the result of the element comparison is False,
561 the function returns
562 False. Otherwise, it calls Equal_Subtree on a cursor designating each child
563 element of the element designated by Left_Position and a cursor designating
564 the corresponding child element of the element designated by Right_Position.
565 If any such call returns False, the function returns False; otherwise, it
566 returns True. Any exception raised during the evaluation of element equality
567 is propagated.]}
568
569 @begin{Ramification}
570 @ChgRef{Version=[3],Kind=[AddedNormal]}
571 @ChgAdded{Version=[3],Text=[Left_Position and Right_Position do not need to
572 be from the same tree.]}
573 @end{Ramification}
574
575 @begin{ImplNote}
576 @ChgRef{Version=[3],Kind=[AddedNormal]}
577 @ChgAdded{Version=[3],Text=[This wording describes the canonical semantics.
578 However, the order and number of calls on the formal equality function
579 is unspecified for all of the operations that use it in this package, so an
580 implementation can call it as many or as few times as it needs to get the
581 correct answer. Similarly, a global rule (see the introduction of
582 @RefSecNum{Predefined Language Environment})
583 says that language-defined routines are not affected by overriding of other
584 language-defined routines. This means that no reasonable program can tell
585 how many times Equal_Subtree is called, and thus an implementation can call
586 it as many or as few times as it needs to get the correct answer.
587 Specifically, there is no requirement to call the formal equality or
588 Equal_Subtree additional times once the answer has been determined.]}
589 @end{ImplNote}
590
591 @begin{Example}
592 @ChgRef{Version=[3],Kind=[AddedNormal]}
593 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} "=" (Left, Right : Tree) @key{return} Boolean;]}
594 @end{Example}
595
596 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0262-1]}
597 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Left and Right denote the same
598 tree object, then the function returns True. Otherwise, it calls Equal_Subtree
599 with cursors designating the root nodes of Left and Right; the result is
600 returned. Any exception raised during the evaluation of Equal_Subtree is
601 propagated.]}
602
603 @begin{ImplNote}
604 @ChgRef{Version=[3],Kind=[AddedNormal]}
605 @ChgAdded{Version=[3],Text=[Similar considerations apply here as apply to
606 Equal_Subtree. The actual number of calls performed is unspecified.]}
607 @end{ImplNote}
608
609 @begin{Example}
610 @ChgRef{Version=[3],Kind=[AddedNormal]}
611 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Node_Count (Container : Tree) @key{return} Count_Type;]}
612 @end{Example}
613
614 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
615 @ChgAdded{Version=[3],Type=[Trailing],Text=[Node_Count returns the number of
616 nodes in Container.]}
617
618 @begin{Ramification}
619 @ChgRef{Version=[3],Kind=[AddedNormal]}
620 @ChgAdded{Version=[3],Text=[Since all tree objects have a root node, this
621 can never return a value of 0. Node_Count (Some_Tree) should always equal
622 Subtree_Node_Count (Root (Some_Tree)).]}
623 @end{Ramification}
624
625 @begin{Example}
626 @ChgRef{Version=[3],Kind=[AddedNormal]}
627 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Subtree_Node_Count (Position : Cursor) @key{return} Count_Type;]}
628 @end{Example}
629
630 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
631 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position is No_Element,
632 Subtree_Node_Count returns 0; otherwise, Subtree_Node_Count returns the number of
633 nodes in the subtree that is rooted by Position.]}
634
635 @begin{Example}
636 @ChgRef{Version=[3],Kind=[AddedNormal]}
637 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Is_Empty (Container : Tree) @key{return} Boolean;]}
638 @end{Example}
639
640 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
641 @ChgAdded{Version=[3],Type=[Trailing],Text=[Equivalent to Node_Count (Container) = 1.]}
642
643 @begin{Ramification}
644 @ChgRef{Version=[3],Kind=[AddedNormal]}
645 @ChgAdded{Version=[3],Text=[An empty tree contains just the root node.]}
646 @end{Ramification}
647
648 @begin{Example}
649 @ChgRef{Version=[3],Kind=[AddedNormal]}
650 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Depth (Position : Cursor) @key{return} Count_Type;]}
651 @end{Example}
652
653 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
654 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position equals No_Element,
655 Depth returns 0; otherwise, Depth returns the number of ancestor nodes of the
656 node designated by Position (including the node itself).]}
657
658 @begin{Ramification}
659 @ChgRef{Version=[3],Kind=[AddedNormal]}
660 @ChgAdded{Version=[3],Text=[Depth (Root (Some_Tree)) = 1.]}
661 @end{Ramification}
662
663
664 @begin{Example}
665 @ChgRef{Version=[3],Kind=[AddedNormal]}
666 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Is_Root (Position : Cursor) @key{return} Boolean;]}
667 @end{Example}
668
669 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
670 @ChgAdded{Version=[3],Type=[Trailing],Text=[Is_Root returns True if the
671 Position designates the root node of some tree; and returns False otherwise.]}
672
673 @begin{Example}
674 @ChgRef{Version=[3],Kind=[AddedNormal]}
675 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Is_Leaf (Position : Cursor) @key{return} Boolean;]}
676 @end{Example}
677
678 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
679 @ChgAdded{Version=[3],Type=[Trailing],Text=[Is_Leaf returns True if Position
680 designates a node that does not have any child nodes; and returns False
681 otherwise.]}
682
683 @begin{Ramification}
684 @ChgRef{Version=[3],Kind=[AddedNormal]}
685 @ChgAdded{Version=[3],Text=[Is_Leaf returns False if passed No_Element,
686 since No_Element does not designate a node. Is_Leaf can be passed a cursor
687 that designates the root node; Is_Leaf will return True if passed the root
688 node of an empty tree.]}
689 @end{Ramification}
690
691 @begin{Example}
692 @ChgRef{Version=[3],Kind=[AddedNormal]}
693 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Root (Container : Tree) @key{return} Cursor;]}
694 @end{Example}
695
696 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
697 @ChgAdded{Version=[3],Type=[Trailing],Text=[Root returns a cursor that
698 designates the root node of Container.]}
699
700 @begin{Ramification}
701 @ChgRef{Version=[3],Kind=[AddedNormal]}
702 @ChgAdded{Version=[3],Text=[There is always a root node, even in an empty
703 container, so this function never returns No_Element.]}
704 @end{Ramification}
705
706 @begin{Example}
707 @ChgRef{Version=[3],Kind=[AddedNormal]}
708 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Clear (Container : @key{in out} Tree);]}
709 @end{Example}
710
711 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
712 @ChgAdded{Version=[3],Type=[Trailing],Text=[Removes all the elements from
713 Container.]}
714
715 @begin{Ramification}
716 @ChgRef{Version=[3],Kind=[AddedNormal]}
717 @ChgAdded{Version=[3],Text=[The root node is not removed; all trees have a
718 root node.]}
719 @end{Ramification}
720
721 @begin{Example}
722 @ChgRef{Version=[3],Kind=[AddedNormal]}
723 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Element (Position : Cursor) @key{return} Element_Type;]}
724 @end{Example}
725
726 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
727 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position equals No_Element,
728 then Constraint_Error is propagated; if Position designates the root node of a
729 tree, then Program_Error is propagated. Otherwise, Element returns the element
730 designated by Position.]}
731
732 @begin{Ramification}
733 @ChgRef{Version=[3],Kind=[AddedNormal]}
734 @ChgAdded{Version=[3],Text=[The root node does not contain an element, so
735 that value cannot be read or written.]}
736 @end{Ramification}
737
738 @begin{Example}
739 @ChgRef{Version=[3],Kind=[AddedNormal]}
740 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Replace_Element (Container : @key{in out} Tree;
741 Position : @key{in} Cursor;
742 New_Item : @key{in} Element_Type);]}
743 @end{Example}
744
745 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0264-1]}
746 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position equals No_Element,
747 then Constraint_Error is propagated; if Position does not designate an element
748 in Container (including if it designates the root node), then Program_Error is
749 propagated. Otherwise, Replace_Element assigns the value New_Item to the
750 element designated by Position.]}
751
752 @begin{Example}
753 @ChgRef{Version=[3],Kind=[AddedNormal]}
754 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Query_Element
755 (Position : @key{in} Cursor;
756 Process : @key{not null access procedure} (Element : @key{in} Element_Type));]}
757 @end{Example}
758
759 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0265-1]}
760 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position equals No_Element,
761 then Constraint_Error is propagated; if Position designates the root node of a
762 tree, then Program_Error is propagated. Otherwise, Query_Element calls
763 Process.@key{all} with the element designated by Position as the argument.
764 Tampering with the elements of the tree that contains the element designated
765 by Position is prohibited during the execution of the call on
766 Process.@key{all}. Any exception raised by Process.@key{all} is propagated.]}
767
768 @begin{Example}
769 @ChgRef{Version=[3],Kind=[AddedNormal]}
770 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Update_Element
771 (Container : @key{in out} Tree;
772 Position : @key{in} Cursor;
773 Process : @key{not null access procedure}
774 (Element : @key{in out} Element_Type));]}
775 @end{Example}
776
777 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0264-1],ARef=[AI05-0265-1]}
778 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position equals No_Element,
779 then Constraint_Error is propagated; if Position does not designate an element
780 in Container (including if it designates the root node), then Program_Error is
781 propagated. Otherwise, Update_Element calls Process.@key{all} with the element
782 designated by Position as the argument. Tampering with the elements of
783 Container is prohibited during the execution of the call on Process.@key{all}.
784 Any exception raised by Process.@key{all} is propagated.]}
785
786 @ChgRef{Version=[3],Kind=[AddedNormal]}
787 @ChgAdded{Version=[3],Text=[If Element_Type is unconstrained and definite,
788 then the actual Element parameter of Process.@key{all} shall be
789 unconstrained.]}
790
791 @begin{Ramification}
792 @ChgRef{Version=[3],Kind=[AddedNormal]}
793 @ChgAdded{Version=[3],Text=[This means that the elements cannot be directly
794 allocated from the heap; it must be possible to change the discriminants of
795 the element in place.]}
796 @end{Ramification}
797
798 @begin{Example}
799 @ChgRef{Version=[3],Kind=[AddedNormal]}
800 @ChgAdded{Version=[3],Text=[@key{type} Constant_Reference_Type
801 (Element : @key[not null access constant] Element_Type) @key[is private]
802 @key[with] Implicit_Dereference => Element;]}
803
804 @ChgRef{Version=[3],Kind=[AddedNormal]}
805 @ChgAdded{Version=[3],Text=[@key[type] Reference_Type (Element : @key[not null access] Element_Type) @key[is private]
806 @key[with] Implicit_Dereference => Element;]}
807 @end{Example}
808
809 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
810 @ChgAdded{Version=[3],Type=[Trailing],Text=[The types Constant_Reference_Type
811 and Reference_Type need finalization.@PDefn2{Term=<needs finalization>,Sec=<language-defined type>}]}
812
813 @ChgRef{Version=[3],Kind=[AddedNormal]}
814 @ChgAdded{Version=[3],Text=[The default initialization of an object of type
815 Constant_Reference_Type or Reference_Type propagates Program_Error.]}
816
817 @begin{Reason}
818 @ChgRef{Version=[3],Kind=[AddedNormal]}
819 @ChgAdded{Version=[3],Text=[It is expected that Reference_Type (and
820 Constant_Reference_Type) will be a controlled type, for which finalization
821 will have some action to terminate the tampering check for the associated
822 container. If the object is created by default, however, there is no
823 associated container. Since this is useless, and supporting this case would
824 take extra work, we define it to raise an exception.]}
825 @end{Reason}
826
827 @begin{Example}
828 @ChgRef{Version=[3],Kind=[AddedNormal]}
829 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Constant_Reference (Container : @key[aliased in] Tree;
830 Position : @key[in] Cursor)
831 @key[return] Constant_Reference_Type;]}
832 @end{Example}
833
834 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0269-1]}
835 @ChgAdded{Version=[3],Type=[Trailing],Text=[This function (combined with the
836 Constant_Indexing and Implicit_Dereference aspects) provides a convenient way
837 to gain read access to an individual element of a tree given a
838 cursor.]}
839
840 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0265-1]}
841 @ChgAdded{Version=[3],Text=[If Position equals No_Element, then
842 Constraint_Error is propagated; if Position does not designate an element in
843 Container, then Program_Error is propagated. Otherwise, Constant_Reference
844 returns an object whose discriminant is an access value that designates the
845 element designated by Position. Tampering with the elements of Container
846 is prohibited while the object returned by Constant_Reference exists
847 and has not been finalized.]}
848
849 @begin{Example}
850 @ChgRef{Version=[3],Kind=[AddedNormal]}
851 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Reference (Container : @key[aliased in out] Tree;
852 Position : @key[in] Cursor)
853 @key[return] Reference_Type;]}
854 @end{Example}
855
856 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0269-1]}
857 @ChgAdded{Version=[3],Type=[Trailing],Text=[This function (combined with the
858 Variable_Indexing and Implicit_Dereference aspects) provides a convenient way
859 to gain read and write access to an individual element of a tree
860 given a cursor.]}
861
862 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0265-1]}
863 @ChgAdded{Version=[3],Text=[If Position equals No_Element, then
864 Constraint_Error is propagated; if Position does not designate an element in
865 Container, then Program_Error is propagated. Otherwise, Reference returns an
866 object whose discriminant is an access value that designates the element
867 designated by Position. Tampering with the elements
868 of Container is prohibited while the object returned by Reference exists
869 and has not been finalized.]}
870
871 @begin{Example}
872 @ChgRef{Version=[3],Kind=[AddedNormal]}
873 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Assign (Target : @key{in out} Tree; Source : @key{in} Tree);]}
874 @end{Example}
875
876 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
877 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Target denotes the same object
878 as Source, the operation has no effect. Otherwise, the elements of Source are
879 copied to Target as for an @nt{assignment_statement} assigning Source to
880 Target.]}
881
882 @begin{Ramification}
883 @ChgRef{Version=[3],Kind=[AddedNormal]}
884 @ChgAdded{Version=[3],Text=[Each element in Target has a
885 parent element that corresponds to the parent element of the Source element,
886 and has child elements that correspond to the child elements of the Source
887 element.]}
888 @end{Ramification}
889 @begin{Discussion}
890 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
891 @ChgAdded{Version=[3],Text=[This routine exists for compatibility with the
892 bounded tree container. For an unbounded tree, @exam{Assign(A, B)} and
893 @exam{A := B} behave identically. For a bounded tree, := will raise an
894 exception if the container capacities are different, while Assign will
895 not raise an exception if there is enough room in the target.]}
896 @end{Discussion}
897
898 @begin{Example}
899 @ChgRef{Version=[3],Kind=[AddedNormal]}
900 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Copy (Source : Tree) @key{return} Tree;]}
901 @end{Example}
902
903 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
904 @ChgAdded{Version=[3],Type=[Trailing],Text=[Returns a tree with the same
905 structure as Source and whose elements are initialized from the corresponding
906 elements of Source.]}
907
908 @begin{Example}
909 @ChgRef{Version=[3],Kind=[AddedNormal]}
910 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Move (Target : @key{in out} Tree;
911 Source : @key{in out} Tree);]}
912 @end{Example}
913
914 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
915 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Target denotes the same object
916 as Source, then the operation has no effect. Otherwise, Move first calls Clear
917 (Target). Then, the nodes other than the root node in Source are moved to
918 Target (in the same positions). After Move completes, Node_Count (Target) is
919 the number of nodes originally in Source, and Node_Count (Source) is 1.]}
920
921 @begin{Example}
922 @ChgRef{Version=[3],Kind=[AddedNormal]}
923 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Delete_Leaf (Container : @key{in out} Tree;
924 Position : @key{in out} Cursor);]}
925 @end{Example}
926
927 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
928 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position equals No_Element,
929 then Constraint_Error is propagated; if Position does not designate an element
930 in Container (including if it designates the root node), then Program_Error is
931 propagated. If the element designated by position has any child elements, then
932 Constraint_Error is propagated. Otherwise, Delete_Leaf removes (from Container)
933 the element designated by Position. Finally, Position is set to No_Element.]}
934
935 @begin{Ramification}
936 @ChgRef{Version=[3],Kind=[AddedNormal]}
937 @ChgAdded{Version=[3],Text=[The check on Position
938 checks that the cursor does not belong to some other Container. This check
939 implies that a reference to the container is included in the cursor value.
940 This wording is not meant to require detection of dangling cursors; such
941 cursors are defined to be invalid, which means that execution is erroneous,
942 and any result is allowed (including not raising an exception).]}
943
944 @ChgRef{Version=[3],Kind=[AddedNormal]}
945 @ChgAdded{Version=[3],Text=[The root node cannot be deleted.]}
946 @end{Ramification}
947
948 @begin{Example}
949 @ChgRef{Version=[3],Kind=[AddedNormal]}
950 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Delete_Subtree (Container : @key{in out} Tree;
951 Position : @key{in out} Cursor);]}
952 @end{Example}
953
954 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0264-1],ARef=[AI05-0269-1]}
955 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position equals No_Element,
956 then Constraint_Error is propagated. If Position does not designate an element
957 in Container (including if it designates the root node), then Program_Error is
958 propagated. Otherwise, Delete_Subtree removes (from Container) the subtree
959 designated by Position (that is, all descendants of the node designated
960 by Position including the node itself), and Position is set to No_Element.]}
961
962 @begin{Ramification}
963 @ChgRef{Version=[3],Kind=[AddedNormal]}
964 @ChgAdded{Version=[3],Text=[The root node cannot be deleted. To delete the
965 entire contents of the tree, call Clear(Container).]}
966 @end{Ramification}
967
968 @begin{Example}
969 @ChgRef{Version=[3],Kind=[AddedNormal]}
970 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Swap (Container : @key{in out} Tree;
971 I, J : @key{in} Cursor);]}
972 @end{Example}
973
974 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
975 @ChgAdded{Version=[3],Type=[Trailing],Text=[If either I or J equals
976 No_Element, then Constraint_Error is propagated. If either I or J do not
977 designate an element in Container (including if either designates the root
978 node), then Program_Error is propagated. Otherwise, Swap exchanges the values
979 of the elements designated by I and J.]}
980
981 @begin{Ramification}
982 @ChgRef{Version=[3],Kind=[AddedNormal]}
983 @ChgAdded{Version=[3],Text=[After a call to Swap, I designates the element
984 value previously designated by J, and J designates the element value
985 previously designated by I. The position of the elements do not change; for
986 instance, the parent node and the first child node of I are unchanged by the
987 operation.]}
988
989 @ChgRef{Version=[3],Kind=[AddedNormal]}
990 @ChgAdded{Version=[3],Text=[The root nodes do not contain element values, so
991 they cannot be swapped.]}
992 @end{Ramification}
993
994 @begin{Honest}
995 @ChgRef{Version=[3],Kind=[AddedNormal]}
996 @ChgAdded{Version=[3],Text=[The implementation is not required to actually
997 copy the elements if it can do the swap some other way. But it is allowed to
998 copy the elements if needed.]}
999 @end{Honest}
1000
1001 @begin{Example}
1002 @ChgRef{Version=[3],Kind=[AddedNormal]}
1003 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Find (Container : Tree;
1004 Item : Element_Type)
1005 @key{return} Cursor;]}
1006 @end{Example}
1007
1008 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0262-1]}
1009 @ChgAdded{Version=[3],Type=[Trailing],Text=[Find searches the elements of
1010 Container for an element equal to Item (using the generic formal equality
1011 operator). The search starts at the root node. The search traverses the tree
1012 in a depth-first order. If no equal element is found, then Find returns
1013 No_Element. Otherwise, it returns a cursor designating the first equal element
1014 encountered.]}
1015
1016 @begin{Example}
1017 @ChgRef{Version=[3],Kind=[AddedNormal]}
1018 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Find_In_Subtree (Position : Cursor;
1019 Item : Element_Type)
1020 @key{return} Cursor;]}
1021 @end{Example}
1022
1023 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1]}
1024 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position equals No_Element,
1025 then Constraint_Error is propagated. Find_In_Subtree searches
1026 the subtree rooted by Position for an element equal to Item (using the
1027 generic formal equality operator). The search starts at the element designated
1028 by Position. The search traverses the subtree in a depth-first
1029 order. If no equal element is found, then Find returns No_Element. Otherwise,
1030 it returns a cursor designating the first equal element encountered.]}
1031
1032 @begin{Ramification}
1033 @ChgRef{Version=[3],Kind=[AddedNormal]}
1034 @ChgAdded{Version=[3],Text=[Find_In_Subtree does not check any siblings of
1035 the element designated by Position. The root node does not contain an
1036 element, and therefore it can never be returned, but it can be explicitly
1037 passed to Position.]}
1038 @end{Ramification}
1039
1040 @begin{Example}
1041 @ChgRef{Version=[3],Kind=[AddedNormal]}
1042 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Ancestor_Find (Position : Cursor;
1043 Item : Element_Type)
1044 @key{return} Cursor;]}
1045 @end{Example}
1046
1047 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
1048 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position equals No_Element,
1049 then Constraint_Error is propagated. Otherwise, Ancestor_Find searches
1050 for an element equal to Item (using the generic formal equality operator). The
1051 search starts at the node designated by Position, and checks each ancestor
1052 proceeding toward the root of the subtree. If no equal element is found, then
1053 Ancestor_Find returns No_Element. Otherwise, it returns a cursor designating
1054 the first equal element encountered.]}
1055 @begin{Ramification}
1056 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0248-1]}
1057 @ChgAdded{Version=[3],Text=[No_Element is returned if Position is the root
1058 node.]}
1059 @end{Ramification}
1060
1061 @begin{Example}
1062 @ChgRef{Version=[3],Kind=[AddedNormal]}
1063 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Contains (Container : Tree;
1064 Item : Element_Type) @key{return} Boolean;]}
1065 @end{Example}
1066
1067 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1068 @ChgAdded{Version=[3],Type=[Trailing],Text=[Equivalent to Find (Container, Item) /= No_Element.]}
1069
1070 @begin{Example}
1071 @ChgRef{Version=[3],Kind=[AddedNormal]}
1072 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Iterate
1073 (Container : @key{in} Tree;
1074 Process : @key{not null access procedure} (Position : @key{in} Cursor));]}
1075 @end{Example}
1076
1077 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0265-1]}
1078 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0069-1]}
1079 @ChgAdded{Version=[3],Type=[Trailing],Text=[Iterate calls Process.@key{all}
1080 with a cursor that designates each element in Container, starting
1081 @Chg{Version=[4],New=[from],Old=[with]} the
1082 root node and proceeding in a depth-first order. Tampering with the cursors
1083 of Container is prohibited during the execution of a call on Process.@key{all}.
1084 Any exception raised by Process.@key{all} is propagated.]}
1085
1086 @begin{Ramification}
1087 @ChgRef{Version=[3],Kind=[AddedNormal]}
1088 @ChgAdded{Version=[3],Text=[Process is not called with the root node, which
1089 does not have an associated element.]}
1090 @end{Ramification}
1091
1092 @begin{ImplNote}
1093 @ChgRef{Version=[3],Kind=[AddedNormal]}
1094 @ChgAdded{Version=[3],Text=[The purpose of the tamper with cursors check is
1095 to prevent erroneous execution from the Position parameter of
1096 Process.@key{all} becoming invalid. This check takes place when the
1097 operations that tamper with the cursors of the container are called. The
1098 check cannot be made later (say in the body of Iterate), because that could
1099 cause the Position cursor to be invalid and potentially cause execution to
1100 become erroneous @em defeating the purpose of the check.]}
1101
1102 @ChgRef{Version=[3],Kind=[AddedNormal]}
1103 @ChgAdded{Version=[3],Text=[See Iterate for vectors
1104 (@RefSecNum{The Generic Package Containers.Vectors}) for a suggested
1105 implementation of the check.]}
1106 @end{ImplNote}
1107
1108 @begin{Example}
1109 @ChgRef{Version=[3],Kind=[AddedNormal]}
1110 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Iterate_Subtree
1111 (Position : @key{in} Cursor;
1112 Process : @key{not null access procedure} (Position : @key{in} Cursor));]}
1113 @end{Example}
1114
1115 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0265-1]}
1116 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0069-1]}
1117 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position equals No_Element,
1118 then Constraint_Error is propagated. Otherwise, Iterate_Subtree calls
1119 Process.@key{all}
1120 with a cursor that designates each element in the subtree rooted by the node
1121 designated by Position, starting
1122 @Chg{Version=[4],New=[from],Old=[with]} the node designated by Position and
1123 proceeding in a depth-first order.
1124 Tampering with the cursors of the tree that contains the element
1125 designated by Position
1126 is prohibited during the execution of a call on Process.@key{all}.
1127 Any exception raised by Process.@key{all} is propagated.]}
1128
1129 @begin{Ramification}
1130 @ChgRef{Version=[3],Kind=[AddedNormal]}
1131 @ChgAdded{Version=[3],Text=[Position can be passed a cursor designating the
1132 root node; in that case, Process is not called with the root node, which
1133 does not have an associated element.]}
1134 @end{Ramification}
1135
1136 @begin{Example}
1137 @ChgRef{Version=[3],Kind=[AddedNormal]}
1138 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Iterate (Container : @key{in} Tree)
1139 @key{return} Tree_Iterator_Interfaces.Forward_Iterator'Class;]}
1140 @end{Example}
1141
1142 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0265-1],ARef=[AI05-0269-1]}
1143 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0069-1]}
1144 @ChgAdded{Version=[3],Type=[Trailing],Text=[Iterate returns an iterator object
1145 (see @RefSecNum{User-Defined Iterator Types}) that will
1146 generate a value for a loop parameter (see @RefSecNum{Generalized Loop Iteration})
1147 designating each @Chg{Version=[4],New=[element],Old=[node]} in Container, starting
1148 @Chg{Version=[4],New=[from],Old=[with]} the root node and proceeding in a depth-first order.
1149 Tampering with the cursors of Container is prohibited while the iterator
1150 object exists (in particular, in the
1151 @nt{sequence_of_statements} of the @nt{loop_statement} whose
1152 @nt{iterator_specification} denotes this object). The iterator object needs
1153 finalization.]}
1154
1155 @begin{Discussion}
1156 @ChgRef{Version=[3],Kind=[AddedNormal]}
1157 @ChgAdded{Version=[3],Type=[Leading],Text=[Exits are allowed from the loops
1158 created using the iterator objects. In particular, to stop the iteration at a
1159 particular cursor, just add]}
1160 @begin{Example}
1161 @ChgRef{Version=[3],Kind=[AddedNormal]}
1162 @ChgAdded{Version=[3],Text=[@key[exit when] Cur = Stop;]}
1163 @end{Example}
1164 @ChgRef{Version=[3],Kind=[AddedNormal]}
1165 @ChgAdded{Version=[3],Type=[Trailing],Text=[in the body of the loop (assuming
1166 that @exam{Cur} is the loop parameter and @exam{Stop} is the cursor that you
1167 want to stop at).]}
1168 @end{Discussion}
1169
1170 @begin{Example}
1171 @ChgRef{Version=[3],Kind=[AddedNormal]}
1172 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Iterate_Subtree (Position : @key{in} Cursor)
1173 @key{return} Tree_Iterator_Interfaces.Forward_Iterator'Class;]}
1174 @end{Example}
1175
1176 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0265-1],ARef=[AI05-0269-1]}
1177 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0069-1]}
1178 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position equals No_Element,
1179 then Constraint_Error is propagated. Otherwise, Iterate_Subtree returns an
1180 iterator object (see @RefSecNum{User-Defined Iterator Types}) that will
1181 generate a value for a loop parameter (see @RefSecNum{Generalized Loop Iteration})
1182 designating each element in the subtree rooted by the node designated by Position,
1183 starting @Chg{Version=[4],New=[from],Old=[with]} the
1184 node designated by Position and proceeding in a depth-first
1185 order. If Position equals No_Element, then Constraint_Error is propagated.
1186 Tampering with the cursors of the container that contains the node
1187 designated by Position is prohibited while the iterator object exists
1188 (in particular, in the
1189 @nt{sequence_of_statements} of the @nt{loop_statement} whose
1190 @nt{iterator_specification} denotes this object). The iterator object
1191 needs finalization.]}
1192
1193 @begin{Example}
1194 @ChgRef{Version=[3],Kind=[AddedNormal]}
1195 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Child_Count (Parent : Cursor) @key{return} Count_Type;]}
1196 @end{Example}
1197
1198 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1199 @ChgAdded{Version=[3],Type=[Trailing],Text=[Child_Count returns the number of
1200 child nodes of the node designated by Parent.]}
1201
1202 @begin{Example}
1203 @ChgRef{Version=[3],Kind=[AddedNormal]}
1204 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Child_Depth (Parent, Child : Cursor) @key{return} Count_Type;]}
1205 @end{Example}
1206
1207 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0262-1]}
1208 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Child or Parent is equal to
1209 No_Element, then Constraint_Error is propagated. Otherwise, Child_Depth
1210 returns the number of ancestor nodes of Child (including Child itself), up to
1211 but not including Parent; Program_Error is propagated if Parent
1212 is not an ancestor of Child.]}
1213
1214 @begin{Ramification}
1215 @ChgRef{Version=[3],Kind=[AddedNormal]}
1216 @ChgAdded{Version=[3],Text=[Program_Error is propagated if Parent and Child
1217 are nodes in different containers.]}
1218
1219 @ChgRef{Version=[3],Kind=[AddedNormal]}
1220 @ChgAdded{Version=[3],Text=[Child_Depth (Root (Some_Tree), Child) + 1 =
1221 Depth (Child) as the root is not counted.]}
1222 @end{Ramification}
1223
1224 @begin{Example}
1225 @ChgRef{Version=[3],Kind=[AddedNormal]}
1226 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Insert_Child (Container : @key{in out} Tree;
1227 Parent : @key{in} Cursor;
1228 Before : @key{in} Cursor;
1229 New_Item : @key{in} Element_Type;
1230 Count : @key{in} Count_Type := 1);]}
1231 @end{Example}
1232
1233 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1]}
1234 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Parent equals No_Element, then
1235 Constraint_Error is propagated. If Parent does not designate a node in
1236 Container, then Program_Error is propagated. If Before is not equal to
1237 No_Element, and does not designate a node in Container, then Program_Error is
1238 propagated. If Before is not equal to No_Element, and
1239 Parent does not designate the parent node of the node designated by Before,
1240 then Constraint_Error is propagated.
1241 Otherwise, Insert_Child allocates Count nodes containing copies of New_Item
1242 and inserts them as children of Parent. If Parent already has child nodes, then
1243 the new nodes are inserted prior to the node designated by Before, or, if
1244 Before equals No_Element, the new nodes are inserted after the last existing
1245 child node of Parent. Any exception raised during allocation of internal
1246 storage is propagated, and Container is not modified.]}
1247
1248 @begin{Example}
1249 @ChgRef{Version=[3],Kind=[AddedNormal]}
1250 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Insert_Child (Container : @key{in out} Tree;
1251 Parent : @key{in} Cursor;
1252 Before : @key{in} Cursor;
1253 New_Item : @key{in} Element_Type;
1254 Position : @key{out} Cursor;
1255 Count : @key{in} Count_Type := 1);]}
1256 @end{Example}
1257
1258 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0257-1],ARef=[AI05-0262-1]}
1259 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Parent equals No_Element, then
1260 Constraint_Error is propagated. If Parent does not designate a node in
1261 Container, then Program_Error is propagated. If Before is not equal to
1262 No_Element, and does not designate a node in Container, then Program_Error is
1263 propagated. If Before is not equal to No_Element, and
1264 Parent does not designate the parent node of the node designated by Before,
1265 then Constraint_Error is propagated.
1266 Otherwise, Insert_Child allocates Count nodes containing copies of New_Item
1267 and inserts them as children of Parent. If Parent already has child nodes, then
1268 the new nodes are inserted prior to the node designated by Before, or, if
1269 Before equals No_Element, the new nodes are inserted after the last existing
1270 child node of Parent. Position designates the first newly-inserted node, or if
1271 Count equals 0, then Position is assigned the value of Before. Any exception
1272 raised during allocation of internal storage is propagated, and Container is
1273 not modified.]}
1274
1275 @begin{Example}
1276 @ChgRef{Version=[3],Kind=[AddedNormal]}
1277 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Insert_Child (Container : @key{in out} Tree;
1278 Parent : @key{in} Cursor;
1279 Before : @key{in} Cursor;
1280 Position : @key{out} Cursor;
1281 Count : @key{in} Count_Type := 1);]}
1282 @end{Example}
1283
1284 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0257-1],ARef=[AI05-0262-1],ARef=[AI05-0264-1]}
1285 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Parent equals No_Element, then
1286 Constraint_Error is propagated. If Parent does not designate a node in
1287 Container, then Program_Error is propagated. If Before is not equal to
1288 No_Element, and does not designate a node in Container, then Program_Error is
1289 propagated. If Before is not equal to No_Element, and
1290 Parent does not designate the parent node of the node designated by Before,
1291 then Constraint_Error is propagated.
1292 Otherwise, Insert_Child allocates Count nodes, the elements contained in the
1293 new nodes are initialized by default (see @RefSecNum{Object Declarations}),
1294 and the new nodes are inserted as children of Parent. If Parent already has
1295 child nodes, then the new nodes are inserted prior to the node designated by
1296 Before, or, if Before equals No_Element, the new nodes are inserted after the
1297 last existing child node of Parent. Position designates the first
1298 newly-inserted node, or if Count equals 0, then Position is assigned the value
1299 of Before. Any exception raised during allocation of internal storage is
1300 propagated, and Container is not modified.]}
1301
1302 @begin{Example}
1303 @ChgRef{Version=[3],Kind=[AddedNormal]}
1304 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Prepend_Child (Container : @key{in out} Tree;
1305 Parent : @key{in} Cursor;
1306 New_Item : @key{in} Element_Type;
1307 Count : @key{in} Count_Type := 1);]}
1308 @end{Example}
1309
1310 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1311 @ChgAdded{Version=[3],Type=[Trailing],Text=[Equivalent to Insert_Child
1312 (Container, Parent, First_Child (Container, Parent), New_Item, Count).]}
1313
1314 @begin{Example}
1315 @ChgRef{Version=[3],Kind=[AddedNormal]}
1316 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Append_Child (Container : @key{in out} Tree;
1317 Parent : @key{in} Cursor;
1318 New_Item : @key{in} Element_Type;
1319 Count : @key{in} Count_Type := 1);]}
1320 @end{Example}
1321
1322 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0269-1]}
1323 @ChgAdded{Version=[3],Type=[Trailing],Text=[Equivalent to Insert_Child
1324 (Container, Parent, No_Element, New_Item, Count).]}
1325
1326 @begin{Example}
1327 @ChgRef{Version=[3],Kind=[AddedNormal]}
1328 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Delete_Children (Container : @key{in out} Tree;
1329 Parent : @key{in} Cursor);]}
1330 @end{Example}
1331
1332 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1333 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Parent equals No_Element, then
1334 Constraint_Error is propagated. If Parent does not designate a node in
1335 Container, Program_Error is propagated. Otherwise, Delete_Children removes
1336 (from Container) all of the descendants of Parent other than Parent itself.]}
1337
1338 @begin{Discussion}
1339 @ChgRef{Version=[3],Kind=[AddedNormal]}
1340 @ChgAdded{Version=[3],Text=[This routine deletes all of the child subtrees
1341 of Parent at once. Use Delete_Subtree to delete an individual subtree.]}
1342 @end{Discussion}
1343
1344 @begin{Example}
1345 @ChgRef{Version=[3],Kind=[AddedNormal]}
1346 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Copy_Subtree (Target : @key{in out} Tree;
1347 Parent : @key{in} Cursor;
1348 Before : @key{in} Cursor;
1349 Source : @key{in} Cursor);]}
1350 @end{Example}
1351
1352 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1]}
1353 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Parent equals No_Element, then
1354 Constraint_Error is propagated. If Parent does not designate a node in Target,
1355 then Program_Error is propagated. If Before is not equal to No_Element, and
1356 does not designate a node in Target, then Program_Error is propagated. If
1357 Before is not equal to No_Element, and
1358 Parent does not designate the parent node of the node designated by Before,
1359 then Constraint_Error is propagated. If Source designates a root node,
1360 then Constraint_Error is propagated. If Source is equal to No_Element, then
1361 the operation has no effect. Otherwise, the subtree rooted by Source (which
1362 can be from any tree; it does not have to be a subtree of Target) is copied
1363 (new nodes are allocated to create a new subtree with the same structure as
1364 the Source subtree, with each element initialized from the corresponding
1365 element of the Source subtree) and inserted into Target as a child of Parent.
1366 If Parent already has child nodes, then the new nodes are inserted prior to the
1367 node designated by Before, or, if Before equals No_Element, the new nodes are
1368 inserted after the last existing child node of Parent. The parent of the newly
1369 created subtree is set to Parent, and the overall count of Target is
1370 incremented by Subtree_Node_Count (Source). Any exception raised during allocation
1371 of internal storage is propagated, and Container is not modified.]}
1372
1373 @begin{Discussion}
1374 @ChgRef{Version=[3],Kind=[AddedNormal]}
1375 @ChgAdded{Version=[3],Text=[We only need one routine here, as the source
1376 object is not modified, so we can use the same routine for both copying
1377 within and between containers.]}
1378 @end{Discussion}
1379
1380 @begin{Ramification}
1381 @ChgRef{Version=[3],Kind=[AddedNormal]}
1382 @ChgAdded{Version=[3],Text=[We do not allow copying a subtree that includes
1383 a root node, as that would require inserting a node with no value in the
1384 middle of the target tree. To copy an entire tree to another tree object,
1385 use Copy.]}
1386 @end{Ramification}
1387
1388 @begin{Example}
1389 @ChgRef{Version=[3],Kind=[AddedNormal]}
1390 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Splice_Subtree (Target : @key{in out} Tree;
1391 Parent : @key{in} Cursor;
1392 Before : @key{in} Cursor;
1393 Source : @key{in out} Tree;
1394 Position : @key{in out} Cursor);]}
1395 @end{Example}
1396
1397 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1],ARef=[AI05-0269-1]}
1398 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Parent equals No_Element, then
1399 Constraint_Error is propagated. If Parent does not designate a node in Target,
1400 then Program_Error is propagated. If Before is not equal to No_Element, and
1401 does not designate a node in Target, then Program_Error is propagated. If
1402 Before is not equal to No_Element, and
1403 Parent does not designate the parent node of the node designated by Before,
1404 then Constraint_Error is propagated. If Position equals No_Element,
1405 Constraint_Error is propagated. If Position does not designate a node in
1406 Source or designates a root node, then Program_Error is propagated. If Source
1407 denotes the same object as Target, then:
1408 if Position equals Before there is no effect; if Position designates an
1409 ancestor of Parent (including Parent itself), Constraint_Error is propagated;
1410 otherwise, the subtree rooted by the element designated by Position is
1411 moved to be a child of Parent. If Parent already has child nodes, then the
1412 moved nodes are inserted prior to the node designated by Before, or, if Before
1413 equals No_Element, the moved nodes are inserted after the last existing child
1414 node of Parent. In each of these cases, Position and the count of Target are
1415 unchanged, and the parent of the element designated by Position is set to
1416 Parent.]}
1417
1418 @begin{Reason}
1419 @ChgRef{Version=[3],Kind=[AddedNormal]}
1420 @ChgAdded{Version=[3],Text=[We can't allow moving the subtree of Position to
1421 a proper descendant node of the subtree, as the descendant node will be part of the
1422 subtree being moved. The result would be a circularly linked tree, or one
1423 with inaccessible nodes. Thus we have to check Position against Parent, even
1424 though such a check is @i<O>(Depth(Source)).]}
1425 @end{Reason}
1426
1427 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
1428 @ChgAdded{Version=[3],Text=[Otherwise (if Source does not denote the same
1429 object as Target), the subtree designated by Position is removed from Source
1430 and moved to Target. The subtree is inserted as a child of Parent. If Parent
1431 already has child nodes, then the moved nodes are inserted prior to the node
1432 designated by Before, or, if Before equals No_Element, the moved nodes are
1433 inserted after the last existing child node of Parent. In each of these cases,
1434 the count of Target is incremented by Subtree_Node_Count (Position), and the
1435 count of Source is decremented by Subtree_Node_Count (Position), Position is
1436 updated to represent an element in Target.]}
1437
1438 @begin{Ramification}
1439 @ChgRef{Version=[3],Kind=[AddedNormal]}
1440 @ChgAdded{Version=[3],Text=[If Source is the same as Target, and Position =
1441 Before, or Next_Sibling(Position) = Before, Splice_Subtree has no effect, as
1442 the subtree does not have to move to meet the postcondition.]}
1443
1444 @ChgRef{Version=[3],Kind=[AddedNormal]}
1445 @ChgAdded{Version=[3],Text=[We do not allow splicing a subtree that includes
1446 a root node, as that would require inserting a node with no value in the
1447 middle of the target tree. Splice the children of the root node instead.]}
1448
1449 @ChgRef{Version=[3],Kind=[AddedNormal]}
1450 @ChgAdded{Version=[3],Text=[For this reason there is no operation to splice
1451 an entire tree, as that would necessarily involve splicing a root node.]}
1452 @end{Ramification}
1453
1454 @begin{Example}
1455 @ChgRef{Version=[3],Kind=[AddedNormal]}
1456 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Splice_Subtree (Container: @key{in out} Tree;
1457 Parent : @key{in} Cursor;
1458 Before : @key{in} Cursor;
1459 Position : @key{in} Cursor);]}
1460 @end{Example}
1461
1462 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1],ARef=[AI05-0269-1]}
1463 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Parent equals No_Element, then
1464 Constraint_Error is propagated. If Parent does not designate a node in
1465 Container, then Program_Error is propagated. If Before is not equal to
1466 No_Element, and does not designate a node in Container, then Program_Error is
1467 propagated. If Before is not equal to No_Element, and
1468 Parent does not designate the parent node of the node designated by Before,
1469 then Constraint_Error is propagated. If Position
1470 equals No_Element, Constraint_Error is propagated. If Position does not
1471 designate a node in Container or designates a root node, then Program_Error is
1472 propagated. If Position equals Before, there is no effect. If Position
1473 designates an ancestor of Parent (including Parent itself), Constraint_Error is
1474 propagated. Otherwise, the subtree rooted by the element designated by
1475 Position is moved to be a child of Parent. If Parent already has child nodes,
1476 then the moved nodes are inserted prior to the node designated by Before, or,
1477 if Before equals No_Element, the moved nodes are inserted after the last
1478 existing child node of Parent. The parent of the element designated by
1479 Position is set to Parent.]}
1480
1481 @begin{Reason}
1482 @ChgRef{Version=[3],Kind=[AddedNormal]}
1483 @ChgAdded{Version=[3],Text=[We can't allow moving the subtree of Position to
1484 a proper descendant node of the subtree, as the descendant node will be part of the
1485 subtree being moved.]}
1486 @end{Reason}
1487
1488
1489 @begin{Example}
1490 @ChgRef{Version=[3],Kind=[AddedNormal]}
1491 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Splice_Children (Target : @key{in out} Tree;
1492 Target_Parent : @key{in} Cursor;
1493 Before : @key{in} Cursor;
1494 Source : @key{in out} Tree;
1495 Source_Parent : @key{in} Cursor);]}
1496 @end{Example}
1497
1498 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0262-1]}
1499 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Target_Parent equals
1500 No_Element, then Constraint_Error is propagated. If Target_Parent does not
1501 designate a node in Target, then Program_Error is propagated. If Before is not
1502 equal to No_Element, and does not designate an element in Target, then
1503 Program_Error is propagated. If Source_Parent equals No_Element, then
1504 Constraint_Error is propagated. If Source_Parent does not designate a node in
1505 Source, then Program_Error is propagated. If Before is not equal to
1506 No_Element, and Target_Parent does not designate the parent node of the
1507 node designated by Before, then Constraint_Error is propagated.]}
1508
1509 @ChgRef{Version=[3],Kind=[AddedNormal]}
1510 @ChgAdded{Version=[3],Type=[Leading],Text=[If Source denotes the same object as Target, then:]}
1511
1512 @begin{Itemize}
1513 @ChgRef{Version=[3],Kind=[AddedNormal]}
1514 @ChgAdded{Version=[3],Text=[if Target_Parent equals Source_Parent there is
1515 no effect; else]}
1516
1517 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0269-1]}
1518 @ChgAdded{Version=[3],Text=[if Source_Parent is an ancestor of
1519 Target_Parent other than Target_Parent itself, then Constraint_Error is propagated; else]}
1520
1521 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0269-1]}
1522 @ChgAdded{Version=[3],Text=[the child elements (and the further descendants) of
1523 Source_Parent are moved to be child elements of Target_Parent. If
1524 Target_Parent already has child elements, then the moved elements are
1525 inserted prior to the node designated by Before, or, if Before equals
1526 No_Element, the moved elements are inserted after the last existing child
1527 node of Target_Parent. The parent of each moved child element is set to
1528 Target_Parent.]}
1529 @end{Itemize}
1530
1531 @begin{Reason}
1532 @ChgRef{Version=[3],Kind=[AddedNormal]}
1533 @ChgAdded{Version=[3],Text=[We can't allow moving the children of
1534 Source_Parent to a proper descendant node, as the descendant node will be
1535 part of one of the subtrees being moved.]}
1536 @end{Reason}
1537
1538 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1],ARef=[AI05-0269-1]}
1539 @ChgAdded{Version=[3],Text=[Otherwise (if Source does not denote the same
1540 object as Target), the child elements (and the further descendants) of Source_Parent
1541 are removed from Source and moved to Target. The child elements are inserted
1542 as children of Target_Parent. If Target_Parent already has child elements, then
1543 the moved elements are inserted prior to the node designated by Before, or, if
1544 Before equals No_Element, the moved elements are inserted after the last
1545 existing child node of Target_Parent. In each of these cases, the overall
1546 count of Target is incremented by Subtree_Node_Count (Source_Parent)-1, and
1547 the overall count of Source is decremented by Subtree_Node_Count
1548 (Source_Parent)-1.]}
1549
1550 @begin{Ramification}
1551 @ChgRef{Version=[3],Kind=[AddedNormal]}
1552 @ChgAdded{Version=[3],Text=[The node designated by Source_Parent is not
1553 moved, thus we never need to update Source_Parent.]}
1554
1555 @ChgRef{Version=[3],Kind=[AddedNormal]}
1556 @ChgAdded{Version=[3],Text=[Move (Target, Source) could be written
1557 Splice_Children (Target, Target.Root, No_Element, Source, Source.Root);]}
1558 @end{Ramification}
1559
1560 @begin{Example}
1561 @ChgRef{Version=[3],Kind=[AddedNormal]}
1562 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Splice_Children (Container : @key{in out} Tree;
1563 Target_Parent : @key{in} Cursor;
1564 Before : @key{in} Cursor;
1565 Source_Parent : @key{in} Cursor);]}
1566 @end{Example}
1567
1568 @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]}
1569 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Target_Parent equals
1570 No_Element, then Constraint_Error is propagated. If Target_Parent does not
1571 designate a node in Container, then Program_Error is propagated. If Before is
1572 not equal to No_Element, and does not designate an element in Container, then
1573 Program_Error is propagated. If Source_Parent equals No_Element, then
1574 Constraint_Error is propagated. If Source_Parent does not designate a node in
1575 Container, then Program_Error is propagated. If Before is not equal to
1576 No_Element, and Target_Parent does not designate the parent node of the
1577 node designated by Before, then Constraint_Error is propagated.
1578 If Target_Parent equals Source_Parent there is
1579 no effect. If Source_Parent is an ancestor of Target_Parent other than
1580 Target_Parent itself, then
1581 Constraint_Error is propagated. Otherwise, the child elements (and the further
1582 descendants) of Source_Parent are moved to be child elements of Target_Parent.
1583 If Target_Parent already has child elements, then the moved elements are
1584 inserted prior to the node designated by Before, or, if Before equals
1585 No_Element, the moved elements are inserted after the last existing child node
1586 of Target_Parent. The parent of each moved child element is set to
1587 Target_Parent.]}
1588
1589 @begin{Example}
1590 @ChgRef{Version=[3],Kind=[AddedNormal]}
1591 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Parent (Position : Cursor) @key{return} Cursor;]}
1592 @end{Example}
1593
1594 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1595 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position is equal to No_Element
1596 or designates a root node, No_Element is returned. Otherwise, a cursor
1597 designating the parent node of the node designated by Position is returned.]}
1598
1599 @begin{Example}
1600 @ChgRef{Version=[3],Kind=[AddedNormal]}
1601 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} First_Child (Parent : Cursor) @key{return} Cursor;]}
1602 @end{Example}
1603
1604 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1605 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Parent is equal to No_Element,
1606 then Constraint_Error is propagated. Otherwise, First_Child returns a cursor
1607 designating the first child node of the node designated by Parent; if there is
1608 no such node, No_Element is returned.]}
1609
1610 @begin{Example}
1611 @ChgRef{Version=[3],Kind=[AddedNormal]}
1612 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} First_Child_Element (Parent : Cursor) @key{return} Element_Type;]}
1613 @end{Example}
1614
1615 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1616 @ChgAdded{Version=[3],Type=[Trailing],Text=[Equivalent to Element (First_Child (Parent)).]}
1617
1618 @begin{Example}
1619 @ChgRef{Version=[3],Kind=[AddedNormal]}
1620 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Last_Child (Parent : Cursor) @key{return} Cursor;]}
1621 @end{Example}
1622
1623 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1624 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Parent is equal to No_Element,
1625 then Constraint_Error is propagated. Otherwise, Last_Child returns a cursor
1626 designating the last child node of the node designated by Parent; if there is
1627 no such node, No_Element is returned.]}
1628
1629 @begin{Example}
1630 @ChgRef{Version=[3],Kind=[AddedNormal]}
1631 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Last_Child_Element (Parent : Cursor) @key{return} Element_Type;]}
1632 @end{Example}
1633
1634 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1635 @ChgAdded{Version=[3],Type=[Trailing],Text=[Equivalent to Element (Last_Child (Parent)).]}
1636
1637 @begin{Example}
1638 @ChgRef{Version=[3],Kind=[AddedNormal]}
1639 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Next_Sibling (Position : Cursor) @key{return} Cursor;]}
1640 @end{Example}
1641
1642 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1643 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position equals No_Element or
1644 designates the last child node of its parent, then Next_Sibling returns the
1645 value No_Element. Otherwise, it returns a cursor that designates the successor
1646 (with the same parent) of the node designated by Position.]}
1647
1648 @begin{Example}
1649 @ChgRef{Version=[3],Kind=[AddedNormal]}
1650 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Previous_Sibling (Position : Cursor) @key{return} Cursor;]}
1651 @end{Example}
1652
1653 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1654 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Position equals No_Element or
1655 designates the first child node of its parent, then Previous_Sibling returns
1656 the value No_Element. Otherwise, it returns a cursor that designates the
1657 predecessor (with the same parent) of the node designated by Position.]}
1658
1659 @begin{Example}
1660 @ChgRef{Version=[3],Kind=[AddedNormal]}
1661 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Next_Sibling (Position : @key{in out} Cursor);]}
1662 @end{Example}
1663
1664 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1665 @ChgAdded{Version=[3],Type=[Trailing],Text=[Equivalent to Position := Next_Sibling (Position);]}
1666
1667 @begin{Example}
1668 @ChgRef{Version=[3],Kind=[AddedNormal]}
1669 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Previous_Sibling (Position : @key{in out} Cursor);]}
1670 @end{Example}
1671
1672 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1673 @ChgAdded{Version=[3],Type=[Trailing],Text=[Equivalent to Position := Previous_Sibling (Position);]}
1674
1675 @begin{Example}
1676 @ChgRef{Version=[3],Kind=[AddedNormal]}
1677 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Iterate_Children
1678 (Parent : @key{in} Cursor;
1679 Process : @key{not null access procedure} (Position : @key{in} Cursor));]}
1680 @end{Example}
1681
1682 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
1683 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Parent equals No_Element, then
1684 Constraint_Error is propagated.]}
1685
1686 @ChgRef{Version=[3],Kind=[AddedNormal]}
1687 @ChgAdded{Version=[3],Text=[Iterate_Children calls Process.@key{all} with a
1688 cursor that designates each child node of Parent, starting with the first child
1689 node and moving the cursor as per the Next_Sibling function.]}
1690
1691 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
1692 @ChgAdded{Version=[3],Text=[Tampering with the cursors of the tree containing
1693 Parent is prohibited during the execution of a call on Process.@key{all}.
1694 Any exception raised by Process.@key{all} is propagated.]}
1695
1696 @begin{Example}
1697 @ChgRef{Version=[3],Kind=[AddedNormal]}
1698 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{procedure} Reverse_Iterate_Children
1699 (Parent : @key{in} Cursor;
1700 Process : @key{not null access procedure} (Position : @key{in} Cursor));]}
1701 @end{Example}
1702
1703 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
1704 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Parent equals No_Element, then
1705 Constraint_Error is propagated.]}
1706
1707 @ChgRef{Version=[3],Kind=[AddedNormal]}
1708 @ChgAdded{Version=[3],Text=[Reverse_Iterate_Children calls Process.@key{all}
1709 with a cursor that designates each child node of Parent, starting with the last
1710 child node and moving the cursor as per the Previous_Sibling function.]}
1711
1712 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
1713 @ChgAdded{Version=[3],Text=[Tampering with the cursors of the tree containing
1714 Parent is prohibited during the execution of a call on Process.@key{all}.
1715 Any exception raised by Process.@key{all} is propagated.]}
1716
1717 @begin{Example}
1718 @ChgRef{Version=[3],Kind=[AddedNormal]}
1719 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} Iterate_Children (Container : @key[in] Tree; Parent : @key[in] Cursor)
1720 @key[return] Tree_Iterator_Interfaces.Reversible_Iterator'Class;]}
1721 @end{Example}
1722
1723 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0265-1]}
1724 @ChgAdded{Version=[3],Type=[Trailing],Text=[Iterate_Children returns a
1725 reversible iterator object
1726 (see @RefSecNum{User-Defined Iterator Types}) that will generate
1727 a value for a loop parameter (see @RefSecNum{Generalized Loop Iteration})
1728 designating each child node of Parent. If Parent equals No_Element, then
1729 Constraint_Error is propagated. If Parent does not designate a node in
1730 Container, then Program_Error is propagated. Otherwise, when used as a forward
1731 iterator, the nodes are designated starting with the first child node and moving
1732 the cursor as per the function Next_Sibling; when used as a reverse iterator,
1733 the nodes are designated starting with the last child node and moving the cursor
1734 as per the function Previous_Sibling. Tampering with the cursors of Container is
1735 prohibited while the iterator object exists (in particular, in the
1736 @nt{sequence_of_statements} of the @nt{loop_statement} whose
1737 @nt{iterator_specification} denotes this object). The iterator object needs
1738 finalization.]}
1739
1740 @end{DescribeCode}
1741
1742 @end{StaticSem}
1743
1744 @begin{Bounded}
1745
1746 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
1747 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
1748 It is a bounded error for the actual function associated with a generic formal
1749 subprogram, when called as part of an operation of this package, to tamper with
1750 elements of any Tree parameter of the operation. Either Program_Error is raised,
1751 or the operation works as defined on the value of the Tree either prior to, or
1752 subsequent to, some or all of the modifications to the Tree.]}
1753
1754 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1755 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
1756 It is a bounded error to call any subprogram declared in the visible part of
1757 Containers.Multiway_Trees when the associated container has been finalized. If
1758 the operation takes Container as an @key[in out] parameter, then it raises
1759 Constraint_Error or Program_Error. Otherwise, the operation either proceeds as
1760 it would for an empty container, or it raises Constraint_Error or Program_Error.]}
1761 @end{Bounded}
1762
1763 @begin{Erron}
1764 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1765 @ChgAdded{Version=[3],Type=[Leading],Keepnext=[T],Text=[A Cursor
1766 value is @i<invalid> if any of the following have occurred since
1767 it was created:@Defn2{Term=[invalid cursor],Sec=[of a tree]}
1768 @PDefn2{Term=[cursor],Sec=[invalid]}]}
1769 @begin{Itemize}
1770
1771 @ChgRef{Version=[3],Kind=[AddedNormal]}
1772 @ChgAdded{Version=[3],Text=[The tree that contains the element it designates has
1773 been finalized;]}
1774
1775 @ChgRef{Version=[3],Kind=[AddedNormal]}
1776 @ChgAdded{Version=[3],Text=[The tree that contains the element it designates has
1777 been used as the Source or Target of a call to Move;]}
1778
1779 @ChgRef{Version=[3],Kind=[AddedNormal]}
1780 @ChgAdded{Version=[3],Text=[The tree that contains the element it designates has
1781 been used as the Target of a call to Assign or the target of an
1782 @nt{assignment_statement};]}
1783
1784 @ChgRef{Version=[3],Kind=[AddedNormal]}
1785 @ChgAdded{Version=[3],Text=[The element it designates has been removed from the
1786 tree that previously contained the element.]}
1787 @begin{Reason}
1788 @ChgRef{Version=[3],Kind=[AddedNormal]}
1789 @ChgAdded{Version=[3],Text=[We talk about which tree the element was removed
1790 from in order to handle splicing nodes from one tree to another. The node
1791 still exists, but any cursors that designate it in the original tree are now
1792 invalid. This bullet covers removals caused by calls to Clear, Delete_Leaf,
1793 Delete_Subtree, Delete_Children, Splice_Children, and Splice_Subtree.]}
1794 @end{Reason}
1795
1796 @end{Itemize}
1797
1798 @ChgRef{Version=[3],Kind=[AddedNormal]}
1799 @ChgAdded{Version=[3],Text=[The result of "=" or Has_Element is unspecified if
1800 it is called with an invalid cursor parameter.@PDefn{unspecified} Execution is
1801 erroneous if any other subprogram declared in Containers.Multiway_Trees is
1802 called with an invalid cursor parameter.]}
1803
1804 @begin{Discussion}
1805 @ChgRef{Version=[3],Kind=[AddedNormal]}
1806 @ChgAdded{Version=[3],Text=[The list above is intended to be exhaustive. In
1807 other cases, a cursor value continues to designate its original element (or
1808 the root node). For instance, cursor values survive the insertion and deletion
1809 of other nodes.]}
1810
1811 @ChgRef{Version=[3],Kind=[AddedNormal]}
1812 @ChgAdded{Version=[3],Text=[While it is possible to check for these cases, in
1813 many cases the overhead necessary to make the check is substantial in time or
1814 space. Implementations are encouraged to check for as many of these cases as
1815 possible and raise Program_Error if detected.]}
1816 @end{Discussion}
1817
1818 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
1819 @ChgAdded{Version=[3],Text=[Execution is erroneous if the tree associated with
1820 the result of a call to Reference or Constant_Reference is finalized before the
1821 result object returned by the call to Reference or Constant_Reference is
1822 finalized.]}
1823 @begin{Reason}
1824 @ChgRef{Version=[3],Kind=[AddedNormal]}
1825 @ChgAdded{Version=[3],Text=[Each object of Reference_Type and
1826 Constant_Reference_Type probably contains some reference to the originating
1827 container. If that container is prematurely finalized (which is only possible
1828 via Unchecked_Deallocation, as accessibility checks prevent passing a
1829 container to Reference that will not live as long as the result), the
1830 finalization of the object of Reference_Type will try to access a nonexistent
1831 object. This is a normal case of a dangling pointer created by
1832 Unchecked_Deallocation; we have to explicitly mention it here as the pointer
1833 in question is not visible in the specification of the type. (This is the same
1834 reason we have to say this for invalid cursors.)]}
1835 @end{Reason}
1836 @end{Erron}
1837
1838 @begin{ImplReq}
1839
1840 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1841 @ChgAdded{Version=[3],Text=[No storage associated with a multiway tree object
1842 shall be lost upon assignment or scope exit.]}
1843
1844 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0262-1]}
1845 @ChgAdded{Version=[3],Text=[The execution of an @nt{assignment_statement} for
1846 a tree shall have the effect of copying the elements from the source tree
1847 object to the target tree object and changing the node count of the target
1848 object to that of the source object.]}
1849
1850 @begin{ImplNote}
1851 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0298-1]}
1852 @ChgAdded{Version=[3],Text=[An assignment of a Tree is a @lquotes@;deep@rquotes
1853 copy; that is the elements are copied as well the data structures.
1854 We say @lquotes@;effect of@rquotes in order to allow the implementation to
1855 avoid copying elements immediately if it wishes. For instance, an
1856 implementation that avoided copying until one of the containers is modified
1857 would be allowed. (Note that this implementation would
1858 require care, see @RefSecNum{The Generic Package Containers.Vectors} for more.)]}
1859 @end{ImplNote}
1860 @end{ImplReq}
1861
1862 @begin{ImplAdvice}
1863
1864 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1865 @ChgAdded{Version=[3],Text=[Containers.Multiway_Trees should be implemented
1866 similarly to a multiway tree. In particular, if @i{N} is the overall number of nodes
1867 for a particular tree, then the worst-case time complexity of Element, Parent,
1868 First_Child, Last_Child, Next_Sibling, Previous_Sibling,
1869 Insert_Child with Count=1, and Delete should be @i{O}(log @i{N}).]}
1870 @ChgImplAdvice{Version=[3],Kind=[AddedNormal],Text=[@ChgAdded{Version=[3],
1871 Text=[The worst-case time complexity of the Element, Parent,
1872 First_Child, Last_Child, Next_Sibling, Previous_Sibling,
1873 Insert_Child with Count=1, and Delete
1874 operations of Containers.Multiway_Trees should be @i{O}(log @i<N>).]}]}
1875
1876 @begin{Reason}
1877 @ChgRef{Version=[3],Kind=[AddedNormal]}
1878 @ChgAdded{Version=[3],Text=[We do not mean to overly constrain implementation
1879 strategies here. However, it is important for portability that the performance
1880 of large containers has roughly the same factors on different implementations.
1881 If a program is moved to an implementation that takes @i{O}(@i<N>) time to access
1882 elements, that program could be unusable when the trees are large. We allow
1883 @i{O}(log @i<N>) access because the proportionality constant and caching effects are
1884 likely to be larger than the log factor, and we don't want to discourage
1885 innovative implementations.]}
1886 @end{Reason}
1887
1888 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1889 @ChgAdded{Version=[3],Text=[Move should not copy elements, and should minimize
1890 copying of internal data structures.]}
1891 @ChgImplAdvice{Version=[3],Kind=[AddedNormal],Text=[@ChgAdded{Version=[3],
1892 Text=[Containers.Multiway_Trees.Move should not copy elements, and should
1893 minimize copying of internal data structures.]}]}
1894
1895 @begin{ImplNote}
1896 @ChgRef{Version=[3],Kind=[AddedNormal]}
1897 @ChgAdded{Version=[3],Text=[Usually that can be accomplished simply by
1898 moving the pointer(s) to the internal data structures from the Source
1899 container to the Target container.]}
1900 @end{ImplNote}
1901
1902 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
1903 @ChgAdded{Version=[3],Text=[If an exception is propagated from a tree
1904 operation, no storage should be lost, nor any elements removed from a tree
1905 unless specified by the operation.]}
1906 @ChgImplAdvice{Version=[3],Kind=[AddedNormal],Text=[@ChgAdded{Version=[3],
1907 Text=[If an exception is propagated from a tree
1908 operation, no storage should be lost, nor any elements removed from a tree
1909 unless specified by the operation.]}]}
1910
1911 @begin{Reason}
1912 @ChgRef{Version=[3],Kind=[AddedNormal]}
1913 @ChgAdded{Version=[3],Text=[This is important so that programs can recover
1914 from errors. But we don't want to require heroic efforts, so we just require
1915 documentation of cases where this can't be accomplished.]}
1916 @end{Reason}
1917 @end{ImplAdvice}
1918
1919 @begin{Extend2005}
1920 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0257-1],ARef=[AI05-0265-1],ARef=[AI05-0269-1]}
1921 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
1922 The generic package Containers.Multiway_Trees is new.]}
1923 @end{Extend2005}
1924
1925 @begin{DiffWord2012}
1926 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0069-1]}
1927 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Fixed the function Iterate
1928 so it is clear that the root node is never visited.]}
1929
1930 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0078-1]}
1931 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> The definition of @i<node> is
1932 clarified so that it it doesn't appear to say all nodes have an element.]}
1933
1934 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0110-1]}
1935 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified that tampering checks
1936 precede all other checks made by a subprogram (but come after those associated
1937 with the call).]}
1938 @end{DiffWord2012}
1939
1940
1941 @LabeledAddedSubclause{Version=[2],Name=[The Generic Package Containers.Indefinite_Vectors]}
1942
1943 @begin{Intro}
1944 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
1945 @ChgAdded{Version=[2],Text=[The language-defined generic package
1946 Containers.Indefinite_Vectors provides a private type Vector and a set of
1947 operations. It provides the same operations as the package Containers.Vectors
1948 (see @RefSecNum{The Generic Package Containers.Vectors}), with the difference that
1949 the generic formal Element_Type is indefinite.]}
1950 @end{Intro}
1951
1952 @begin{StaticSem}
1953
1954 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
1955 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
1956 @ChgAdded{Version=[2],Type=[Leading],Text=[The declaration
1957 of the generic library package
1958 Containers.Indefinite_Vectors@ChildUnit{Parent=[Ada.Containers],Child=[Indefinite_Vectors]}
1959 has the same contents @Chg{Version=[3],New=[and semantics ],Old=[]}as
1960 Containers.Vectors except:]}
1961
1962 @begin{Itemize}
1963 @ChgRef{Version=[2],Kind=[AddedNormal]}
1964 @ChgAdded{Version=[2],Text=[The generic formal Element_Type is indefinite.]}
1965
1966 @ChgRef{Version=[2],Kind=[AddedNormal]}
1967 @ChgAdded{Version=[2],Keepnext=[T],Type=[Leading],Text=[The procedures with
1968 the profiles:]}
1969 @begin{Example}
1970 @ChgRef{Version=[2],Kind=[AddedNormal]}
1971 @ChgAdded{Version=[2],Noprefix=[T],Keepnext=[F],Type=[Leading],Text=[@key{procedure} Insert (Container : @key{in out} Vector;
1972 Before : @key{in} Extended_Index;
1973 Count : @key{in} Count_Type := 1);]}
1974
1975 @ChgRef{Version=[2],Kind=[AddedNormal]}
1976 @ChgAdded{Version=[2],Noprefix=[T],Keepnext=[T],Type=[Leading],Text=[@key{procedure} Insert (Container : @key{in out} Vector;
1977 Before : @key{in} Cursor;
1978 Position : @key{out} Cursor;
1979 Count : @key{in} Count_Type := 1);]}
1980 @end{Example}
1981 @ChgRef{Version=[2],Kind=[AddedNormal]}
1982 @ChgAdded{Version=[2],Noprefix=[T],Text=[are omitted.]}
1983
1984 @begin{Discussion}
1985 @ChgRef{Version=[2],Kind=[AddedNormal]}
1986 @ChgAdded{Version=[2],Text=[These procedures are omitted because there is no
1987 way to create a default-initialized object of an indefinite type. Note that
1988 Insert_Space can be used instead of this routine in most cases. Omitting
1989 the routine completely allows any problems to be diagnosed by
1990 the compiler when converting from a definite to indefinite vector.]}
1991 @end{Discussion}
1992
1993 @ChgRef{Version=[2],Kind=[AddedNormal]}
1994 @ChgAdded{Version=[2],Text=[The actual Element parameter of access subprogram Process
1995 of Update_Element may be constrained even if Element_Type is unconstrained.]}
1996
1997 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
1998 @ChgAdded{Version=[4],Text=[The operations "&", Append, Insert, Prepend,
1999 Replace_Element, and To_Vector that have a formal parameter of type
2000 Element_Type perform indefinite insertion (see @RefSecNum{Containers}).]}
2001 @end{Itemize}
2002 @end{StaticSem}
2003
2004 @begin{Extend95}
2005 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
2006 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2007 The generic package Containers.Indefinite_Vectors is new.]}
2008 @end{Extend95}
2009
2010 @begin{Inconsistent2012}
2011 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
2012 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
2013 Defined some routines to @ldquote@;perform indefinite insertion@rdquote.
2014 This could mean that some calls to those routines would now raise
2015 Program_Error where they previously worked. However, this is extremely
2016 unlikely, as it would require that the package was not implemented in Ada
2017 (an Ada @nt{allocator} would raise Program_Error in these circumstances), and
2018 that a program inserted a more nested tagged type (or access discriminant)
2019 into a container, and then used that object before its type or discriminant
2020 went out of scope. All known implementations are implemented in Ada, so we
2021 believe there is no practical incompatibility. As such, we
2022 mention this only for completeness.]}
2023 @end{Inconsistent2012}
2024
2025
2026 @LabeledAddedSubclause{Version=[2],Name=[The Generic Package Containers.Indefinite_Doubly_Linked_Lists]}
2027
2028 @begin{Intro}
2029 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
2030 @ChgAdded{Version=[2],Text=[The language-defined generic package Containers.Indefinite_Doubly_Linked_Lists
2031 provides private types List and Cursor, and a set of operations for each
2032 type. It provides the same operations as the package
2033 Containers.Doubly_Linked_Lists
2034 (see @RefSecNum{The Generic Package Containers.Doubly_Linked_Lists}),
2035 with the difference that the generic formal Element_Type is indefinite.]}
2036 @end{Intro}
2037
2038 @begin{StaticSem}
2039
2040 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
2041 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
2042 @ChgAdded{Version=[2],Type=[Leading],Text=[The declaration of
2043 the generic library package
2044 Containers.@!Indefinite_@!Doubly_@!Linked_@!Lists@ChildUnit{Parent=[Ada.Containers],Child=[Indefinite_Doubly_Linked_Lists]}
2045 has the same contents @Chg{Version=[3],New=[and semantics ],Old=[]}as
2046 Containers.@!Doubly_@!Linked_@!Lists except:]}
2047
2048 @begin{Itemize}
2049 @ChgRef{Version=[2],Kind=[AddedNormal]}
2050 @ChgAdded{Version=[2],Text=[The generic formal Element_Type is indefinite.]}
2051
2052 @ChgRef{Version=[2],Kind=[AddedNormal]}
2053 @ChgAdded{Version=[2],Keepnext=[T],Type=[Leading],Text=[The procedure with
2054 the profile:]}
2055 @begin{Example}
2056 @ChgRef{Version=[2],Kind=[AddedNormal]}
2057 @ChgAdded{Version=[2],Noprefix=[T],Keepnext=[T],Type=[Leading],Text=[@key{procedure} Insert (Container : @key{in out} List;
2058 Before : @key{in} Cursor;
2059 Position : @key{out} Cursor;
2060 Count : @key{in} Count_Type := 1);]}
2061 @end{Example}
2062 @ChgRef{Version=[2],Kind=[AddedNormal]}
2063 @ChgAdded{Version=[2],Noprefix=[T],Text=[is omitted.]}
2064
2065 @begin{Discussion}
2066 @ChgRef{Version=[2],Kind=[AddedNormal]}
2067 @ChgAdded{Version=[2],Text=[This procedure is omitted because there is no way
2068 to create a default-initialized object of an indefinite type. We considered
2069 having this routine insert an empty element similar to the empty elements of
2070 a vector, but rejected this possibility because the semantics are fairly
2071 complex and very different from the existing definite container. That would
2072 make it more error-prone to convert a container from a definite type to an
2073 indefinite type; by omitting the routine completely, any problems will be
2074 diagnosed by the compiler.]}
2075 @end{Discussion}
2076
2077 @ChgRef{Version=[2],Kind=[AddedNormal]}
2078 @ChgAdded{Version=[2],Text=[The actual Element parameter of access subprogram Process
2079 of Update_Element may be constrained even if Element_Type is unconstrained.]}
2080
2081 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
2082 @ChgAdded{Version=[4],Text=[The operations Append, Insert, Prepend, and
2083 Replace_Element that have a formal parameter of type Element_Type perform
2084 indefinite insertion (see @RefSecNum{Containers}).]}
2085 @end{Itemize}
2086 @end{StaticSem}
2087
2088 @begin{Extend95}
2089 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
2090 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2091 The generic package Containers.Indefinite_Doubly_Linked_Lists is new.]}
2092 @end{Extend95}
2093
2094 @begin{Inconsistent2012}
2095 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
2096 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
2097 Defined some routines to @ldquote@;perform indefinite insertion@rdquote.
2098 This could mean that some calls to those routines would now raise
2099 Program_Error where they previously worked. However, this is extremely
2100 unlikely; see @Inconsistent2012Title in
2101 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
2102 @end{Inconsistent2012}
2103
2104
2105 @LabeledAddedSubclause{Version=[2],Name=[The Generic Package Containers.Indefinite_Hashed_Maps]}
2106
2107 @begin{Intro}
2108 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
2109 @ChgAdded{Version=[2],Text=[The language-defined generic package Containers.Indefinite_Hashed_Maps provides
2110 a map with the same operations as the package Containers.Hashed_Maps
2111 (see @RefSecNum{The Generic Package Containers.Hashed_Maps}),
2112 with the difference that the generic formal types Key_Type and Element_Type are
2113 indefinite.]}
2114 @end{Intro}
2115
2116 @begin{StaticSem}
2117
2118 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
2119 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
2120 @ChgAdded{Version=[2],Type=[Leading],Text=[The declaration of
2121 the generic library package
2122 Containers.Indefinite_Hashed_Maps@ChildUnit{Parent=[Ada.Containers],Child=[Indefinite_Hashed_Maps]}
2123 has the same contents @Chg{Version=[3],New=[and semantics ],Old=[]}as
2124 Containers.Hashed_Maps except:]}
2125
2126 @begin{Itemize}
2127 @ChgRef{Version=[2],Kind=[AddedNormal]}
2128 @ChgAdded{Version=[2],Text=[The generic formal Key_Type is indefinite.]}
2129
2130 @ChgRef{Version=[2],Kind=[AddedNormal]}
2131 @ChgAdded{Version=[2],Text=[The generic formal Element_Type is indefinite.]}
2132
2133 @ChgRef{Version=[2],Kind=[AddedNormal]}
2134 @ChgAdded{Version=[2],Keepnext=[T],Type=[Leading],Text=[The procedure with
2135 the profile:]}
2136 @begin{Example}
2137 @ChgRef{Version=[2],Kind=[AddedNormal]}
2138 @ChgAdded{Version=[2],Noprefix=[T],Keepnext=[T],Type=[Leading],Text=[@key{procedure} Insert (Container : @key{in out} Map;
2139 Key : @key{in} Key_Type;
2140 Position : @key{out} Cursor;
2141 Inserted : @key{out} Boolean);]}
2142 @end{Example}
2143 @ChgRef{Version=[2],Kind=[AddedNormal]}
2144 @ChgAdded{Version=[2],Noprefix=[T],Text=[is omitted.]}
2145
2146 @begin{Discussion}
2147 @ChgRef{Version=[2],Kind=[AddedNormal]}
2148 @ChgAdded{Version=[2],Text=[This procedure is omitted because there is no way
2149 to create a default-initialized object of an indefinite type. We considered
2150 having this routine insert an empty element similar to the empty elements of
2151 a vector, but rejected this possibility because the semantics are fairly
2152 complex and very different from the existing case. That would make it more
2153 error-prone to convert a container from a definite type to an indefinite
2154 type; by omitting the routine completely, any problems will be diagnosed by
2155 the compiler.]}
2156 @end{Discussion}
2157
2158 @ChgRef{Version=[2],Kind=[AddedNormal]}
2159 @ChgAdded{Version=[2],Text=[The actual Element parameter of access subprogram Process
2160 of Update_Element may be constrained even if Element_Type is unconstrained.]}
2161
2162 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
2163 @ChgAdded{Version=[4],Text=[The operations Include, Insert, Replace, and
2164 Replace_Element that have a formal parameter of type Element_Type perform
2165 indefinite insertion (see @RefSecNum{Containers}).]}
2166 @begin{Discussion}
2167 @ChgRef{Version=[4],Kind=[AddedNormal]}
2168 @ChgAdded{Version=[4],Text=[Some of the named operations also have a formal
2169 of the indefinite formal type Key_Type and perform indefinite insertion using
2170 that value, but it is sufficient to mention the formal of type Element_Type
2171 to cover those.]}
2172 @end{Discussion}
2173
2174 @end{Itemize}
2175 @end{StaticSem}
2176
2177 @begin{Extend95}
2178 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
2179 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2180 The generic package Containers.Indefinite_Hashed_Maps is new.]}
2181 @end{Extend95}
2182
2183 @begin{Inconsistent2012}
2184 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
2185 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
2186 Defined some routines to @ldquote@;perform indefinite insertion@rdquote.
2187 This could mean that some calls to those routines would now raise
2188 Program_Error where they previously worked. However, this is extremely
2189 unlikely; see @Inconsistent2012Title in
2190 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
2191 @end{Inconsistent2012}
2192
2193
2194 @LabeledAddedSubclause{Version=[2],Name=[The Generic Package Containers.Indefinite_Ordered_Maps]}
2195
2196 @begin{Intro}
2197 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
2198 @ChgAdded{Version=[2],Text=[The language-defined generic package Containers.Indefinite_Ordered_Maps
2199 provides a map with the same operations as the package Containers.Ordered_Maps
2200 (see @RefSecNum{The Generic Package Containers.Ordered_Maps}), with the difference that
2201 the generic formal types Key_Type and Element_Type are indefinite.]}
2202 @end{Intro}
2203
2204 @begin{StaticSem}
2205
2206 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
2207 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
2208 @ChgAdded{Version=[2],Type=[Leading],Text=[The declaration of
2209 the generic library package
2210 Containers.Indefinite_Ordered_Maps@ChildUnit{Parent=[Ada.Containers],Child=[Indefinite_Ordered_Maps]}
2211 has the same contents @Chg{Version=[3],New=[and semantics ],Old=[]}as
2212 Containers.Ordered_Maps except:]}
2213
2214 @begin{Itemize}
2215 @ChgRef{Version=[2],Kind=[AddedNormal]}
2216 @ChgAdded{Version=[2],Text=[The generic formal Key_Type is indefinite.]}
2217
2218 @ChgRef{Version=[2],Kind=[AddedNormal]}
2219 @ChgAdded{Version=[2],Text=[The generic formal Element_Type is indefinite.]}
2220
2221 @ChgRef{Version=[2],Kind=[AddedNormal]}
2222 @ChgAdded{Version=[2],Keepnext=[T],Type=[Leading],Text=[The procedure with
2223 the profile:]}
2224 @begin{Example}
2225 @ChgRef{Version=[2],Kind=[AddedNormal]}
2226 @ChgAdded{Version=[2],Noprefix=[T],Keepnext=[T],Type=[Leading],Text=[@key{procedure} Insert (Container : @key{in out} Map;
2227 Key : @key{in} Key_Type;
2228 Position : @key{out} Cursor;
2229 Inserted : @key{out} Boolean);]}
2230 @end{Example}
2231 @ChgRef{Version=[2],Kind=[AddedNormal]}
2232 @ChgAdded{Version=[2],Noprefix=[T],Text=[is omitted.]}
2233
2234 @begin{Discussion}
2235 @ChgRef{Version=[2],Kind=[AddedNormal]}
2236 @ChgAdded{Version=[2],Text=[This procedure is omitted because there is no way
2237 to create a default-initialized object of an indefinite type. We considered
2238 having this routine insert an empty element similar to the empty elements of
2239 a vector, but rejected this possibility because the semantics are fairly
2240 complex and very different from the existing case. That would make it more
2241 error-prone to convert a container from a definite type to an indefinite
2242 type; by omitting the routine completely, any problems will be diagnosed by
2243 the compiler.]}
2244 @end{Discussion}
2245
2246 @ChgRef{Version=[2],Kind=[AddedNormal]}
2247 @ChgAdded{Version=[2],Text=[The actual Element parameter of access subprogram Process
2248 of Update_Element may be constrained even if Element_Type is unconstrained.]}
2249
2250 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
2251 @ChgAdded{Version=[4],Text=[The operations Include, Insert, Replace, and
2252 Replace_Element that have a formal parameter of type Element_Type perform
2253 indefinite insertion (see @RefSecNum{Containers}).]}
2254 @begin{Discussion}
2255 @ChgRef{Version=[4],Kind=[AddedNormal]}
2256 @ChgAdded{Version=[4],Text=[Some of the named operations also have a formal
2257 of the indefinite formal type Key_Type and perform indefinite insertion using
2258 that value, but it is sufficient to mention the formal of type Element_Type
2259 to cover those.]}
2260 @end{Discussion}
2261
2262 @end{Itemize}
2263 @end{StaticSem}
2264
2265 @begin{Extend95}
2266 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
2267 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2268 The generic package Containers.Indefinite_Ordered_Maps is new.]}
2269 @end{Extend95}
2270
2271 @begin{Inconsistent2012}
2272 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
2273 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
2274 Defined some routines to @ldquote@;perform indefinite insertion@rdquote.
2275 This could mean that some calls to those routines would now raise
2276 Program_Error where they previously worked. However, this is extremely
2277 unlikely; see @Inconsistent2012Title in
2278 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
2279 @end{Inconsistent2012}
2280
2281
2282 @LabeledAddedSubclause{Version=[2],Name=[The Generic Package Containers.Indefinite_Hashed_Sets]}
2283
2284 @begin{Intro}
2285 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
2286 @ChgAdded{Version=[2],Text=[The language-defined generic package
2287 Containers.Indefinite_Hashed_Sets provides a set with the same operations as
2288 the package Containers.Hashed_Sets
2289 (see @RefSecNum{The Generic Package Containers.Hashed_Sets}), with the difference
2290 that the generic formal type Element_Type is indefinite.]}
2291 @end{Intro}
2292
2293 @begin{StaticSem}
2294
2295 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
2296 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
2297 @ChgAdded{Version=[2],Type=[Leading],Text=[The declaration
2298 of the generic library package
2299 Containers.Indefinite_Hashed_Sets@ChildUnit{Parent=[Ada.Containers],Child=[Indefinite_Hashed_Sets]}
2300 has the same contents @Chg{Version=[3],New=[and semantics ],Old=[]}as
2301 Containers.Hashed_Sets except:]}
2302
2303 @begin{Itemize}
2304 @ChgRef{Version=[2],Kind=[AddedNormal]}
2305 @ChgAdded{Version=[2],Text=[The generic formal Element_Type is indefinite.]}
2306
2307 @ChgRef{Version=[2],Kind=[AddedNormal]}
2308 @ChgAdded{Version=[2],Text=[The actual Element parameter of access subprogram Process
2309 of Update_@!Element_@!Preserving_Key may be constrained even if Element_Type is
2310 unconstrained.]}
2311
2312 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
2313 @ChgAdded{Version=[4],Text=[The operations Include, Insert, Replace,
2314 Replace_Element, and To_Set that have a formal parameter of type Element_Type
2315 perform indefinite insertion (see @RefSecNum{Containers}).]}
2316 @begin{Ramification}
2317 @ChgRef{Version=[4],Kind=[AddedNormal]}
2318 @ChgAdded{Version=[4],Text=[This includes the procedure Replace declared in
2319 the nested generic package Generic_Keys, as well as the routines declared
2320 directly in the Containers.Indefinite_Hashed_Sets package.]}
2321 @end{Ramification}
2322 @end{Itemize}
2323 @end{StaticSem}
2324
2325 @begin{Extend95}
2326 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
2327 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2328 The generic package Containers.Indefinite_Hashed_Sets is new.]}
2329 @end{Extend95}
2330
2331 @begin{Inconsistent2012}
2332 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
2333 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
2334 Defined some routines to @ldquote@;perform indefinite insertion@rdquote.
2335 This could mean that some calls to those routines would now raise
2336 Program_Error where they previously worked. However, this is extremely
2337 unlikely; see @Inconsistent2012Title in
2338 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
2339 @end{Inconsistent2012}
2340
2341
2342 @LabeledAddedSubclause{Version=[2],Name=[The Generic Package Containers.Indefinite_Ordered_Sets]}
2343
2344 @begin{Intro}
2345 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
2346 @ChgAdded{Version=[2],Text=[The language-defined generic package
2347 Containers.Indefinite_Ordered_Sets provides a set with the same operations as
2348 the package Containers.Ordered_Sets
2349 (see @RefSecNum{The Generic Package Containers.Ordered_Sets}), with the difference
2350 that the generic formal type Element_Type is indefinite.]}
2351 @end{Intro}
2352
2353 @begin{StaticSem}
2354
2355 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
2356 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
2357 @ChgAdded{Version=[2],Type=[Leading],Text=[The declaration
2358 of the generic library package
2359 Containers.Indefinite_Ordered_Sets@ChildUnit{Parent=[Ada.Containers],Child=[Indefinite_Ordered_Sets]}
2360 has the same contents @Chg{Version=[3],New=[and semantics ],Old=[]}as
2361 Containers.Ordered_Sets except:]}
2362
2363 @begin{Itemize}
2364 @ChgRef{Version=[2],Kind=[AddedNormal]}
2365 @ChgAdded{Version=[2],Text=[The generic formal Element_Type is indefinite.]}
2366
2367 @ChgRef{Version=[2],Kind=[AddedNormal]}
2368 @ChgAdded{Version=[2],Text=[The actual Element parameter of access subprogram Process
2369 of Update_@!Element_@!Preserving_Key may be constrained even if Element_Type is
2370 unconstrained.]}
2371
2372 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
2373 @ChgAdded{Version=[4],Text=[The operations Include, Insert, Replace,
2374 Replace_Element, and To_Set that have a formal parameter of type Element_Type
2375 perform indefinite insertion (see @RefSecNum{Containers}).]}
2376 @begin{Ramification}
2377 @ChgRef{Version=[4],Kind=[AddedNormal]}
2378 @ChgAdded{Version=[4],Text=[This includes the procedure Replace declared in
2379 the nested generic package Generic_Keys, as well as the routines declared
2380 directly in the Containers.Indefinite_Ordered_Sets package.]}
2381 @end{Ramification}
2382 @end{Itemize}
2383 @end{StaticSem}
2384
2385 @begin{Extend95}
2386 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
2387 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2388 The generic package Containers.Indefinite_Ordered_Sets is new.]}
2389 @end{Extend95}
2390
2391 @begin{Inconsistent2012}
2392 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
2393 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
2394 Defined some routines to @ldquote@;perform indefinite insertion@rdquote.
2395 This could mean that some calls to those routines would now raise
2396 Program_Error where they previously worked. However, this is extremely
2397 unlikely; see @Inconsistent2012Title in
2398 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
2399 @end{Inconsistent2012}
2400
2401
2402 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Indefinite_Multiway_Trees]}
2403
2404 @begin{Intro}
2405 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
2406 @ChgAdded{Version=[3],Text=[The language-defined generic package
2407 Containers.Indefinite_Multiway_Trees
2408 provides a multiway tree with the same operations as the package
2409 Containers.Multiway_Trees (see @RefSecNum{The Generic Package Containers.Multiway_Trees}),
2410 with the difference that the generic formal Element_Type is indefinite.]}
2411 @end{Intro}
2412
2413 @begin{StaticSem}
2414
2415 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
2416 @ChgAdded{Version=[3],Type=[Leading],Text=[The declaration
2417 of the generic library package
2418 Containers.Indefinite_Multiway_Trees@ChildUnit{Parent=[Ada.Containers],Child=[Indefinite_Multiway_Trees]}
2419 has the same contents and semantics as
2420 Containers.Multiway_Trees except:]}
2421
2422 @begin{Itemize}
2423 @ChgRef{Version=[3],Kind=[AddedNormal]}
2424 @ChgAdded{Version=[3],Text=[The generic formal Element_Type is indefinite.]}
2425
2426 @ChgRef{Version=[3],Kind=[AddedNormal]}
2427 @ChgAdded{Version=[3],Keepnext=[T],Type=[Leading],Text=[The procedure with
2428 the profile:]}
2429 @begin{Example}
2430 @ChgRef{Version=[3],Kind=[AddedNormal]}
2431 @ChgAdded{Version=[3],Noprefix=[T],Keepnext=[T],Type=[Leading],Text=[@key{procedure} Insert_Child (Container : @key{in out} Tree;
2432 Parent : @key{in} Cursor;
2433 Before : @key{in} Cursor;
2434 Position : @key{out} Cursor;
2435 Count : @key{in} Count_Type := 1);]}
2436 @end{Example}
2437 @ChgRef{Version=[3],Kind=[AddedNormal]}
2438 @ChgAdded{Version=[3],Noprefix=[T],Text=[is omitted.]}
2439
2440 @begin{Discussion}
2441 @ChgRef{Version=[3],Kind=[AddedNormal]}
2442 @ChgAdded{Version=[3],Text=[This procedure is omitted because there is no way to create a
2443 default-initialized object of an indefinite type. We considered having this
2444 routine insert an empty element similar to the empty elements of a vector, but
2445 rejected this possibility because the semantics are fairly complex and very
2446 different from the existing case. That would make it more error-prone to convert
2447 a container from a definite type to an indefinite type; by omitting the routine
2448 completely, any problems will be diagnosed by the compiler.]}
2449 @end{Discussion}
2450
2451 @ChgRef{Version=[3],Kind=[AddedNormal]}
2452 @ChgAdded{Version=[3],Text=[The actual Element parameter of access subprogram
2453 Process of Update_Element may be constrained even if Element_Type is
2454 unconstrained.]}
2455
2456 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
2457 @ChgAdded{Version=[4],Text=[The operations Append_Child, Insert_Child,
2458 Prepend_Child, and Replace_Element that have a formal parameter of type
2459 Element_Type perform indefinite insertion (see @RefSecNum{Containers}).]}
2460
2461 @end{Itemize}
2462 @end{StaticSem}
2463
2464 @begin{Extend2005}
2465 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
2466 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
2467 The generic package Containers.Indefinite_Multiway_Trees is new.]}
2468 @end{Extend2005}
2469
2470 @begin{Inconsistent2012}
2471 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
2472 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
2473 Defined some routines to @ldquote@;perform indefinite insertion@rdquote.
2474 This could mean that some calls to those routines would now raise
2475 Program_Error where they previously worked. However, this is extremely
2476 unlikely; see @Inconsistent2012Title in
2477 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
2478 @end{Inconsistent2012}
2479
2480
2481 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Indefinite_Holders]}
2482
2483 @begin{Intro}
2484 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
2485 @ChgAdded{Version=[3],Text=[The language-defined generic package
2486 Containers.Indefinite_Holders provides a private type Holder and a set of
2487 operations for that type. A holder container holds a single element of an
2488 indefinite type.]}
2489
2490 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
2491 @ChgAdded{Version=[3],Text=[A holder container allows the declaration of an
2492 object that can be used like an uninitialized variable or component of an
2493 indefinite type.]}
2494
2495 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
2496 @ChgAdded{Version=[3],Text=[A holder container may be @i{empty}.
2497 An empty holder does not contain an element.@Defn{empty holder}]}
2498 @end{Intro}
2499
2500 @begin{StaticSem}
2501
2502 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
2503 @ChgAdded{Version=[3],KeepNext=[T],Type=[Leading],Text=[The generic library
2504 package Containers.Indefinite_Holders has the following declaration:]}
2505 @begin{Example}
2506 @ChgRef{Version=[3],Kind=[AddedNormal],Aref=[AI05-0069-1],Aref=[AI05-0084-1]}
2507 @ChgAdded{Version=[3],Text=[@key[generic]
2508 @key[type] Element_Type (<>) @key[is private];
2509 @key[with function] "=" (Left, Right : Element_Type) @key[return] Boolean @key[is] <>;
2510 @key[package] Ada.Containers.Indefinite_Holders @key[is]@ChildUnit{Parent=[Ada.Containers],Child=[Indefinite_Holders]}
2511 @key[pragma] Preelaborate(Indefinite_Holders);
2512 @key[pragma] Remote_Types(Indefinite_Holders);]}
2513
2514 @ChgRef{Version=[3],Kind=[AddedNormal]}
2515 @ChgAdded{Version=[3],Text=[ @key[type] @AdaTypeDefn{Holder} @key[is tagged private];
2516 @key[pragma] Preelaborable_Initialization (Holder);]}
2517
2518 @ChgRef{Version=[3],Kind=[AddedNormal]}
2519 @ChgAdded{Version=[3],Text=[ @AdaObjDefn{Empty_Holder} : @key[constant] Holder;]}
2520
2521 @ChgRef{Version=[3],Kind=[AddedNormal]}
2522 @ChgAdded{Version=[3],Text=[ @key[function] "=" (Left, Right : Holder) @key[return] Boolean;]}
2523
2524 @ChgRef{Version=[3],Kind=[AddedNormal]}
2525 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{To_Holder} (New_Item : Element_Type) @key[return] Holder;]}
2526
2527 @ChgRef{Version=[3],Kind=[AddedNormal]}
2528 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Is_Empty} (Container : Holder) @key[return] Boolean;]}
2529
2530 @ChgRef{Version=[3],Kind=[AddedNormal]}
2531 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Clear} (Container : @key[in out] Holder);]}
2532
2533 @ChgRef{Version=[3],Kind=[AddedNormal]}
2534 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Element} (Container : Holder) @key[return] Element_Type;]}
2535
2536 @ChgRef{Version=[3],Kind=[AddedNormal]}
2537 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Replace_Element} (Container : @key[in out] Holder;
2538 New_Item : @key[in] Element_Type);]}
2539
2540 @ChgRef{Version=[3],Kind=[AddedNormal]}
2541 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Query_Element}
2542 (Container : @key[in] Holder;
2543 Process : @key[not null access procedure] (Element : @key[in] Element_Type));]}
2544
2545 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0248-1]}
2546 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Update_Element}
2547 (Container : @key[in out] Holder;
2548 Process : @key[not null access procedure] (Element : @key[in out] Element_Type));]}
2549
2550 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
2551 @ChgAdded{Version=[3],Text=[ @key[type] @AdaTypeDefn{Constant_Reference_Type}
2552 (Element : @key[not null access constant] Element_Type) @key[is private]
2553 @key[with] Implicit_Dereference => Element;]}
2554
2555 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
2556 @ChgAdded{Version=[3],Text=[ @key[type] @AdaTypeDefn{Reference_Type} (Element : @key[not null access] Element_Type) @key[is private]
2557 @key[with] Implicit_Dereference => Element;]}
2558
2559 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
2560 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Constant_Reference} (Container : @key[aliased in] Holder)
2561 @key[return] Constant_Reference_Type;]}
2562
2563 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
2564 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Reference} (Container : @key[aliased in out] Holder)
2565 @key[return] Reference_Type;]}
2566
2567 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
2568 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Assign} (Target : @key[in out] Holder; Source : @key[in] Holder);]}
2569
2570 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
2571 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Copy} (Source : Holder) @key[return] Holder;]}
2572
2573 @ChgRef{Version=[3],Kind=[AddedNormal]}
2574 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Move} (Target : @key[in out] Holder; Source : @key[in out] Holder);]}
2575
2576 @ChgRef{Version=[3],Kind=[AddedNormal]}
2577 @ChgAdded{Version=[3],Text=[@key{private}]}
2578
2579 @ChgRef{Version=[3],Kind=[AddedNormal]}
2580 @ChgAdded{Version=[3],Text=[ ... -- @Examcom[not specified by the language]]}
2581
2582 @ChgRef{Version=[3],Kind=[AddedNormal]}
2583 @ChgAdded{Version=[3],Text=[@key{end} Ada.Containers.Indefinite_Holders;]}
2584
2585 @end{Example}
2586
2587 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
2588 @ChgAdded{Version=[3],Text=[The actual function for the generic formal
2589 function "=" on Element_Type values is expected to define a reflexive and
2590 symmetric relationship and return the same result value each time it is called
2591 with a particular pair of values. If it behaves in some other manner, the
2592 function "=" on holder values returns an unspecified value. The exact arguments
2593 and number of calls of this generic formal function by the function "=" on
2594 holder values are unspecified.]}
2595
2596 @begin{Ramification}
2597 @ChgRef{Version=[3],Kind=[AddedNormal]}
2598 @ChgAdded{Version=[3],Text=[If the actual function for "=" is not symmetric
2599 and consistent, the result returned by any of the functions defined to use
2600 "=" cannot be predicted. The implementation is not required to protect
2601 against "=" raising an exception, or returning random results, or any other
2602 "bad" behavior. And it can call "=" in whatever manner makes sense. But
2603 note that only the results of the function "=" is unspecified; other
2604 subprograms are not allowed to break if "=" is bad.]}
2605 @end{Ramification}
2606
2607 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
2608 @ChgAdded{Version=[3],Text=[The type Holder is used to represent holder
2609 containers. The type Holder needs finalization@PDefn2{Term=<needs finalization>,
2610 Sec=<language-defined type>}
2611 (see @RefSecNum{Assignment and Finalization}).]}
2612
2613 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
2614 @ChgAdded{Version=[3],Text=[Empty_Holder represents an empty holder object. If
2615 an object of type Holder is not otherwise initialized, it is initialized to the
2616 same value as Empty_Holder.]}
2617
2618 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0262-1]}
2619 @ChgAdded{Version=[3],Text=[@Redundant[Some operations of this generic package
2620 have access-to-subprogram parameters. To ensure such operations are
2621 well-defined, they guard against certain actions by the designated subprogram.
2622 In particular, some operations check for @ldquote@;tampering with
2623 the element@rdquote of a container because they depend on the element of the
2624 container not being replaced.]]}
2625
2626 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0262-1]}
2627 @ChgAdded{Version=[3],Type=[Leading],Text=[@Defn2{Term=[tamper with elements],Sec=[of a holder]}
2628 A subprogram is said to @i{tamper with the element} of a holder object @i<H> if:]}
2629
2630 @begin{Itemize}
2631 @ChgRef{Version=[3],Kind=[AddedNormal]}
2632 @ChgAdded{Version=[3],Text=[It clears the element contained by @i<H>, that is,
2633 it calls the Clear procedure with @i<H> as a parameter;]}
2634
2635 @ChgRef{Version=[3],Kind=[AddedNormal]}
2636 @ChgAdded{Version=[3],Text=[It replaces the element contained by @i<H>, that is,
2637 it calls the Replace_Element procedure with @i<H> as a parameter;]}
2638
2639 @ChgRef{Version=[3],Kind=[AddedNormal]}
2640 @ChgAdded{Version=[3],Text=[It calls the Move procedure with @i<H> as a parameter;]}
2641
2642 @ChgRef{Version=[3],Kind=[AddedNormal]}
2643 @ChgAdded{Version=[3],Text=[It finalizes @i<H>.]}
2644
2645 @begin{Reason}
2646 @ChgRef{Version=[3],Kind=[AddedNormal]}
2647 @ChgAdded{Version=[3],Text=[Complete replacement of an element can cause its
2648 memory to be deallocated while another operation is holding onto a reference
2649 to it. That can't be allowed. However, a simple modification of (part of) an
2650 element is not a problem, so Update_Element does not cause a problem.]}
2651 @end{Reason}
2652 @end{Itemize}
2653
2654 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
2655 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0110-1]}
2656 @ChgAdded{Version=[3],Text=[@Defn2{Term=[prohibited],Sec=[tampering with a holder]}
2657 @Defn2{Term=[tampering],Sec=[prohibited for a holder]}
2658 When tampering with the element is @i<prohibited> for a particular holder object
2659 @i<H>, Program_Error is propagated by a call of any language-defined subprogram
2660 that is defined to tamper with the element of @i<H>, leaving @i<H>
2661 unmodified.@Chg{Version=[4],New=[ These checks are made before any other
2662 defined behavior of the body of the language-defined subprogram.],Old=[]}]}
2663
2664 @begin{DescribeCode}
2665
2666 @begin{Example}
2667 @ChgRef{Version=[3],Kind=[AddedNormal]}
2668 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key{function} "=" (Left, Right : Holder) @key{return} Boolean;]}
2669 @end{Example}
2670
2671 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
2672 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Left and Right denote the same
2673 holder object, then the function returns True. Otherwise, it compares the
2674 element contained in Left to the element contained in Right using the
2675 generic formal equality operator, returning the result of that operation. Any
2676 exception raised during the evaluation of element equality is propagated.]}
2677
2678 @begin{ImplNote}
2679 @ChgRef{Version=[3],Kind=[AddedNormal]}
2680 @ChgAdded{Version=[3],Text=[This wording describes the canonical semantics.
2681 However, the order and number of calls on the formal equality @key[function]
2682 is unspecified, so an implementation need not call the equality function
2683 if the correct answer can be determined without doing so.]}
2684 @end{ImplNote}
2685
2686 @begin{Example}
2687 @ChgRef{Version=[3],Kind=[AddedNormal]}
2688 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] To_Holder (New_Item : Element_Type) @key[return] Holder;]}
2689 @end{Example}
2690
2691 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
2692 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0035-1]}
2693 @ChgAdded{Version=[3],Type=[Trailing],Text=[Returns a nonempty holder
2694 containing an element initialized to New_Item.@Chg{Version=[4],New=[
2695 To_Holder performs indefinite insertion (see @RefSecNum{Containers}).],Old=[]}]}
2696
2697 @begin{Example}
2698 @ChgRef{Version=[3],Kind=[AddedNormal]}
2699 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Is_Empty (Container : Holder) @key[return] Boolean;]}
2700 @end{Example}
2701
2702 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
2703 @ChgAdded{Version=[3],Type=[Trailing],Text=[Returns True if Container is
2704 empty, and False if it contains an element.]}
2705
2706 @begin{Example}
2707 @ChgRef{Version=[3],Kind=[AddedNormal]}
2708 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[procedure] Clear (Container : @key[in out] Holder);]}
2709 @end{Example}
2710
2711 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
2712 @ChgAdded{Version=[3],Type=[Trailing],Text=[Removes the element from Container.
2713 Container is empty after a successful Clear operation.]}
2714
2715 @begin{Example}
2716 @ChgRef{Version=[3],Kind=[AddedNormal]}
2717 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Element (Container : Holder) @key[return] Element_Type;]}
2718 @end{Example}
2719
2720 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
2721 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Container is empty,
2722 Constraint_Error is propagated. Otherwise, returns the element stored in
2723 Container.]}
2724
2725 @begin{Example}
2726 @ChgRef{Version=[3],Kind=[AddedNormal]}
2727 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[procedure] Replace_Element (Container : @key[in out] Holder;
2728 New_Item : @key[in] Element_Type);]}
2729 @end{Example}
2730
2731 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
2732 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0035-1]}
2733 @ChgAdded{Version=[3],Type=[Trailing],Text=[Replace_Element assigns the value
2734 New_Item into Container, replacing any preexisting content of
2735 Container@Chg{Version=[4],New=[; Replace_Element performs indefinite insertion
2736 (see @RefSecNum{Containers})],Old=[]}.
2737 Container is not empty after a successful call to Replace_Element.]}
2738
2739 @begin{Example}
2740 @ChgRef{Version=[3],Kind=[AddedNormal]}
2741 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[procedure] Query_Element
2742 (Container : @key[in] Holder;
2743 Process : @key[not null access procedure] (Element : @key[in] Element_Type));]}
2744 @end{Example}
2745
2746 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0262-1],ARef=[AI05-0265-1]}
2747 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Container is empty,
2748 Constraint_Error is propagated. Otherwise, Query_Element calls
2749 Process.@key[all] with the contained element as the argument.
2750 Tampering with the element
2751 of Container is prohibited during the execution of the call on
2752 Process.@key[all]. Any exception raised by Process.@key[all] is propagated.]}
2753
2754 @begin{ImplNote}
2755 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
2756 @ChgAdded{Version=[3],Text=[The @ldquote@;tamper with the element@rdquote
2757 check is intended to prevent the Element parameter of Process from being
2758 replaced or deleted outside of Process. The check prevents data loss (if
2759 Element_Type is passed by copy) or erroneous execution (if Element_Type is an
2760 unconstrained type).]}
2761 @end{ImplNote}
2762
2763 @begin{Example}
2764 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0248-1]}
2765 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[procedure] Update_Element
2766 (Container : @key[in out] Holder;
2767 Process : @key[not null access procedure] (Element : @key[in out] Element_Type));]}
2768 @end{Example}
2769
2770 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0262-1],ARef=[AI05-0265-1]}
2771 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Container is empty,
2772 Constraint_Error is propagated. Otherwise, Update_Element calls
2773 Process.@key[all] with the contained element as the argument.
2774 Tampering with the element
2775 of Container is prohibited during the execution of the call on Process.@key[all].
2776 Any exception raised by Process.@key[all] is propagated.]}
2777
2778 @begin{ImplNote}
2779 @ChgRef{Version=[3],Kind=[AddedNormal]}
2780 @ChgAdded{Version=[3],Text=[The Element parameter of Process.@key[all] may be
2781 constrained even if Element_Type is unconstrained.]}
2782 @end{ImplNote}
2783
2784 @begin{Example}
2785 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
2786 @ChgAdded{Version=[3],Text=[@key[type] Constant_Reference_Type
2787 (Element : @key[not null access constant] Element_Type) @key[is private]
2788 @key[with] Implicit_Dereference => Element;]}
2789
2790 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
2791 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[type] Reference_Type (Element : @key[not null access] Element_Type) @key[is private]
2792 @key[with] Implicit_Dereference => Element;]}
2793 @end{Example}
2794
2795 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
2796 @ChgAdded{Version=[3],Type=[Trailing],Text=[The types Constant_Reference_Type and Reference_Type
2797 need finalization.@PDefn2{Term=<needs finalization>,Sec=<language-defined type>}]}
2798
2799 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
2800 @ChgAdded{Version=[3],Text=[The default initialization of an object of type
2801 Constant_Reference_Type or Reference_Type propagates Program_Error.]}
2802
2803 @begin{Reason}
2804 @ChgRef{Version=[3],Kind=[AddedNormal]}
2805 @ChgAdded{Version=[3],Text=[It is expected that Reference_Type (and
2806 Constant_Reference_Type) will be a controlled type, for which finalization
2807 will have some action to terminate the tampering check for the associated
2808 container. If the object is created by default, however, there is no
2809 associated container. Since this is useless, and supporting this case would
2810 take extra work, we define it to raise an exception.]}
2811 @end{Reason}
2812
2813 @begin{Example}
2814 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
2815 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Constant_Reference (Container : @key[aliased in] Holder)
2816 @key[return] Constant_Reference_Type;]}
2817 @end{Example}
2818
2819 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
2820 @ChgAdded{Version=[3],Type=[Trailing],Text=[This function (combined with the
2821 Implicit_Dereference aspect) provides a convenient way to gain read access to
2822 the contained element of a holder container.]}
2823
2824 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0262-1],ARef=[AI05-0265-1]}
2825 @ChgAdded{Version=[3],Text=[If Container is empty, Constraint_Error is
2826 propagated. Otherwise, Constant_Reference returns an object whose discriminant
2827 is an access value that designates the contained element. Tampering with the
2828 elements of Container is prohibited while the object returned by
2829 Constant_Reference exists and has not been finalized.]}
2830
2831 @begin{Example}
2832 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
2833 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Reference (Container : @key[aliased in out] Holder)
2834 @key[return] Reference_Type;]}
2835 @end{Example}
2836
2837 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
2838 @ChgAdded{Version=[3],Type=[Trailing],Text=[This function (combined with the
2839 Implicit_Dereference aspects) provides a convenient way to gain read and write
2840 access to the contained element of a holder container.]}
2841
2842 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0262-1],ARef=[AI05-0265-1]}
2843 @ChgAdded{Version=[3],Text=[If Container is empty, Constraint_Error is
2844 propagated. Otherwise, Reference returns an object whose discriminant is an
2845 access value that designates the contained element. Tampering with the
2846 elements of Container is prohibited while the object returned by
2847 Reference exists and has not been finalized.]}
2848 @begin{Example}
2849 @ChgRef{Version=[3],Kind=[AddedNormal]}
2850 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[procedure] Assign (Target : @key[in out] Holder; Source : @key[in] Holder);]}
2851 @end{Example}
2852
2853 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
2854 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Target denotes the same object as
2855 Source, the operation has no effect. If Source is empty, Clear (Target) is
2856 called. Otherwise, Replace_Element (Target, Element (Source)) is called.]}
2857 @begin{Discussion}
2858 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
2859 @ChgAdded{Version=[3],Text=[This routine exists for compatibility with the
2860 other containers. For a holder, @exam{Assign(A, B)} and
2861 @exam{A := B} behave effectively the same. (Assign Clears the Target, while
2862 := finalizes the Target, but these should have similar effects.)]}
2863 @end{Discussion}
2864
2865 @begin{Example}
2866 @ChgRef{Version=[3],Kind=[AddedNormal]}
2867 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Copy (Source : Holder) @key[return] Holder;]}
2868 @end{Example}
2869
2870 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
2871 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Source is empty, returns an empty
2872 holder container; otherwise, returns To_Holder (Element (Source)).]}
2873
2874 @begin{Example}
2875 @ChgRef{Version=[3],Kind=[AddedNormal]}
2876 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[procedure] Move (Target : @key[in out] Holder; Source : @key[in out] Holder);]}
2877 @end{Example}
2878
2879 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0248-1]}
2880 @ChgAdded{Version=[3],Type=[Trailing],Text=[If Target denotes the same object
2881 as Source, then the operation has no effect. Otherwise, the element contained
2882 by Source (if any) is removed from Source and inserted into Target, replacing
2883 any preexisting content. Source is empty after a successful call to Move.]}
2884
2885 @end{DescribeCode}
2886
2887 @end{StaticSem}
2888
2889 @begin{Bounded}
2890
2891 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0022-1],ARef=[AI05-0069-1],ARef=[AI05-0248-1],ARef=[AI05-0262-1]}
2892 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
2893 It is a bounded error for the actual function associated with a
2894 generic formal subprogram, when called as part of an operation of
2895 this package, to tamper with the element of any Holder parameter of the
2896 operation. Either Program_Error is raised, or the operation works as
2897 defined on the value of the Holder either prior to, or subsequent to,
2898 some or all of the modifications to the Holder.]}
2899
2900 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0027-1],ARef=[AI05-0069-1]}
2901 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
2902 It is a bounded error to call any subprogram declared in the visible part
2903 of Containers.Indefinite_Holders when the associated container has been
2904 finalized. If the operation takes Container as an @key[in out] parameter,
2905 then it raises Constraint_Error or Program_Error. Otherwise, the operation
2906 either proceeds as it would for an empty container, or it raises
2907 Constraint_Error or Program_Error.]}
2908 @end{Bounded}
2909
2910 @begin{Erron}
2911 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1],ARef=[AI05-0269-1]}
2912 @ChgAdded{Version=[3],Text=[Execution is erroneous if the holder container
2913 associated with the result of a call to Reference or Constant_Reference is
2914 finalized before the result object returned by the call to Reference or
2915 Constant_Reference is finalized.@PDefn2{Term=(erroneous execution),Sec=(cause)}]}
2916
2917 @begin{Reason}
2918 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
2919 @ChgAdded{Version=[3],Text=[Each object of Reference_Type and
2920 Constant_Reference_Type probably contains some reference to the originating
2921 container. If that container is prematurely finalized (which is only possible
2922 via Unchecked_Deallocation, as accessibility checks prevent passing a
2923 container to Reference that will not live as long as the result), the
2924 finalization of the object of Reference_Type will try to access a nonexistent
2925 object. This is a normal case of a dangling pointer created by
2926 Unchecked_Deallocation; we have to explicitly mention it here as the pointer
2927 in question is not visible in the specification of the type. (This is the same
2928 reason we have to say this for invalid cursors.)]}
2929 @end{Reason}
2930 @end{Erron}
2931
2932 @begin{ImplReq}
2933
2934 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1]}
2935 @ChgAdded{Version=[3],Text=[No storage associated with a holder object shall be
2936 lost upon assignment or scope exit.]}
2937
2938 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0269-1]}
2939 @ChgAdded{Version=[3],Text=[The execution of an @nt{assignment_statement}
2940 for a holder container shall have the effect of copying the element (if any)
2941 from the source holder object to the target holder object.]}
2942
2943 @begin{ImplNote}
2944 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0298-1]}
2945 @ChgAdded{Version=[3],Text=[An assignment of a holder container is a
2946 @ldquote@;deep@rdquote copy; that is the element is copied as well as any
2947 data structures. We say @ldquote@;effect of@rdquote in order to allow the
2948 implementation to avoid copying the element immediately if it wishes. For
2949 instance, an implementation that avoided copying until one of the containers
2950 is modified would be allowed. (Note that this implementation would
2951 require care, see @RefSecNum{The Generic Package Containers.Vectors} for more.)]}
2952 @end{ImplNote}
2953 @end{ImplReq}
2954
2955 @begin{ImplAdvice}
2956
2957 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0269-1]}
2958 @ChgAdded{Version=[3],Text=[Move should not copy the element, and should minimize
2959 copying of internal data structures.]}
2960 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
2961 Text=[Containers.Indefinite_Holders.Move should not copy the element, and should
2962 minimize copying of internal data structures.]}]}
2963
2964 @begin{ImplNote}
2965 @ChgRef{Version=[3],Kind=[AddedNormal]}
2966 @ChgAdded{Version=[3],Text=[Usually that can be accomplished simply by moving
2967 the pointer(s) to the internal data structures from the Source holder to the
2968 Target holder.]}
2969 @end{ImplNote}
2970
2971 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0269-1]}
2972 @ChgAdded{Version=[3],Text=[If an exception is propagated from a holder
2973 operation, no storage should be lost, nor should the element be removed from a
2974 holder container unless specified by the operation.]}
2975 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
2976 Text=[If an exception is propagated from a holder
2977 operation, no storage should be lost, nor should the element be removed from a
2978 holder container unless specified by the operation.]}]}
2979
2980 @begin{Reason}
2981 @ChgRef{Version=[3],Kind=[AddedNormal]}
2982 @ChgAdded{Version=[3],Text=[This is important so that programs can recover
2983 from errors. But we don't want to require heroic efforts, so we just require
2984 documentation of cases where this can't be accomplished.]}
2985 @end{Reason}
2986 @end{ImplAdvice}
2987
2988 @begin{Extend2005}
2989 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0069-1],ARef=[AI05-0084-1],ARef=[AI05-0265-1]}
2990 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic package
2991 Containers.Indefinite_Holders is new.]}
2992 @end{Extend2005}
2993
2994 @begin{Inconsistent2012}
2995 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0035-1]}
2996 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
2997 Defined some routines to @ldquote@;perform indefinite insertion@rdquote.
2998 This could mean that some calls to those routines would now raise
2999 Program_Error where they previously worked. However, this is extremely
3000 unlikely; see @Inconsistent2012Title in
3001 @RefSecNum{The Generic Package Containers.Indefinite_Vectors} for details.]}
3002 @end{Inconsistent2012}
3003
3004 @begin{DiffWord2012}
3005 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0110-1]}
3006 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified that tampering checks
3007 precede all other checks made by a subprogram (but come after those associated
3008 with the call).]}
3009 @end{DiffWord2012}
3010
3011 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Vectors]}
3012
3013 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3014 @ChgAdded{Version=[3],Text=[The language-defined generic package
3015 Containers.Bounded_Vectors provides a private type Vector and a set of
3016 operations. It provides the same operations as the package Containers.Vectors
3017 (see @RefSecNum{The Generic Package Containers.Vectors}), with the difference that the
3018 maximum storage is bounded.]}
3019
3020 @begin{StaticSem}
3021
3022 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3023 @ChgAdded{Version=[3],Type=[Leading],Text=[The declaration of the generic
3024 library package Containers.Bounded_Vectors has the same contents and semantics
3025 as Containers.Vectors except:]}
3026
3027 @begin{Itemize}
3028 @ChgRef{Version=[3],Kind=[AddedNormal]}
3029 @ChgAdded{Version=[3],Text=[The @nt{pragma} Preelaborate is replaced with @nt{pragma} Pure.]}
3030
3031 @ChgRef{Version=[3],Kind=[AddedNormal]}
3032 @ChgAdded{Version=[3],Type=[Leading],Text=[The type Vector is declared with a
3033 discriminant that specifies the capacity:]}
3034 @begin{Example}
3035 @ChgRef{Version=[3],Kind=[AddedNormal]}
3036 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key{type} Vector (Capacity : Count_Type) @key[is tagged private];]}
3037 @end{Example}
3038
3039 @ChgRef{Version=[3],Kind=[AddedNormal]}
3040 @ChgAdded{Version=[3],Text=[The type Vector needs finalization if and only if
3041 type Element_Type needs finalization.]}
3042
3043 @begin{ImplNote}
3044 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
3045 @ChgAdded{Version=[3],Text=[The type Vector cannot depend on package
3046 Ada.Finalization unless the element type depends on that package.
3047 The objects returned from the Iterator and Reference functions probably do
3048 depend on package Ada.Finalization. Restricted environments may need to
3049 avoid use of those functions and their associated types.]}
3050 @end{ImplNote}
3051
3052 @ChgRef{Version=[3],Kind=[AddedNormal]}
3053 @ChgAdded{Version=[3],Text=[In function Copy, if the Capacity parameter is
3054 equal to or greater than the length of Source, the vector capacity exactly equals
3055 the value of the Capacity parameter.]}
3056
3057 @ChgRef{Version=[3],Kind=[AddedNormal]}
3058 @ChgAdded{Version=[3],Type=[Leading],Text=[The description of Reserve_Capacity
3059 is replaced with:]}
3060 @begin{Indent}
3061 @ChgRef{Version=[3],Kind=[AddedNormal]}
3062 @ChgAdded{Version=[3],NoPrefix=[T],Text=[If the specified Capacity is larger
3063 than the capacity of Container, then Reserve_Capacity propagates Capacity_Error.
3064 Otherwise, the operation has no effect.]}
3065 @end{Indent}
3066 @end{Itemize}
3067 @end{StaticSem}
3068
3069 @begin{Bounded}
3070 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0160-1],ARef=[AI05-0265-1]}
3071 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
3072 It is a bounded error to assign from a bounded vector object while tampering
3073 with elements @Redundant[or cursors] of that object is prohibited. Either
3074 Program_Error is raised by the assignment, execution proceeds with the target
3075 object prohibiting tampering with elements @Redundant[or cursors], or execution
3076 proceeds normally.]}
3077 @begin{TheProof}
3078 @ChgRef{Version=[3],Kind=[AddedNormal]}
3079 @ChgAdded{Version=[3],Text=[Tampering with elements includes tampering
3080 with cursors, so we only really need to talk about tampering with elements
3081 here; we mention cursors for clarity.]}
3082 @end{TheProof}
3083 @end{Bounded}
3084
3085 @begin{Erron}
3086 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
3087 @ChgAdded{Version=[3],Text=[When a bounded vector object @i<V> is
3088 finalized, if tampering with cursors is prohibited for @i<V> other than due
3089 to an assignment from another vector, then execution is erroneous.
3090 @PDefn2{Term=(erroneous execution),Sec=(cause)}]}
3091
3092 @begin{Reason}
3093 @ChgRef{Version=[3],Kind=[AddedNormal]}
3094 @ChgAdded{Version=[3],Text=[This is a tampering event, but since the
3095 implementation is not allowed to use Ada.Finalization, it is not possible in a
3096 pure Ada implementation to detect this error. (There is no Finalize routine
3097 that will be called that could make the check.) Since the check probably
3098 cannot be made, the bad effects that could occur (such as an iterator going
3099 into an infinite loop or accessing a nonexistent element) cannot be prevented
3100 and we have to allow anything. We do allow re-assigning an object that only
3101 prohibits tampering because it was copied from another object as that cannot
3102 cause any negative effects.]}
3103 @end{Reason}
3104 @end{Erron}
3105
3106 @begin{ImplReq}
3107 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0264-1]}
3108 @ChgAdded{Version=[3],Type=[Leading],Text=[For each instance of
3109 Containers.Vectors and each instance of Containers.Bounded_Vectors,
3110 if the two instances meet the following conditions,
3111 then the output generated by
3112 the Vector'Output or Vector'Write subprograms of either instance
3113 shall be readable by the Vector'Input
3114 or Vector'Read of the other instance, respectively:]}
3115
3116 @begin{Itemize}
3117 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0248-1]}
3118 @ChgAdded{Version=[3],Text=[the Element_Type parameters of the two instances
3119 are statically matching subtypes of the same type; and]}
3120
3121 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
3122 @ChgAdded{Version=[3],Text=[the output generated by Element_Type'Output or
3123 Element_Type'Write is readable by Element_Type'Input or Element_Type'Read,
3124 respectively (where Element_Type denotes the type of the two actual
3125 Element_Type parameters); and]}
3126
3127 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
3128 @ChgAdded{Version=[3],Text=[the preceding two conditions also hold for the
3129 Index_Type parameters of the instances.]}
3130 @end{Itemize}
3131 @end{ImplReq}
3132
3133 @begin{ImplAdvice}
3134 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3135 @ChgAdded{Version=[3],Text=[Bounded vector objects should be implemented without
3136 implicit pointers or dynamic allocation.]}
3137 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
3138 Text=[Bounded vector objects should be implemented without
3139 implicit pointers or dynamic allocation.]}]}
3140
3141 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3142 @ChgAdded{Version=[3],Text=[The implementation advice for procedure Move to
3143 minimize copying does not apply.]}
3144 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
3145 Text=[The implementation advice for procedure Move to
3146 minimize copying does not apply to bounded vectors.]}]}
3147
3148 @end{ImplAdvice}
3149
3150 @begin{Extend2005}
3151 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0160-1],ARef=[AI05-0184-1]}
3152 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic package
3153 Containers.Bounded_Vectors is new.]}
3154 @end{Extend2005}
3155
3156
3157 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Doubly_Linked_Lists]}
3158
3159 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3160 @ChgAdded{Version=[3],Text=[The language-defined generic package
3161 Containers.Bounded_Doubly_Linked_Lists provides a private type List
3162 and a set of operations. It provides the same operations as the
3163 package Containers.Doubly_Linked_Lists
3164 (see @RefSecNum{The Generic Package Containers.Doubly_Linked_Lists}), with the
3165 difference that the maximum storage is bounded.]}
3166
3167 @begin{StaticSem}
3168
3169 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3170 @ChgAdded{Version=[3],Type=[Leading],Text=[The declaration of the generic
3171 library package Containers.Bounded_Doubly_Linked_Lists has the same contents and semantics
3172 as Containers.Doubly_Linked_Lists except:]}
3173
3174 @begin{Itemize}
3175 @ChgRef{Version=[3],Kind=[AddedNormal]}
3176 @ChgAdded{Version=[3],Text=[The @nt{pragma} Preelaborate is replaced with @nt{pragma} Pure.]}
3177
3178 @ChgRef{Version=[3],Kind=[AddedNormal]}
3179 @ChgAdded{Version=[3],Type=[Leading],Text=[The type List is declared with a
3180 discriminant that specifies the capacity (maximum number of elements)
3181 as follows:]}
3182 @begin{Example}
3183 @ChgRef{Version=[3],Kind=[AddedNormal]}
3184 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key{type} List (Capacity : Count_Type) @key[is tagged private];]}
3185 @end{Example}
3186
3187 @ChgRef{Version=[3],Kind=[AddedNormal]}
3188 @ChgAdded{Version=[3],Text=[The type List needs finalization if and only if
3189 type Element_Type needs finalization.]}
3190
3191 @begin{ImplNote}
3192 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
3193 @ChgAdded{Version=[3],Text=[The type List cannot depend on package
3194 Ada.Finalization unless the element type depends on that package.
3195 The objects returned from the Iterator and Reference functions probably do
3196 depend on package Ada.Finalization. Restricted environments may need to
3197 avoid use of those functions and their associated types.]}
3198 @end{ImplNote}
3199
3200 @ChgRef{Version=[3],Kind=[AddedNormal]}
3201 @ChgAdded{Version=[3],Text=[The allocation of internal storage includes a
3202 check that the capacity is not exceeded, and Capacity_Error is raised
3203 if this check fails.]}
3204
3205 @ChgRef{Version=[3],Kind=[AddedNormal]}
3206 @ChgAdded{Version=[3],Text=[In procedure Assign, if Source length is greater
3207 than Target capacity, then Capacity_Error is propagated.]}
3208
3209 @ChgRef{Version=[3],Kind=[AddedNormal]}
3210 @ChgAdded{Version=[3],Type=[Leading],Text=[The function Copy is replaced with:]}
3211 @begin{Example}
3212 @ChgRef{Version=[3],Kind=[AddedNormal]}
3213 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[function] @AdaSubDefn{Copy} (Source : List; Capacity : Count_Type := 0)
3214 @key[return] List;]}
3215 @end{Example}
3216 @begin{Indent}
3217 @ChgRef{Version=[3],Kind=[AddedNormal]}
3218 @ChgAdded{Version=[3],Noprefix=[T],Text=[If Capacity is 0, then the list capacity is the length of
3219 Source; if Capacity is equal to or greater than the length of Source,
3220 the list capacity equals the value of the Capacity parameter;
3221 otherwise, the operation propagates Capacity_Error.]}
3222 @end{Indent}
3223
3224 @ChgRef{Version=[3],Kind=[AddedNormal]}
3225 @ChgAdded{Version=[3],Text=[In the three-parameter procedure Splice whose
3226 Source has type List, if the sum of the length of Target and the length
3227 of Source is greater than the capacity of Target, then Splice propagates
3228 Capacity_Error.]}
3229
3230 @ChgRef{Version=[3],Kind=[AddedNormal]}
3231 @ChgAdded{Version=[3],Text=[In the four-parameter procedure Splice, if
3232 the length of Target equals the capacity of Target, then Splice
3233 propagates Capacity_Error.]}
3234
3235 @end{Itemize}
3236 @end{StaticSem}
3237
3238 @begin{Bounded}
3239 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0160-1],ARef=[AI05-0265-1]}
3240 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
3241 It is a bounded error to assign from a bounded list object while tampering
3242 with elements @Redundant[or cursors] of that object is prohibited. Either
3243 Program_Error is raised by the assignment, execution proceeds with the target
3244 object prohibiting tampering with elements @Redundant[or cursors], or execution
3245 proceeds normally.]}
3246 @begin{TheProof}
3247 @ChgRef{Version=[3],Kind=[AddedNormal]}
3248 @ChgAdded{Version=[3],Text=[Tampering with elements includes tampering
3249 with cursors, so we only really need to talk about tampering with elements
3250 here; we mention cursors for clarity.]}
3251 @end{TheProof}
3252 @end{Bounded}
3253
3254 @begin{Erron}
3255 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
3256 @ChgAdded{Version=[3],Text=[When a bounded list object @i<L> is
3257 finalized, if tampering with cursors is prohibited for @i<L> other than due
3258 to an assignment from another list, then execution is erroneous.
3259 @PDefn2{Term=(erroneous execution),Sec=(cause)}]}
3260
3261 @begin{Reason}
3262 @ChgRef{Version=[3],Kind=[AddedNormal]}
3263 @ChgAdded{Version=[3],Text=[This is a tampering event, but since the
3264 implementation is not allowed to use Ada.Finalization, it is not possible in a
3265 pure Ada implementation to detect this error. (There is no Finalize routine
3266 that will be called that could make the check.) Since the check probably
3267 cannot be made, the bad effects that could occur (such as an iterator going
3268 into an infinite loop or accessing a nonexistent element) cannot be prevented
3269 and we have to allow anything. We do allow re-assigning an object that only
3270 prohibits tampering because it was copied from another object as that cannot
3271 cause any negative effects.]}
3272 @end{Reason}
3273 @end{Erron}
3274
3275
3276 @begin{ImplReq}
3277 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0264-1]}
3278 @ChgAdded{Version=[3],Type=[Leading],Text=[For each instance of
3279 Containers.Doubly_Linked_Lists and each instance of
3280 Containers.Bounded_Doubly_Linked_Lists,
3281 if the two instances meet the following conditions,
3282 then the output generated by
3283 the List'Output or List'Write subprograms of either instance
3284 shall be readable by the List'Input
3285 or List'Read of the other instance, respectively:]}
3286
3287 @begin{Itemize}
3288 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0248-1]}
3289 @ChgAdded{Version=[3],Text=[the Element_Type parameters of the two instances
3290 are statically matching subtypes of the same type; and]}
3291
3292 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
3293 @ChgAdded{Version=[3],Text=[the output generated by Element_Type'Output or
3294 Element_Type'Write is readable by Element_Type'Input or Element_Type'Read,
3295 respectively (where Element_Type denotes the type of the two actual
3296 Element_Type parameters).]}
3297 @end{Itemize}
3298 @end{ImplReq}
3299
3300 @begin{ImplAdvice}
3301 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3302 @ChgAdded{Version=[3],Text=[Bounded list objects should be implemented without
3303 implicit pointers or dynamic allocation.]}
3304 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
3305 Text=[Bounded list objects should be implemented without
3306 implicit pointers or dynamic allocation.]}]}
3307
3308 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3309 @ChgAdded{Version=[3],Text=[The implementation advice for procedure Move to
3310 minimize copying does not apply.]}
3311 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
3312 Text=[The implementation advice for procedure Move to
3313 minimize copying does not apply to bounded lists.]}]}
3314
3315 @end{ImplAdvice}
3316
3317 @begin{Extend2005}
3318 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0160-1],ARef=[AI05-0184-1]}
3319 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic package
3320 Containers.Bounded_Doubly_Linked_Lists is new.]}
3321 @end{Extend2005}
3322
3323
3324 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Hashed_Maps]}
3325
3326 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3327 @ChgAdded{Version=[3],Text=[The language-defined generic package
3328 Containers.Bounded_Hashed_Maps provides a private type Map
3329 and a set of operations. It provides the same operations as the
3330 package Containers.Hashed_Maps
3331 (see @RefSecNum{The Generic Package Containers.Hashed_Maps}), with the
3332 difference that the maximum storage is bounded.]}
3333
3334 @begin{StaticSem}
3335
3336 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3337 @ChgAdded{Version=[3],Type=[Leading],Text=[The declaration of the generic
3338 library package Containers.Bounded_Hashed_Maps has the same contents and semantics
3339 as Containers.Hashed_Maps except:]}
3340
3341 @begin{Itemize}
3342 @ChgRef{Version=[3],Kind=[AddedNormal]}
3343 @ChgAdded{Version=[3],Text=[The @nt{pragma} Preelaborate is replaced with @nt{pragma} Pure.]}
3344
3345 @ChgRef{Version=[3],Kind=[AddedNormal]}
3346 @ChgAdded{Version=[3],Type=[Leading],Text=[The type Map is declared with
3347 discriminants that specify both the capacity (number of elements) and
3348 modulus (number of distinct hash values) of the hash table as follows:]}
3349 @begin{Example}
3350 @ChgRef{Version=[3],Kind=[AddedNormal]}
3351 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[type] Map (Capacity : Count_Type;
3352 Modulus : Hash_Type) @key[is tagged private];]}
3353 @end{Example}
3354
3355 @ChgRef{Version=[3],Kind=[AddedNormal]}
3356 @ChgAdded{Version=[3],Text=[The type Map needs finalization if and only if type
3357 Key_Type or type Element_Type needs finalization.]}
3358
3359 @begin{ImplNote}
3360 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
3361 @ChgAdded{Version=[3],Text=[The type Map cannot depend on package
3362 Ada.Finalization unless the element or key type depends on that package.
3363 The objects returned from the Iterator and Reference functions probably do
3364 depend on package Ada.Finalization. Restricted environments may need to
3365 avoid use of those functions and their associated types.]}
3366 @end{ImplNote}
3367
3368 @ChgRef{Version=[3],Kind=[AddedNormal]}
3369 @ChgAdded{Version=[3],Type=[Leading],Text=[The description of Reserve_Capacity
3370 is replaced with:]}
3371 @begin{Indent}
3372 @ChgRef{Version=[3],Kind=[AddedNormal]}
3373 @ChgAdded{Version=[3],NoPrefix=[T],Text=[If the specified Capacity is larger
3374 than the capacity of Container, then Reserve_Capacity propagates Capacity_Error.
3375 Otherwise, the operation has no effect.]}
3376 @end{Indent}
3377
3378
3379 @ChgRef{Version=[3],Kind=[AddedNormal]}
3380 @ChgAdded{Version=[3],Type=[Leading],Text=[An additional operation is added immediately following Reserve_Capacity:]}
3381 @begin{Example}
3382 @ChgRef{Version=[3],Kind=[AddedNormal]}
3383 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[function] @AdaSubDefn{Default_Modulus} (Capacity : Count_Type) @key[return] Hash_Type;]}
3384 @end{Example}
3385 @begin{Indent}
3386 @ChgRef{Version=[3],Kind=[AddedNormal]}
3387 @ChgAdded{Version=[3],Noprefix=[T],Text=[Default_Modulus returns an
3388 implementation-defined value for the number of distinct hash values to be
3389 used for the given capacity (maximum number of elements).]}
3390 @end{Indent}
3391
3392 @ChgRef{Version=[3],Kind=[AddedNormal]}
3393 @ChgAdded{Version=[3],Type=[Leading],Text=[The function Copy is replaced with:]}
3394 @begin{Example}
3395 @ChgRef{Version=[3],Kind=[AddedNormal]}
3396 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[function] @AdaSubDefn{Copy} (Source : Map;
3397 Capacity : Count_Type := 0;
3398 Modulus : Hash_Type := 0) @key[return] Map;]}
3399 @end{Example}
3400 @begin{Indent}
3401 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0264-1]}
3402 @ChgAdded{Version=[3],Noprefix=[T],Text=[Returns a map with key/element pairs initialized from the values
3403 in Source. If Capacity is 0, then the map capacity is the
3404 length of Source; if Capacity is equal to or greater than
3405 the length of Source, the map capacity is the value of the Capacity
3406 parameter; otherwise, the operation propagates Capacity_Error. If
3407 the Modulus argument is 0, then the map modulus is the value
3408 returned by a call to Default_Modulus with the map capacity as its
3409 argument; otherwise, the map modulus is the value of the Modulus parameter.]}
3410 @end{Indent}
3411
3412 @end{Itemize}
3413 @end{StaticSem}
3414
3415 @begin{Bounded}
3416 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0160-1],ARef=[AI05-0265-1]}
3417 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
3418 It is a bounded error to assign from a bounded map object while tampering
3419 with elements @Redundant[or cursors] of that object is prohibited. Either
3420 Program_Error is raised by the assignment, execution proceeds with the target
3421 object prohibiting tampering with elements @Redundant[or cursors], or execution
3422 proceeds normally.]}
3423 @begin{TheProof}
3424 @ChgRef{Version=[3],Kind=[AddedNormal]}
3425 @ChgAdded{Version=[3],Text=[Tampering with elements includes tampering
3426 with cursors, so we only really need to talk about tampering with elements
3427 here; we mention cursors for clarity.]}
3428 @end{TheProof}
3429 @end{Bounded}
3430
3431 @begin{Erron}
3432 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
3433 @ChgAdded{Version=[3],Text=[When a bounded map object @i<M> is
3434 finalized, if tampering with cursors is prohibited for @i<M> other than due
3435 to an assignment from another map, then execution is erroneous.
3436 @PDefn2{Term=(erroneous execution),Sec=(cause)}]}
3437
3438 @begin{Reason}
3439 @ChgRef{Version=[3],Kind=[AddedNormal]}
3440 @ChgAdded{Version=[3],Text=[This is a tampering event, but since the
3441 implementation is not allowed to use Ada.Finalization, it is not possible in a
3442 pure Ada implementation to detect this error. (There is no Finalize routine
3443 that will be called that could make the check.) Since the check probably
3444 cannot be made, the bad effects that could occur (such as an iterator going
3445 into an infinite loop or accessing a nonexistent element) cannot be prevented
3446 and we have to allow anything. We do allow re-assigning an object that only
3447 prohibits tampering because it was copied from another object as that cannot
3448 cause any negative effects.]}
3449 @end{Reason}
3450 @end{Erron}
3451
3452 @begin{ImplReq}
3453 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0264-1]}
3454 @ChgAdded{Version=[3],Type=[Leading],Text=[For each instance of
3455 Containers.Hashed_Maps and each instance of Containers.Bounded_Hashed_Maps,
3456 if the two instances meet the following conditions,
3457 then the output generated by
3458 the Map'Output or Map'Write subprograms of either instance
3459 shall be readable by the Map'Input
3460 or Map'Read of the other instance, respectively:]}
3461
3462 @begin{Itemize}
3463 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0248-1]}
3464 @ChgAdded{Version=[3],Text=[the Element_Type parameters of the two instances
3465 are statically matching subtypes of the same type; and]}
3466
3467 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
3468 @ChgAdded{Version=[3],Text=[the output generated by Element_Type'Output or
3469 Element_Type'Write is readable by Element_Type'Input or Element_Type'Read,
3470 respectively (where Element_Type denotes the type of the two actual
3471 Element_Type parameters); and]}
3472
3473 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
3474 @ChgAdded{Version=[3],Text=[the preceding two conditions also hold for the
3475 Key_Type parameters of the instances.]}
3476 @end{Itemize}
3477 @end{ImplReq}
3478
3479 @begin{ImplAdvice}
3480 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0269-1]}
3481 @ChgAdded{Version=[3],Text=[Bounded hashed map objects should be implemented without
3482 implicit pointers or dynamic allocation.]}
3483 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
3484 Text=[Bounded hashed map objects should be implemented without
3485 implicit pointers or dynamic allocation.]}]}
3486
3487 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3488 @ChgAdded{Version=[3],Text=[The implementation advice for procedure Move to
3489 minimize copying does not apply.]}
3490 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
3491 Text=[The implementation advice for procedure Move to
3492 minimize copying does not apply to bounded hashed maps.]}]}
3493
3494 @end{ImplAdvice}
3495
3496 @begin{Extend2005}
3497 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0160-1],ARef=[AI05-0184-1]}
3498 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic package
3499 Containers.Bounded_Hashed_Maps is new.]}
3500 @end{Extend2005}
3501
3502
3503 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Ordered_Maps]}
3504
3505 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3506 @ChgAdded{Version=[3],Text=[The language-defined generic package
3507 Containers.Bounded_Ordered_Maps provides a private type Map
3508 and a set of operations. It provides the same operations as the
3509 package Containers.Ordered_Maps
3510 (see @RefSecNum{The Generic Package Containers.Ordered_Maps}), with the
3511 difference that the maximum storage is bounded.]}
3512
3513 @begin{StaticSem}
3514
3515 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3516 @ChgAdded{Version=[3],Type=[Leading],Text=[The declaration of the generic
3517 library package Containers.Bounded_Ordered_Maps has the same contents and semantics
3518 as Containers.Ordered_Maps except:]}
3519
3520 @begin{Itemize}
3521 @ChgRef{Version=[3],Kind=[AddedNormal]}
3522 @ChgAdded{Version=[3],Text=[The @nt{pragma} Preelaborate is replaced with @nt{pragma} Pure.]}
3523
3524 @ChgRef{Version=[3],Kind=[AddedNormal]}
3525 @ChgAdded{Version=[3],Type=[Leading],Text=[The type Map is declared with a
3526 discriminant that specifies the capacity (maximum number of elements)
3527 as follows:]}
3528 @begin{Example}
3529 @ChgRef{Version=[3],Kind=[AddedNormal]}
3530 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[type] Map (Capacity : Count_Type) @key[is tagged private];]}
3531 @end{Example}
3532
3533 @ChgRef{Version=[3],Kind=[AddedNormal]}
3534 @ChgAdded{Version=[3],Text=[The type Map needs finalization if and only if
3535 type Key_Type or type Element_Type needs finalization.]}
3536
3537 @begin{ImplNote}
3538 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
3539 @ChgAdded{Version=[3],Text=[The type Map cannot depend on package
3540 Ada.Finalization unless the element type depends on that package.
3541 The objects returned from the Iterator and Reference functions probably do
3542 depend on package Ada.Finalization. Restricted environments may need to
3543 avoid use of those functions and their associated types.]}
3544 @end{ImplNote}
3545
3546 @ChgRef{Version=[3],Kind=[AddedNormal]}
3547 @ChgAdded{Version=[3],Text=[The allocation of a new node includes a check that
3548 the capacity is not exceeded, and Capacity_Error is raised if this check
3549 fails.]}
3550
3551 @ChgRef{Version=[3],Kind=[AddedNormal]}
3552 @ChgAdded{Version=[3],Text=[In procedure Assign, if Source length is greater
3553 than Target capacity, then Capacity_Error is propagated.]}
3554
3555 @ChgRef{Version=[3],Kind=[AddedNormal]}
3556 @ChgAdded{Version=[3],Type=[Leading],Text=[The function Copy is replaced with:]}
3557 @begin{Example}
3558 @ChgRef{Version=[3],Kind=[AddedNormal]}
3559 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[function] @AdaSubDefn{Copy} (Source : Map;
3560 Capacity : Count_Type := 0) @key[return] Map;]}
3561 @end{Example}
3562 @begin{Indent}
3563 @ChgRef{Version=[3],Kind=[AddedNormal]}
3564 @ChgAdded{Version=[3],Noprefix=[T],Text=[Returns a map with key/element pairs
3565 initialized from the values in Source. If Capacity is 0, then the map
3566 capacity is the length of Source; if Capacity is equal to or greater than
3567 the length of Source, the map capacity is the specified value; otherwise, the
3568 operation propagates Capacity_Error.]}
3569 @end{Indent}
3570
3571 @end{Itemize}
3572 @end{StaticSem}
3573
3574 @begin{Bounded}
3575 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0160-1],ARef=[AI05-0265-1]}
3576 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
3577 It is a bounded error to assign from a bounded map object while tampering
3578 with elements @Redundant[or cursors] of that object is prohibited. Either
3579 Program_Error is raised by the assignment, execution proceeds with the target
3580 object prohibiting tampering with elements @Redundant[or cursors], or execution
3581 proceeds normally.]}
3582 @begin{TheProof}
3583 @ChgRef{Version=[3],Kind=[AddedNormal]}
3584 @ChgAdded{Version=[3],Text=[Tampering with elements includes tampering
3585 with cursors, so we only really need to talk about tampering with elements
3586 here; we mention cursors for clarity.]}
3587 @end{TheProof}
3588 @end{Bounded}
3589
3590 @begin{Erron}
3591 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
3592 @ChgAdded{Version=[3],Text=[When a bounded map object @i<M> is
3593 finalized, if tampering with cursors is prohibited for @i<M> other than due
3594 to an assignment from another map, then execution is erroneous.
3595 @PDefn2{Term=(erroneous execution),Sec=(cause)}]}
3596
3597 @begin{Reason}
3598 @ChgRef{Version=[3],Kind=[AddedNormal]}
3599 @ChgAdded{Version=[3],Text=[This is a tampering event, but since the
3600 implementation is not allowed to use Ada.Finalization, it is not possible in a
3601 pure Ada implementation to detect this error. (There is no Finalize routine
3602 that will be called that could make the check.) Since the check probably
3603 cannot be made, the bad effects that could occur (such as an iterator going
3604 into an infinite loop or accessing a nonexistent element) cannot be prevented
3605 and we have to allow anything. We do allow re-assigning an object that only
3606 prohibits tampering because it was copied from another object as that cannot
3607 cause any negative effects.]}
3608 @end{Reason}
3609 @end{Erron}
3610
3611 @begin{ImplReq}
3612 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0264-1]}
3613 @ChgAdded{Version=[3],Type=[Leading],Text=[For each instance of
3614 Containers.Ordered_Maps and each instance of Containers.Bounded_Ordered_Maps,
3615 if the two instances meet the following conditions,
3616 then the output generated by
3617 the Map'Output or Map'Write subprograms of either instance
3618 shall be readable by the Map'Input
3619 or Map'Read of the other instance, respectively:]}
3620
3621 @begin{Itemize}
3622 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0248-1]}
3623 @ChgAdded{Version=[3],Text=[the Element_Type parameters of the two instances
3624 are statically matching subtypes of the same type; and]}
3625
3626 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
3627 @ChgAdded{Version=[3],Text=[the output generated by Element_Type'Output or
3628 Element_Type'Write is readable by Element_Type'Input or Element_Type'Read,
3629 respectively (where Element_Type denotes the type of the two actual
3630 Element_Type parameters); and]}
3631
3632 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
3633 @ChgAdded{Version=[3],Text=[the preceding two conditions also hold for the
3634 Key_Type parameters of the instances.]}
3635 @end{Itemize}
3636 @end{ImplReq}
3637
3638 @begin{ImplAdvice}
3639 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0269-1]}
3640 @ChgAdded{Version=[3],Text=[Bounded ordered map objects should be implemented
3641 without implicit pointers or dynamic allocation.]}
3642 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
3643 Text=[Bounded ordered map objects should be implemented without
3644 implicit pointers or dynamic allocation.]}]}
3645
3646 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3647 @ChgAdded{Version=[3],Text=[The implementation advice for procedure Move to
3648 minimize copying does not apply.]}
3649 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
3650 Text=[The implementation advice for procedure Move to
3651 minimize copying does not apply to bounded ordered maps.]}]}
3652
3653 @end{ImplAdvice}
3654
3655 @begin{Extend2005}
3656 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0160-1],ARef=[AI05-0184-1]}
3657 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic package
3658 Containers.Bounded_Ordered_Maps is new.]}
3659 @end{Extend2005}
3660
3661
3662 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Hashed_Sets]}
3663
3664 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3665 @ChgAdded{Version=[3],Text=[The language-defined generic package
3666 Containers.Bounded_Hashed_Sets provides a private type Set
3667 and a set of operations. It provides the same operations as the
3668 package Containers.Hashed_Sets
3669 (see @RefSecNum{The Generic Package Containers.Hashed_Sets}), with the
3670 difference that the maximum storage is bounded.]}
3671
3672 @begin{StaticSem}
3673
3674 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3675 @ChgAdded{Version=[3],Type=[Leading],Text=[The declaration of the generic
3676 library package Containers.Bounded_Hashed_Sets has the same contents and semantics
3677 as Containers.Hashed_Sets except:]}
3678
3679 @begin{Itemize}
3680 @ChgRef{Version=[3],Kind=[AddedNormal]}
3681 @ChgAdded{Version=[3],Text=[The @nt{pragma} Preelaborate is replaced with @nt{pragma} Pure.]}
3682
3683 @ChgRef{Version=[3],Kind=[AddedNormal]}
3684 @ChgAdded{Version=[3],Type=[Leading],Text=[The type Set is declared with
3685 discriminants that specify both the capacity (number of elements) and
3686 modulus (number of distinct hash values) of the hash table as follows:]}
3687 @begin{Example}
3688 @ChgRef{Version=[3],Kind=[AddedNormal]}
3689 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[type] Set (Capacity : Count_Type;
3690 Modulus : Hash_Type) @key[is tagged private];]}
3691 @end{Example}
3692
3693 @ChgRef{Version=[3],Kind=[AddedNormal]}
3694 @ChgAdded{Version=[3],Text=[The type Set needs finalization if and only if
3695 type Element_Type needs finalization.]}
3696
3697 @begin{ImplNote}
3698 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
3699 @ChgAdded{Version=[3],Text=[The type Set cannot depend on package
3700 Ada.Finalization unless the element or key type depends on that package.
3701 The objects returned from the Iterator and Reference functions probably do
3702 depend on package Ada.Finalization. Restricted environments may need to
3703 avoid use of those functions and their associated types.]}
3704 @end{ImplNote}
3705
3706 @ChgRef{Version=[3],Kind=[AddedNormal]}
3707 @ChgAdded{Version=[3],Type=[Leading],Text=[The description of Reserve_Capacity
3708 is replaced with:]}
3709 @begin{Indent}
3710 @ChgRef{Version=[3],Kind=[AddedNormal]}
3711 @ChgAdded{Version=[3],NoPrefix=[T],Text=[If the specified Capacity is larger
3712 than the capacity of Container, then Reserve_Capacity propagates Capacity_Error.
3713 Otherwise, the operation has no effect.]}
3714 @end{Indent}
3715
3716 @ChgRef{Version=[3],Kind=[AddedNormal]}
3717 @ChgAdded{Version=[3],Type=[Leading],Text=[An additional operation is added immediately following Reserve_Capacity:]}
3718 @begin{Example}
3719 @ChgRef{Version=[3],Kind=[AddedNormal]}
3720 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[function] @AdaSubDefn{Default_Modulus} (Capacity : Count_Type) @key[return] Hash_Type;]}
3721 @end{Example}
3722 @begin{Indent}
3723 @ChgRef{Version=[3],Kind=[AddedNormal]}
3724 @ChgAdded{Version=[3],Noprefix=[T],Text=[Default_Modulus returns an
3725 implementation-defined value for the number of distinct hash values to be
3726 used for the given capacity (maximum number of elements).]}
3727 @end{Indent}
3728
3729 @ChgRef{Version=[3],Kind=[AddedNormal]}
3730 @ChgAdded{Version=[3],Type=[Leading],Text=[The function Copy is replaced with:]}
3731 @begin{Example}
3732 @ChgRef{Version=[3],Kind=[AddedNormal]}
3733 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[function] @AdaSubDefn{Copy} (Source : Set;
3734 Capacity : Count_Type := 0;
3735 Modulus : Hash_Type := 0) @key[return] Set;]}
3736 @end{Example}
3737 @begin{Indent}
3738 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0264-1]}
3739 @ChgAdded{Version=[3],Noprefix=[T],Text=[Returns a set whose elements are
3740 initialized from the values in Source. If Capacity is 0, then the set
3741 capacity is the length of Source; if Capacity is equal to or greater than
3742 the length of Source, the set capacity is the value of the Capacity parameter;
3743 otherwise, the operation propagates Capacity_Error. If the Modulus argument is
3744 0, then the set modulus is the value returned by a call to Default_Modulus
3745 with the set capacity as its argument; otherwise, the set modulus is the
3746 value of the Modulus parameter.]}
3747 @end{Indent}
3748
3749 @end{Itemize}
3750 @end{StaticSem}
3751
3752 @begin{Bounded}
3753 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0160-1],ARef=[AI05-0265-1]}
3754 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
3755 It is a bounded error to assign from a bounded set object while tampering
3756 with elements @Redundant[or cursors] of that object is prohibited. Either
3757 Program_Error is raised by the assignment, execution proceeds with the target
3758 object prohibiting tampering with elements @Redundant[or cursors], or execution
3759 proceeds normally.]}
3760 @begin{TheProof}
3761 @ChgRef{Version=[3],Kind=[AddedNormal]}
3762 @ChgAdded{Version=[3],Text=[Tampering with elements includes tampering
3763 with cursors, so we only really need to talk about tampering with elements
3764 here; we mention cursors for clarity.]}
3765 @end{TheProof}
3766 @end{Bounded}
3767
3768 @begin{Erron}
3769 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
3770 @ChgAdded{Version=[3],Text=[When a bounded set object @i<S> is
3771 finalized, if tampering with cursors is prohibited for @i<S> other than due
3772 to an assignment from another set, then execution is erroneous.
3773 @PDefn2{Term=(erroneous execution),Sec=(cause)}]}
3774
3775 @begin{Reason}
3776 @ChgRef{Version=[3],Kind=[AddedNormal]}
3777 @ChgAdded{Version=[3],Text=[This is a tampering event, but since the
3778 implementation is not allowed to use Ada.Finalization, it is not possible in a
3779 pure Ada implementation to detect this error. (There is no Finalize routine
3780 that will be called that could make the check.) Since the check probably
3781 cannot be made, the bad effects that could occur (such as an iterator going
3782 into an infinite loop or accessing a nonexistent element) cannot be prevented
3783 and we have to allow anything. We do allow re-assigning an object that only
3784 prohibits tampering because it was copied from another object as that cannot
3785 cause any negative effects.]}
3786 @end{Reason}
3787 @end{Erron}
3788
3789 @begin{ImplReq}
3790 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0264-1]}
3791 @ChgAdded{Version=[3],Type=[Leading],Text=[For each instance of
3792 Containers.Hashed_Sets and each instance of Containers.Bounded_Hashed_Sets,
3793 if the two instances meet the following conditions,
3794 then the output generated by
3795 the Set'Output or Set'Write subprograms of either instance
3796 shall be readable by the Set'Input
3797 or Set'Read of the other instance, respectively:]}
3798
3799 @begin{Itemize}
3800 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0248-1]}
3801 @ChgAdded{Version=[3],Text=[the Element_Type parameters of the two instances
3802 are statically matching subtypes of the same type; and]}
3803
3804 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
3805 @ChgAdded{Version=[3],Text=[the output generated by Element_Type'Output or
3806 Element_Type'Write is readable by Element_Type'Input or Element_Type'Read,
3807 respectively (where Element_Type denotes the type of the two actual
3808 Element_Type parameters).]}
3809 @end{Itemize}
3810 @end{ImplReq}
3811
3812 @begin{ImplAdvice}
3813 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0269-1]}
3814 @ChgAdded{Version=[3],Text=[Bounded hashed set objects should be implemented
3815 without implicit pointers or dynamic allocation.]}
3816 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
3817 Text=[Bounded hashed set objects should be implemented without
3818 implicit pointers or dynamic allocation.]}]}
3819
3820 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3821 @ChgAdded{Version=[3],Text=[The implementation advice for procedure Move to
3822 minimize copying does not apply.]}
3823 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
3824 Text=[The implementation advice for procedure Move to
3825 minimize copying does not apply to bounded hashed sets.]}]}
3826
3827 @end{ImplAdvice}
3828
3829 @begin{Extend2005}
3830 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0160-1],ARef=[AI05-0184-1]}
3831 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic package
3832 Containers.Bounded_Hashed_Sets is new.]}
3833 @end{Extend2005}
3834
3835
3836 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Ordered_Sets]}
3837
3838 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3839 @ChgAdded{Version=[3],Text=[The language-defined generic package
3840 Containers.Bounded_Ordered_Sets provides a private type Set
3841 and a set of operations. It provides the same operations as the
3842 package Containers.Ordered_Sets
3843 (see @RefSecNum{The Generic Package Containers.Ordered_Sets}), with the
3844 difference that the maximum storage is bounded.]}
3845
3846 @begin{StaticSem}
3847
3848 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3849 @ChgAdded{Version=[3],Type=[Leading],Text=[The declaration of the generic
3850 library package Containers.Bounded_Ordered_Sets has the same contents and semantics
3851 as Containers.Ordered_Sets except:]}
3852
3853 @begin{Itemize}
3854 @ChgRef{Version=[3],Kind=[AddedNormal]}
3855 @ChgAdded{Version=[3],Text=[The @nt{pragma} Preelaborate is replaced with @nt{pragma} Pure.]}
3856
3857 @ChgRef{Version=[3],Kind=[AddedNormal]}
3858 @ChgAdded{Version=[3],Type=[Leading],Text=[The type Set is declared with a
3859 discriminant that specifies the capacity (maximum number of elements)
3860 as follows:]}
3861 @begin{Example}
3862 @ChgRef{Version=[3],Kind=[AddedNormal]}
3863 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key{type} Set (Capacity : Count_Type) @key[is tagged private];]}
3864 @end{Example}
3865
3866 @ChgRef{Version=[3],Kind=[AddedNormal]}
3867 @ChgAdded{Version=[3],Text=[The type Set needs finalization if and only if
3868 type Element_Type needs finalization.]}
3869
3870 @begin{ImplNote}
3871 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
3872 @ChgAdded{Version=[3],Text=[The type Set cannot depend on package
3873 Ada.Finalization unless the element type depends on that package. The
3874 objects returned from the Iterator and Reference functions probably do
3875 depend on package Ada.Finalization. Restricted environments may need to
3876 avoid use of those functions and their associated types.]}
3877 @end{ImplNote}
3878
3879 @ChgRef{Version=[3],Kind=[AddedNormal]}
3880 @ChgAdded{Version=[3],Text=[If Insert (or Include) adds an element, a check is
3881 made that the capacity is not exceeded, and Capacity_Error is raised
3882 if this check fails.]}
3883
3884 @ChgRef{Version=[3],Kind=[AddedNormal]}
3885 @ChgAdded{Version=[3],Text=[In procedure Assign, if Source length is greater
3886 than Target capacity, then Capacity_Error is propagated.]}
3887
3888 @ChgRef{Version=[3],Kind=[AddedNormal]}
3889 @ChgAdded{Version=[3],Type=[Leading],Text=[The function Copy is replaced with:]}
3890 @begin{Example}
3891 @ChgRef{Version=[3],Kind=[AddedNormal]}
3892 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key[function] @AdaSubDefn{Copy} (Source : Set;
3893 Capacity : Count_Type := 0) @key[return] Set;]}
3894 @end{Example}
3895 @begin{Indent}
3896 @ChgRef{Version=[3],Kind=[AddedNormal]}
3897 @ChgAdded{Version=[3],Noprefix=[T],Text=[Returns a set whose elements
3898 are initialized from the values in Source. If Capacity is 0, then the set
3899 capacity is the length of Source; if Capacity is equal to or greater than
3900 the length of Source, the set capacity is the specified value; otherwise, the
3901 operation propagates Capacity_Error.]}
3902 @end{Indent}
3903
3904 @end{Itemize}
3905 @end{StaticSem}
3906
3907 @begin{Bounded}
3908 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0160-1],ARef=[AI05-0265-1]}
3909 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
3910 It is a bounded error to assign from a bounded set object while tampering
3911 with elements @Redundant[or cursors] of that object is prohibited. Either
3912 Program_Error is raised by the assignment, execution proceeds with the target
3913 object prohibiting tampering with elements @Redundant[or cursors], or execution
3914 proceeds normally.]}
3915 @begin{TheProof}
3916 @ChgRef{Version=[3],Kind=[AddedNormal]}
3917 @ChgAdded{Version=[3],Text=[Tampering with elements includes tampering
3918 with cursors, so we only really need to talk about tampering with elements
3919 here; we mention cursors for clarity.]}
3920 @end{TheProof}
3921 @end{Bounded}
3922
3923 @begin{Erron}
3924 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
3925 @ChgAdded{Version=[3],Text=[When a bounded set object @i<S> is
3926 finalized, if tampering with cursors is prohibited for @i<S> other than due
3927 to an assignment from another set, then execution is erroneous.
3928 @PDefn2{Term=(erroneous execution),Sec=(cause)}]}
3929
3930 @begin{Reason}
3931 @ChgRef{Version=[3],Kind=[AddedNormal]}
3932 @ChgAdded{Version=[3],Text=[This is a tampering event, but since the
3933 implementation is not allowed to use Ada.Finalization, it is not possible in a
3934 pure Ada implementation to detect this error. (There is no Finalize routine
3935 that will be called that could make the check.) Since the check probably
3936 cannot be made, the bad effects that could occur (such as an iterator going
3937 into an infinite loop or accessing a nonexistent element) cannot be prevented
3938 and we have to allow anything. We do allow re-assigning an object that only
3939 prohibits tampering because it was copied from another object as that cannot
3940 cause any negative effects.]}
3941 @end{Reason}
3942 @end{Erron}
3943
3944 @begin{ImplReq}
3945 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0264-1]}
3946 @ChgAdded{Version=[3],Type=[Leading],Text=[For each instance of
3947 Containers.Ordered_Sets and each instance of Containers.Bounded_Ordered_Sets,
3948 if the two instances meet the following conditions,
3949 then the output generated by
3950 the Set'Output or Set'Write subprograms of either instance
3951 shall be readable by the Set'Input
3952 or Set'Read of the other instance, respectively:]}
3953
3954 @begin{Itemize}
3955 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0248-1]}
3956 @ChgAdded{Version=[3],Text=[the Element_Type parameters of the two instances
3957 are statically matching subtypes of the same type; and]}
3958
3959 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
3960 @ChgAdded{Version=[3],Text=[the output generated by Element_Type'Output or
3961 Element_Type'Write is readable by Element_Type'Input or Element_Type'Read,
3962 respectively (where Element_Type denotes the type of the two actual
3963 Element_Type parameters).]}
3964 @end{Itemize}
3965 @end{ImplReq}
3966
3967 @begin{ImplAdvice}
3968 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0269-1]}
3969 @ChgAdded{Version=[3],Text=[Bounded ordered set objects should be implemented
3970 without implicit pointers or dynamic allocation.]}
3971 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
3972 Text=[Bounded ordered set objects should be implemented without
3973 implicit pointers or dynamic allocation.]}]}
3974
3975 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1]}
3976 @ChgAdded{Version=[3],Text=[The implementation advice for procedure Move to
3977 minimize copying does not apply.]}
3978 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
3979 Text=[The implementation advice for procedure Move to
3980 minimize copying does not apply to bounded ordered sets.]}]}
3981
3982 @end{ImplAdvice}
3983
3984 @begin{Extend2005}
3985 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0160-1],ARef=[AI05-0184-1]}
3986 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic package
3987 Containers.Bounded_Ordered_Sets is new.]}
3988 @end{Extend2005}
3989
3990
3991 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Multiway_Trees]}
3992
3993 @begin{Intro}
3994 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
3995 @ChgAdded{Version=[3],Text=[The language-defined generic package
3996 Containers.Bounded_Multiway_Trees provides a private type Tree and a set of
3997 operations. It provides the same operations as the package
3998 Containers.Multiway_Trees (see
3999 @RefSecNum{The Generic Package Containers.Multiway_Trees}), with the difference
4000 that the maximum storage is bounded.]}
4001
4002 @end{Intro}
4003
4004 @begin{StaticSem}
4005
4006 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
4007 @ChgAdded{Version=[3],Type=[Leading],Text=[The declaration of the generic
4008 library package Containers.Bounded_Multiway_Trees has the same contents and
4009 semantics as Containers.Multiway_Trees except:]}
4010
4011 @begin{Itemize}
4012 @ChgRef{Version=[3],Kind=[AddedNormal]}
4013 @ChgAdded{Version=[3],Text=[The @nt{pragma} Preelaborate is replaced with @nt{pragma} Pure.]}
4014
4015 @ChgRef{Version=[3],Kind=[AddedNormal]}
4016 @ChgAdded{Version=[3],Type=[Leading],Text=[The type Tree is declared with a
4017 discriminant that specifies the capacity (maximum number of elements)
4018 as follows:]}
4019 @begin{Example}
4020 @ChgRef{Version=[3],Kind=[AddedNormal]}
4021 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key{type} Tree (Capacity : Count_Type) @key[is tagged private];]}
4022 @end{Example}
4023
4024 @ChgRef{Version=[3],Kind=[AddedNormal]}
4025 @ChgAdded{Version=[3],Text=[The type Tree needs finalization if and only if
4026 type Element_Type needs finalization.]}
4027
4028 @begin{ImplNote}
4029 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
4030 @ChgAdded{Version=[3],Text=[The type Tree cannot depend on package
4031 Ada.Finalization unless the element type depends on that package. The
4032 objects returned from the Iterator and Reference functions probably do
4033 depend on package Ada.Finalization. Restricted environments may need to
4034 avoid use of those functions and their associated types.]}
4035 @end{ImplNote}
4036
4037 @ChgRef{Version=[3],Kind=[AddedNormal]}
4038 @ChgAdded{Version=[3],Text=[The allocation of internal storage includes a
4039 check that the capacity is not exceeded, and Capacity_Error is raised if
4040 this check fails.]}
4041
4042 @ChgRef{Version=[3],Kind=[AddedNormal]}
4043 @ChgAdded{Version=[3],Text=[In procedure Assign, if Source length is greater
4044 than Target capacity, then Capacity_Error is propagated.]}
4045
4046 @ChgRef{Version=[3],Kind=[AddedNormal]}
4047 @ChgAdded{Version=[3],Type=[Leading],Text=[Function Copy is declared as follows:]}
4048 @begin{Example}
4049 @ChgRef{Version=[3],Kind=[AddedNormal]}
4050 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0056-1]}
4051 @ChgAdded{Version=[3],Noprefix=[T],Text=[ @key{function} Copy (Source : Tree; Capacity : Count_Type := 0)
4052 @key{return} @Chg{Version=[4],New=[Tree],Old=[List]};]}
4053 @end{Example}
4054
4055 @ChgRef{Version=[3],Kind=[AddedNormal]}
4056 @ChgAdded{Version=[3],Noprefix=[T],Text=[If Capacity is 0, then the tree
4057 capacity is the count of Source; if Capacity is equal to or greater than
4058 Source.Count, the tree capacity equals the value of the Capacity parameter;
4059 otherwise, the operation propagates Capacity_Error.]}
4060
4061 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
4062 @ChgAdded{Version=[3],Text=[In the five-parameter procedure Splice_Subtree, if
4063 Source is not the same object as Target, and if the sum of Target.Count and
4064 Subtree_Node_Count (Position) is greater than Target.Capacity, then
4065 Splice_Subtree propagates Capacity_Error.]}
4066
4067 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0248-1]}
4068 @ChgAdded{Version=[3],Text=[In the five-parameter procedure Splice_Children,
4069 if Source is not the same object as Target, and if the sum of Target.Count
4070 and Subtree_Node_Count (Source_Parent)-1 is greater than Target.Capacity,
4071 then Splice_Children propagates Capacity_Error.]}
4072 @end{Itemize}
4073 @end{StaticSem}
4074
4075 @begin{Bounded}
4076 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0160-1],ARef=[AI05-0265-1]}
4077 @ChgAdded{Version=[3],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
4078 It is a bounded error to assign from a bounded tree object while tampering
4079 with elements @Redundant[or cursors] of that object is prohibited. Either
4080 Program_Error is raised by the assignment, execution proceeds with the target
4081 object prohibiting tampering with elements @Redundant[or cursors], or execution
4082 proceeds normally.]}
4083 @begin{TheProof}
4084 @ChgRef{Version=[3],Kind=[AddedNormal]}
4085 @ChgAdded{Version=[3],Text=[Tampering with elements includes tampering
4086 with cursors, so we only really need to talk about tampering with elements
4087 here; we mention cursors for clarity.]}
4088 @end{TheProof}
4089 @end{Bounded}
4090
4091 @begin{Erron}
4092 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0265-1]}
4093 @ChgAdded{Version=[3],Text=[When a bounded tree object @i<T> is
4094 finalized, if tampering with cursors is prohibited for @i<T> other than due
4095 to an assignment from another tree, then execution is erroneous.
4096 @PDefn2{Term=(erroneous execution),Sec=(cause)}]}
4097
4098 @begin{Reason}
4099 @ChgRef{Version=[3],Kind=[AddedNormal]}
4100 @ChgAdded{Version=[3],Text=[This is a tampering event, but since the
4101 implementation is not allowed to use Ada.Finalization, it is not possible in a
4102 pure Ada implementation to detect this error. (There is no Finalize routine
4103 that will be called that could make the check.) Since the check probably
4104 cannot be made, the bad effects that could occur (such as an iterator going
4105 into an infinite loop or accessing a nonexistent element) cannot be prevented
4106 and we have to allow anything. We do allow re-assigning an object that only
4107 prohibits tampering because it was copied from another object as that cannot
4108 cause any negative effects.]}
4109 @end{Reason}
4110 @end{Erron}
4111
4112 @begin{ImplReq}
4113 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0264-1]}
4114 @ChgAdded{Version=[3],Type=[Leading],Text=[For each instance of
4115 Containers.Multiway_Trees and each instance of Containers.Bounded_Multiway_Trees,
4116 if the two instances meet the following conditions,
4117 then the output generated by
4118 the Tree'Output or Tree'Write subprograms of either instance
4119 shall be readable by the Tree'Input
4120 or Tree'Read of the other instance, respectively:]}
4121
4122 @begin{Itemize}
4123 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1],ARef=[AI05-0248-1]}
4124 @ChgAdded{Version=[3],Text=[the Element_Type parameters of the two instances
4125 are statically matching subtypes of the same type; and]}
4126
4127 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0184-1]}
4128 @ChgAdded{Version=[3],Text=[the output generated by Element_Type'Output or
4129 Element_Type'Write is readable by Element_Type'Input or Element_Type'Read,
4130 respectively (where Element_Type denotes the type of the two actual
4131 Element_Type parameters).]}
4132 @end{Itemize}
4133 @end{ImplReq}
4134
4135 @begin{ImplAdvice}
4136 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
4137 @ChgAdded{Version=[3],Text=[Bounded tree objects should be implemented without
4138 implicit pointers or dynamic allocation.]}
4139 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
4140 Text=[Bounded tree objects should be implemented without
4141 implicit pointers or dynamic allocation.]}]}
4142
4143 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1]}
4144 @ChgAdded{Version=[3],Text=[The implementation advice for procedure Move to
4145 minimize copying does not apply.]}
4146 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
4147 Text=[The implementation advice for procedure Move to
4148 minimize copying does not apply to bounded trees.]}]}
4149 @end{ImplAdvice}
4150
4151
4152 @begin{Extend2005}
4153 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0136-1],ARef=[AI05-0184-1]}
4154 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
4155 The generic package Containers.Bounded_Multiway_Trees is new.]}
4156 @end{Extend2005}
4157
4158
4159 @RMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
4160 @LabeledAddedSubclause{Version=[2],Name=[Array Sorting]}
4161
4162 @begin{Intro}
4163 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4164 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0001-1]}
4165 @ChgAdded{Version=[2],Text=[The language-defined generic procedures
4166 Containers.@!Generic_@!Array_Sort@Chg{Version=[3],New=[,],Old=[ and]}
4167 Containers.@!Generic_@!Constrained_@!Array_Sort@Chg{Version=[3],New=[, and
4168 Containers.@!Generic_Sort],Old=[]}
4169 provide sorting on arbitrary array types.]}
4170 @end{Intro}
4171
4172 @begin{StaticSem}
4173
4174 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4175 @ChgAdded{Version=[2],KeepNext=[T],Type=[Leading],Text=[The generic library
4176 procedure Containers.Generic_Array_Sort has the following declaration:]}
4177 @begin{Example}
4178 @ChgRef{Version=[2],Kind=[AddedNormal]}
4179 @ChgAdded{Version=[2],Text=[@key{generic}
4180 @key{type} Index_Type @key{is} (<>);
4181 @key{type} Element_Type @key{is private};
4182 @key{type} Array_Type @key{is array} (Index_Type @key{range} <>) @key{of} Element_Type;
4183 @key{with function} "<" (Left, Right : Element_Type)
4184 @key{return} Boolean @key{is} <>;
4185 @key{procedure} Ada.Containers.Generic_Array_Sort (Container : @key{in out} Array_Type);@SubChildUnit{Parent=[Ada.Containers],Child=[Generic_Array_Sort]}
4186 @key{pragma} Pure(Ada.Containers.Generic_Array_Sort);]}
4187 @end{Example}
4188
4189 @begin{DescribeCode}
4190 @ChgRef{Version=[2],Kind=[AddedNormal]}
4191 @ChgAdded{Version=[2],Text=[Reorders the elements of Container such that the elements are
4192 sorted smallest first as determined by the generic formal "<" operator
4193 provided. Any exception raised during evaluation of "<" is propagated.]}
4194
4195 @ChgRef{Version=[2],Kind=[AddedNormal]}
4196 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0044-1],ARef=[AI05-0262-1]}
4197 @ChgAdded{Version=[2],Text=[The actual function for the generic formal function
4198 "<" of Generic_Array_Sort is expected to return the same value each time it is
4199 called with a particular pair of element values. It should define a strict
4200 @Chg{Version=[3],New=[weak ],Old=[]}ordering relationship@Chg{Version=[3],
4201 New=[ (see @RefSecNum{Containers})],Old=[, that is, be irreflexive, asymmetric,
4202 and transitive]}; it
4203 should not modify Container. If the actual for "<" behaves in some other
4204 manner, the behavior of the instance of Generic_Array_Sort is unspecified.
4205 @Chg{Version=[3],New=[The number of],Old=[How many]}
4206 times Generic_Array_Sort calls "<" is unspecified.@PDefn{unspecified}]}
4207
4208 @begin{Ramification}
4209 @ChgRef{Version=[2],Kind=[AddedNormal]}
4210 @ChgAdded{Version=[2],Text=[This implies swapping the elements, usually
4211 including an intermediate copy. This of course means that the elements will be
4212 copied. Since the elements are nonlimited, this usually will not be a problem.
4213 Note that there is Implementation Advice below that the implementation should
4214 use a sort that minimizes copying of elements.]}
4215
4216 @ChgRef{Version=[2],Kind=[AddedNormal]}
4217 @ChgAdded{Version=[2],Text=[The sort is not required to be stable (and the fast
4218 algorithm required will not be stable). If a stable sort is needed, the user
4219 can include the original location of the element as an extra "sort key". We
4220 considered requiring the implementation to do that, but it is mostly extra
4221 overhead -- usually there is something already in the element that provides the
4222 needed stability.]}
4223 @end{Ramification}
4224
4225 @end{DescribeCode}
4226
4227 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4228 @ChgAdded{Version=[2],KeepNext=[T],Type=[Leading],Text=[The generic library
4229 procedure Containers.@!Generic_@!Constrained_@!Array_Sort has the following
4230 declaration:]}
4231 @begin{Example}
4232 @ChgRef{Version=[2],Kind=[AddedNormal]}
4233 @ChgAdded{Version=[2],Text=[@key{generic}
4234 @key{type} Index_Type @key{is} (<>);
4235 @key{type} Element_Type @key{is private};
4236 @key{type} Array_Type @key{is array} (Index_Type) @key{of} Element_Type;
4237 @key{with function} "<" (Left, Right : Element_Type)
4238 @key{return} Boolean @key{is} <>;
4239 @key{procedure} Ada.Containers.Generic_Constrained_Array_Sort@SubChildUnit{Parent=[Ada.Containers],Child=[Generic_Constrained_Array_Sort]}
4240 (Container : @key{in out} Array_Type);
4241 @key{pragma} Pure(Ada.Containers.Generic_Constrained_Array_Sort);]}
4242 @end{Example}
4243
4244 @begin{DescribeCode}
4245 @ChgRef{Version=[2],Kind=[AddedNormal]}
4246 @ChgAdded{Version=[2],Text=[Reorders the elements of Container such that the
4247 elements are sorted smallest first as determined by the generic formal "<"
4248 operator provided. Any exception raised during evaluation of "<" is
4249 propagated.]}
4250
4251 @ChgRef{Version=[2],Kind=[AddedNormal]}
4252 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0044-1],ARef=[AI05-0262-1]}
4253 @ChgAdded{Version=[2],Text=[The actual function for the generic formal function
4254 "<" of Generic_Constrained_Array_Sort is expected to return the same value each
4255 time it is called with a particular pair of element values. It should define a
4256 strict @Chg{Version=[3],New=[weak ],Old=[]}ordering relationship@Chg{Version=[3],
4257 New=[ (see @RefSecNum{Containers})],Old=[, that is, be irreflexive, asymmetric,
4258 and transitive]}; it should not modify Container. If the actual for "<" behaves in
4259 some other manner, the behavior of the instance of
4260 Generic_Constrained_Array_Sort is unspecified. @Chg{Version=[3],New=[The number
4261 of],Old=[How many]} times Generic_Constrained_Array_Sort calls "<" is
4262 unspecified.@PDefn{unspecified}]}
4263
4264 @end{DescribeCode}
4265
4266 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0001-1]}
4267 @ChgAdded{Version=[3],KeepNext=[T],Type=[Leading],Text=[The generic library
4268 procedure Containers.@!Generic_@!Sort has the following declaration:]}
4269 @begin{Example}
4270 @ChgRef{Version=[3],Kind=[Added]}
4271 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0056-1]}
4272 @ChgAdded{Version=[3],Text=[@key{generic}
4273 @key{type} Index_Type @key{is} (<>);
4274 @key{with function} Before (Left, Right : Index_Type) @key{return} Boolean;
4275 @key{with procedure} Swap (Left, Right : @Chg{Version=[4],New=[@key[in] ],Old=[]}Index_Type);
4276 @key{procedure} Ada.Containers.Generic_Sort@SubChildUnit{Parent=[Ada.Containers],Child=[Generic_Sort]}
4277 (First, Last : Index_Type'Base);
4278 @key{pragma} Pure(Ada.Containers.Generic_Sort);]}
4279 @end{Example}
4280
4281 @begin{DescribeCode}
4282 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0001-1],ARef=[AI05-0248-1]}
4283 @ChgAdded{Version=[3],Text=[Reorders the elements of an indexable structure,
4284 over the range First .. Last, such that the elements are sorted in the ordering
4285 determined by the generic formal function Before; Before should return True if
4286 Left is to be sorted before Right. The generic formal Before
4287 compares the elements having the given indices, and the generic formal Swap
4288 exchanges the values of the indicated elements. Any exception raised during
4289 evaluation of Before or Swap is propagated.]}
4290
4291 @ChgRef{Version=[3],Kind=[Added]}
4292 @ChgAdded{Version=[3],Text=[The actual function for the generic formal function Before of
4293 Generic_Sort is expected to return the same value each time it is
4294 called with index values that identify a particular pair of element values.
4295 It should define a strict weak ordering relationship (see @RefSecNum{Containers});
4296 it should not modify the elements. The actual function for the generic formal
4297 Swap should exchange the values of the indicated elements. If the actual for
4298 either Before or Swap behaves in some other manner, the behavior of
4299 Generic_Sort is unspecified. The number of times the Generic_Sort calls Before
4300 or Swap is unspecified.@PDefn{unspecified}]}
4301
4302 @end{DescribeCode}
4303
4304 @end{StaticSem}
4305
4306 @begin{ImplAdvice}
4307
4308 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4309 @ChgAdded{Version=[2],Text=[
4310 The worst-case time complexity of a call on an instance of
4311 Containers.Generic_Array_Sort or
4312 Containers.Generic_Constrained_Array_Sort should be @i{O}(@i<N>**2) or better,
4313 and the average time complexity should be better
4314 than @i{O}(@i<N>**2), where @i<N> is the length of the Container parameter.]}
4315 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
4316 Text=[Containers.Generic_Array_Sort and Containers.Generic_Constrained_Array_Sort
4317 should have an average time complexity better than @i{O}(@i{N}**2) and worst case no
4318 worse than @i{O}(@i{N}**2).]}]}
4319
4320 @begin{Discussion}
4321 @ChgRef{Version=[2],Kind=[AddedNormal]}
4322 @ChgAdded{Version=[2],Text=[In other words, we're requiring the use of
4323 a sorting algorithm better than @i{O}(@i<N>**2), such as Quicksort. No bubble
4324 sorts allowed!]}
4325 @end{Discussion}
4326
4327 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4328 @ChgAdded{Version=[2],Text=[
4329 Containers.Generic_Array_Sort and Containers.Generic_Constrained_Array_Sort
4330 should minimize copying of elements.]}
4331 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
4332 Text=[Containers.Generic_Array_Sort and Containers.Generic_Constrained_Array_Sort
4333 should minimize copying of elements.]}]}
4334
4335 @begin{Honest}
4336 @ChgRef{Version=[2],Kind=[AddedNormal]}
4337 @ChgAdded{Version=[2],Text=[We do not mean @lquotes@;absolutely minimize@rquotes@;
4338 here; we're not intending to require a single copy for each element. Rather,
4339 we want to suggest that the sorting algorithm chosen is one that does not
4340 copy items unnecessarily. Bubble sort would not meet this advice, for
4341 instance.]}
4342 @end{Honest}
4343
4344 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0248-1]}
4345 @ChgAdded{Version=[3],Text=[
4346 The worst-case time complexity of a call on an instance of
4347 Containers.Generic_Sort should be @i{O}(@i<N>**2) or better,
4348 and the average time complexity should be better
4349 than @i{O}(@i<N>**2), where @i<N> is the difference between the Last and First
4350 parameters plus 1.]}
4351 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
4352 Text=[Containers.Generic_Sort
4353 should have an average time complexity better than @i{O}(@i{N}**2) and worst case no
4354 worse than @i{O}(@i{N}**2).]}]}
4355
4356 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0248-1]}
4357 @ChgAdded{Version=[3],Text=[Containers.Generic_Sort
4358 should minimize calls to the generic formal Swap.]}
4359 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
4360 Text=[Containers.Generic_Sort should minimize calls to the generic formal Swap.]}]}
4361 @end{ImplAdvice}
4362
4363 @begin{Extend95}
4364 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00302-03]}
4365 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
4366 The generic procedures Containers.Generic_Array_Sort and
4367 Containers.Generic_Constrained_Array_Sort are new.]}
4368 @end{Extend95}
4369
4370 @begin{Extend2005}
4371 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0001-1],ARef=[AI05-0248-1]}
4372 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic
4373 procedure Containers.Generic_Sort is new.]}
4374 @end{Extend2005}
4375
4376 @begin{DiffWord2005}
4377 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0044-1]}
4378 @ChgAdded{Version=[3],Text=[@b<Correction:> Redefined "<" actuals
4379 to require a strict weak ordering; the old definition allowed
4380 indeterminant comparisons that would not have worked in a sort.]}
4381 @end{DiffWord2005}
4382
4383
4384
4385 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Synchronized_Queue_Interfaces]}
4386
4387 @begin{Intro}
4388 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4389 @ChgAdded{Version=[3],Text=[The language-defined generic package
4390 Containers.Synchronized_Queue_Interfaces provides interface type Queue, and a
4391 set of operations for that type. Interface Queue specifies a first-in, first-out
4392 queue.]}
4393 @end{Intro}
4394
4395 @begin{StaticSem}
4396 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4397 @ChgAdded{Version=[3],KeepNext=[T],Type=[Leading],Text=[The generic library
4398 package Containers.Synchronized_Queue_Interfaces has the following declaration:]}
4399 @begin{Example}
4400 @ChgRef{Version=[3],Kind=[AddedNormal]}
4401 @ChgAdded{Version=[3],Text=[@key[generic]
4402 @key[type] Element_Type @key[is private];
4403 @key[package] Ada.Containers.Synchronized_Queue_Interfaces @key[is]@ChildUnit{Parent=[Ada.Containers],Child=[Synchronized_Queue_Interfaces]}
4404 @key[pragma] Pure(Synchronized_Queue_Interfaces);]}
4405
4406 @ChgRef{Version=[3],Kind=[AddedNormal]}
4407 @ChgAdded{Version=[3],Text=[ @key[type] @AdaTypeDefn{Queue} @key[is synchronized interface];]}
4408
4409 @ChgRef{Version=[3],Kind=[AddedNormal]}
4410 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Enqueue}
4411 (Container : @key[in out] Queue;
4412 New_Item : @key[in] Element_Type) @key[is abstract]
4413 @key[with] Synchronization => By_Entry;]}
4414
4415 @ChgRef{Version=[3],Kind=[AddedNormal]}
4416 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Dequeue}
4417 (Container : @key[in out] Queue;
4418 Element : @key[out] Element_Type) @key[is abstract]
4419 @key[with] Synchronization => By_Entry;]}
4420
4421 @ChgRef{Version=[3],Kind=[AddedNormal]}
4422 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Current_Use} (Container : Queue) @key[return] Count_Type @key[is abstract];
4423 @key[function] @AdaSubDefn{Peak_Use} (Container : Queue) @key[return] Count_Type @key[is abstract];]}
4424
4425 @ChgRef{Version=[3],Kind=[AddedNormal]}
4426 @ChgAdded{Version=[3],Text=[@key{end} Ada.Containers.Synchronized_Queue_Interfaces;]}
4427 @end{Example}
4428
4429 @begin{DescribeCode}
4430
4431 @begin{Example}
4432 @ChgRef{Version=[3],Kind=[AddedNormal]}
4433 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[procedure] Enqueue
4434 (Container : @key[in out] Queue;
4435 New_Item : @key[in] Element_Type) @key[is abstract];]}
4436 @end{Example}
4437
4438 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0262-1],ARef=[AI05-0264-1]}
4439 @ChgAdded{Version=[3],Type=[Trailing],Text=[A queue type that implements this
4440 interface is allowed to have a bounded @i<capacity>@Defn2{Term=[capacity],Sec=[of a queue]}.
4441 If the queue object has a bounded
4442 capacity, and the number of existing elements equals the capacity, then Enqueue
4443 blocks until storage becomes available; otherwise, Enqueue does not block. In any
4444 case, it then copies New_Item onto the queue.]}
4445
4446 @begin{Example}
4447 @ChgRef{Version=[3],Kind=[AddedNormal]}
4448 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[procedure] Dequeue
4449 (Container : @key[in out] Queue;
4450 Element : @key[out] Element_Type) @key[is abstract];]}
4451 @end{Example}
4452
4453 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0251-1]}
4454 @ChgAdded{Version=[3],Type=[Trailing],Text=[If the queue is empty, then Dequeue
4455 blocks until an item becomes available. In any case, it then assigns the
4456 element at the head of the queue to Element, and removes it from the queue.]}
4457
4458 @begin{Example}
4459 @ChgRef{Version=[3],Kind=[AddedNormal]}
4460 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Current_Use (Container : Queue) @key[return] Count_Type @key[is abstract];]}
4461 @end{Example}
4462
4463 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4464 @ChgAdded{Version=[3],Type=[Trailing],Text=[Returns the number of elements
4465 currently in the queue.]}
4466
4467 @begin{Example}
4468 @ChgRef{Version=[3],Kind=[AddedNormal]}
4469 @ChgAdded{Version=[3],KeepNext=[T],Text=[@key[function] Peak_Use (Container : Queue) @key[return] Count_Type @key[is abstract];]}
4470 @end{Example}
4471
4472 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4473 @ChgAdded{Version=[3],Type=[Trailing],Text=[Returns the maximum number of
4474 elements that have been in the queue at any one time.]}
4475
4476 @end{DescribeCode}
4477
4478 @end{StaticSem}
4479
4480 @begin{Notes}
4481 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0251-1]}
4482 @ChgAdded{Version=[3],Text=[Unlike other language-defined containers, there are
4483 no queues whose element types are indefinite. Elements of an indefinite type can
4484 be handled by defining the element of the queue to be a holder container (see
4485 @RefSecNum{The Generic Package Containers.Indefinite_Holders}) of the indefinite
4486 type, or to be an explicit access type that designates the indefinite type.]}
4487
4488 @begin{Reason}
4489 @ChgRef{Version=[3],Kind=[AddedNormal]}
4490 @ChgAdded{Version=[3],Text=[There are no indefinite queues, as a useful
4491 definition for Dequeue is not possible. Dequeue cannot be a function, as Ada
4492 does not have entries that are functions (thus conditional and timed calls
4493 would not be possible). Moreover, protected functions do not allow modifying
4494 the queue object (thus it doesn't work even if we decided we didn't care about
4495 conditional and timed calls). If Dequeue is an entry, then the dequeued object
4496 would have to be an @key[out] parameter and that would require the queue client to
4497 guess the tag and constraints of the value that will be dequeued (otherwise
4498 Constraint_Error would be raised), and that is rarely going to be possible.]}
4499 @end{Reason}
4500 @end{Notes}
4501
4502 @begin{Extend2005}
4503 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0251-1]}
4504 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic
4505 package Containers.Synchronized_Queue_Interfaces is new.]}
4506 @end{Extend2005}
4507
4508
4509 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Unbounded_Synchronized_Queues]}
4510
4511 @begin{StaticSem}
4512 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4513 @ChgAdded{Version=[3],Text=[The language-defined generic package
4514 Containers.Unbounded_Synchronized_Queues provides type Queue, which implements
4515 the interface type Containers.Synchronized_Queue_Interfaces.Queue.]}
4516
4517 @begin{Example}
4518 @ChgRef{Version=[3],Kind=[AddedNormal]}
4519 @ChgAdded{Version=[3],Text=[@key[with] System;
4520 @key[with] Ada.Containers.Synchronized_Queue_Interfaces;
4521 @key[generic]
4522 @key[with package] Queue_Interfaces @key[is new] Ada.Containers.Synchronized_Queue_Interfaces (<>);
4523 Default_Ceiling : System.Any_Priority := System.Priority'Last;
4524 @key[package] Ada.Containers.Unbounded_Synchronized_Queues @key[is]@ChildUnit{Parent=[Ada.Containers],Child=[Unbounded_Synchronized_Queues]}
4525 @key[pragma] Preelaborate(Unbounded_Synchronized_Queues);]}
4526
4527 @ChgRef{Version=[3],Kind=[AddedNormal]}
4528 @ChgAdded{Version=[3],Text=[ @key[package] Implementation @key[is]
4529 ... -- @Examcom[not specified by the language]
4530 @key[end] Implementation;]}
4531
4532 @ChgRef{Version=[3],Kind=[AddedNormal]}
4533 @ChgAdded{Version=[3],Text=[ @key[protected type] @AdaTypeDefn{Queue}
4534 (Ceiling : System.Any_Priority := Default_Ceiling)
4535 @key[with] Priority => Ceiling @key[is]
4536 @key[new] Queue_Interfaces.Queue @key[with]]}
4537
4538 @ChgRef{Version=[3],Kind=[AddedNormal]}
4539 @ChgAdded{Version=[3],Text=[ @key[overriding]
4540 @key[entry] @AdaSubDefn{Enqueue} (New_Item : @key[in] Queue_Interfaces.Element_Type);
4541 @key[overriding]
4542 @key[entry] @AdaSubDefn{Dequeue} (Element : @key[out] Queue_Interfaces.Element_Type);]}
4543
4544 @ChgRef{Version=[3],Kind=[AddedNormal]}
4545 @ChgAdded{Version=[3],Text=[ @key[overriding]
4546 @key[function] @AdaSubDefn{Current_Use} @key[return] Count_Type;
4547 @key[overriding]
4548 @key[function] @AdaSubDefn{Peak_Use} @key[return] Count_Type;]}
4549
4550 @ChgRef{Version=[3],Kind=[AddedNormal]}
4551 @ChgAdded{Version=[3],Text=[ @key[private]
4552 ... -- @Examcom[not specified by the language]
4553 @key[end] Queue;]}
4554
4555 @ChgRef{Version=[3],Kind=[AddedNormal]}
4556 @ChgAdded{Version=[3],Text=[@key{private}]}
4557
4558 @ChgRef{Version=[3],Kind=[AddedNormal]}
4559 @ChgAdded{Version=[3],Text=[ ... -- @Examcom[not specified by the language]]}
4560
4561 @ChgRef{Version=[3],Kind=[AddedNormal]}
4562 @ChgAdded{Version=[3],Text=[@key{end} Ada.Containers.Unbounded_Synchronized_Queues;]}
4563 @end{Example}
4564
4565 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4566 @ChgAdded{Version=[3],Text=[The type Queue is used to represent task-safe
4567 queues.]}
4568
4569 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4570 @ChgAdded{Version=[3],Text=[The capacity for instances of type Queue is
4571 unbounded.]}
4572
4573 @begin{Ramification}
4574 @ChgRef{Version=[3],Kind=[AddedNormal]}
4575 @ChgAdded{Version=[3],Text=[Enqueue never blocks; if more storage is needed
4576 for a new element, it is allocated dynamically. We don't need to explicitly
4577 specify that Queue needs finalization, because it is visibly protected.]}
4578 @end{Ramification}
4579
4580 @begin{Discussion}
4581 @ChgRef{Version=[3],Kind=[AddedNormal]}
4582 @ChgAdded{Version=[3],Text=[Nested package Implementation can be used to
4583 declare the types needed to implement the protected type Queue. This
4584 nested package is necessary as types cannot be declared in the private
4585 part of a protected type, and the types have to be declared within the
4586 generic unit in order to depend on the types imported with package
4587 Queue_Interfaces. Clients should never depend on the contents of
4588 nested package Implementation.]}
4589 @end{Discussion}
4590
4591 @end{StaticSem}
4592
4593 @begin{Extend2005}
4594 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4595 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic
4596 package Containers.Unbounded_Synchronized_Queues is new.]}
4597 @end{Extend2005}
4598
4599
4600
4601 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Synchronized_Queues]}
4602
4603 @begin{StaticSem}
4604 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4605 @ChgAdded{Version=[3],Text=[The language-defined generic package
4606 Containers.Bounded_Synchronized_Queues provides type Queue, which implements
4607 the interface type Containers.Synchronized_Queue_Interfaces.Queue.]}
4608
4609 @begin{Example}
4610 @ChgRef{Version=[3],Kind=[AddedNormal]}
4611 @ChgAdded{Version=[3],Text=[@key[with] System;
4612 @key[with] Ada.Containers.Synchronized_Queue_Interfaces;
4613 @key[generic]
4614 @key[with package] Queue_Interfaces @key[is new] Ada.Containers.Synchronized_Queue_Interfaces (<>);
4615 Default_Capacity : Count_Type;
4616 Default_Ceiling : System.Any_Priority := System.Priority'Last;
4617 @key[package] Ada.Containers.Bounded_Synchronized_Queues @key[is]@ChildUnit{Parent=[Ada.Containers],Child=[Bounded_Synchronized_Queues]}
4618 @key[pragma] Preelaborate(Bounded_Synchronized_Queues);]}
4619
4620 @ChgRef{Version=[3],Kind=[AddedNormal]}
4621 @ChgAdded{Version=[3],Text=[ @key[package] Implementation @key[is]
4622 ... -- @Examcom[not specified by the language]
4623 @key[end] Implementation;]}
4624
4625 @ChgRef{Version=[3],Kind=[AddedNormal]}
4626 @ChgAdded{Version=[3],Text=[ @key[protected type] @AdaTypeDefn{Queue}
4627 (Capacity : Count_Type := Default_Capacity;
4628 Ceiling : System.Any_Priority := Default_Ceiling)
4629 @key[with] Priority => Ceiling @key[is]
4630 @key[new] Queue_Interfaces.Queue @key[with]]}
4631
4632 @ChgRef{Version=[3],Kind=[AddedNormal]}
4633 @ChgAdded{Version=[3],Text=[ @key[overriding]
4634 @key[entry] @AdaSubDefn{Enqueue} (New_Item : @key[in] Queue_Interfaces.Element_Type);
4635 @key[overriding]
4636 @key[entry] @AdaSubDefn{Dequeue} (Element : @key[out] Queue_Interfaces.Element_Type);]}
4637
4638 @ChgRef{Version=[3],Kind=[AddedNormal]}
4639 @ChgAdded{Version=[3],Text=[ @key[overriding]
4640 @key[function] @AdaSubDefn{Current_Use} @key[return] Count_Type;
4641 @key[overriding]
4642 @key[function] @AdaSubDefn{Peak_Use} @key[return] Count_Type;]}
4643
4644 @ChgRef{Version=[3],Kind=[AddedNormal]}
4645 @ChgAdded{Version=[3],Text=[ @key[private]
4646 ... -- @Examcom[not specified by the language]
4647 @key[end] Queue;]}
4648
4649 @ChgRef{Version=[3],Kind=[AddedNormal]}
4650 @ChgAdded{Version=[3],Text=[@key{private}]}
4651
4652 @ChgRef{Version=[3],Kind=[AddedNormal]}
4653 @ChgAdded{Version=[3],Text=[ ... -- @Examcom[not specified by the language]]}
4654
4655 @ChgRef{Version=[3],Kind=[AddedNormal]}
4656 @ChgAdded{Version=[3],Text=[@key{end} Ada.Containers.Bounded_Synchronized_Queues;]}
4657 @end{Example}
4658
4659 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4660 @ChgAdded{Version=[3],Keepnext=[T],Type=[Leading],Text=[The semantics are the
4661 same as for Unbounded_Synchronized_Queues, except:]}
4662
4663 @begin{Itemize}
4664 @ChgRef{Version=[3],Kind=[AddedNormal]}
4665 @ChgAdded{Version=[3],Text=[The capacity for instances of type Queue is
4666 bounded and specified by the discriminant Capacity.]}
4667 @end{Itemize}
4668
4669 @begin{Ramification}
4670 @ChgRef{Version=[3],Kind=[AddedNormal]}
4671 @ChgAdded{Version=[3],Text=[Since this type has a bounded capacity, Enqueue
4672 might block if the queue is full.]}
4673 @end{Ramification}
4674
4675 @end{StaticSem}
4676
4677 @begin{ImplAdvice}
4678 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4679 @ChgAdded{Version=[3],Text=[Bounded queue objects should be implemented without
4680 implicit pointers or dynamic allocation.]}
4681 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
4682 Text=[Bounded queue objects should be implemented without
4683 implicit pointers or dynamic allocation.]}]}
4684 @end{ImplAdvice}
4685
4686
4687 @begin{Extend2005}
4688 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4689 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic
4690 package Containers.Bounded_Synchronized_Queues is new.]}
4691 @end{Extend2005}
4692
4693
4694
4695 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Unbounded_Priority_Queues]}
4696
4697 @begin{StaticSem}
4698 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4699 @ChgAdded{Version=[3],Text=[The language-defined generic package
4700 Containers.Unbounded_Priority_Queues provides type Queue, which implements
4701 the interface type Containers.Synchronized_Queue_Interfaces.Queue.]}
4702
4703 @begin{Example}
4704 @ChgRef{Version=[3],Kind=[AddedNormal]}
4705 @ChgAdded{Version=[3],Text=[@key[with] System;
4706 @key[with] Ada.Containers.Synchronized_Queue_Interfaces;
4707 @key[generic]
4708 @key[with package] Queue_Interfaces @key[is new] Ada.Containers.Synchronized_Queue_Interfaces (<>);
4709 @key[type] Queue_Priority @key[is private];
4710 @key[with] @key[function] Get_Priority
4711 (Element : Queue_Interfaces.Element_Type) @key[return] Queue_Priority @key[is] <>;
4712 @key[with] @key[function] Before
4713 (Left, Right : Queue_Priority) @key[return] Boolean @key[is] <>;
4714 Default_Ceiling : System.Any_Priority := System.Priority'Last;
4715 @key[package] Ada.Containers.Unbounded_Priority_Queues @key[is]@ChildUnit{Parent=[Ada.Containers],Child=[Unbounded_Priority_Queues]}
4716 @key[pragma] Preelaborate(Unbounded_Priority_Queues);]}
4717
4718 @ChgRef{Version=[3],Kind=[AddedNormal]}
4719 @ChgAdded{Version=[3],Text=[ @key[package] Implementation @key[is]
4720 ... -- @Examcom[not specified by the language]
4721 @key[end] Implementation;]}
4722
4723 @ChgRef{Version=[3],Kind=[AddedNormal]}
4724 @ChgAdded{Version=[3],Text=[ @key[protected type] @AdaTypeDefn{Queue}
4725 (Ceiling : System.Any_Priority := Default_Ceiling)
4726 @key[with] Priority => Ceiling @key[is]
4727 @key[new] Queue_Interfaces.Queue @key[with]]}
4728
4729 @ChgRef{Version=[3],Kind=[AddedNormal]}
4730 @ChgAdded{Version=[3],Text=[ @key[overriding]
4731 @key[entry] @AdaSubDefn{Enqueue} (New_Item : @key[in] Queue_Interfaces.Element_Type);
4732 @key[overriding]
4733 @key[entry] @AdaSubDefn{Dequeue} (Element : @key[out] Queue_Interfaces.Element_Type);]}
4734
4735 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0251-1]}
4736 @ChgAdded{Version=[3],Text=[ @key[not overriding]
4737 @key[procedure] @AdaSubDefn{Dequeue_Only_High_Priority}
4738 (At_Least : @key[in] Queue_Priority;
4739 Element : @key[in out] Queue_Interfaces.Element_Type;
4740 Success : @key[out] Boolean);]}
4741
4742 @ChgRef{Version=[3],Kind=[AddedNormal]}
4743 @ChgAdded{Version=[3],Text=[ @key[overriding]
4744 @key[function] @AdaSubDefn{Current_Use} @key[return] Count_Type;
4745 @key[overriding]
4746 @key[function] @AdaSubDefn{Peak_Use} @key[return] Count_Type;]}
4747
4748 @ChgRef{Version=[3],Kind=[AddedNormal]}
4749 @ChgAdded{Version=[3],Text=[ @key[private]
4750 ... -- @Examcom[not specified by the language]
4751 @key[end] Queue;]}
4752
4753 @ChgRef{Version=[3],Kind=[AddedNormal]}
4754 @ChgAdded{Version=[3],Text=[@key{private}]}
4755
4756 @ChgRef{Version=[3],Kind=[AddedNormal]}
4757 @ChgAdded{Version=[3],Text=[ ... -- @Examcom[not specified by the language]]}
4758
4759 @ChgRef{Version=[3],Kind=[AddedNormal]}
4760 @ChgAdded{Version=[3],Text=[@key{end} Ada.Containers.Unbounded_Priority_Queues;]}
4761 @end{Example}
4762
4763 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4764 @ChgAdded{Version=[3],Text=[The type Queue is used to represent task-safe
4765 priority queues.]}
4766
4767 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4768 @ChgAdded{Version=[3],Text=[The capacity for instances of type Queue is
4769 unbounded.]}
4770
4771 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4772 @ChgAdded{Version=[3],Text=[Two elements @i<E1> and @i<E2> are equivalent if
4773 Before(Get_Priority(@i<E1>), Get_Priority(@i<E2>)) and
4774 Before(Get_Priority(@i<E2>), Get_Priority(@i<E1>)) both return False.]}
4775
4776 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0248-1]}
4777 @ChgAdded{Version=[3],Text=[The actual functions for Get_Priority and Before are
4778 expected to return the same value each time they are called with the same
4779 actuals, and should not modify their actuals. Before should define a strict weak
4780 ordering relationship (see @RefSecNum{Containers}). If the actual
4781 functions behave in some other manner, the behavior of Unbounded_Priority_Queues
4782 is unspecified.]}
4783
4784 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4785 @ChgAdded{Version=[3],Text=[Enqueue inserts an item according to the order
4786 specified by the Before function on the result of Get_Priority on the elements;
4787 Before should return True if Left is to be inserted before Right.
4788 If the queue already contains elements equivalent to New_Item, then it is
4789 inserted after the existing equivalent elements.]}
4790
4791 @begin{Ramification}
4792 @ChgRef{Version=[3],Kind=[AddedNormal]}
4793 @ChgAdded{Version=[3],Text=[Enqueue never blocks; if more storage is needed
4794 for a new element, it is allocated dynamically. We don't need to explicitly
4795 specify that Queue needs finalization, because it is visibly protected.]}
4796 @end{Ramification}
4797
4798 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0251-1],ARef=[AI05-0262-1]}
4799 @ChgAdded{Version=[3],Text=[For a call on Dequeue_Only_High_Priority, if the
4800 head of the nonempty queue is @i<E>, and the function Before(At_Least,
4801 Get_Priority(@i<E>)) returns False, then @i<E> is assigned to
4802 Element and then removed from the queue, and Success is set to True;
4803 otherwise, Success is set to False and Element is unchanged.]}
4804
4805 @begin{Ramification}
4806 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0251-1]}
4807 @ChgAdded{Version=[3],Text=[Unlike Dequeue, Dequeue_Only_High_Priority is not
4808 blocking; it always returns immediately.]}
4809 @end{Ramification}
4810
4811 @begin{Reason}
4812 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0251-1]}
4813 @ChgAdded{Version=[3],Text=[The use of Before is "backwards" so that it acts
4814 like ">=" (it is defined similarly to ">"); thus we dequeue only when it is
4815 False.]}
4816 @end{Reason}
4817
4818 @end{StaticSem}
4819
4820 @begin{Extend2005}
4821 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0251-1]}
4822 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic
4823 package Containers.Unbounded_Priority_Queues is new.]}
4824 @end{Extend2005}
4825
4826
4827 @LabeledAddedSubclause{Version=[3],Name=[The Generic Package Containers.Bounded_Priority_Queues]}
4828
4829 @begin{StaticSem}
4830 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4831 @ChgAdded{Version=[3],Text=[The language-defined generic package
4832 Containers.Bounded_Priority_Queues provides type Queue, which implements
4833 the interface type Containers.Synchronized_Queue_Interfaces.Queue.]}
4834
4835 @begin{Example}
4836 @ChgRef{Version=[3],Kind=[AddedNormal]}
4837 @ChgAdded{Version=[3],Text=[@key[with] System;
4838 @key[with] Ada.Containers.Synchronized_Queue_Interfaces;
4839 @key[generic]
4840 @key[with package] Queue_Interfaces @key[is new] Ada.Containers.Synchronized_Queue_Interfaces (<>);
4841 @key[type] Queue_Priority @key[is private];
4842 @key[with function] Get_Priority
4843 (Element : Queue_Interfaces.Element_Type) @key[return] Queue_Priority @key[is] <>;
4844 @key[with function] Before
4845 (Left, Right : Queue_Priority) @key[return] Boolean @key[is] <>;
4846 Default_Capacity : Count_Type;
4847 Default_Ceiling : System.Any_Priority := System.Priority'Last;
4848 @key[package] Ada.Containers.Bounded_Priority_Queues @key[is]@ChildUnit{Parent=[Ada.Containers],Child=[Bounded_Priority_Queues]}
4849 @key[pragma] Preelaborate(Bounded_Priority_Queues);]}
4850
4851 @ChgRef{Version=[3],Kind=[AddedNormal]}
4852 @ChgAdded{Version=[3],Text=[ @key[package] Implementation @key[is]
4853 ... -- @Examcom[not specified by the language]
4854 @key[end] Implementation;]}
4855
4856 @ChgRef{Version=[3],Kind=[AddedNormal]}
4857 @ChgAdded{Version=[3],Text=[ @key[protected type] @AdaTypeDefn{Queue}
4858 (Capacity : Count_Type := Default_Capacity;
4859 Ceiling : System.Any_Priority := Default_Ceiling)
4860 @key[with] Priority => Ceiling @key[is]
4861 @key[new] Queue_Interfaces.Queue @key[with]]}
4862
4863 @ChgRef{Version=[3],Kind=[AddedNormal]}
4864 @ChgAdded{Version=[3],Text=[ @key[overriding]
4865 @key[entry] @AdaSubDefn{Enqueue} (New_Item : @key[in] Queue_Interfaces.Element_Type);
4866 @key[overriding]
4867 @key[entry] @AdaSubDefn{Dequeue} (Element : @key[out] Queue_Interfaces.Element_Type);]}
4868
4869 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0251-1]}
4870 @ChgAdded{Version=[3],Text=[ @key[not overriding]
4871 @key[procedure] @AdaSubDefn{Dequeue_Only_High_Priority}
4872 (At_Least : @key[in] Queue_Priority;
4873 Element : @key[in out] Queue_Interfaces.Element_Type;
4874 Success : @key[out] Boolean);]}
4875
4876 @ChgRef{Version=[3],Kind=[AddedNormal]}
4877 @ChgAdded{Version=[3],Text=[ @key[overriding]
4878 @key[function] @AdaSubDefn{Current_Use} @key[return] Count_Type;
4879 @key[overriding]
4880 @key[function] @AdaSubDefn{Peak_Use} @key[return] Count_Type;]}
4881
4882 @ChgRef{Version=[3],Kind=[AddedNormal]}
4883 @ChgAdded{Version=[3],Text=[ @key[private]
4884 ... -- @Examcom[not specified by the language]
4885 @key[end] Queue;]}
4886
4887 @ChgRef{Version=[3],Kind=[AddedNormal]}
4888 @ChgAdded{Version=[3],Text=[@key{private}]}
4889
4890 @ChgRef{Version=[3],Kind=[AddedNormal]}
4891 @ChgAdded{Version=[3],Text=[ ... -- @Examcom[not specified by the language]]}
4892
4893 @ChgRef{Version=[3],Kind=[AddedNormal]}
4894 @ChgAdded{Version=[3],Text=[@key{end} Ada.Containers.Bounded_Priority_Queues;]}
4895 @end{Example}
4896
4897 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4898 @ChgAdded{Version=[3],Keepnext=[T],Type=[Leading],Text=[The semantics are the
4899 same as for Unbounded_Priority_Queues, except:]}
4900
4901 @begin{Itemize}
4902 @ChgRef{Version=[3],Kind=[AddedNormal]}
4903 @ChgAdded{Version=[3],Text=[The capacity for instances of type Queue is
4904 bounded and specified by the discriminant Capacity.]}
4905 @end{Itemize}
4906
4907 @begin{Ramification}
4908 @ChgRef{Version=[3],Kind=[AddedNormal]}
4909 @ChgAdded{Version=[3],Text=[Since this type has a bounded capacity, Enqueue
4910 might block if the queue is full.]}
4911 @end{Ramification}
4912
4913 @end{StaticSem}
4914
4915 @begin{ImplAdvice}
4916 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1]}
4917 @ChgAdded{Version=[3],Text=[Bounded priority queue objects should be implemented without
4918 implicit pointers or dynamic allocation.]}
4919 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
4920 Text=[Bounded priority queue objects should be implemented without
4921 implicit pointers or dynamic allocation.]}]}
4922 @end{ImplAdvice}
4923
4924 @begin{Extend2005}
4925 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0159-1],ARef=[AI05-0251-1]}
4926 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} The generic
4927 package Containers.Bounded_Priority_Queues is new.]}
4928 @end{Extend2005}
4929
4930
4931 @LabeledAddedSubclause{Version=[3],Name=[Example of Container Use]}
4932
4933 @begin{Examples}
4934
4935 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
4936 @ChgAdded{Version=[3],Text=[The following example is an implementation of
4937 Dijkstra's shortest path algorithm in a directed graph with positive distances.
4938 The graph is represented by a map from nodes to sets of edges.]}
4939
4940 @begin{Example}
4941
4942 @ChgRef{Version=[3],Kind=[AddedNormal]}
4943 @ChgAdded{Version=[3],Text=[@key[with] Ada.Containers.Vectors;
4944 @key[with] Ada.Containers.Doubly_Linked_Lists;
4945 @key[use] Ada.Containers;
4946 @key[generic]
4947 @key[type] Node @key[is range] <>;
4948 @key[package] Shortest_Paths @key[is]
4949 @key[type] Distance @key[is new] Float @key[range] 0.0 .. Float'Last;
4950 @key[type] Edge @key[is record]
4951 To, From : Node;
4952 Length : Distance;
4953 @key[end record];]}
4954
4955 @ChgRef{Version=[3],Kind=[AddedNormal]}
4956 @ChgAdded{Version=[3],Text=[ @key[package] Node_Maps @key[is new] Vectors (Node, Node);
4957 -- @Examcom{The algorithm builds a map to indicate the node used to reach a given}
4958 -- @Examcom{node in the shortest distance.}]}
4959
4960 @ChgRef{Version=[3],Kind=[AddedNormal]}
4961 @ChgAdded{Version=[3],Text=[ @key[package] Adjacency_Lists @key[is new] Doubly_Linked_Lists (Edge);
4962 @key[use] Adjacency_Lists;]}
4963
4964 @ChgRef{Version=[3],Kind=[AddedNormal]}
4965 @ChgAdded{Version=[3],Text=[ @key[package] Graphs @key[is new] Vectors (Node, Adjacency_Lists.List);]}
4966
4967 @ChgRef{Version=[3],Kind=[AddedNormal]}
4968 @ChgAdded{Version=[3],Text=[ @key[package] Paths @key[is new] Doubly_Linked_Lists (Node);]}
4969
4970 @ChgRef{Version=[3],Kind=[AddedNormal]}
4971 @ChgAdded{Version=[3],Text=[ @key[function] Shortest_Path
4972 (G : Graphs.Vector; Source : Node; Target : Node) @key[return] Paths.List
4973 @key[with] Pre => G (Source) /= Adjacency_Lists.Empty_List;]}
4974
4975 @ChgRef{Version=[3],Kind=[AddedNormal]}
4976 @ChgAdded{Version=[3],Text=[@key[end] Shortest_Paths;]}
4977
4978 @ChgRef{Version=[3],Kind=[AddedNormal]}
4979 @ChgAdded{Version=[3],Text=[@key[package body] Shortest_Paths @key[is]
4980 @key[function] Shortest_Path
4981 (G : Graphs.Vector; Source : Node; Target : Node) @key[return] Paths.List
4982 @key[is]
4983 @key[use] Adjacency_Lists, Node_Maps, Paths, Graphs;
4984 Reached : @key[array] (Node) @key[of] Boolean := (@key[others] => False);
4985 -- @ExamCom{The set of nodes whose shortest distance to the source is known.}]}
4986
4987 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0299-1]}
4988 @ChgAdded{Version=[3],Text=[ Reached_From : @key[array] (Node) @key[of] Node;
4989 So_Far : @key[array] (Node) @key[of] Distance := (@key[others] => Distance'Last);
4990 The_Path : Paths.List := Paths.Empty_List;
4991 Nearest_Distance : Distance;
4992 Next : Node;
4993 @key[begin]
4994 So_Far(Source) := 0.0;]}
4995
4996 @ChgRef{Version=[3],Kind=[AddedNormal]}
4997 @ChgAdded{Version=[3],Text=[ @key[while not] Reached(Target) @key[loop]
4998 Nearest_Distance := Distance'Last;]}
4999
5000 @ChgRef{Version=[3],Kind=[AddedNormal]}
5001 @ChgAdded{Version=[3],Text=[ -- @Examcom{Find closest node not reached yet, by iterating over all nodes.}
5002 -- @Examcom{A more efficient algorithm uses a priority queue for this step.}]}
5003
5004 @ChgRef{Version=[3],Kind=[AddedNormal]}
5005 @ChgAdded{Version=[3],Text=[ Next := Source;
5006 @key[for] N @key[in] Node'First .. Node'Last @key[loop]
5007 @key[if not] Reached(N)
5008 @key[and then] So_Far(N) < Nearest_Distance @key[then]
5009 Next := N;
5010 Nearest_Distance := So_Far(N);
5011 @key[end if];
5012 @key[end loop];]}
5013
5014 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0299-1]}
5015 @ChgAdded{Version=[3],Text=[ @key[if] Nearest_Distance = Distance'Last @key[then]
5016 -- @Examcom{No next node found, graph is not connected}
5017 @key[return] Paths.Empty_List;]}
5018
5019 @ChgRef{Version=[3],Kind=[AddedNormal]}
5020 @ChgAdded{Version=[3],Text=[ @key[else]
5021 Reached(Next) := True;
5022 @key[end if];]}
5023
5024 @ChgRef{Version=[3],Kind=[AddedNormal]}
5025 @ChgAdded{Version=[3],Text=[ -- @ExamCom{Update minimum distance to newly reachable nodes.}]}
5026
5027 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0299-1]}
5028 @ChgAdded{Version=[3],Text=[ @key[for] E @key[of] G (Next) @key[loop]
5029 @key[if not] Reached(E.To) @key[then]
5030 Nearest_Distance := E.Length + So_Far(Next);]}
5031
5032 @ChgRef{Version=[3],Kind=[AddedNormal]}
5033 @ChgAdded{Version=[3],Text=[ @key[if] Nearest_Distance < So_Far(E.To) @key[then]
5034 Reached_From(E.To) := Next;
5035 So_Far(E.To) := Nearest_Distance;
5036 @key[end if];
5037 @key[end if];
5038 @key[end loop];
5039 @key[end loop];]}
5040
5041 @ChgRef{Version=[3],Kind=[AddedNormal]}
5042 @ChgAdded{Version=[3],Text=[ -- @ExamCom{Rebuild path from target to source.}]}
5043
5044 @ChgRef{Version=[3],Kind=[AddedNormal]}
5045 @ChgAdded{Version=[3],Text=[ @key[declare]
5046 N : Node := Target;
5047 @key[begin]
5048 @key[while] N /= Source @key[loop]
5049 N := Reached_From(N);
5050 Prepend (The_Path, N);
5051 @key[end loop];
5052 @key[end];]}
5053
5054 @ChgRef{Version=[3],Kind=[AddedNormal]}
5055 @ChgAdded{Version=[3],Text=[ @key[return] The_Path;
5056 @key[end];
5057 @key[end] Shortest_Paths;]}
5058
5059 @end{Example}
5060
5061 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5062 @ChgAdded{Version=[3],Type=[Leading],Text=[Note that the effect of the
5063 Constant_Indexing aspect (on type Vector) and the Implicit_Dereference aspect
5064 (on type Reference_Type) is that]}
5065
5066 @begin{Example}
5067
5068 @ChgRef{Version=[3],Kind=[AddedNormal]}
5069 @ChgAdded{Version=[3],Text=[G (Next)]}
5070
5071 @end{Example}
5072
5073 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5074 @ChgAdded{Version=[3],Type=[Leading],Text=[is a convenient short hand for]}
5075
5076 @begin{Example}
5077
5078 @ChgRef{Version=[3],Kind=[AddedNormal]}
5079 @ChgAdded{Version=[3],Text=[G.Constant_Reference (Next).Element.@key[all]]}
5080
5081 @end{Example}
5082
5083 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5084 @ChgAdded{Version=[3],Type=[Leading],Keepnext=[T],Text=[Similarly, the effect of the loop:]}
5085
5086 @begin{Example}
5087 @ChgRef{Version=[3],Kind=[AddedNormal]}
5088 @ChgAdded{Version=[3],Text=[@key[for] E @key[of] G (Next) @key[loop]
5089 @key[if not] Reached(E.To) @key[then]
5090 ...
5091 @key[end if];
5092 @key[end loop];]}
5093
5094 @end{Example}
5095
5096 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5097 @ChgAdded{Version=[3],Type=[Leading],Keepnext=[T],Text=[is the same as:]}
5098
5099 @begin{Example}
5100
5101 @ChgRef{Version=[3],Kind=[AddedNormal]}
5102 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0080-1]}
5103 @ChgAdded{Version=[3],Text=[@key[for] C @key[in] G (Next).Iterate @key[loop]
5104 @key[declare]
5105 E : Edge @key[renames] G (Next)(C)@Chg{Version=[4],New=[],Old=[.@key[all]]};
5106 @key[begin]
5107 @key[if not] Reached(E.To) @key[then]
5108 ...
5109 @key[end if];
5110 @key[end];
5111 @key[end loop];]}
5112
5113 @end{Example}
5114
5115 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5116 @ChgAdded{Version=[3],Type=[Leading],Keepnext=[T],Text=[which is the same as:]}
5117
5118 @begin{Example}
5119
5120 @ChgRef{Version=[3],Kind=[AddedNormal]}
5121 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0080-1]}
5122 @ChgAdded{Version=[3],Text=[@key[declare]
5123 L : Adjacency_Lists.List @key[renames] G (Next);
5124 C : Adjacency_Lists.Cursor := L.First;
5125 @key[begin]
5126 @key[while] Has_Element (C) @key[loop]
5127 @key[declare]
5128 E : Edge @key[renames] L(C)@Chg{Version=[4],New=[],Old=[.@key[all]]};
5129 @key[begin]
5130 @key[if not] Reached(E.To) @key[then]
5131 ...
5132 @key[end if];
5133 @key[end];
5134 C := L.Next (C);
5135 @key[end loop];
5136 @key[end];]}
5137
5138 @end{Example}
5139 @end{Examples}
5140
5141 @begin{DiffWord2005}
5142 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0212-1]}
5143 @ChgAdded{Version=[3],Text=[This example of container use is new.]}
5144 @end{DiffWord2005}
5145
5146
5147