OSDN Git Service

2008-04-08 Hristian Kirtchev <kirtchev@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-crbtgo.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --             ADA.CONTAINERS.RED_BLACK_TREES.GENERIC_OPERATIONS            --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2004-2007, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- This unit was originally developed by Matthew J Heaney.                  --
30 ------------------------------------------------------------------------------
31
32 --  Tree_Type is used to implement the ordered containers. This package
33 --  declares the tree operations that do not depend on keys.
34
35 with Ada.Streams; use Ada.Streams;
36
37 generic
38    with package Tree_Types is new Generic_Tree_Types (<>);
39    use Tree_Types;
40
41    with function  Parent (Node : Node_Access) return Node_Access is <>;
42    with procedure Set_Parent (Node : Node_Access; Parent : Node_Access) is <>;
43    with function  Left (Node : Node_Access) return Node_Access is <>;
44    with procedure Set_Left (Node : Node_Access; Left : Node_Access) is <>;
45    with function  Right (Node : Node_Access) return Node_Access is <>;
46    with procedure Set_Right (Node : Node_Access; Right : Node_Access) is <>;
47    with function  Color (Node : Node_Access) return Color_Type is <>;
48    with procedure Set_Color (Node : Node_Access; Color : Color_Type) is <>;
49
50 package Ada.Containers.Red_Black_Trees.Generic_Operations is
51    pragma Pure;
52
53    function Min (Node : Node_Access) return Node_Access;
54    --  Returns the smallest-valued node of the subtree rooted at Node
55
56    function Max (Node : Node_Access) return Node_Access;
57    --  Returns the largest-valued node of the subtree rooted at Node
58
59    --  NOTE: The Check_Invariant operation was used during early
60    --  development of the red-black tree. Now that the tree type
61    --  implementation has matured, we don't really need Check_Invariant
62    --  anymore.
63
64    --  procedure Check_Invariant (Tree : Tree_Type);
65
66    function Vet (Tree : Tree_Type; Node : Node_Access) return Boolean;
67    --  Inspects Node to determine (to the extent possible) whether
68    --  the node is valid; used to detect if the node is dangling.
69
70    function Next (Node : Node_Access) return Node_Access;
71    --  Returns the smallest node greater than Node
72
73    function Previous (Node : Node_Access) return Node_Access;
74    --  Returns the largest node less than Node
75
76    generic
77       with function Is_Equal (L, R : Node_Access) return Boolean;
78    function Generic_Equal (Left, Right : Tree_Type) return Boolean;
79    --  Uses Is_Equal to perform a node-by-node comparison of the
80    --  Left and Right trees; processing stops as soon as the first
81    --  non-equal node is found.
82
83    procedure Delete_Node_Sans_Free
84      (Tree : in out Tree_Type;
85       Node : Node_Access);
86    --  Removes Node from Tree without deallocating the node. If Tree
87    --  is busy then Program_Error is raised.
88
89    generic
90       with procedure Free (X : in out Node_Access);
91    procedure Generic_Delete_Tree (X : in out Node_Access);
92    --  Deallocates the tree rooted at X, calling Free on each node
93
94    generic
95       with function Copy_Node (Source : Node_Access) return Node_Access;
96       with procedure Delete_Tree (X : in out Node_Access);
97    function Generic_Copy_Tree (Source_Root : Node_Access) return Node_Access;
98    --  Copies the tree rooted at Source_Root, using Copy_Node to copy each
99    --  node of the source tree. If Copy_Node propagates an exception
100    --  (e.g. Storage_Error), then Delete_Tree is first used to deallocate
101    --  the target tree, and then the exception is propagated.
102
103    generic
104       with function Copy_Tree (Root : Node_Access) return Node_Access;
105    procedure Generic_Adjust (Tree : in out Tree_Type);
106    --  Used to implement controlled Adjust. On input to Generic_Adjust, Tree
107    --  holds a bitwise (shallow) copy of the source tree (as would be the case
108    --  when controlled Adjust is called). On output, Tree holds its own (deep)
109    --  copy of the source tree, which is constructed by calling Copy_Tree.
110
111    generic
112       with procedure Delete_Tree (X : in out Node_Access);
113    procedure Generic_Clear (Tree : in out Tree_Type);
114    --  Clears Tree by deallocating all of its nodes. If Tree is busy then
115    --  Program_Error is raised.
116
117    generic
118       with procedure Clear (Tree : in out Tree_Type);
119    procedure Generic_Move (Target, Source : in out Tree_Type);
120    --  Moves the tree belonging to Source onto Target. If Source is busy then
121    --  Program_Error is raised. Otherwise Target is first cleared (by calling
122    --  Clear, to deallocate its existing tree), then given the Source tree, and
123    --  then finally Source is cleared (by setting its pointers to null).
124
125    generic
126       with procedure Process (Node : Node_Access) is <>;
127    procedure Generic_Iteration (Tree : Tree_Type);
128    --  Calls Process for each node in Tree, in order from smallest-valued
129    --  node to largest-valued node.
130
131    generic
132       with procedure Process (Node : Node_Access) is <>;
133    procedure Generic_Reverse_Iteration (Tree : Tree_Type);
134    --  Calls Process for each node in Tree, in order from largest-valued
135    --  node to smallest-valued node.
136
137    generic
138       with procedure Write_Node
139         (Stream : not null access Root_Stream_Type'Class;
140          Node   : Node_Access);
141    procedure Generic_Write
142      (Stream : not null access Root_Stream_Type'Class;
143       Tree   : Tree_Type);
144    --  Used to implement stream attribute T'Write. Generic_Write
145    --  first writes the number of nodes into Stream, then calls
146    --  Write_Node for each node in Tree.
147
148    generic
149       with procedure Clear (Tree : in out Tree_Type);
150       with function Read_Node
151         (Stream : not null access Root_Stream_Type'Class) return Node_Access;
152    procedure Generic_Read
153      (Stream : not null access Root_Stream_Type'Class;
154       Tree   : in out Tree_Type);
155    --  Used to implement stream attribute T'Read. Generic_Read
156    --  first clears Tree. It then reads the number of nodes out of
157    --  Stream, and calls Read_Node for each node in Stream.
158
159    procedure Rebalance_For_Insert
160      (Tree : in out Tree_Type;
161       Node : Node_Access);
162    --  This rebalances Tree to complete the insertion of Node (which
163    --  must already be linked in at its proper insertion position).
164
165 end Ada.Containers.Red_Black_Trees.Generic_Operations;