1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.FUNCTIONAL_MAPS --
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 ------------------------------------------------------------------------------
33 package body Ada
.Containers
.Functional_Maps
with SPARK_Mode
=> Off
is
35 use Element_Containers
;
41 function "=" (Left
: Map
; Right
: Map
) return Boolean is
42 (Left
.Keys
<= Right
.Keys
and Right
<= Left
);
48 function "<=" (Left
: Map
; Right
: Map
) return Boolean is
52 for I1
in 1 .. Length
(Left
.Keys
) loop
53 I2
:= Find
(Right
.Keys
, Get
(Left
.Keys
, I1
));
55 or else Get
(Right
.Elements
, I2
) /= Get
(Left
.Elements
, I1
)
70 New_Item
: Element_Type
) return Map
75 Add
(Container
.Keys
, Length
(Container
.Keys
) + 1, New_Key
),
78 (Container
.Elements
, Length
(Container
.Elements
) + 1, New_Item
));
81 ---------------------------
82 -- Elements_Equal_Except --
83 ---------------------------
85 function Elements_Equal_Except
88 New_Key
: Key_Type
) return Boolean
91 for I
in 1 .. Length
(Left
.Keys
) loop
93 K
: constant Key_Type
:= Get
(Left
.Keys
, I
);
95 if not Equivalent_Keys
(K
, New_Key
)
97 (Find
(Right
.Keys
, K
) = 0
98 or else Get
(Right
.Elements
, Find
(Right
.Keys
, K
)) /=
99 Get
(Left
.Elements
, I
))
106 end Elements_Equal_Except
;
108 function Elements_Equal_Except
112 Y
: Key_Type
) return Boolean
115 for I
in 1 .. Length
(Left
.Keys
) loop
117 K
: constant Key_Type
:= Get
(Left
.Keys
, I
);
119 if not Equivalent_Keys
(K
, X
)
120 and then not Equivalent_Keys
(K
, Y
)
122 (Find
(Right
.Keys
, K
) = 0
123 or else Get
(Right
.Elements
, Find
(Right
.Keys
, K
)) /=
124 Get
(Left
.Elements
, I
))
131 end Elements_Equal_Except
;
137 function Get
(Container
: Map
; Key
: Key_Type
) return Element_Type
is
139 return Get
(Container
.Elements
, Find
(Container
.Keys
, Key
));
146 function Has_Key
(Container
: Map
; Key
: Key_Type
) return Boolean is
148 return Find
(Container
.Keys
, Key
) > 0;
157 Witness
: Count_Type
) return Boolean
159 (Witness
in 1 .. Length
(Container
.Keys
));
165 function Is_Empty
(Container
: Map
) return Boolean is
167 return Length
(Container
.Keys
) = 0;
174 function Keys_Included
(Left
: Map
; Right
: Map
) return Boolean is
176 for I
in 1 .. Length
(Left
.Keys
) loop
178 K
: constant Key_Type
:= Get
(Left
.Keys
, I
);
180 if Find
(Right
.Keys
, K
) = 0 then
189 --------------------------
190 -- Keys_Included_Except --
191 --------------------------
193 function Keys_Included_Except
196 New_Key
: Key_Type
) return Boolean
199 for I
in 1 .. Length
(Left
.Keys
) loop
201 K
: constant Key_Type
:= Get
(Left
.Keys
, I
);
203 if not Equivalent_Keys
(K
, New_Key
)
204 and then Find
(Right
.Keys
, K
) = 0
212 end Keys_Included_Except
;
214 function Keys_Included_Except
218 Y
: Key_Type
) return Boolean
221 for I
in 1 .. Length
(Left
.Keys
) loop
223 K
: constant Key_Type
:= Get
(Left
.Keys
, I
);
225 if not Equivalent_Keys
(K
, X
)
226 and then not Equivalent_Keys
(K
, Y
)
227 and then Find
(Right
.Keys
, K
) = 0
235 end Keys_Included_Except
;
241 function Length
(Container
: Map
) return Count_Type
is
243 return Length
(Container
.Elements
);
250 function Same_Keys
(Left
: Map
; Right
: Map
) return Boolean is
251 (Keys_Included
(Left
, Right
)
252 and Keys_Included
(Left
=> Right
, Right
=> Left
));
261 New_Item
: Element_Type
) return Map
263 (Keys
=> Container
.Keys
,
265 Set
(Container
.Elements
, Find
(Container
.Keys
, Key
), New_Item
));
273 Witness
: Count_Type
) return Element_Type
275 (Get
(Container
.Elements
, Witness
));
281 function Witness
(Container
: Map
; Key
: Key_Type
) return Count_Type
is
282 (Find
(Container
.Keys
, Key
));
284 end Ada
.Containers
.Functional_Maps
;