1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.INDEFINITE_ORDERED_SETS --
9 -- Copyright (C) 2004-2011, 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 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. --
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. --
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/>. --
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 with Ada
.Streams
; use Ada
.Streams
;
37 with Ada
.Iterator_Interfaces
;
40 type Element_Type
(<>) is private;
42 with function "<" (Left
, Right
: Element_Type
) return Boolean is <>;
43 with function "=" (Left
, Right
: Element_Type
) return Boolean is <>;
45 package Ada
.Containers
.Indefinite_Ordered_Sets
is
49 function Equivalent_Elements
(Left
, Right
: Element_Type
) return Boolean;
51 type Set
is tagged private with
52 Constant_Indexing
=> Constant_Reference
,
53 Default_Iterator
=> Iterate
,
54 Iterator_Element
=> Element_Type
;
56 pragma Preelaborable_Initialization
(Set
);
58 type Cursor
is private;
59 pragma Preelaborable_Initialization
(Cursor
);
61 Empty_Set
: constant Set
;
63 No_Element
: constant Cursor
;
65 function Has_Element
(Position
: Cursor
) return Boolean;
67 package Set_Iterator_Interfaces
is new
68 Ada
.Iterator_Interfaces
(Cursor
, Has_Element
);
70 type Constant_Reference_Type
71 (Element
: not null access constant Element_Type
) is
73 Implicit_Dereference
=> Element
;
75 function Constant_Reference
77 Position
: Cursor
) return Constant_Reference_Type
;
80 (Stream
: not null access Root_Stream_Type
'Class;
81 Item
: out Constant_Reference_Type
);
83 for Constant_Reference_Type
'Read use Read
;
86 (Stream
: not null access Root_Stream_Type
'Class;
87 Item
: Constant_Reference_Type
);
89 for Constant_Reference_Type
'Write use Write
;
91 function "=" (Left
, Right
: Set
) return Boolean;
93 function Equivalent_Sets
(Left
, Right
: Set
) return Boolean;
95 function To_Set
(New_Item
: Element_Type
) return Set
;
97 function Length
(Container
: Set
) return Count_Type
;
99 function Is_Empty
(Container
: Set
) return Boolean;
101 procedure Clear
(Container
: in out Set
);
103 function Element
(Position
: Cursor
) return Element_Type
;
105 procedure Replace_Element
106 (Container
: in out Set
;
108 New_Item
: Element_Type
);
110 procedure Query_Element
112 Process
: not null access procedure (Element
: Element_Type
));
114 procedure Assign
(Target
: in out Set
; Source
: Set
);
116 function Copy
(Source
: Set
) return Set
;
118 procedure Move
(Target
: in out Set
; Source
: in out Set
);
121 (Container
: in out Set
;
122 New_Item
: Element_Type
;
123 Position
: out Cursor
;
124 Inserted
: out Boolean);
127 (Container
: in out Set
;
128 New_Item
: Element_Type
);
131 (Container
: in out Set
;
132 New_Item
: Element_Type
);
135 (Container
: in out Set
;
136 New_Item
: Element_Type
);
139 (Container
: in out Set
;
140 Item
: Element_Type
);
143 (Container
: in out Set
;
144 Item
: Element_Type
);
147 (Container
: in out Set
;
148 Position
: in out Cursor
);
150 procedure Delete_First
(Container
: in out Set
);
152 procedure Delete_Last
(Container
: in out Set
);
154 procedure Union
(Target
: in out Set
; Source
: Set
);
156 function Union
(Left
, Right
: Set
) return Set
;
158 function "or" (Left
, Right
: Set
) return Set
renames Union
;
160 procedure Intersection
(Target
: in out Set
; Source
: Set
);
162 function Intersection
(Left
, Right
: Set
) return Set
;
164 function "and" (Left
, Right
: Set
) return Set
renames Intersection
;
166 procedure Difference
(Target
: in out Set
; Source
: Set
);
168 function Difference
(Left
, Right
: Set
) return Set
;
170 function "-" (Left
, Right
: Set
) return Set
renames Difference
;
172 procedure Symmetric_Difference
(Target
: in out Set
; Source
: Set
);
174 function Symmetric_Difference
(Left
, Right
: Set
) return Set
;
176 function "xor" (Left
, Right
: Set
) return Set
renames Symmetric_Difference
;
178 function Overlap
(Left
, Right
: Set
) return Boolean;
180 function Is_Subset
(Subset
: Set
; Of_Set
: Set
) return Boolean;
182 function First
(Container
: Set
) return Cursor
;
184 function First_Element
(Container
: Set
) return Element_Type
;
186 function Last
(Container
: Set
) return Cursor
;
188 function Last_Element
(Container
: Set
) return Element_Type
;
190 function Next
(Position
: Cursor
) return Cursor
;
192 procedure Next
(Position
: in out Cursor
);
194 function Previous
(Position
: Cursor
) return Cursor
;
196 procedure Previous
(Position
: in out Cursor
);
200 Item
: Element_Type
) return Cursor
;
204 Item
: Element_Type
) return Cursor
;
208 Item
: Element_Type
) return Cursor
;
212 Item
: Element_Type
) return Boolean;
214 function "<" (Left
, Right
: Cursor
) return Boolean;
216 function ">" (Left
, Right
: Cursor
) return Boolean;
218 function "<" (Left
: Cursor
; Right
: Element_Type
) return Boolean;
220 function ">" (Left
: Cursor
; Right
: Element_Type
) return Boolean;
222 function "<" (Left
: Element_Type
; Right
: Cursor
) return Boolean;
224 function ">" (Left
: Element_Type
; Right
: Cursor
) return Boolean;
228 Process
: not null access procedure (Position
: Cursor
));
230 procedure Reverse_Iterate
232 Process
: not null access procedure (Position
: Cursor
));
236 return Set_Iterator_Interfaces
.Reversible_Iterator
'class;
241 return Set_Iterator_Interfaces
.Reversible_Iterator
'class;
244 type Key_Type
(<>) is private;
246 with function Key
(Element
: Element_Type
) return Key_Type
;
248 with function "<" (Left
, Right
: Key_Type
) return Boolean is <>;
250 package Generic_Keys
is
252 function Equivalent_Keys
(Left
, Right
: Key_Type
) return Boolean;
254 function Key
(Position
: Cursor
) return Key_Type
;
256 function Element
(Container
: Set
; Key
: Key_Type
) return Element_Type
;
259 (Container
: in out Set
;
261 New_Item
: Element_Type
);
263 procedure Exclude
(Container
: in out Set
; Key
: Key_Type
);
265 procedure Delete
(Container
: in out Set
; Key
: Key_Type
);
269 Key
: Key_Type
) return Cursor
;
273 Key
: Key_Type
) return Cursor
;
277 Key
: Key_Type
) return Cursor
;
281 Key
: Key_Type
) return Boolean;
283 procedure Update_Element_Preserving_Key
284 (Container
: in out Set
;
286 Process
: not null access
287 procedure (Element
: in out Element_Type
));
289 type Reference_Type
(Element
: not null access Element_Type
) is private
291 Implicit_Dereference
=> Element
;
293 function Reference_Preserving_Key
294 (Container
: aliased in out Set
;
295 Key
: Key_Type
) return Constant_Reference_Type
;
297 function Reference_Preserving_Key
298 (Container
: aliased in out Set
;
299 Key
: Key_Type
) return Reference_Type
;
303 (Element
: not null access Element_Type
) is null record;
306 (Stream
: not null access Root_Stream_Type
'Class;
307 Item
: Reference_Type
);
309 for Reference_Type
'Write use Write
;
312 (Stream
: not null access Root_Stream_Type
'Class;
313 Item
: out Reference_Type
);
315 for Reference_Type
'Read use Read
;
319 pragma Inline
(Next
);
320 pragma Inline
(Previous
);
323 type Node_Access
is access Node_Type
;
325 type Element_Access
is access Element_Type
;
327 type Node_Type
is limited record
328 Parent
: Node_Access
;
331 Color
: Red_Black_Trees
.Color_Type
:= Red_Black_Trees
.Red
;
332 Element
: Element_Access
;
335 package Tree_Types
is new Red_Black_Trees
.Generic_Tree_Types
339 type Set
is new Ada
.Finalization
.Controlled
with record
340 Tree
: Tree_Types
.Tree_Type
;
343 overriding
procedure Adjust
(Container
: in out Set
);
345 overriding
procedure Finalize
(Container
: in out Set
) renames Clear
;
349 use Ada
.Finalization
;
351 type Set_Access
is access all Set
;
352 for Set_Access
'Storage_Size use 0;
354 type Cursor
is record
355 Container
: Set_Access
;
360 (Stream
: not null access Root_Stream_Type
'Class;
363 for Cursor
'Write use Write
;
366 (Stream
: not null access Root_Stream_Type
'Class;
369 for Cursor
'Read use Read
;
371 No_Element
: constant Cursor
:= Cursor
'(null, null);
374 (Stream : not null access Root_Stream_Type'Class;
377 for Set'Write use Write;
380 (Stream : not null access Root_Stream_Type'Class;
381 Container : out Set);
383 for Set'Read use Read;
385 type Constant_Reference_Type
386 (Element : not null access constant Element_Type) is null record;
388 Empty_Set : constant Set :=
389 (Controlled with Tree => (First => null,
396 end Ada.Containers.Indefinite_Ordered_Sets;