fixing pr42337
[official-gcc.git] / gcc / ada / a-coorma.ads
blob9d404c29d44457e279ef857c1f646de0348647c7
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-2009, 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 3, 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. --
21 -- --
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
23 -- additional permissions described in the GCC Runtime Library Exception, --
24 -- version 3.1, as published by the Free Software Foundation. --
25 -- --
26 -- You should have received a copy of the GNU General Public License and --
27 -- a copy of the GCC Runtime Library Exception along with this program; --
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
29 -- <http://www.gnu.org/licenses/>. --
30 -- --
31 -- This unit was originally developed by Matthew J Heaney. --
32 ------------------------------------------------------------------------------
34 private with Ada.Containers.Red_Black_Trees;
35 private with Ada.Finalization;
36 private with Ada.Streams;
38 generic
39 type Key_Type is private;
40 type Element_Type is private;
42 with function "<" (Left, Right : Key_Type) return Boolean is <>;
43 with function "=" (Left, Right : Element_Type) return Boolean is <>;
45 package Ada.Containers.Ordered_Maps is
46 pragma Preelaborate;
47 pragma Remote_Types;
49 function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
51 type Map is tagged private;
52 pragma Preelaborable_Initialization (Map);
54 type Cursor is private;
55 pragma Preelaborable_Initialization (Cursor);
57 Empty_Map : constant Map;
59 No_Element : constant Cursor;
61 function "=" (Left, Right : Map) return Boolean;
63 function Length (Container : Map) return Count_Type;
65 function Is_Empty (Container : Map) return Boolean;
67 procedure Clear (Container : in out Map);
69 function Key (Position : Cursor) return Key_Type;
71 function Element (Position : Cursor) return Element_Type;
73 procedure Replace_Element
74 (Container : in out Map;
75 Position : Cursor;
76 New_Item : Element_Type);
78 procedure Query_Element
79 (Position : Cursor;
80 Process : not null access
81 procedure (Key : Key_Type; Element : Element_Type));
83 procedure Update_Element
84 (Container : in out Map;
85 Position : Cursor;
86 Process : not null access
87 procedure (Key : Key_Type; Element : in out Element_Type));
89 procedure Move (Target : in out Map; Source : in out Map);
91 procedure Insert
92 (Container : in out Map;
93 Key : Key_Type;
94 New_Item : Element_Type;
95 Position : out Cursor;
96 Inserted : out Boolean);
98 procedure Insert
99 (Container : in out Map;
100 Key : Key_Type;
101 Position : out Cursor;
102 Inserted : out Boolean);
104 procedure Insert
105 (Container : in out Map;
106 Key : Key_Type;
107 New_Item : Element_Type);
109 procedure Include
110 (Container : in out Map;
111 Key : Key_Type;
112 New_Item : Element_Type);
114 procedure Replace
115 (Container : in out Map;
116 Key : Key_Type;
117 New_Item : Element_Type);
119 procedure Exclude (Container : in out Map; Key : Key_Type);
121 procedure Delete (Container : in out Map; Key : Key_Type);
123 procedure Delete (Container : in out Map; Position : in out Cursor);
125 procedure Delete_First (Container : in out Map);
127 procedure Delete_Last (Container : in out Map);
129 function First (Container : Map) return Cursor;
131 function First_Element (Container : Map) return Element_Type;
133 function First_Key (Container : Map) return Key_Type;
135 function Last (Container : Map) return Cursor;
137 function Last_Element (Container : Map) return Element_Type;
139 function Last_Key (Container : Map) return Key_Type;
141 function Next (Position : Cursor) return Cursor;
143 procedure Next (Position : in out Cursor);
145 function Previous (Position : Cursor) return Cursor;
147 procedure Previous (Position : in out Cursor);
149 function Find (Container : Map; Key : Key_Type) return Cursor;
151 function Element (Container : Map; Key : Key_Type) return Element_Type;
153 function Floor (Container : Map; Key : Key_Type) return Cursor;
155 function Ceiling (Container : Map; Key : Key_Type) return Cursor;
157 function Contains (Container : Map; Key : Key_Type) return Boolean;
159 function Has_Element (Position : Cursor) return Boolean;
161 function "<" (Left, Right : Cursor) return Boolean;
163 function ">" (Left, Right : Cursor) return Boolean;
165 function "<" (Left : Cursor; Right : Key_Type) return Boolean;
167 function ">" (Left : Cursor; Right : Key_Type) return Boolean;
169 function "<" (Left : Key_Type; Right : Cursor) return Boolean;
171 function ">" (Left : Key_Type; Right : Cursor) return Boolean;
173 procedure Iterate
174 (Container : Map;
175 Process : not null access procedure (Position : Cursor));
177 procedure Reverse_Iterate
178 (Container : Map;
179 Process : not null access procedure (Position : Cursor));
181 private
183 pragma Inline (Next);
184 pragma Inline (Previous);
186 type Node_Type;
187 type Node_Access is access Node_Type;
189 type Node_Type is limited record
190 Parent : Node_Access;
191 Left : Node_Access;
192 Right : Node_Access;
193 Color : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
194 Key : Key_Type;
195 Element : Element_Type;
196 end record;
198 package Tree_Types is
199 new Red_Black_Trees.Generic_Tree_Types (Node_Type, Node_Access);
201 type Map is new Ada.Finalization.Controlled with record
202 Tree : Tree_Types.Tree_Type;
203 end record;
205 overriding
206 procedure Adjust (Container : in out Map);
208 overriding
209 procedure Finalize (Container : in out Map) renames Clear;
211 use Red_Black_Trees;
212 use Tree_Types;
213 use Ada.Finalization;
214 use Ada.Streams;
216 type Map_Access is access all Map;
217 for Map_Access'Storage_Size use 0;
219 type Cursor is record
220 Container : Map_Access;
221 Node : Node_Access;
222 end record;
224 procedure Write
225 (Stream : not null access Root_Stream_Type'Class;
226 Item : Cursor);
228 for Cursor'Write use Write;
230 procedure Read
231 (Stream : not null access Root_Stream_Type'Class;
232 Item : out Cursor);
234 for Cursor'Read use Read;
236 No_Element : constant Cursor := Cursor'(null, null);
238 procedure Write
239 (Stream : not null access Root_Stream_Type'Class;
240 Container : Map);
242 for Map'Write use Write;
244 procedure Read
245 (Stream : not null access Root_Stream_Type'Class;
246 Container : out Map);
248 for Map'Read use Read;
250 Empty_Map : constant Map :=
251 (Controlled with Tree => (First => null,
252 Last => null,
253 Root => null,
254 Length => 0,
255 Busy => 0,
256 Lock => 0));
258 end Ada.Containers.Ordered_Maps;