1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.FUNCTIONAL_SETS --
9 -- Copyright (C) 2016-2017, 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/>. --
30 ------------------------------------------------------------------------------
34 package body Ada
.Containers
.Functional_Sets
with SPARK_Mode
=> Off
is
41 function "=" (Left
: Set
; Right
: Set
) return Boolean is
42 (Left
.Content
<= Right
.Content
and Right
.Content
<= Left
.Content
);
48 function "<=" (Left
: Set
; Right
: Set
) return Boolean is
49 (Left
.Content
<= Right
.Content
);
55 function Add
(Container
: Set
; Item
: Element_Type
) return Set
is
57 Add
(Container
.Content
, Length
(Container
.Content
) + 1, Item
));
63 function Contains
(Container
: Set
; Item
: Element_Type
) return Boolean is
64 (Find
(Container
.Content
, Item
) > 0);
70 function Included_Except
73 Item
: Element_Type
) return Boolean
76 Equivalent_Elements
(E
, Item
) or Contains
(Right
, E
));
78 -----------------------
79 -- Included_In_Union --
80 -----------------------
82 function Included_In_Union
85 Right
: Set
) return Boolean
87 (for all Item
of Container
=>
88 Contains
(Left
, Item
) or Contains
(Right
, Item
));
90 ---------------------------
91 -- Includes_Intersection --
92 ---------------------------
94 function Includes_Intersection
97 Right
: Set
) return Boolean
99 (for all Item
of Left
=>
100 (if Contains
(Right
, Item
) then Contains
(Container
, Item
)));
106 function Intersection
(Left
: Set
; Right
: Set
) return Set
is
107 (Content
=> Intersection
(Left
.Content
, Right
.Content
));
113 function Is_Empty
(Container
: Set
) return Boolean is
114 (Length
(Container
.Content
) = 0);
120 function Is_Singleton
122 New_Item
: Element_Type
) return Boolean
124 (Length
(Container
.Content
) = 1
125 and New_Item
= Get
(Container
.Content
, 1));
131 function Length
(Container
: Set
) return Count_Type
is
132 (Length
(Container
.Content
));
141 Right
: Set
) return Boolean
143 (for all Item
of Container
=>
144 not Contains
(Right
, Item
) or not Contains
(Left
, Item
));
150 function No_Overlap
(Left
: Set
; Right
: Set
) return Boolean is
151 (Num_Overlaps
(Left
.Content
, Right
.Content
) = 0);
157 function Num_Overlaps
(Left
: Set
; Right
: Set
) return Count_Type
is
158 (Num_Overlaps
(Left
.Content
, Right
.Content
));
164 function Remove
(Container
: Set
; Item
: Element_Type
) return Set
is
165 (Content
=> Remove
(Container
.Content
, Find
(Container
.Content
, Item
)));
171 function Union
(Left
: Set
; Right
: Set
) return Set
is
172 (Content
=> Union
(Left
.Content
, Right
.Content
));
174 end Ada
.Containers
.Functional_Sets
;