OSDN Git Service

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