annotate gcc/ada/libgnat/a-crbtgk.ads @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
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.RED_BLACK_TREES.GENERIC_KEYS --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
kono
parents:
diff changeset
9 -- Copyright (C) 2004-2017, Free Software Foundation, Inc. --
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 -- Tree_Type is used to implement ordered containers. This package declares
kono
parents:
diff changeset
31 -- the tree operations that depend on keys.
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 with Ada.Containers.Red_Black_Trees.Generic_Operations;
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 generic
kono
parents:
diff changeset
36 with package Tree_Operations is new Generic_Operations (<>);
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 use Tree_Operations.Tree_Types, Tree_Operations.Tree_Types.Implementation;
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 type Key_Type (<>) is limited private;
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 with function Is_Less_Key_Node
kono
parents:
diff changeset
43 (L : Key_Type;
kono
parents:
diff changeset
44 R : Node_Access) return Boolean;
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 with function Is_Greater_Key_Node
kono
parents:
diff changeset
47 (L : Key_Type;
kono
parents:
diff changeset
48 R : Node_Access) return Boolean;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 package Ada.Containers.Red_Black_Trees.Generic_Keys is
kono
parents:
diff changeset
51 pragma Pure;
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 generic
kono
parents:
diff changeset
54 with function New_Node return Node_Access;
kono
parents:
diff changeset
55 procedure Generic_Insert_Post
kono
parents:
diff changeset
56 (Tree : in out Tree_Type;
kono
parents:
diff changeset
57 Y : Node_Access;
kono
parents:
diff changeset
58 Before : Boolean;
kono
parents:
diff changeset
59 Z : out Node_Access);
kono
parents:
diff changeset
60 -- Completes an insertion after the insertion position has been
kono
parents:
diff changeset
61 -- determined. On output Z contains a pointer to the newly inserted
kono
parents:
diff changeset
62 -- node, allocated using New_Node. If Tree is busy then
kono
parents:
diff changeset
63 -- Program_Error is raised. If Y is null, then Tree must be empty.
kono
parents:
diff changeset
64 -- Otherwise Y denotes the insertion position, and Before specifies
kono
parents:
diff changeset
65 -- whether the new node is Y's left (True) or right (False) child.
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 generic
kono
parents:
diff changeset
68 with procedure Insert_Post
kono
parents:
diff changeset
69 (T : in out Tree_Type;
kono
parents:
diff changeset
70 Y : Node_Access;
kono
parents:
diff changeset
71 B : Boolean;
kono
parents:
diff changeset
72 Z : out Node_Access);
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 procedure Generic_Conditional_Insert
kono
parents:
diff changeset
75 (Tree : in out Tree_Type;
kono
parents:
diff changeset
76 Key : Key_Type;
kono
parents:
diff changeset
77 Node : out Node_Access;
kono
parents:
diff changeset
78 Inserted : out Boolean);
kono
parents:
diff changeset
79 -- Inserts a new node in Tree, but only if the tree does not already
kono
parents:
diff changeset
80 -- contain Key. Generic_Conditional_Insert first searches for a key
kono
parents:
diff changeset
81 -- equivalent to Key in Tree. If an equivalent key is found, then on
kono
parents:
diff changeset
82 -- output Node designates the node with that key and Inserted is
kono
parents:
diff changeset
83 -- False; there is no allocation and Tree is not modified. Otherwise
kono
parents:
diff changeset
84 -- Node designates a new node allocated using Insert_Post, and
kono
parents:
diff changeset
85 -- Inserted is True.
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 generic
kono
parents:
diff changeset
88 with procedure Insert_Post
kono
parents:
diff changeset
89 (T : in out Tree_Type;
kono
parents:
diff changeset
90 Y : Node_Access;
kono
parents:
diff changeset
91 B : Boolean;
kono
parents:
diff changeset
92 Z : out Node_Access);
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 procedure Generic_Unconditional_Insert
kono
parents:
diff changeset
95 (Tree : in out Tree_Type;
kono
parents:
diff changeset
96 Key : Key_Type;
kono
parents:
diff changeset
97 Node : out Node_Access);
kono
parents:
diff changeset
98 -- Inserts a new node in Tree. On output Node designates the new
kono
parents:
diff changeset
99 -- node, which is allocated using Insert_Post. The node is inserted
kono
parents:
diff changeset
100 -- immediately after already-existing equivalent keys.
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 generic
kono
parents:
diff changeset
103 with procedure Insert_Post
kono
parents:
diff changeset
104 (T : in out Tree_Type;
kono
parents:
diff changeset
105 Y : Node_Access;
kono
parents:
diff changeset
106 B : Boolean;
kono
parents:
diff changeset
107 Z : out Node_Access);
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 with procedure Unconditional_Insert_Sans_Hint
kono
parents:
diff changeset
110 (Tree : in out Tree_Type;
kono
parents:
diff changeset
111 Key : Key_Type;
kono
parents:
diff changeset
112 Node : out Node_Access);
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 procedure Generic_Unconditional_Insert_With_Hint
kono
parents:
diff changeset
115 (Tree : in out Tree_Type;
kono
parents:
diff changeset
116 Hint : Node_Access;
kono
parents:
diff changeset
117 Key : Key_Type;
kono
parents:
diff changeset
118 Node : out Node_Access);
kono
parents:
diff changeset
119 -- Inserts a new node in Tree near position Hint, to avoid having to
kono
parents:
diff changeset
120 -- search from the root for the insertion position. If Hint is null
kono
parents:
diff changeset
121 -- then Generic_Unconditional_Insert_With_Hint attempts to insert
kono
parents:
diff changeset
122 -- the new node after Tree.Last. If Hint is non-null then if Key is
kono
parents:
diff changeset
123 -- less than Hint, it attempts to insert the new node immediately
kono
parents:
diff changeset
124 -- prior to Hint. Otherwise it attempts to insert the node
kono
parents:
diff changeset
125 -- immediately following Hint. We say "attempts" above to emphasize
kono
parents:
diff changeset
126 -- that insertions always preserve invariants with respect to key
kono
parents:
diff changeset
127 -- order, even when there's a hint. So if Key can't be inserted
kono
parents:
diff changeset
128 -- immediately near Hint, then the new node is inserted in the
kono
parents:
diff changeset
129 -- normal way, by searching for the correct position starting from
kono
parents:
diff changeset
130 -- the root.
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 generic
kono
parents:
diff changeset
133 with procedure Insert_Post
kono
parents:
diff changeset
134 (T : in out Tree_Type;
kono
parents:
diff changeset
135 Y : Node_Access;
kono
parents:
diff changeset
136 B : Boolean;
kono
parents:
diff changeset
137 Z : out Node_Access);
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 with procedure Conditional_Insert_Sans_Hint
kono
parents:
diff changeset
140 (Tree : in out Tree_Type;
kono
parents:
diff changeset
141 Key : Key_Type;
kono
parents:
diff changeset
142 Node : out Node_Access;
kono
parents:
diff changeset
143 Inserted : out Boolean);
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 procedure Generic_Conditional_Insert_With_Hint
kono
parents:
diff changeset
146 (Tree : in out Tree_Type;
kono
parents:
diff changeset
147 Position : Node_Access; -- the hint
kono
parents:
diff changeset
148 Key : Key_Type;
kono
parents:
diff changeset
149 Node : out Node_Access;
kono
parents:
diff changeset
150 Inserted : out Boolean);
kono
parents:
diff changeset
151 -- Inserts a new node in Tree if the tree does not already contain
kono
parents:
diff changeset
152 -- Key, using Position as a hint about where to insert the new node.
kono
parents:
diff changeset
153 -- See Generic_Unconditional_Insert_With_Hint for more details about
kono
parents:
diff changeset
154 -- hint semantics.
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 function Find
kono
parents:
diff changeset
157 (Tree : Tree_Type;
kono
parents:
diff changeset
158 Key : Key_Type) return Node_Access;
kono
parents:
diff changeset
159 -- Searches Tree for the smallest node equivalent to Key
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 function Ceiling
kono
parents:
diff changeset
162 (Tree : Tree_Type;
kono
parents:
diff changeset
163 Key : Key_Type) return Node_Access;
kono
parents:
diff changeset
164 -- Searches Tree for the smallest node equal to or greater than Key
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 function Floor
kono
parents:
diff changeset
167 (Tree : Tree_Type;
kono
parents:
diff changeset
168 Key : Key_Type) return Node_Access;
kono
parents:
diff changeset
169 -- Searches Tree for the largest node less than or equal to Key
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 function Upper_Bound
kono
parents:
diff changeset
172 (Tree : Tree_Type;
kono
parents:
diff changeset
173 Key : Key_Type) return Node_Access;
kono
parents:
diff changeset
174 -- Searches Tree for the smallest node greater than Key
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 generic
kono
parents:
diff changeset
177 with procedure Process (Node : Node_Access);
kono
parents:
diff changeset
178 procedure Generic_Iteration
kono
parents:
diff changeset
179 (Tree : Tree_Type;
kono
parents:
diff changeset
180 Key : Key_Type);
kono
parents:
diff changeset
181 -- Calls Process for each node in Tree equivalent to Key, in order
kono
parents:
diff changeset
182 -- from earliest in range to latest.
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 generic
kono
parents:
diff changeset
185 with procedure Process (Node : Node_Access);
kono
parents:
diff changeset
186 procedure Generic_Reverse_Iteration
kono
parents:
diff changeset
187 (Tree : Tree_Type;
kono
parents:
diff changeset
188 Key : Key_Type);
kono
parents:
diff changeset
189 -- Calls Process for each node in Tree equivalent to Key, but in
kono
parents:
diff changeset
190 -- order from largest in range to earliest.
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 end Ada.Containers.Red_Black_Trees.Generic_Keys;