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

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT LIBRARY COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- ADA.CONTAINERS.RESTRICTED_DOUBLY_LINKED_LISTS --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 2004-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- This unit was originally developed by Matthew J Heaney. --
kono
parents:
diff changeset
28 ------------------------------------------------------------------------------
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 -- The doubly-linked list container provides constant-time insertion and
kono
parents:
diff changeset
31 -- deletion at all positions, and allows iteration in both the forward and
kono
parents:
diff changeset
32 -- reverse directions. This list form allocates storage for all nodes
kono
parents:
diff changeset
33 -- statically (there is no dynamic allocation), and a discriminant is used to
kono
parents:
diff changeset
34 -- specify the capacity. This container is also "restricted", meaning that
kono
parents:
diff changeset
35 -- even though it does raise exceptions (as described below), it does not use
kono
parents:
diff changeset
36 -- internal exception handlers. No state changes are made that would need to
kono
parents:
diff changeset
37 -- be reverted (in the event of an exception), and so as a consequence, this
kono
parents:
diff changeset
38 -- container cannot detect tampering (of cursors or elements).
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 generic
kono
parents:
diff changeset
41 type Element_Type is private;
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 with function "=" (Left, Right : Element_Type)
kono
parents:
diff changeset
44 return Boolean is <>;
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 package Ada.Containers.Restricted_Doubly_Linked_Lists is
kono
parents:
diff changeset
47 pragma Pure;
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 type List (Capacity : Count_Type) is tagged limited private;
kono
parents:
diff changeset
50 pragma Preelaborable_Initialization (List);
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 type Cursor is private;
kono
parents:
diff changeset
53 pragma Preelaborable_Initialization (Cursor);
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 Empty_List : constant List;
kono
parents:
diff changeset
56 -- The default value for list objects declared without an explicit
kono
parents:
diff changeset
57 -- initialization expression.
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 No_Element : constant Cursor;
kono
parents:
diff changeset
60 -- The default value for cursor objects declared without an explicit
kono
parents:
diff changeset
61 -- initialization expression.
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 function "=" (Left, Right : List) return Boolean;
kono
parents:
diff changeset
64 -- If Left denotes the same list object as Right, then equality returns
kono
parents:
diff changeset
65 -- True. If the length of Left is different from the length of Right, then
kono
parents:
diff changeset
66 -- it returns False. Otherwise, list equality iterates over Left and Right,
kono
parents:
diff changeset
67 -- comparing the element of Left to the corresponding element of Right
kono
parents:
diff changeset
68 -- using the generic actual equality operator for elements. If the elements
kono
parents:
diff changeset
69 -- compare False, then the iteration terminates and list equality returns
kono
parents:
diff changeset
70 -- False. Otherwise, if all elements return True, then list equality
kono
parents:
diff changeset
71 -- returns True.
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 procedure Assign (Target : in out List; Source : List);
kono
parents:
diff changeset
74 -- If Target denotes the same list object as Source, the operation does
kono
parents:
diff changeset
75 -- nothing. If Target.Capacity is less than Source.Length, then it raises
kono
parents:
diff changeset
76 -- Constraint_Error. Otherwise, it clears Target, and then inserts each
kono
parents:
diff changeset
77 -- element of Source into Target.
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 function Length (Container : List) return Count_Type;
kono
parents:
diff changeset
80 -- Returns the total number of (active) elements in Container
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 function Is_Empty (Container : List) return Boolean;
kono
parents:
diff changeset
83 -- Returns True if Container.Length is 0
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 procedure Clear (Container : in out List);
kono
parents:
diff changeset
86 -- Deletes all elements from Container. Note that this is a bounded
kono
parents:
diff changeset
87 -- container and so the element is not "deallocated" in the same sense that
kono
parents:
diff changeset
88 -- an unbounded form would deallocate the element. Rather, the node is
kono
parents:
diff changeset
89 -- relinked off of the active part of the list and onto the inactive part
kono
parents:
diff changeset
90 -- of the list (the storage from which new elements are "allocated").
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 function Element (Position : Cursor) return Element_Type;
kono
parents:
diff changeset
93 -- If Position equals No_Element, then Constraint_Error is raised.
kono
parents:
diff changeset
94 -- Otherwise, function Element returns the element designed by Position.
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 procedure Replace_Element
kono
parents:
diff changeset
97 (Container : in out List;
kono
parents:
diff changeset
98 Position : Cursor;
kono
parents:
diff changeset
99 New_Item : Element_Type);
kono
parents:
diff changeset
100 -- If Position equals No_Element, then Constraint_Error is raised. If
kono
parents:
diff changeset
101 -- Position is associated with a list object different from Container,
kono
parents:
diff changeset
102 -- Program_Error is raised. Otherwise, the element designated by Position
kono
parents:
diff changeset
103 -- is assigned the value New_Item.
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 procedure Query_Element
kono
parents:
diff changeset
106 (Position : Cursor;
kono
parents:
diff changeset
107 Process : not null access procedure (Element : Element_Type));
kono
parents:
diff changeset
108 -- If Position equals No_Element, then Constraint_Error is raised.
kono
parents:
diff changeset
109 -- Otherwise, it calls Process with (a constant view of) the element
kono
parents:
diff changeset
110 -- designated by Position as the parameter.
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 procedure Update_Element
kono
parents:
diff changeset
113 (Container : in out List;
kono
parents:
diff changeset
114 Position : Cursor;
kono
parents:
diff changeset
115 Process : not null access procedure (Element : in out Element_Type));
kono
parents:
diff changeset
116 -- If Position equals No_Element, then Constraint_Error is raised.
kono
parents:
diff changeset
117 -- Otherwise, it calls Process with (a variable view of) the element
kono
parents:
diff changeset
118 -- designated by Position as the parameter.
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 procedure Insert
kono
parents:
diff changeset
121 (Container : in out List;
kono
parents:
diff changeset
122 Before : Cursor;
kono
parents:
diff changeset
123 New_Item : Element_Type;
kono
parents:
diff changeset
124 Count : Count_Type := 1);
kono
parents:
diff changeset
125 -- Inserts Count new elements, all with the value New_Item, into Container,
kono
parents:
diff changeset
126 -- immediately prior to the position specified by Before. If Before has the
kono
parents:
diff changeset
127 -- value No_Element, this is interpreted to mean that the elements are
kono
parents:
diff changeset
128 -- appended to the list. If Before is associated with a list object
kono
parents:
diff changeset
129 -- different from Container, then Program_Error is raised. If there are
kono
parents:
diff changeset
130 -- fewer than Count nodes available, then Constraint_Error is raised.
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 procedure Insert
kono
parents:
diff changeset
133 (Container : in out List;
kono
parents:
diff changeset
134 Before : Cursor;
kono
parents:
diff changeset
135 New_Item : Element_Type;
kono
parents:
diff changeset
136 Position : out Cursor;
kono
parents:
diff changeset
137 Count : Count_Type := 1);
kono
parents:
diff changeset
138 -- Inserts elements into Container as described above, but with the
kono
parents:
diff changeset
139 -- difference that cursor Position is returned, which designates the first
kono
parents:
diff changeset
140 -- of the new elements inserted. If Count is 0, Position returns the value
kono
parents:
diff changeset
141 -- Before.
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 procedure Insert
kono
parents:
diff changeset
144 (Container : in out List;
kono
parents:
diff changeset
145 Before : Cursor;
kono
parents:
diff changeset
146 Position : out Cursor;
kono
parents:
diff changeset
147 Count : Count_Type := 1);
kono
parents:
diff changeset
148 -- Inserts elements in Container as described above, but with the
kono
parents:
diff changeset
149 -- difference that the new elements are initialized to the default value
kono
parents:
diff changeset
150 -- for objects of type Element_Type.
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 procedure Prepend
kono
parents:
diff changeset
153 (Container : in out List;
kono
parents:
diff changeset
154 New_Item : Element_Type;
kono
parents:
diff changeset
155 Count : Count_Type := 1);
kono
parents:
diff changeset
156 -- Inserts Count elements, all having the value New_Item, prior to the
kono
parents:
diff changeset
157 -- first element of Container.
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 procedure Append
kono
parents:
diff changeset
160 (Container : in out List;
kono
parents:
diff changeset
161 New_Item : Element_Type;
kono
parents:
diff changeset
162 Count : Count_Type := 1);
kono
parents:
diff changeset
163 -- Inserts Count elements, all having the value New_Item, following the
kono
parents:
diff changeset
164 -- last element of Container.
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 procedure Delete
kono
parents:
diff changeset
167 (Container : in out List;
kono
parents:
diff changeset
168 Position : in out Cursor;
kono
parents:
diff changeset
169 Count : Count_Type := 1);
kono
parents:
diff changeset
170 -- If Position equals No_Element, Constraint_Error is raised. If Position
kono
parents:
diff changeset
171 -- is associated with a list object different from Container, then
kono
parents:
diff changeset
172 -- Program_Error is raised. Otherwise, the Count nodes starting from
kono
parents:
diff changeset
173 -- Position are removed from Container ("removed" meaning that the nodes
kono
parents:
diff changeset
174 -- are unlinked from the active nodes of the list and relinked to inactive
kono
parents:
diff changeset
175 -- storage). On return, Position is set to No_Element.
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 procedure Delete_First
kono
parents:
diff changeset
178 (Container : in out List;
kono
parents:
diff changeset
179 Count : Count_Type := 1);
kono
parents:
diff changeset
180 -- Removes the first Count nodes from Container
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 procedure Delete_Last
kono
parents:
diff changeset
183 (Container : in out List;
kono
parents:
diff changeset
184 Count : Count_Type := 1);
kono
parents:
diff changeset
185 -- Removes the last Count nodes from Container
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 procedure Reverse_Elements (Container : in out List);
kono
parents:
diff changeset
188 -- Relinks the nodes in reverse order
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 procedure Swap
kono
parents:
diff changeset
191 (Container : in out List;
kono
parents:
diff changeset
192 I, J : Cursor);
kono
parents:
diff changeset
193 -- If I or J equals No_Element, then Constraint_Error is raised. If I or J
kono
parents:
diff changeset
194 -- is associated with a list object different from Container, then
kono
parents:
diff changeset
195 -- Program_Error is raised. Otherwise, Swap exchanges (copies) the values
kono
parents:
diff changeset
196 -- of the elements (on the nodes) designated by I and J.
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 procedure Swap_Links
kono
parents:
diff changeset
199 (Container : in out List;
kono
parents:
diff changeset
200 I, J : Cursor);
kono
parents:
diff changeset
201 -- If I or J equals No_Element, then Constraint_Error is raised. If I or J
kono
parents:
diff changeset
202 -- is associated with a list object different from Container, then
kono
parents:
diff changeset
203 -- Program_Error is raised. Otherwise, Swap exchanges (relinks) the nodes
kono
parents:
diff changeset
204 -- designated by I and J.
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 procedure Splice
kono
parents:
diff changeset
207 (Container : in out List;
kono
parents:
diff changeset
208 Before : Cursor;
kono
parents:
diff changeset
209 Position : in out Cursor);
kono
parents:
diff changeset
210 -- If Before is associated with a list object different from Container,
kono
parents:
diff changeset
211 -- then Program_Error is raised. If Position equals No_Element, then
kono
parents:
diff changeset
212 -- Constraint_Error is raised; if it associated with a list object
kono
parents:
diff changeset
213 -- different from Container, then Program_Error is raised. Otherwise, the
kono
parents:
diff changeset
214 -- node designated by Position is relinked immediately prior to Before. If
kono
parents:
diff changeset
215 -- Before equals No_Element, this is interpreted to mean to move the node
kono
parents:
diff changeset
216 -- designed by Position to the last end of the list.
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 function First (Container : List) return Cursor;
kono
parents:
diff changeset
219 -- If Container is empty, the function returns No_Element. Otherwise, it
kono
parents:
diff changeset
220 -- returns a cursor designating the first element.
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 function First_Element (Container : List) return Element_Type;
kono
parents:
diff changeset
223 -- Equivalent to Element (First (Container))
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 function Last (Container : List) return Cursor;
kono
parents:
diff changeset
226 -- If Container is empty, the function returns No_Element. Otherwise, it
kono
parents:
diff changeset
227 -- returns a cursor designating the last element.
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 function Last_Element (Container : List) return Element_Type;
kono
parents:
diff changeset
230 -- Equivalent to Element (Last (Container))
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 function Next (Position : Cursor) return Cursor;
kono
parents:
diff changeset
233 -- If Position equals No_Element or Last (Container), the function returns
kono
parents:
diff changeset
234 -- No_Element. Otherwise, it returns a cursor designating the node that
kono
parents:
diff changeset
235 -- immediately follows the node designated by Position.
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 procedure Next (Position : in out Cursor);
kono
parents:
diff changeset
238 -- Equivalent to Position := Next (Position)
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 function Previous (Position : Cursor) return Cursor;
kono
parents:
diff changeset
241 -- If Position equals No_Element or First (Container), the function returns
kono
parents:
diff changeset
242 -- No_Element. Otherwise, it returns a cursor designating the node that
kono
parents:
diff changeset
243 -- immediately precedes the node designated by Position.
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 procedure Previous (Position : in out Cursor);
kono
parents:
diff changeset
246 -- Equivalent to Position := Previous (Position)
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 function Find
kono
parents:
diff changeset
249 (Container : List;
kono
parents:
diff changeset
250 Item : Element_Type;
kono
parents:
diff changeset
251 Position : Cursor := No_Element) return Cursor;
kono
parents:
diff changeset
252 -- Searches for the node whose element is equal to Item, starting from
kono
parents:
diff changeset
253 -- Position and continuing to the last end of the list. If Position equals
kono
parents:
diff changeset
254 -- No_Element, the search starts from the first node. If Position is
kono
parents:
diff changeset
255 -- associated with a list object different from Container, then
kono
parents:
diff changeset
256 -- Program_Error is raised. If no node is found having an element equal to
kono
parents:
diff changeset
257 -- Item, then Find returns No_Element.
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 function Reverse_Find
kono
parents:
diff changeset
260 (Container : List;
kono
parents:
diff changeset
261 Item : Element_Type;
kono
parents:
diff changeset
262 Position : Cursor := No_Element) return Cursor;
kono
parents:
diff changeset
263 -- Searches in reverse for the node whose element is equal to Item,
kono
parents:
diff changeset
264 -- starting from Position and continuing to the first end of the list. If
kono
parents:
diff changeset
265 -- Position equals No_Element, the search starts from the last node. If
kono
parents:
diff changeset
266 -- Position is associated with a list object different from Container, then
kono
parents:
diff changeset
267 -- Program_Error is raised. If no node is found having an element equal to
kono
parents:
diff changeset
268 -- Item, then Reverse_Find returns No_Element.
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 function Contains
kono
parents:
diff changeset
271 (Container : List;
kono
parents:
diff changeset
272 Item : Element_Type) return Boolean;
kono
parents:
diff changeset
273 -- Equivalent to Container.Find (Item) /= No_Element
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275 function Has_Element (Position : Cursor) return Boolean;
kono
parents:
diff changeset
276 -- Equivalent to Position /= No_Element
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 procedure Iterate
kono
parents:
diff changeset
279 (Container : List;
kono
parents:
diff changeset
280 Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
281 -- Calls Process with a cursor designating each element of Container, in
kono
parents:
diff changeset
282 -- order from Container.First to Container.Last.
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 procedure Reverse_Iterate
kono
parents:
diff changeset
285 (Container : List;
kono
parents:
diff changeset
286 Process : not null access procedure (Position : Cursor));
kono
parents:
diff changeset
287 -- Calls Process with a cursor designating each element of Container, in
kono
parents:
diff changeset
288 -- order from Container.Last to Container.First.
kono
parents:
diff changeset
289
kono
parents:
diff changeset
290 generic
kono
parents:
diff changeset
291 with function "<" (Left, Right : Element_Type) return Boolean is <>;
kono
parents:
diff changeset
292 package Generic_Sorting is
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 function Is_Sorted (Container : List) return Boolean;
kono
parents:
diff changeset
295 -- Returns False if there exists an element which is less than its
kono
parents:
diff changeset
296 -- predecessor.
kono
parents:
diff changeset
297
kono
parents:
diff changeset
298 procedure Sort (Container : in out List);
kono
parents:
diff changeset
299 -- Sorts the elements of Container (by relinking nodes), according to
kono
parents:
diff changeset
300 -- the order specified by the generic formal less-than operator, such
kono
parents:
diff changeset
301 -- that smaller elements are first in the list. The sort is stable,
kono
parents:
diff changeset
302 -- meaning that the relative order of elements is preserved.
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 end Generic_Sorting;
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 private
kono
parents:
diff changeset
307
kono
parents:
diff changeset
308 type Node_Type is limited record
kono
parents:
diff changeset
309 Prev : Count_Type'Base;
kono
parents:
diff changeset
310 Next : Count_Type;
kono
parents:
diff changeset
311 Element : Element_Type;
kono
parents:
diff changeset
312 end record;
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 type Node_Array is array (Count_Type range <>) of Node_Type;
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 type List (Capacity : Count_Type) is tagged limited record
kono
parents:
diff changeset
317 Nodes : Node_Array (1 .. Capacity) := (others => <>);
kono
parents:
diff changeset
318 Free : Count_Type'Base := -1;
kono
parents:
diff changeset
319 First : Count_Type := 0;
kono
parents:
diff changeset
320 Last : Count_Type := 0;
kono
parents:
diff changeset
321 Length : Count_Type := 0;
kono
parents:
diff changeset
322 end record;
kono
parents:
diff changeset
323
kono
parents:
diff changeset
324 type List_Access is access all List;
kono
parents:
diff changeset
325 for List_Access'Storage_Size use 0;
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 type Cursor is
kono
parents:
diff changeset
328 record
kono
parents:
diff changeset
329 Container : List_Access;
kono
parents:
diff changeset
330 Node : Count_Type := 0;
kono
parents:
diff changeset
331 end record;
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 Empty_List : constant List := (0, others => <>);
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 No_Element : constant Cursor := (null, 0);
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 end Ada.Containers.Restricted_Doubly_Linked_Lists;