Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / gcc / ada / a-cborse.ads
blobf9719dcdbc63641b09ce259904448924aee862d5
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- A D A . C O N T A I N E R S . B O U N D E D _ O R D E R E D _ S E T S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2004-2010, 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.Streams;
37 generic
38 type Element_Type is private;
40 with function "<" (Left, Right : Element_Type) return Boolean is <>;
41 with function "=" (Left, Right : Element_Type) return Boolean is <>;
43 package Ada.Containers.Bounded_Ordered_Sets is
44 pragma Pure;
45 pragma Remote_Types;
47 function Equivalent_Elements (Left, Right : Element_Type) return Boolean;
49 type Set (Capacity : Count_Type) is tagged private;
50 pragma Preelaborable_Initialization (Set);
52 type Cursor is private;
53 pragma Preelaborable_Initialization (Cursor);
55 Empty_Set : constant Set;
57 No_Element : constant Cursor;
59 function "=" (Left, Right : Set) return Boolean;
61 function Equivalent_Sets (Left, Right : Set) return Boolean;
63 function To_Set (New_Item : Element_Type) return Set;
65 function Length (Container : Set) return Count_Type;
67 function Is_Empty (Container : Set) return Boolean;
69 procedure Clear (Container : in out Set);
71 function Element (Position : Cursor) return Element_Type;
73 procedure Replace_Element
74 (Container : in out Set;
75 Position : Cursor;
76 New_Item : Element_Type);
78 procedure Query_Element
79 (Position : Cursor;
80 Process : not null access procedure (Element : Element_Type));
82 procedure Assign (Target : in out Set; Source : Set);
84 function Copy (Source : Set; Capacity : Count_Type := 0) return Set;
86 procedure Move (Target : in out Set; Source : in out Set);
88 procedure Insert
89 (Container : in out Set;
90 New_Item : Element_Type;
91 Position : out Cursor;
92 Inserted : out Boolean);
94 procedure Insert
95 (Container : in out Set;
96 New_Item : Element_Type);
98 procedure Include
99 (Container : in out Set;
100 New_Item : Element_Type);
102 procedure Replace
103 (Container : in out Set;
104 New_Item : Element_Type);
106 procedure Exclude
107 (Container : in out Set;
108 Item : Element_Type);
110 procedure Delete
111 (Container : in out Set;
112 Item : Element_Type);
114 procedure Delete
115 (Container : in out Set;
116 Position : in out Cursor);
118 procedure Delete_First (Container : in out Set);
120 procedure Delete_Last (Container : in out Set);
122 procedure Union (Target : in out Set; Source : Set);
124 function Union (Left, Right : Set) return Set;
126 function "or" (Left, Right : Set) return Set renames Union;
128 procedure Intersection (Target : in out Set; Source : Set);
130 function Intersection (Left, Right : Set) return Set;
132 function "and" (Left, Right : Set) return Set renames Intersection;
134 procedure Difference (Target : in out Set; Source : Set);
136 function Difference (Left, Right : Set) return Set;
138 function "-" (Left, Right : Set) return Set renames Difference;
140 procedure Symmetric_Difference (Target : in out Set; Source : Set);
142 function Symmetric_Difference (Left, Right : Set) return Set;
144 function "xor" (Left, Right : Set) return Set renames Symmetric_Difference;
146 function Overlap (Left, Right : Set) return Boolean;
148 function Is_Subset (Subset : Set; Of_Set : Set) return Boolean;
150 function First (Container : Set) return Cursor;
152 function First_Element (Container : Set) return Element_Type;
154 function Last (Container : Set) return Cursor;
156 function Last_Element (Container : Set) return Element_Type;
158 function Next (Position : Cursor) return Cursor;
160 procedure Next (Position : in out Cursor);
162 function Previous (Position : Cursor) return Cursor;
164 procedure Previous (Position : in out Cursor);
166 function Find (Container : Set; Item : Element_Type) return Cursor;
168 function Floor (Container : Set; Item : Element_Type) return Cursor;
170 function Ceiling (Container : Set; Item : Element_Type) return Cursor;
172 function Contains (Container : Set; Item : Element_Type) return Boolean;
174 function Has_Element (Position : Cursor) return Boolean;
176 function "<" (Left, Right : Cursor) return Boolean;
178 function ">" (Left, Right : Cursor) return Boolean;
180 function "<" (Left : Cursor; Right : Element_Type) return Boolean;
182 function ">" (Left : Cursor; Right : Element_Type) return Boolean;
184 function "<" (Left : Element_Type; Right : Cursor) return Boolean;
186 function ">" (Left : Element_Type; Right : Cursor) return Boolean;
188 procedure Iterate
189 (Container : Set;
190 Process : not null access procedure (Position : Cursor));
192 procedure Reverse_Iterate
193 (Container : Set;
194 Process : not null access procedure (Position : Cursor));
196 generic
197 type Key_Type (<>) is private;
199 with function Key (Element : Element_Type) return Key_Type;
201 with function "<" (Left, Right : Key_Type) return Boolean is <>;
203 package Generic_Keys is
205 function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
207 function Key (Position : Cursor) return Key_Type;
209 function Element (Container : Set; Key : Key_Type) return Element_Type;
211 procedure Replace
212 (Container : in out Set;
213 Key : Key_Type;
214 New_Item : Element_Type);
216 procedure Exclude (Container : in out Set; Key : Key_Type);
218 procedure Delete (Container : in out Set; Key : Key_Type);
220 function Find (Container : Set; Key : Key_Type) return Cursor;
222 function Floor (Container : Set; Key : Key_Type) return Cursor;
224 function Ceiling (Container : Set; Key : Key_Type) return Cursor;
226 function Contains (Container : Set; Key : Key_Type) return Boolean;
228 procedure Update_Element_Preserving_Key
229 (Container : in out Set;
230 Position : Cursor;
231 Process : not null access
232 procedure (Element : in out Element_Type));
234 end Generic_Keys;
236 private
238 pragma Inline (Next);
239 pragma Inline (Previous);
241 type Node_Type is record
242 Parent : Count_Type;
243 Left : Count_Type;
244 Right : Count_Type;
245 Color : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
246 Element : Element_Type;
247 end record;
249 package Tree_Types is
250 new Red_Black_Trees.Generic_Bounded_Tree_Types (Node_Type);
252 type Set (Capacity : Count_Type) is
253 new Tree_Types.Tree_Type (Capacity) with null record;
255 type Set_Access is access all Set;
256 for Set_Access'Storage_Size use 0;
258 type Cursor is record
259 Container : Set_Access;
260 Node : Count_Type;
261 end record;
263 use Tree_Types;
264 use Ada.Streams;
266 procedure Write
267 (Stream : not null access Root_Stream_Type'Class;
268 Item : Cursor);
270 for Cursor'Write use Write;
272 procedure Read
273 (Stream : not null access Root_Stream_Type'Class;
274 Item : out Cursor);
276 for Cursor'Read use Read;
278 No_Element : constant Cursor := Cursor'(null, 0);
280 procedure Write
281 (Stream : not null access Root_Stream_Type'Class;
282 Container : Set);
284 for Set'Write use Write;
286 procedure Read
287 (Stream : not null access Root_Stream_Type'Class;
288 Container : out Set);
290 for Set'Read use Read;
292 Empty_Set : constant Set := Set'(Tree_Type with Capacity => 0);
294 end Ada.Containers.Bounded_Ordered_Sets;