annotate gcc/ada/libgnat/a-rbtgbk.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.RED_BLACK_TREES.GENERIC_BOUNDED_KEYS --
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 -- 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_Bounded_Operations;
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 generic
kono
parents:
diff changeset
36 with package Tree_Operations is new Generic_Bounded_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_Type) 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_Type) return Boolean;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 package Ada.Containers.Red_Black_Trees.Generic_Bounded_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 Count_Type;
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 procedure Generic_Insert_Post
kono
parents:
diff changeset
57 (Tree : in out Tree_Type'Class;
kono
parents:
diff changeset
58 Y : Count_Type;
kono
parents:
diff changeset
59 Before : Boolean;
kono
parents:
diff changeset
60 Z : out Count_Type);
kono
parents:
diff changeset
61 -- Completes an insertion after the insertion position has been
kono
parents:
diff changeset
62 -- determined. On output Z contains the index of the newly inserted
kono
parents:
diff changeset
63 -- node, allocated using Allocate. If Tree is busy then
kono
parents:
diff changeset
64 -- Program_Error is raised. If Y is 0, then Tree must be empty.
kono
parents:
diff changeset
65 -- Otherwise Y denotes the insertion position, and Before specifies
kono
parents:
diff changeset
66 -- whether the new node is Y's left (True) or right (False) child.
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 generic
kono
parents:
diff changeset
69 with procedure Insert_Post
kono
parents:
diff changeset
70 (T : in out Tree_Type'Class;
kono
parents:
diff changeset
71 Y : Count_Type;
kono
parents:
diff changeset
72 B : Boolean;
kono
parents:
diff changeset
73 Z : out Count_Type);
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 procedure Generic_Conditional_Insert
kono
parents:
diff changeset
76 (Tree : in out Tree_Type'Class;
kono
parents:
diff changeset
77 Key : Key_Type;
kono
parents:
diff changeset
78 Node : out Count_Type;
kono
parents:
diff changeset
79 Inserted : out Boolean);
kono
parents:
diff changeset
80 -- Inserts a new node in Tree, but only if the tree does not already
kono
parents:
diff changeset
81 -- contain Key. Generic_Conditional_Insert first searches for a key
kono
parents:
diff changeset
82 -- equivalent to Key in Tree. If an equivalent key is found, then on
kono
parents:
diff changeset
83 -- output Node designates the node with that key and Inserted is
kono
parents:
diff changeset
84 -- False; there is no allocation and Tree is not modified. Otherwise
kono
parents:
diff changeset
85 -- Node designates a new node allocated using Insert_Post, and
kono
parents:
diff changeset
86 -- Inserted is True.
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 generic
kono
parents:
diff changeset
89 with procedure Insert_Post
kono
parents:
diff changeset
90 (T : in out Tree_Type'Class;
kono
parents:
diff changeset
91 Y : Count_Type;
kono
parents:
diff changeset
92 B : Boolean;
kono
parents:
diff changeset
93 Z : out Count_Type);
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 procedure Generic_Unconditional_Insert
kono
parents:
diff changeset
96 (Tree : in out Tree_Type'Class;
kono
parents:
diff changeset
97 Key : Key_Type;
kono
parents:
diff changeset
98 Node : out Count_Type);
kono
parents:
diff changeset
99 -- Inserts a new node in Tree. On output Node designates the new
kono
parents:
diff changeset
100 -- node, which is allocated using Insert_Post. The node is inserted
kono
parents:
diff changeset
101 -- immediately after already-existing equivalent keys.
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 generic
kono
parents:
diff changeset
104 with procedure Insert_Post
kono
parents:
diff changeset
105 (T : in out Tree_Type'Class;
kono
parents:
diff changeset
106 Y : Count_Type;
kono
parents:
diff changeset
107 B : Boolean;
kono
parents:
diff changeset
108 Z : out Count_Type);
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 with procedure Unconditional_Insert_Sans_Hint
kono
parents:
diff changeset
111 (Tree : in out Tree_Type'Class;
kono
parents:
diff changeset
112 Key : Key_Type;
kono
parents:
diff changeset
113 Node : out Count_Type);
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 procedure Generic_Unconditional_Insert_With_Hint
kono
parents:
diff changeset
116 (Tree : in out Tree_Type'Class;
kono
parents:
diff changeset
117 Hint : Count_Type;
kono
parents:
diff changeset
118 Key : Key_Type;
kono
parents:
diff changeset
119 Node : out Count_Type);
kono
parents:
diff changeset
120 -- Inserts a new node in Tree near position Hint, to avoid having to
kono
parents:
diff changeset
121 -- search from the root for the insertion position. If Hint is 0
kono
parents:
diff changeset
122 -- then Generic_Unconditional_Insert_With_Hint attempts to insert
kono
parents:
diff changeset
123 -- the new node after Tree.Last. If Hint is non-zero then if Key is
kono
parents:
diff changeset
124 -- less than Hint, it attempts to insert the new node immediately
kono
parents:
diff changeset
125 -- prior to Hint. Otherwise it attempts to insert the node
kono
parents:
diff changeset
126 -- immediately following Hint. We say "attempts" above to emphasize
kono
parents:
diff changeset
127 -- that insertions always preserve invariants with respect to key
kono
parents:
diff changeset
128 -- order, even when there's a hint. So if Key can't be inserted
kono
parents:
diff changeset
129 -- immediately near Hint, then the new node is inserted in the
kono
parents:
diff changeset
130 -- normal way, by searching for the correct position starting from
kono
parents:
diff changeset
131 -- the root.
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 generic
kono
parents:
diff changeset
134 with procedure Insert_Post
kono
parents:
diff changeset
135 (T : in out Tree_Type'Class;
kono
parents:
diff changeset
136 Y : Count_Type;
kono
parents:
diff changeset
137 B : Boolean;
kono
parents:
diff changeset
138 Z : out Count_Type);
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 with procedure Conditional_Insert_Sans_Hint
kono
parents:
diff changeset
141 (Tree : in out Tree_Type'Class;
kono
parents:
diff changeset
142 Key : Key_Type;
kono
parents:
diff changeset
143 Node : out Count_Type;
kono
parents:
diff changeset
144 Inserted : out Boolean);
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 procedure Generic_Conditional_Insert_With_Hint
kono
parents:
diff changeset
147 (Tree : in out Tree_Type'Class;
kono
parents:
diff changeset
148 Position : Count_Type; -- the hint
kono
parents:
diff changeset
149 Key : Key_Type;
kono
parents:
diff changeset
150 Node : out Count_Type;
kono
parents:
diff changeset
151 Inserted : out Boolean);
kono
parents:
diff changeset
152 -- Inserts a new node in Tree if the tree does not already contain
kono
parents:
diff changeset
153 -- Key, using Position as a hint about where to insert the new node.
kono
parents:
diff changeset
154 -- See Generic_Unconditional_Insert_With_Hint for more details about
kono
parents:
diff changeset
155 -- hint semantics.
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 function Find
kono
parents:
diff changeset
158 (Tree : Tree_Type'Class;
kono
parents:
diff changeset
159 Key : Key_Type) return Count_Type;
kono
parents:
diff changeset
160 -- Searches Tree for the smallest node equivalent to Key
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 function Ceiling
kono
parents:
diff changeset
163 (Tree : Tree_Type'Class;
kono
parents:
diff changeset
164 Key : Key_Type) return Count_Type;
kono
parents:
diff changeset
165 -- Searches Tree for the smallest node equal to or greater than Key
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 function Floor
kono
parents:
diff changeset
168 (Tree : Tree_Type'Class;
kono
parents:
diff changeset
169 Key : Key_Type) return Count_Type;
kono
parents:
diff changeset
170 -- Searches Tree for the largest node less than or equal to Key
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 function Upper_Bound
kono
parents:
diff changeset
173 (Tree : Tree_Type'Class;
kono
parents:
diff changeset
174 Key : Key_Type) return Count_Type;
kono
parents:
diff changeset
175 -- Searches Tree for the smallest node greater than Key
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 generic
kono
parents:
diff changeset
178 with procedure Process (Index : Count_Type);
kono
parents:
diff changeset
179 procedure Generic_Iteration
kono
parents:
diff changeset
180 (Tree : Tree_Type'Class;
kono
parents:
diff changeset
181 Key : Key_Type);
kono
parents:
diff changeset
182 -- Calls Process for each node in Tree equivalent to Key, in order
kono
parents:
diff changeset
183 -- from earliest in range to latest.
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 generic
kono
parents:
diff changeset
186 with procedure Process (Index : Count_Type);
kono
parents:
diff changeset
187 procedure Generic_Reverse_Iteration
kono
parents:
diff changeset
188 (Tree : Tree_Type'Class;
kono
parents:
diff changeset
189 Key : Key_Type);
kono
parents:
diff changeset
190 -- Calls Process for each node in Tree equivalent to Key, but in
kono
parents:
diff changeset
191 -- order from largest in range to earliest.
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 end Ada.Containers.Red_Black_Trees.Generic_Bounded_Keys;