1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.ORDERED_SETS --
9 -- Copyright (C) 2004 Free Software Foundation, Inc. --
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. --
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, 59 Temple Place - Suite 330, Boston, --
24 -- MA 02111-1307, USA. --
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. --
33 -- This unit was originally developed by Matthew J Heaney. --
34 ------------------------------------------------------------------------------
36 with Ada.Containers.Red_Black_Trees;
37 with Ada.Finalization;
42 type Element_Type is private;
44 with function "<" (Left, Right : Element_Type) return Boolean is <>;
45 with function "=" (Left, Right : Element_Type) return Boolean is <>;
47 package Ada.Containers.Ordered_Sets is
48 pragma Preelaborate (Ordered_Sets);
50 type Set is tagged private;
52 type Cursor is private;
54 Empty_Set : constant Set;
56 No_Element : constant Cursor;
58 function "=" (Left, Right : Set) return Boolean;
60 function Length (Container : Set) return Count_Type;
62 function Is_Empty (Container : Set) return Boolean;
64 procedure Clear (Container : in out Set);
66 function Element (Position : Cursor) return Element_Type;
68 procedure Query_Element
70 Process : not null access procedure (Element : Element_Type));
72 -- TODO: resolve in Atlanta. ???
73 -- procedure Replace_Element
74 -- (Container : in out Set;
76 -- By : Element_Type);
83 (Container : in out Set;
84 New_Item : Element_Type;
85 Position : out Cursor;
86 Inserted : out Boolean);
89 (Container : in out Set;
90 New_Item : Element_Type);
93 (Container : in out Set;
94 New_Item : Element_Type);
97 (Container : in out Set;
98 New_Item : Element_Type);
101 (Container : in out Set;
102 Item : Element_Type);
105 (Container : in out Set;
106 Item : Element_Type);
109 (Container : in out Set;
110 Position : in out Cursor);
112 procedure Delete_First (Container : in out Set);
114 procedure Delete_Last (Container : in out Set);
116 procedure Union (Target : in out Set; Source : Set);
118 function Union (Left, Right : Set) return Set;
120 function "or" (Left, Right : Set) return Set renames Union;
122 procedure Intersection (Target : in out Set; Source : Set);
124 function Intersection (Left, Right : Set) return Set;
126 function "and" (Left, Right : Set) return Set renames Intersection;
128 procedure Difference (Target : in out Set;
131 function Difference (Left, Right : Set) return Set;
133 function "-" (Left, Right : Set) return Set renames Difference;
135 procedure Symmetric_Difference (Target : in out Set; Source : Set);
137 function Symmetric_Difference (Left, Right : Set) return Set;
139 function "xor" (Left, Right : Set) return Set renames Symmetric_Difference;
141 function Overlap (Left, Right : Set) return Boolean;
143 function Is_Subset (Subset : Set; Of_Set : Set) return Boolean;
145 function Contains (Container : Set; Item : Element_Type) return Boolean;
147 function Find (Container : Set; Item : Element_Type) return Cursor;
149 function Floor (Container : Set; Item : Element_Type) return Cursor;
151 function Ceiling (Container : Set; Item : Element_Type) return Cursor;
153 function First (Container : Set) return Cursor;
155 function First_Element (Container : Set) return Element_Type;
157 function Last (Container : Set) return Cursor;
159 function Last_Element (Container : Set) return Element_Type;
161 function Next (Position : Cursor) return Cursor;
163 function Previous (Position : Cursor) return Cursor;
165 procedure Next (Position : in out Cursor);
167 procedure Previous (Position : in out Cursor);
169 function Has_Element (Position : Cursor) return Boolean;
171 function "<" (Left, Right : Cursor) return Boolean;
173 function ">" (Left, Right : Cursor) return Boolean;
175 function "<" (Left : Cursor; Right : Element_Type) return Boolean;
177 function ">" (Left : Cursor; Right : Element_Type) return Boolean;
179 function "<" (Left : Element_Type; Right : Cursor) return Boolean;
181 function ">" (Left : Element_Type; Right : Cursor) return Boolean;
185 Process : not null access procedure (Position : Cursor));
187 procedure Reverse_Iterate
189 Process : not null access procedure (Position : Cursor));
192 type Key_Type (<>) is limited private;
194 with function Key (Element : Element_Type) return Key_Type;
198 Right : Element_Type) return Boolean is <>;
202 Right : Element_Type) return Boolean is <>;
204 package Generic_Keys is
206 function Contains (Container : Set; Key : Key_Type) return Boolean;
208 function Find (Container : Set; Key : Key_Type) return Cursor;
210 function Floor (Container : Set; Key : Key_Type) return Cursor;
212 function Ceiling (Container : Set; Key : Key_Type) return Cursor;
214 function Key (Position : Cursor) return Key_Type;
216 function Element (Container : Set; Key : Key_Type) return Element_Type;
218 -- TODO: resolve in Atlanta ???
220 -- (Container : in out Set;
222 -- New_Item : Element_Type);
224 procedure Delete (Container : in out Set; Key : Key_Type);
226 procedure Exclude (Container : in out Set; Key : Key_Type);
228 function "<" (Left : Cursor; Right : Key_Type) return Boolean;
230 function ">" (Left : Cursor; Right : Key_Type) return Boolean;
232 function "<" (Left : Key_Type; Right : Cursor) return Boolean;
234 function ">" (Left : Key_Type; Right : Cursor) return Boolean;
236 -- TODO: resolve name in Atlanta. Should name be just "Update_Element" ???
237 procedure Checked_Update_Element
238 (Container : in out Set;
240 Process : not null access
241 procedure (Element : in out Element_Type));
248 type Node_Access is access Node_Type;
250 package Tree_Types is
251 new Red_Black_Trees.Generic_Tree_Types (Node_Access);
254 use Ada.Finalization;
256 type Set is new Controlled with record
257 Tree : Tree_Type := (Length => 0, others => null);
260 procedure Adjust (Container : in out Set);
262 procedure Finalize (Container : in out Set) renames Clear;
264 type Set_Access is access constant Set;
266 type Cursor is record
267 Container : Set_Access;
271 No_Element : constant Cursor := Cursor'(null, null);
276 (Stream : access Root_Stream_Type'Class;
279 for Set'Write use Write;
282 (Stream : access Root_Stream_Type'Class;
283 Container : out Set);
285 for Set'Read use Read;
287 Empty_Set : constant Set :=
288 (Controlled with Tree => (Length => 0, others => null));
290 end Ada.Containers.Ordered_Sets;