OSDN Git Service

2007-04-20 Vincent Celier <celier@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-coorma.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --           A D A . C O N T A I N E R S . O R D E R E D _ M A P S          --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2004-2006, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the  contents of the part following the private keyword. --
14 --                                                                          --
15 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
16 -- terms of the  GNU General Public License as published  by the Free Soft- --
17 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
18 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
21 -- for  more details.  You should have  received  a copy of the GNU General --
22 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
23 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
24 -- Boston, MA 02110-1301, USA.                                              --
25 --                                                                          --
26 -- As a special exception,  if other files  instantiate  generics from this --
27 -- unit, or you link  this unit with other files  to produce an executable, --
28 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
29 -- covered  by the  GNU  General  Public  License.  This exception does not --
30 -- however invalidate  any other reasons why  the executable file  might be --
31 -- covered by the  GNU Public License.                                      --
32 --                                                                          --
33 -- This unit was originally developed by Matthew J Heaney.                  --
34 ------------------------------------------------------------------------------
35
36 with Ada.Containers.Red_Black_Trees;
37 with Ada.Finalization;
38 with Ada.Streams;
39
40 generic
41    type Key_Type is private;
42    type Element_Type is private;
43
44    with function "<" (Left, Right : Key_Type) return Boolean is <>;
45    with function "=" (Left, Right : Element_Type) return Boolean is <>;
46
47 package Ada.Containers.Ordered_Maps is
48    pragma Preelaborate;
49
50    function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
51
52    type Map is tagged private;
53    pragma Preelaborable_Initialization (Map);
54
55    type Cursor is private;
56    pragma Preelaborable_Initialization (Cursor);
57
58    Empty_Map : constant Map;
59
60    No_Element : constant Cursor;
61
62    function "=" (Left, Right : Map) return Boolean;
63
64    function Length (Container : Map) return Count_Type;
65
66    function Is_Empty (Container : Map) return Boolean;
67
68    procedure Clear (Container : in out Map);
69
70    function Key (Position : Cursor) return Key_Type;
71
72    function Element (Position : Cursor) return Element_Type;
73
74    procedure Replace_Element
75      (Container : in out Map;
76       Position  : Cursor;
77       New_Item  : Element_Type);
78
79    procedure Query_Element
80      (Position : Cursor;
81       Process  : not null access
82                    procedure (Key : Key_Type; Element : Element_Type));
83
84    procedure Update_Element
85      (Container : in out Map;
86       Position  : Cursor;
87       Process   : not null access
88                    procedure (Key : Key_Type; Element : in out Element_Type));
89
90    procedure Move (Target : in out Map; Source : in out Map);
91
92    procedure Insert
93      (Container : in out Map;
94       Key       : Key_Type;
95       New_Item  : Element_Type;
96       Position  : out Cursor;
97       Inserted  : out Boolean);
98
99    procedure Insert
100      (Container : in out Map;
101       Key       : Key_Type;
102       Position  : out Cursor;
103       Inserted  : out Boolean);
104
105    procedure Insert
106      (Container : in out Map;
107       Key       : Key_Type;
108       New_Item  : Element_Type);
109
110    procedure Include
111      (Container : in out Map;
112       Key       : Key_Type;
113       New_Item  : Element_Type);
114
115    procedure Replace
116      (Container : in out Map;
117       Key       : Key_Type;
118       New_Item  : Element_Type);
119
120    procedure Exclude (Container : in out Map; Key : Key_Type);
121
122    procedure Delete (Container : in out Map; Key : Key_Type);
123
124    procedure Delete (Container : in out Map; Position : in out Cursor);
125
126    procedure Delete_First (Container : in out Map);
127
128    procedure Delete_Last (Container : in out Map);
129
130    function First (Container : Map) return Cursor;
131
132    function First_Element (Container : Map) return Element_Type;
133
134    function First_Key (Container : Map) return Key_Type;
135
136    function Last (Container : Map) return Cursor;
137
138    function Last_Element (Container : Map) return Element_Type;
139
140    function Last_Key (Container : Map) return Key_Type;
141
142    function Next (Position : Cursor) return Cursor;
143
144    procedure Next (Position : in out Cursor);
145
146    function Previous (Position : Cursor) return Cursor;
147
148    procedure Previous (Position : in out Cursor);
149
150    function Find (Container : Map; Key : Key_Type) return Cursor;
151
152    function Element (Container : Map; Key : Key_Type) return Element_Type;
153
154    function Floor (Container : Map; Key : Key_Type) return Cursor;
155
156    function Ceiling (Container : Map; Key : Key_Type) return Cursor;
157
158    function Contains (Container : Map; Key : Key_Type) return Boolean;
159
160    function Has_Element (Position : Cursor) return Boolean;
161
162    function "<" (Left, Right : Cursor) return Boolean;
163
164    function ">" (Left, Right : Cursor) return Boolean;
165
166    function "<" (Left : Cursor; Right : Key_Type) return Boolean;
167
168    function ">" (Left : Cursor; Right : Key_Type) return Boolean;
169
170    function "<" (Left : Key_Type; Right : Cursor) return Boolean;
171
172    function ">" (Left : Key_Type; Right : Cursor) return Boolean;
173
174    procedure Iterate
175      (Container : Map;
176       Process   : not null access procedure (Position : Cursor));
177
178    procedure Reverse_Iterate
179      (Container : Map;
180       Process   : not null access procedure (Position : Cursor));
181
182 private
183
184    type Node_Type;
185    type Node_Access is access Node_Type;
186
187    type Node_Type is limited record
188       Parent  : Node_Access;
189       Left    : Node_Access;
190       Right   : Node_Access;
191       Color   : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
192       Key     : Key_Type;
193       Element : Element_Type;
194    end record;
195
196    package Tree_Types is new Red_Black_Trees.Generic_Tree_Types
197      (Node_Type,
198       Node_Access);
199
200    type Map is new Ada.Finalization.Controlled with record
201       Tree : Tree_Types.Tree_Type;
202    end record;
203
204    procedure Adjust (Container : in out Map);
205
206    procedure Finalize (Container : in out Map) renames Clear;
207
208    use Red_Black_Trees;
209    use Tree_Types;
210    use Ada.Finalization;
211    use Ada.Streams;
212
213    type Map_Access is access all Map;
214    for Map_Access'Storage_Size use 0;
215
216    type Cursor is record
217       Container : Map_Access;
218       Node      : Node_Access;
219    end record;
220
221    procedure Write
222      (Stream : not null access Root_Stream_Type'Class;
223       Item   : Cursor);
224
225    for Cursor'Write use Write;
226
227    procedure Read
228      (Stream : not null access Root_Stream_Type'Class;
229       Item   : out Cursor);
230
231    for Cursor'Read use Read;
232
233    No_Element : constant Cursor := Cursor'(null, null);
234
235    procedure Write
236      (Stream    : not null access Root_Stream_Type'Class;
237       Container : Map);
238
239    for Map'Write use Write;
240
241    procedure Read
242      (Stream    : not null access Root_Stream_Type'Class;
243       Container : out Map);
244
245    for Map'Read use Read;
246
247    Empty_Map : constant Map :=
248                  (Controlled with Tree => (First  => null,
249                                            Last   => null,
250                                            Root   => null,
251                                            Length => 0,
252                                            Busy   => 0,
253                                            Lock   => 0));
254
255 end Ada.Containers.Ordered_Maps;