1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
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 --
9 -- Copyright (C) 2004-2010, 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
.Streams
;
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
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
;
76 New_Item
: Element_Type
);
78 procedure Query_Element
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
);
89 (Container
: in out Set
;
90 New_Item
: Element_Type
;
91 Position
: out Cursor
;
92 Inserted
: out Boolean);
95 (Container
: in out Set
;
96 New_Item
: Element_Type
);
99 (Container
: in out Set
;
100 New_Item
: Element_Type
);
103 (Container
: in out Set
;
104 New_Item
: Element_Type
);
107 (Container
: in out Set
;
108 Item
: Element_Type
);
111 (Container
: in out Set
;
112 Item
: Element_Type
);
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;
190 Process
: not null access procedure (Position
: Cursor
));
192 procedure Reverse_Iterate
194 Process
: not null access procedure (Position
: Cursor
));
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
;
212 (Container
: in out Set
;
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
;
231 Process
: not null access
232 procedure (Element
: in out Element_Type
));
238 pragma Inline
(Next
);
239 pragma Inline
(Previous
);
241 type Node_Type
is record
245 Color
: Red_Black_Trees
.Color_Type
:= Red_Black_Trees
.Red
;
246 Element
: Element_Type
;
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
;
267 (Stream
: not null access Root_Stream_Type
'Class;
270 for Cursor
'Write use Write
;
273 (Stream
: not null access Root_Stream_Type
'Class;
276 for Cursor
'Read use Read
;
278 No_Element
: constant Cursor
:= Cursor
'(null, 0);
281 (Stream : not null access Root_Stream_Type'Class;
284 for Set'Write use Write;
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
;