Chris@16
|
1 /*-----------------------------------------------------------------------------+
|
Chris@16
|
2 Copyright (c) 2007-2011: Joachim Faulhaber
|
Chris@16
|
3 +------------------------------------------------------------------------------+
|
Chris@16
|
4 Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
5 (See accompanying file LICENCE.txt or copy at
|
Chris@16
|
6 http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7 +-----------------------------------------------------------------------------*/
|
Chris@16
|
8 #ifndef BOOST_ICL_MAP_HPP_JOFA_070519
|
Chris@16
|
9 #define BOOST_ICL_MAP_HPP_JOFA_070519
|
Chris@16
|
10
|
Chris@16
|
11 #include <boost/icl/impl_config.hpp>
|
Chris@16
|
12
|
Chris@16
|
13 #if defined(ICL_USE_BOOST_MOVE_IMPLEMENTATION)
|
Chris@16
|
14 # include <boost/container/map.hpp>
|
Chris@16
|
15 # include <boost/container/set.hpp>
|
Chris@16
|
16 #elif defined(ICL_USE_STD_IMPLEMENTATION)
|
Chris@16
|
17 # include <map>
|
Chris@16
|
18 # include <set>
|
Chris@16
|
19 #else // Default for implementing containers
|
Chris@16
|
20 # include <map>
|
Chris@16
|
21 # include <set>
|
Chris@16
|
22 #endif
|
Chris@16
|
23
|
Chris@16
|
24 #include <string>
|
Chris@16
|
25 #include <boost/type_traits/ice.hpp>
|
Chris@16
|
26 #include <boost/call_traits.hpp>
|
Chris@16
|
27 #include <boost/icl/detail/notate.hpp>
|
Chris@16
|
28 #include <boost/icl/detail/design_config.hpp>
|
Chris@16
|
29 #include <boost/icl/detail/concept_check.hpp>
|
Chris@16
|
30 #include <boost/icl/detail/on_absorbtion.hpp>
|
Chris@16
|
31 #include <boost/icl/type_traits/is_map.hpp>
|
Chris@16
|
32 #include <boost/icl/type_traits/absorbs_identities.hpp>
|
Chris@16
|
33 #include <boost/icl/type_traits/is_total.hpp>
|
Chris@16
|
34 #include <boost/icl/type_traits/is_element_container.hpp>
|
Chris@16
|
35 #include <boost/icl/type_traits/has_inverse.hpp>
|
Chris@16
|
36 #include <boost/icl/type_traits/to_string.hpp>
|
Chris@16
|
37
|
Chris@16
|
38 #include <boost/icl/associative_element_container.hpp>
|
Chris@16
|
39 #include <boost/icl/functors.hpp>
|
Chris@16
|
40
|
Chris@16
|
41 namespace boost{namespace icl
|
Chris@16
|
42 {
|
Chris@16
|
43
|
Chris@16
|
44 struct partial_absorber
|
Chris@16
|
45 {
|
Chris@16
|
46 enum { absorbs_identities = true };
|
Chris@16
|
47 enum { is_total = false };
|
Chris@16
|
48 };
|
Chris@16
|
49
|
Chris@16
|
50 template<>
|
Chris@16
|
51 inline std::string type_to_string<partial_absorber>::apply() { return "@0"; }
|
Chris@16
|
52
|
Chris@16
|
53 struct partial_enricher
|
Chris@16
|
54 {
|
Chris@16
|
55 enum { absorbs_identities = false };
|
Chris@16
|
56 enum { is_total = false };
|
Chris@16
|
57 };
|
Chris@16
|
58
|
Chris@16
|
59 template<>
|
Chris@16
|
60 inline std::string type_to_string<partial_enricher>::apply() { return "e0"; }
|
Chris@16
|
61
|
Chris@16
|
62 struct total_absorber
|
Chris@16
|
63 {
|
Chris@16
|
64 enum { absorbs_identities = true };
|
Chris@16
|
65 enum { is_total = true };
|
Chris@16
|
66 };
|
Chris@16
|
67
|
Chris@16
|
68 template<>
|
Chris@16
|
69 inline std::string type_to_string<total_absorber>::apply() { return "^0"; }
|
Chris@16
|
70
|
Chris@16
|
71 struct total_enricher
|
Chris@16
|
72 {
|
Chris@16
|
73 enum { absorbs_identities = false };
|
Chris@16
|
74 enum { is_total = true };
|
Chris@16
|
75 };
|
Chris@16
|
76
|
Chris@16
|
77 template<>
|
Chris@16
|
78 inline std::string type_to_string<total_enricher>::apply() { return "e^0"; }
|
Chris@16
|
79
|
Chris@16
|
80
|
Chris@16
|
81
|
Chris@16
|
82 /** \brief Addable, subractable and intersectable maps */
|
Chris@16
|
83 template
|
Chris@16
|
84 <
|
Chris@16
|
85 typename DomainT,
|
Chris@16
|
86 typename CodomainT,
|
Chris@16
|
87 class Traits = icl::partial_absorber,
|
Chris@16
|
88 ICL_COMPARE Compare = ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, DomainT),
|
Chris@16
|
89 ICL_COMBINE Combine = ICL_COMBINE_INSTANCE(icl::inplace_plus, CodomainT),
|
Chris@16
|
90 ICL_SECTION Section = ICL_SECTION_INSTANCE(icl::inter_section, CodomainT),
|
Chris@16
|
91 ICL_ALLOC Alloc = std::allocator
|
Chris@16
|
92 >
|
Chris@16
|
93 class map: private ICL_IMPL_SPACE::map<DomainT, CodomainT, ICL_COMPARE_DOMAIN(Compare,DomainT),
|
Chris@16
|
94 Alloc<std::pair<const DomainT, CodomainT> > >
|
Chris@16
|
95 {
|
Chris@16
|
96 public:
|
Chris@16
|
97 typedef Alloc<typename std::pair<const DomainT, CodomainT> > allocator_type;
|
Chris@16
|
98
|
Chris@16
|
99 typedef typename icl::map<DomainT,CodomainT,Traits, Compare,Combine,Section,Alloc> type;
|
Chris@16
|
100 typedef typename ICL_IMPL_SPACE::map<DomainT, CodomainT, ICL_COMPARE_DOMAIN(Compare,DomainT),
|
Chris@16
|
101 allocator_type> base_type;
|
Chris@16
|
102
|
Chris@16
|
103 typedef Traits traits;
|
Chris@16
|
104
|
Chris@16
|
105 public:
|
Chris@16
|
106 typedef DomainT domain_type;
|
Chris@16
|
107 typedef typename boost::call_traits<DomainT>::param_type domain_param;
|
Chris@16
|
108 typedef DomainT key_type;
|
Chris@16
|
109 typedef CodomainT codomain_type;
|
Chris@16
|
110 typedef CodomainT mapped_type;
|
Chris@16
|
111 typedef CodomainT data_type;
|
Chris@16
|
112 typedef std::pair<const DomainT, CodomainT> element_type;
|
Chris@16
|
113 typedef std::pair<const DomainT, CodomainT> value_type;
|
Chris@16
|
114 typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
|
Chris@16
|
115 typedef ICL_COMBINE_CODOMAIN(Combine,CodomainT) codomain_combine;
|
Chris@16
|
116 typedef domain_compare key_compare;
|
Chris@16
|
117 typedef ICL_COMPARE_DOMAIN(Compare,element_type) element_compare;
|
Chris@16
|
118 typedef typename inverse<codomain_combine >::type inverse_codomain_combine;
|
Chris@16
|
119 typedef typename mpl::if_
|
Chris@16
|
120 <has_set_semantics<codomain_type>
|
Chris@16
|
121 , ICL_SECTION_CODOMAIN(Section,CodomainT)
|
Chris@16
|
122 , codomain_combine
|
Chris@16
|
123 >::type codomain_intersect;
|
Chris@16
|
124 typedef typename inverse<codomain_intersect>::type inverse_codomain_intersect;
|
Chris@16
|
125 typedef typename base_type::value_compare value_compare;
|
Chris@16
|
126
|
Chris@16
|
127 typedef typename ICL_IMPL_SPACE::set<DomainT, domain_compare, Alloc<DomainT> > set_type;
|
Chris@16
|
128 typedef set_type key_object_type;
|
Chris@16
|
129
|
Chris@16
|
130
|
Chris@16
|
131 BOOST_STATIC_CONSTANT(bool, _total = (Traits::is_total));
|
Chris@16
|
132 BOOST_STATIC_CONSTANT(bool, _absorbs = (Traits::absorbs_identities));
|
Chris@16
|
133 BOOST_STATIC_CONSTANT(bool,
|
Chris@16
|
134 total_invertible = (mpl::and_<is_total<type>, has_inverse<codomain_type> >::value));
|
Chris@16
|
135
|
Chris@16
|
136 typedef on_absorbtion<type,codomain_combine,Traits::absorbs_identities>
|
Chris@16
|
137 on_identity_absorbtion;
|
Chris@16
|
138
|
Chris@16
|
139 public:
|
Chris@16
|
140 typedef typename base_type::pointer pointer;
|
Chris@16
|
141 typedef typename base_type::const_pointer const_pointer;
|
Chris@16
|
142 typedef typename base_type::reference reference;
|
Chris@16
|
143 typedef typename base_type::const_reference const_reference;
|
Chris@16
|
144 typedef typename base_type::iterator iterator;
|
Chris@16
|
145 typedef typename base_type::const_iterator const_iterator;
|
Chris@16
|
146 typedef typename base_type::size_type size_type;
|
Chris@16
|
147 typedef typename base_type::difference_type difference_type;
|
Chris@16
|
148 typedef typename base_type::reverse_iterator reverse_iterator;
|
Chris@16
|
149 typedef typename base_type::const_reverse_iterator const_reverse_iterator;
|
Chris@16
|
150
|
Chris@16
|
151 public:
|
Chris@16
|
152 BOOST_STATIC_CONSTANT(bool,
|
Chris@16
|
153 is_total_invertible = ( Traits::is_total
|
Chris@16
|
154 && has_inverse<codomain_type>::value));
|
Chris@16
|
155
|
Chris@16
|
156 BOOST_STATIC_CONSTANT(int, fineness = 4);
|
Chris@16
|
157
|
Chris@16
|
158 public:
|
Chris@16
|
159 //==========================================================================
|
Chris@16
|
160 //= Construct, copy, destruct
|
Chris@16
|
161 //==========================================================================
|
Chris@16
|
162 map()
|
Chris@16
|
163 {
|
Chris@16
|
164 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
|
Chris@16
|
165 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
|
Chris@16
|
166 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<CodomainT>));
|
Chris@16
|
167 BOOST_CONCEPT_ASSERT((EqualComparableConcept<CodomainT>));
|
Chris@16
|
168 }
|
Chris@16
|
169
|
Chris@16
|
170 map(const key_compare& comp): base_type(comp){}
|
Chris@16
|
171
|
Chris@16
|
172 template <class InputIterator>
|
Chris@16
|
173 map(InputIterator first, InputIterator past)
|
Chris@16
|
174 : base_type(first,past){}
|
Chris@16
|
175
|
Chris@16
|
176 template <class InputIterator>
|
Chris@16
|
177 map(InputIterator first, InputIterator past, const key_compare& comp)
|
Chris@16
|
178 : base_type(first,past,comp)
|
Chris@16
|
179 {}
|
Chris@16
|
180
|
Chris@16
|
181 map(const map& src)
|
Chris@16
|
182 : base_type(src)
|
Chris@16
|
183 {
|
Chris@16
|
184 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
|
Chris@16
|
185 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
|
Chris@16
|
186 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<CodomainT>));
|
Chris@16
|
187 BOOST_CONCEPT_ASSERT((EqualComparableConcept<CodomainT>));
|
Chris@16
|
188 }
|
Chris@16
|
189
|
Chris@16
|
190 explicit map(const element_type& key_value_pair): base_type::map()
|
Chris@16
|
191 {
|
Chris@16
|
192 insert(key_value_pair);
|
Chris@16
|
193 }
|
Chris@16
|
194
|
Chris@16
|
195 map& operator = (const map& src)
|
Chris@16
|
196 {
|
Chris@16
|
197 base_type::operator=(src);
|
Chris@16
|
198 return *this;
|
Chris@16
|
199 }
|
Chris@16
|
200
|
Chris@16
|
201 # ifndef BOOST_ICL_NO_CXX11_RVALUE_REFERENCES
|
Chris@16
|
202 //==========================================================================
|
Chris@16
|
203 //= Move semantics
|
Chris@16
|
204 //==========================================================================
|
Chris@16
|
205
|
Chris@16
|
206 map(map&& src)
|
Chris@16
|
207 : base_type(boost::move(src))
|
Chris@16
|
208 {
|
Chris@16
|
209 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
|
Chris@16
|
210 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
|
Chris@16
|
211 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<CodomainT>));
|
Chris@16
|
212 BOOST_CONCEPT_ASSERT((EqualComparableConcept<CodomainT>));
|
Chris@16
|
213 }
|
Chris@16
|
214
|
Chris@16
|
215 map& operator = (map&& src)
|
Chris@16
|
216 {
|
Chris@16
|
217 base_type::operator=(src);
|
Chris@16
|
218 return *this;
|
Chris@16
|
219 }
|
Chris@16
|
220 //==========================================================================
|
Chris@16
|
221 # endif // BOOST_ICL_NO_CXX11_RVALUE_REFERENCES
|
Chris@16
|
222
|
Chris@16
|
223 void swap(map& src) { base_type::swap(src); }
|
Chris@16
|
224
|
Chris@16
|
225 //==========================================================================
|
Chris@16
|
226 using base_type::empty;
|
Chris@16
|
227 using base_type::clear;
|
Chris@16
|
228
|
Chris@16
|
229 using base_type::begin;
|
Chris@16
|
230 using base_type::end;
|
Chris@16
|
231 using base_type::rbegin;
|
Chris@16
|
232 using base_type::rend;
|
Chris@16
|
233
|
Chris@16
|
234 using base_type::size;
|
Chris@16
|
235 using base_type::max_size;
|
Chris@16
|
236
|
Chris@16
|
237 using base_type::key_comp;
|
Chris@16
|
238 using base_type::value_comp;
|
Chris@16
|
239
|
Chris@16
|
240 using base_type::erase;
|
Chris@16
|
241 using base_type::find;
|
Chris@16
|
242 using base_type::count;
|
Chris@16
|
243
|
Chris@16
|
244 using base_type::lower_bound;
|
Chris@16
|
245 using base_type::upper_bound;
|
Chris@16
|
246 using base_type::equal_range;
|
Chris@16
|
247
|
Chris@16
|
248 using base_type::operator[];
|
Chris@16
|
249
|
Chris@16
|
250 public:
|
Chris@16
|
251 //==========================================================================
|
Chris@16
|
252 //= Containedness
|
Chris@16
|
253 //==========================================================================
|
Chris@16
|
254
|
Chris@16
|
255 template<class SubObject>
|
Chris@16
|
256 bool contains(const SubObject& sub)const
|
Chris@16
|
257 { return icl::contains(*this, sub); }
|
Chris@16
|
258
|
Chris@16
|
259 bool within(const map& super)const
|
Chris@16
|
260 { return icl::contains(super, *this); }
|
Chris@16
|
261
|
Chris@16
|
262 //==========================================================================
|
Chris@16
|
263 //= Size
|
Chris@16
|
264 //==========================================================================
|
Chris@16
|
265 /** \c iterative_size() yields the number of elements that is visited
|
Chris@16
|
266 throu complete iteration. For interval sets \c iterative_size() is
|
Chris@16
|
267 different from \c size(). */
|
Chris@16
|
268 std::size_t iterative_size()const { return base_type::size(); }
|
Chris@16
|
269
|
Chris@16
|
270 //==========================================================================
|
Chris@16
|
271 //= Selection
|
Chris@16
|
272 //==========================================================================
|
Chris@16
|
273
|
Chris@16
|
274 /** Total select function. */
|
Chris@16
|
275 codomain_type operator()(const domain_type& key)const
|
Chris@16
|
276 {
|
Chris@16
|
277 const_iterator it = find(key);
|
Chris@16
|
278 return it==end() ? identity_element<codomain_type>::value()
|
Chris@16
|
279 : it->second;
|
Chris@16
|
280 }
|
Chris@16
|
281
|
Chris@16
|
282 //==========================================================================
|
Chris@16
|
283 //= Addition
|
Chris@16
|
284 //==========================================================================
|
Chris@16
|
285 /** \c add inserts \c value_pair into the map if it's key does
|
Chris@16
|
286 not exist in the map.
|
Chris@16
|
287 If \c value_pairs's key value exists in the map, it's data
|
Chris@16
|
288 value is added to the data value already found in the map. */
|
Chris@16
|
289 map& add(const value_type& value_pair)
|
Chris@16
|
290 {
|
Chris@16
|
291 return _add<codomain_combine>(value_pair);
|
Chris@16
|
292 }
|
Chris@16
|
293
|
Chris@16
|
294 /** \c add add \c value_pair into the map using \c prior as a hint to
|
Chris@16
|
295 insert \c value_pair after the position \c prior is pointing to. */
|
Chris@16
|
296 iterator add(iterator prior, const value_type& value_pair)
|
Chris@16
|
297 {
|
Chris@16
|
298 return _add<codomain_combine>(prior, value_pair);
|
Chris@16
|
299 }
|
Chris@16
|
300
|
Chris@16
|
301 //==========================================================================
|
Chris@16
|
302 //= Subtraction
|
Chris@16
|
303 //==========================================================================
|
Chris@16
|
304 /** If the \c value_pair's key value is in the map, it's data value is
|
Chris@16
|
305 subtraced from the data value stored in the map. */
|
Chris@16
|
306 map& subtract(const element_type& value_pair)
|
Chris@16
|
307 {
|
Chris@16
|
308 on_invertible<type, is_total_invertible>
|
Chris@16
|
309 ::subtract(*this, value_pair);
|
Chris@16
|
310 return *this;
|
Chris@16
|
311 }
|
Chris@16
|
312
|
Chris@16
|
313 map& subtract(const domain_type& key)
|
Chris@16
|
314 {
|
Chris@16
|
315 icl::erase(*this, key);
|
Chris@16
|
316 return *this;
|
Chris@16
|
317 }
|
Chris@16
|
318
|
Chris@16
|
319 //==========================================================================
|
Chris@16
|
320 //= Insertion, erasure
|
Chris@16
|
321 //==========================================================================
|
Chris@16
|
322 std::pair<iterator,bool> insert(const value_type& value_pair)
|
Chris@16
|
323 {
|
Chris@16
|
324 if(on_identity_absorbtion::is_absorbable(value_pair.second))
|
Chris@16
|
325 return std::pair<iterator,bool>(end(),true);
|
Chris@16
|
326 else
|
Chris@16
|
327 return base_type::insert(value_pair);
|
Chris@16
|
328 }
|
Chris@16
|
329
|
Chris@16
|
330 iterator insert(iterator prior, const value_type& value_pair)
|
Chris@16
|
331 {
|
Chris@16
|
332 if(on_identity_absorbtion::is_absorbable(value_pair.second))
|
Chris@16
|
333 return end();
|
Chris@16
|
334 else
|
Chris@16
|
335 return base_type::insert(prior, value_pair);
|
Chris@16
|
336 }
|
Chris@16
|
337
|
Chris@16
|
338 template<class Iterator>
|
Chris@16
|
339 iterator insert(Iterator first, Iterator last)
|
Chris@16
|
340 {
|
Chris@16
|
341 iterator prior = end(), it = first;
|
Chris@16
|
342 while(it != last)
|
Chris@16
|
343 prior = this->insert(prior, *it++);
|
Chris@16
|
344 }
|
Chris@16
|
345
|
Chris@16
|
346 /** With <tt>key_value_pair = (k,v)</tt> set value \c v for key \c k */
|
Chris@16
|
347 map& set(const element_type& key_value_pair)
|
Chris@16
|
348 {
|
Chris@16
|
349 return icl::set_at(*this, key_value_pair);
|
Chris@16
|
350 }
|
Chris@16
|
351
|
Chris@16
|
352 /** erase \c key_value_pair from the map.
|
Chris@16
|
353 Erase only if, the exact value content \c val is stored for the given key. */
|
Chris@16
|
354 size_type erase(const element_type& key_value_pair)
|
Chris@16
|
355 {
|
Chris@16
|
356 return icl::erase(*this, key_value_pair);
|
Chris@16
|
357 }
|
Chris@16
|
358
|
Chris@16
|
359 //==========================================================================
|
Chris@16
|
360 //= Intersection
|
Chris@16
|
361 //==========================================================================
|
Chris@16
|
362 /** The intersection of \c key_value_pair and \c *this map is added to \c section. */
|
Chris@16
|
363 void add_intersection(map& section, const element_type& key_value_pair)const
|
Chris@16
|
364 {
|
Chris@16
|
365 on_definedness<type, Traits::is_total>
|
Chris@16
|
366 ::add_intersection(section, *this, key_value_pair);
|
Chris@16
|
367 }
|
Chris@16
|
368
|
Chris@16
|
369 //==========================================================================
|
Chris@16
|
370 //= Symmetric difference
|
Chris@16
|
371 //==========================================================================
|
Chris@16
|
372
|
Chris@16
|
373 map& flip(const element_type& operand)
|
Chris@16
|
374 {
|
Chris@16
|
375 on_total_absorbable<type,_total,_absorbs>::flip(*this, operand);
|
Chris@16
|
376 return *this;
|
Chris@16
|
377 }
|
Chris@16
|
378
|
Chris@16
|
379 private:
|
Chris@16
|
380 template<class Combiner>
|
Chris@16
|
381 map& _add(const element_type& value_pair);
|
Chris@16
|
382
|
Chris@16
|
383 template<class Combiner>
|
Chris@16
|
384 iterator _add(iterator prior, const element_type& value_pair);
|
Chris@16
|
385
|
Chris@16
|
386 template<class Combiner>
|
Chris@16
|
387 map& _subtract(const element_type& value_pair);
|
Chris@16
|
388
|
Chris@16
|
389 template<class FragmentT>
|
Chris@16
|
390 void total_add_intersection(type& section, const FragmentT& fragment)const
|
Chris@16
|
391 {
|
Chris@16
|
392 section += *this;
|
Chris@16
|
393 section.add(fragment);
|
Chris@16
|
394 }
|
Chris@16
|
395
|
Chris@16
|
396 void partial_add_intersection(type& section, const element_type& operand)const
|
Chris@16
|
397 {
|
Chris@16
|
398 const_iterator it_ = find(operand.first);
|
Chris@16
|
399 if(it_ != end())
|
Chris@16
|
400 {
|
Chris@16
|
401 section.template _add<codomain_combine >(*it_);
|
Chris@16
|
402 section.template _add<codomain_intersect>(operand);
|
Chris@16
|
403 }
|
Chris@16
|
404 }
|
Chris@16
|
405
|
Chris@16
|
406
|
Chris@16
|
407 private:
|
Chris@16
|
408 //--------------------------------------------------------------------------
|
Chris@16
|
409 template<class Type, bool is_total_invertible>
|
Chris@16
|
410 struct on_invertible;
|
Chris@16
|
411
|
Chris@16
|
412 template<class Type>
|
Chris@16
|
413 struct on_invertible<Type, true>
|
Chris@16
|
414 {
|
Chris@16
|
415 typedef typename Type::element_type element_type;
|
Chris@16
|
416 typedef typename Type::inverse_codomain_combine inverse_codomain_combine;
|
Chris@16
|
417
|
Chris@16
|
418 static void subtract(Type& object, const element_type& operand)
|
Chris@16
|
419 { object.template _add<inverse_codomain_combine>(operand); }
|
Chris@16
|
420 };
|
Chris@16
|
421
|
Chris@16
|
422 template<class Type>
|
Chris@16
|
423 struct on_invertible<Type, false>
|
Chris@16
|
424 {
|
Chris@16
|
425 typedef typename Type::element_type element_type;
|
Chris@16
|
426 typedef typename Type::inverse_codomain_combine inverse_codomain_combine;
|
Chris@16
|
427
|
Chris@16
|
428 static void subtract(Type& object, const element_type& operand)
|
Chris@16
|
429 { object.template _subtract<inverse_codomain_combine>(operand); }
|
Chris@16
|
430 };
|
Chris@16
|
431
|
Chris@16
|
432 friend struct on_invertible<type, true>;
|
Chris@16
|
433 friend struct on_invertible<type, false>;
|
Chris@16
|
434 //--------------------------------------------------------------------------
|
Chris@16
|
435
|
Chris@16
|
436 //--------------------------------------------------------------------------
|
Chris@16
|
437 template<class Type, bool is_total>
|
Chris@16
|
438 struct on_definedness;
|
Chris@16
|
439
|
Chris@16
|
440 template<class Type>
|
Chris@16
|
441 struct on_definedness<Type, true>
|
Chris@16
|
442 {
|
Chris@16
|
443 static void add_intersection(Type& section, const Type& object,
|
Chris@16
|
444 const element_type& operand)
|
Chris@16
|
445 { object.total_add_intersection(section, operand); }
|
Chris@16
|
446 };
|
Chris@16
|
447
|
Chris@16
|
448 template<class Type>
|
Chris@16
|
449 struct on_definedness<Type, false>
|
Chris@16
|
450 {
|
Chris@16
|
451 static void add_intersection(Type& section, const Type& object,
|
Chris@16
|
452 const element_type& operand)
|
Chris@16
|
453 { object.partial_add_intersection(section, operand); }
|
Chris@16
|
454 };
|
Chris@16
|
455
|
Chris@16
|
456 friend struct on_definedness<type, true>;
|
Chris@16
|
457 friend struct on_definedness<type, false>;
|
Chris@16
|
458 //--------------------------------------------------------------------------
|
Chris@16
|
459
|
Chris@16
|
460 //--------------------------------------------------------------------------
|
Chris@16
|
461 template<class Type, bool has_set_semantics, bool absorbs_identities>
|
Chris@16
|
462 struct on_codomain_model;
|
Chris@16
|
463
|
Chris@16
|
464 template<class Type>
|
Chris@16
|
465 struct on_codomain_model<Type, false, false>
|
Chris@16
|
466 { // !codomain_is_set, !absorbs_identities
|
Chris@16
|
467 static void subtract(Type&, typename Type::iterator it_,
|
Chris@16
|
468 const typename Type::codomain_type& )
|
Chris@16
|
469 { (*it_).second = identity_element<typename Type::codomain_type>::value(); }
|
Chris@16
|
470 };
|
Chris@16
|
471
|
Chris@16
|
472 template<class Type>
|
Chris@16
|
473 struct on_codomain_model<Type, false, true>
|
Chris@16
|
474 { // !codomain_is_set, absorbs_identities
|
Chris@16
|
475 static void subtract(Type& object, typename Type::iterator it_,
|
Chris@16
|
476 const typename Type::codomain_type& )
|
Chris@16
|
477 { object.erase(it_); }
|
Chris@16
|
478 };
|
Chris@16
|
479
|
Chris@16
|
480 template<class Type>
|
Chris@16
|
481 struct on_codomain_model<Type, true, false>
|
Chris@16
|
482 { // !codomain_is_set, !absorbs_identities
|
Chris@16
|
483 typedef typename Type::inverse_codomain_intersect inverse_codomain_intersect;
|
Chris@16
|
484 static void subtract(Type&, typename Type::iterator it_,
|
Chris@16
|
485 const typename Type::codomain_type& co_value)
|
Chris@16
|
486 {
|
Chris@16
|
487 inverse_codomain_intersect()((*it_).second, co_value);
|
Chris@16
|
488 }
|
Chris@16
|
489 };
|
Chris@16
|
490
|
Chris@16
|
491 template<class Type>
|
Chris@16
|
492 struct on_codomain_model<Type, true, true>
|
Chris@16
|
493 { // !codomain_is_set, absorbs_identities
|
Chris@16
|
494 typedef typename Type::inverse_codomain_intersect inverse_codomain_intersect;
|
Chris@16
|
495 static void subtract(Type& object, typename Type::iterator it_,
|
Chris@16
|
496 const typename Type::codomain_type& co_value)
|
Chris@16
|
497 {
|
Chris@16
|
498 inverse_codomain_intersect()((*it_).second, co_value);
|
Chris@16
|
499 if((*it_).second == identity_element<codomain_type>::value())
|
Chris@16
|
500 object.erase(it_);
|
Chris@16
|
501 }
|
Chris@16
|
502 };
|
Chris@16
|
503 //--------------------------------------------------------------------------
|
Chris@16
|
504
|
Chris@16
|
505 //--------------------------------------------------------------------------
|
Chris@16
|
506 template<class Type, bool is_total, bool absorbs_identities>
|
Chris@16
|
507 struct on_total_absorbable;
|
Chris@16
|
508
|
Chris@16
|
509 template<class Type>
|
Chris@16
|
510 struct on_total_absorbable<Type, true, true>
|
Chris@16
|
511 {
|
Chris@16
|
512 typedef typename Type::element_type element_type;
|
Chris@16
|
513 static void flip(Type& object, const typename Type::element_type&)
|
Chris@16
|
514 { icl::clear(object); }
|
Chris@16
|
515 };
|
Chris@16
|
516
|
Chris@16
|
517 template<class Type>
|
Chris@16
|
518 struct on_total_absorbable<Type, true, false>
|
Chris@16
|
519 {
|
Chris@16
|
520 typedef typename Type::element_type element_type;
|
Chris@16
|
521 typedef typename Type::codomain_type codomain_type;
|
Chris@16
|
522
|
Chris@16
|
523 static void flip(Type& object, const element_type& operand)
|
Chris@16
|
524 {
|
Chris@16
|
525 object.add(operand);
|
Chris@16
|
526 ICL_FORALL(typename Type, it_, object)
|
Chris@16
|
527 (*it_).second = identity_element<codomain_type>::value();
|
Chris@16
|
528 }
|
Chris@16
|
529 };
|
Chris@16
|
530
|
Chris@16
|
531 template<class Type>
|
Chris@16
|
532 struct on_total_absorbable<Type, false, true>
|
Chris@16
|
533 { // !is_total, absorbs_identities
|
Chris@16
|
534 typedef typename Type::element_type element_type;
|
Chris@16
|
535 typedef typename Type::codomain_type codomain_type;
|
Chris@16
|
536 typedef typename Type::iterator iterator;
|
Chris@16
|
537 typedef typename Type::inverse_codomain_intersect inverse_codomain_intersect;
|
Chris@16
|
538
|
Chris@16
|
539 static void flip(Type& object, const element_type& operand)
|
Chris@16
|
540 {
|
Chris@16
|
541 std::pair<iterator,bool> insertion = object.insert(operand);
|
Chris@16
|
542 if(!insertion.second)
|
Chris@16
|
543 on_codomain_model<Type, has_set_semantics<codomain_type>::value, true>
|
Chris@16
|
544 ::subtract(object, insertion.first, operand.second);
|
Chris@16
|
545 }
|
Chris@16
|
546 };
|
Chris@16
|
547
|
Chris@16
|
548 template<class Type>
|
Chris@16
|
549 struct on_total_absorbable<Type, false, false>
|
Chris@16
|
550 { // !is_total !absorbs_identities
|
Chris@16
|
551 typedef typename Type::element_type element_type;
|
Chris@16
|
552 typedef typename Type::codomain_type codomain_type;
|
Chris@16
|
553 typedef typename Type::iterator iterator;
|
Chris@16
|
554 typedef typename Type::inverse_codomain_intersect inverse_codomain_intersect;
|
Chris@16
|
555
|
Chris@16
|
556 static void flip(Type& object, const element_type& operand)
|
Chris@16
|
557 {
|
Chris@16
|
558 std::pair<iterator,bool> insertion = object.insert(operand);
|
Chris@16
|
559 if(!insertion.second)
|
Chris@16
|
560 on_codomain_model<Type, has_set_semantics<codomain_type>::value, false>
|
Chris@16
|
561 ::subtract(object, insertion.first, operand.second);
|
Chris@16
|
562 }
|
Chris@16
|
563 };
|
Chris@16
|
564
|
Chris@16
|
565 friend struct on_total_absorbable<type, true, true >;
|
Chris@16
|
566 friend struct on_total_absorbable<type, false, true >;
|
Chris@16
|
567 friend struct on_total_absorbable<type, true, false>;
|
Chris@16
|
568 friend struct on_total_absorbable<type, false, false>;
|
Chris@16
|
569 //--------------------------------------------------------------------------
|
Chris@16
|
570 };
|
Chris@16
|
571
|
Chris@16
|
572
|
Chris@16
|
573
|
Chris@16
|
574 //==============================================================================
|
Chris@16
|
575 //= Addition<ElementMap>
|
Chris@16
|
576 //==============================================================================
|
Chris@16
|
577 template <class DomainT, class CodomainT, class Traits, ICL_COMPARE Compare, ICL_COMBINE Combine, ICL_SECTION Section, ICL_ALLOC Alloc>
|
Chris@16
|
578 template <class Combiner>
|
Chris@16
|
579 map<DomainT,CodomainT,Traits,Compare,Combine,Section,Alloc>&
|
Chris@16
|
580 map<DomainT,CodomainT,Traits,Compare,Combine,Section,Alloc>
|
Chris@16
|
581 ::_add(const element_type& addend)
|
Chris@16
|
582 {
|
Chris@16
|
583 typedef typename on_absorbtion
|
Chris@16
|
584 <type,Combiner,absorbs_identities<type>::value>::type on_absorbtion_;
|
Chris@16
|
585
|
Chris@16
|
586 const codomain_type& co_val = addend.second;
|
Chris@16
|
587 if(on_absorbtion_::is_absorbable(co_val))
|
Chris@16
|
588 return *this;
|
Chris@16
|
589
|
Chris@16
|
590 std::pair<iterator,bool> insertion
|
Chris@16
|
591 = base_type::insert(value_type(addend.first, version<Combiner>()(co_val)));
|
Chris@16
|
592
|
Chris@16
|
593 if(!insertion.second)
|
Chris@16
|
594 {
|
Chris@16
|
595 iterator it = insertion.first;
|
Chris@16
|
596 Combiner()((*it).second, co_val);
|
Chris@16
|
597
|
Chris@16
|
598 if(on_absorbtion_::is_absorbable((*it).second))
|
Chris@16
|
599 erase(it);
|
Chris@16
|
600 }
|
Chris@16
|
601 return *this;
|
Chris@16
|
602 }
|
Chris@16
|
603
|
Chris@16
|
604
|
Chris@16
|
605 template <class DomainT, class CodomainT, class Traits, ICL_COMPARE Compare, ICL_COMBINE Combine, ICL_SECTION Section, ICL_ALLOC Alloc>
|
Chris@16
|
606 template <class Combiner>
|
Chris@16
|
607 typename map<DomainT,CodomainT,Traits,Compare,Combine,Section,Alloc>::iterator
|
Chris@16
|
608 map<DomainT,CodomainT,Traits,Compare,Combine,Section,Alloc>
|
Chris@16
|
609 ::_add(iterator prior_, const value_type& addend)
|
Chris@16
|
610 {
|
Chris@16
|
611 typedef typename on_absorbtion
|
Chris@16
|
612 <type,Combiner,absorbs_identities<type>::value>::type on_absorbtion_;
|
Chris@16
|
613
|
Chris@16
|
614 const codomain_type& co_val = addend.second;
|
Chris@16
|
615 if(on_absorbtion_::is_absorbable(co_val))
|
Chris@16
|
616 return end();
|
Chris@16
|
617
|
Chris@16
|
618 iterator inserted_
|
Chris@16
|
619 = base_type::insert(prior_,
|
Chris@16
|
620 value_type(addend.first, Combiner::identity_element()));
|
Chris@16
|
621 Combiner()((*inserted_).second, addend.second);
|
Chris@16
|
622
|
Chris@16
|
623 if(on_absorbtion_::is_absorbable((*inserted_).second))
|
Chris@16
|
624 {
|
Chris@16
|
625 erase(inserted_);
|
Chris@16
|
626 return end();
|
Chris@16
|
627 }
|
Chris@16
|
628 else
|
Chris@16
|
629 return inserted_;
|
Chris@16
|
630 }
|
Chris@16
|
631
|
Chris@16
|
632
|
Chris@16
|
633 //==============================================================================
|
Chris@16
|
634 //= Subtraction<ElementMap>
|
Chris@16
|
635 //==============================================================================
|
Chris@16
|
636 template <class DomainT, class CodomainT, class Traits, ICL_COMPARE Compare, ICL_COMBINE Combine, ICL_SECTION Section, ICL_ALLOC Alloc>
|
Chris@16
|
637 template <class Combiner>
|
Chris@16
|
638 map<DomainT,CodomainT,Traits,Compare,Combine,Section,Alloc>&
|
Chris@16
|
639 map<DomainT,CodomainT,Traits,Compare,Combine,Section,Alloc>::_subtract(const value_type& minuend)
|
Chris@16
|
640 {
|
Chris@16
|
641 typedef typename on_absorbtion
|
Chris@16
|
642 <type,Combiner,absorbs_identities<type>::value>::type on_absorbtion_;
|
Chris@16
|
643
|
Chris@16
|
644 iterator it_ = find(minuend.first);
|
Chris@16
|
645 if(it_ != end())
|
Chris@16
|
646 {
|
Chris@16
|
647 Combiner()((*it_).second, minuend.second);
|
Chris@16
|
648 if(on_absorbtion_::is_absorbable((*it_).second))
|
Chris@16
|
649 erase(it_);
|
Chris@16
|
650 }
|
Chris@16
|
651 return *this;
|
Chris@16
|
652 }
|
Chris@16
|
653
|
Chris@16
|
654
|
Chris@16
|
655 //-----------------------------------------------------------------------------
|
Chris@16
|
656 // type traits
|
Chris@16
|
657 //-----------------------------------------------------------------------------
|
Chris@16
|
658 template <class DomainT, class CodomainT, class Traits, ICL_COMPARE Compare, ICL_COMBINE Combine, ICL_SECTION Section, ICL_ALLOC Alloc>
|
Chris@16
|
659 struct is_map<icl::map<DomainT,CodomainT,Traits,Compare,Combine,Section,Alloc> >
|
Chris@16
|
660 {
|
Chris@16
|
661 typedef is_map<icl::map<DomainT,CodomainT,Traits,Compare,Combine,Section,Alloc> > type;
|
Chris@16
|
662 BOOST_STATIC_CONSTANT(bool, value = true);
|
Chris@16
|
663 };
|
Chris@16
|
664
|
Chris@16
|
665 template <class DomainT, class CodomainT, class Traits, ICL_COMPARE Compare, ICL_COMBINE Combine, ICL_SECTION Section, ICL_ALLOC Alloc>
|
Chris@16
|
666 struct has_inverse<icl::map<DomainT,CodomainT,Traits,Compare,Combine,Section,Alloc> >
|
Chris@16
|
667 {
|
Chris@16
|
668 typedef has_inverse<icl::map<DomainT,CodomainT,Traits,Compare,Combine,Section,Alloc> > type;
|
Chris@16
|
669 BOOST_STATIC_CONSTANT(bool, value = (has_inverse<CodomainT>::value));
|
Chris@16
|
670 };
|
Chris@16
|
671
|
Chris@16
|
672 template <class DomainT, class CodomainT, class Traits, ICL_COMPARE Compare, ICL_COMBINE Combine, ICL_SECTION Section, ICL_ALLOC Alloc>
|
Chris@16
|
673 struct absorbs_identities<icl::map<DomainT,CodomainT,Traits,Compare,Combine,Section,Alloc> >
|
Chris@16
|
674 {
|
Chris@16
|
675 typedef absorbs_identities type;
|
Chris@16
|
676 BOOST_STATIC_CONSTANT(int, value = Traits::absorbs_identities);
|
Chris@16
|
677 };
|
Chris@16
|
678
|
Chris@16
|
679 template <class DomainT, class CodomainT, class Traits, ICL_COMPARE Compare, ICL_COMBINE Combine, ICL_SECTION Section, ICL_ALLOC Alloc>
|
Chris@16
|
680 struct is_total<icl::map<DomainT,CodomainT,Traits,Compare,Combine,Section,Alloc> >
|
Chris@16
|
681 {
|
Chris@16
|
682 typedef is_total type;
|
Chris@16
|
683 BOOST_STATIC_CONSTANT(int, value = Traits::is_total);
|
Chris@16
|
684 };
|
Chris@16
|
685
|
Chris@16
|
686 template <class DomainT, class CodomainT, class Traits, ICL_COMPARE Compare, ICL_COMBINE Combine, ICL_SECTION Section, ICL_ALLOC Alloc>
|
Chris@16
|
687 struct type_to_string<icl::map<DomainT,CodomainT,Traits,Compare,Combine,Section,Alloc> >
|
Chris@16
|
688 {
|
Chris@16
|
689 static std::string apply()
|
Chris@16
|
690 {
|
Chris@16
|
691 return "map<"+ type_to_string<DomainT>::apply() + ","
|
Chris@16
|
692 + type_to_string<CodomainT>::apply() + ","
|
Chris@16
|
693 + type_to_string<Traits>::apply() +">";
|
Chris@16
|
694 }
|
Chris@16
|
695 };
|
Chris@16
|
696
|
Chris@16
|
697
|
Chris@16
|
698
|
Chris@16
|
699 }} // namespace icl boost
|
Chris@16
|
700
|
Chris@16
|
701 #endif // BOOST_ICL_MAP_HPP_JOFA_070519
|
Chris@16
|
702
|