annotate gcc/ada/libgnat/a-crbtgo.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
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_OPERATIONS --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 2004-2018, 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 the ordered containers. This package
kono
parents:
diff changeset
31 -- declares the tree operations that do not depend on keys.
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 with Ada.Streams; use Ada.Streams;
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 generic
kono
parents:
diff changeset
36 with package Tree_Types is new Generic_Tree_Types (<>);
kono
parents:
diff changeset
37 use Tree_Types, Tree_Types.Implementation;
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 with function Parent (Node : Node_Access) return Node_Access is <>;
kono
parents:
diff changeset
40 with procedure Set_Parent (Node : Node_Access; Parent : Node_Access) is <>;
kono
parents:
diff changeset
41 with function Left (Node : Node_Access) return Node_Access is <>;
kono
parents:
diff changeset
42 with procedure Set_Left (Node : Node_Access; Left : Node_Access) is <>;
kono
parents:
diff changeset
43 with function Right (Node : Node_Access) return Node_Access is <>;
kono
parents:
diff changeset
44 with procedure Set_Right (Node : Node_Access; Right : Node_Access) is <>;
kono
parents:
diff changeset
45 with function Color (Node : Node_Access) return Color_Type is <>;
kono
parents:
diff changeset
46 with procedure Set_Color (Node : Node_Access; Color : Color_Type) is <>;
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 package Ada.Containers.Red_Black_Trees.Generic_Operations is
kono
parents:
diff changeset
49 pragma Pure;
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 function Min (Node : Node_Access) return Node_Access;
kono
parents:
diff changeset
52 -- Returns the smallest-valued node of the subtree rooted at Node
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 function Max (Node : Node_Access) return Node_Access;
kono
parents:
diff changeset
55 -- Returns the largest-valued node of the subtree rooted at Node
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 -- NOTE: The Check_Invariant operation was used during early
kono
parents:
diff changeset
58 -- development of the red-black tree. Now that the tree type
kono
parents:
diff changeset
59 -- implementation has matured, we don't really need Check_Invariant
kono
parents:
diff changeset
60 -- anymore.
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 -- procedure Check_Invariant (Tree : Tree_Type);
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 function Vet (Tree : Tree_Type; Node : Node_Access) return Boolean;
kono
parents:
diff changeset
65 -- Inspects Node to determine (to the extent possible) whether
kono
parents:
diff changeset
66 -- the node is valid; used to detect if the node is dangling.
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 function Next (Node : Node_Access) return Node_Access;
kono
parents:
diff changeset
69 -- Returns the smallest node greater than Node
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 function Previous (Node : Node_Access) return Node_Access;
kono
parents:
diff changeset
72 -- Returns the largest node less than Node
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 generic
kono
parents:
diff changeset
75 with function Is_Equal (L, R : Node_Access) return Boolean;
kono
parents:
diff changeset
76 function Generic_Equal (Left, Right : Tree_Type) return Boolean;
kono
parents:
diff changeset
77 -- Uses Is_Equal to perform a node-by-node comparison of the
kono
parents:
diff changeset
78 -- Left and Right trees; processing stops as soon as the first
kono
parents:
diff changeset
79 -- non-equal node is found.
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 procedure Delete_Node_Sans_Free
kono
parents:
diff changeset
82 (Tree : in out Tree_Type;
kono
parents:
diff changeset
83 Node : Node_Access);
kono
parents:
diff changeset
84 -- Removes Node from Tree without deallocating the node. If Tree
kono
parents:
diff changeset
85 -- is busy then Program_Error is raised.
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 generic
kono
parents:
diff changeset
88 with procedure Free (X : in out Node_Access);
kono
parents:
diff changeset
89 procedure Generic_Delete_Tree (X : in out Node_Access);
kono
parents:
diff changeset
90 -- Deallocates the tree rooted at X, calling Free on each node
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 generic
kono
parents:
diff changeset
93 with function Copy_Node (Source : Node_Access) return Node_Access;
kono
parents:
diff changeset
94 with procedure Delete_Tree (X : in out Node_Access);
kono
parents:
diff changeset
95 function Generic_Copy_Tree (Source_Root : Node_Access) return Node_Access;
kono
parents:
diff changeset
96 -- Copies the tree rooted at Source_Root, using Copy_Node to copy each
kono
parents:
diff changeset
97 -- node of the source tree. If Copy_Node propagates an exception
kono
parents:
diff changeset
98 -- (e.g. Storage_Error), then Delete_Tree is first used to deallocate
kono
parents:
diff changeset
99 -- the target tree, and then the exception is propagated.
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 generic
kono
parents:
diff changeset
102 with function Copy_Tree (Root : Node_Access) return Node_Access;
kono
parents:
diff changeset
103 procedure Generic_Adjust (Tree : in out Tree_Type);
kono
parents:
diff changeset
104 -- Used to implement controlled Adjust. On input to Generic_Adjust, Tree
kono
parents:
diff changeset
105 -- holds a bitwise (shallow) copy of the source tree (as would be the case
kono
parents:
diff changeset
106 -- when controlled Adjust is called). On output, Tree holds its own (deep)
kono
parents:
diff changeset
107 -- copy of the source tree, which is constructed by calling Copy_Tree.
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 generic
kono
parents:
diff changeset
110 with procedure Delete_Tree (X : in out Node_Access);
kono
parents:
diff changeset
111 procedure Generic_Clear (Tree : in out Tree_Type);
kono
parents:
diff changeset
112 -- Clears Tree by deallocating all of its nodes. If Tree is busy then
kono
parents:
diff changeset
113 -- Program_Error is raised.
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 generic
kono
parents:
diff changeset
116 with procedure Clear (Tree : in out Tree_Type);
kono
parents:
diff changeset
117 procedure Generic_Move (Target, Source : in out Tree_Type);
kono
parents:
diff changeset
118 -- Moves the tree belonging to Source onto Target. If Source is busy then
kono
parents:
diff changeset
119 -- Program_Error is raised. Otherwise Target is first cleared (by calling
kono
parents:
diff changeset
120 -- Clear, to deallocate its existing tree), then given the Source tree, and
kono
parents:
diff changeset
121 -- then finally Source is cleared (by setting its pointers to null).
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 generic
kono
parents:
diff changeset
124 with procedure Process (Node : Node_Access) is <>;
kono
parents:
diff changeset
125 procedure Generic_Iteration (Tree : Tree_Type);
kono
parents:
diff changeset
126 -- Calls Process for each node in Tree, in order from smallest-valued
kono
parents:
diff changeset
127 -- node to largest-valued node.
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 generic
kono
parents:
diff changeset
130 with procedure Process (Node : Node_Access) is <>;
kono
parents:
diff changeset
131 procedure Generic_Reverse_Iteration (Tree : Tree_Type);
kono
parents:
diff changeset
132 -- Calls Process for each node in Tree, in order from largest-valued
kono
parents:
diff changeset
133 -- node to smallest-valued node.
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 generic
kono
parents:
diff changeset
136 with procedure Write_Node
kono
parents:
diff changeset
137 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
138 Node : Node_Access);
kono
parents:
diff changeset
139 procedure Generic_Write
kono
parents:
diff changeset
140 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
141 Tree : Tree_Type);
kono
parents:
diff changeset
142 -- Used to implement stream attribute T'Write. Generic_Write
kono
parents:
diff changeset
143 -- first writes the number of nodes into Stream, then calls
kono
parents:
diff changeset
144 -- Write_Node for each node in Tree.
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 generic
kono
parents:
diff changeset
147 with procedure Clear (Tree : in out Tree_Type);
kono
parents:
diff changeset
148 with function Read_Node
kono
parents:
diff changeset
149 (Stream : not null access Root_Stream_Type'Class) return Node_Access;
kono
parents:
diff changeset
150 procedure Generic_Read
kono
parents:
diff changeset
151 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
152 Tree : in out Tree_Type);
kono
parents:
diff changeset
153 -- Used to implement stream attribute T'Read. Generic_Read
kono
parents:
diff changeset
154 -- first clears Tree. It then reads the number of nodes out of
kono
parents:
diff changeset
155 -- Stream, and calls Read_Node for each node in Stream.
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 procedure Rebalance_For_Insert
kono
parents:
diff changeset
158 (Tree : in out Tree_Type;
kono
parents:
diff changeset
159 Node : Node_Access);
kono
parents:
diff changeset
160 -- This rebalances Tree to complete the insertion of Node (which
kono
parents:
diff changeset
161 -- must already be linked in at its proper insertion position).
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 end Ada.Containers.Red_Black_Trees.Generic_Operations;