26 #ifndef MLN_CORE_SITE_SET_P_KEY_HH
27 # define MLN_CORE_SITE_SET_P_KEY_HH
36 # include <mln/core/concept/function.hh>
37 # include <mln/core/site_set/p_set.hh>
38 # include <mln/core/site_set/p_double.hh>
39 # include <mln/core/internal/site_set_base.hh>
40 # include <mln/util/ord.hh>
47 template <
typename K,
typename P>
class p_key;
54 template <
typename K,
typename P>
55 struct site_set_< p_key<K,P> >
57 typedef trait::site_set::nsites::known
nsites;
58 typedef trait::site_set::bbox::unknown bbox;
59 typedef trait::site_set::contents::growing contents;
60 typedef trait::site_set::arity::unique arity;
71 template <
typename K,
typename P>
72 class p_key :
public internal::site_set_base_< P,
83 typedef p_double_psite< self_, p_set<P> >
psite;
86 typedef p_double_piter<
self_,
91 typedef p_double_piter<
self_,
107 bool has(
const P& p)
const;
124 void insert(
const K& k,
const P& p);
127 void unsafe_insert_(
const K& k,
const P& p);
135 void remove(
const P& p);
144 template <
typename F>
159 const K&
key(
const P& p)
const;
187 typedef std::map<P, K, util::ord<P> > k_t;
199 template <
typename K,
typename P>
200 std::ostream& operator<<(std::ostream& ostr, const p_key<K,P>& pk);
204 # ifndef MLN_INCLUDE_ONLY
206 template <
typename K,
typename P>
211 mln_invariant(run_());
214 template <
typename K,
typename P>
219 mln_invariant(run_());
224 template <
typename K,
typename P>
229 mln_invariant(run_());
230 return k_.find(p) != k_.end();
233 template <
typename K,
typename P>
238 mln_invariant(run_());
242 template <
typename K,
typename P>
247 mln_invariant(run_());
252 template <
typename K,
typename P>
261 mln_invariant(run_());
265 template <
typename K,
typename P>
270 mln_invariant(run_());
271 typename k_t::iterator p_k = k_.find(p);
275 K
p_key = p_k->second;
276 mln_assertion(b_.has(p_key));
277 mln_assertion(s_[p_key].has(p));
295 mln_invariant(run_());
298 template <
typename K,
typename P>
303 this->insert(k_p.first, k_p.second);
306 template <
typename K,
typename P>
311 mln_invariant(run_());
312 typename k_t::iterator p_k = k_.find(p);
318 K
p_key = p_k->second;
319 mln_assertion(b_.has(p_key));
325 typename s_t::iterator k_s = s_.find(p_key);
326 mln_assertion(k_s != s_.end());
328 mln_assertion(s.has(p));
345 mln_invariant(run_());
348 template <
typename K,
typename P>
353 mln_invariant(run_());
354 typename s_t::iterator k_s = s_.find(k);
375 mln_invariant(run_());
379 template <
typename K,
typename P>
384 mln_invariant(run_());
390 typename s_t::iterator k_s = s_.find(k);
411 typename k_t::iterator p_k;
412 for (p_k = k_.begin(); p_k != k_.end(); ++p_k)
413 if (p_k->second == k)
421 mln_invariant(run_());
424 template <
typename K,
typename P>
425 template <
typename F>
430 mln_invariant(run_());
432 const F& f = exact(f_);
440 new_b.
insert(lut[k] = f(k));
447 typename k_t::iterator p_k;
448 for (p_k = k_.begin(); p_k != k_.end(); ++p_k)
450 p_k->second = lut[p_k->second];
451 new_s[p_k->second].insert(p_k->first);
456 mln_invariant(run_());
459 template <
typename K,
typename P>
464 mln_invariant(run_());
469 mln_invariant(run_());
472 template <
typename K,
typename P>
477 mln_invariant(run_());
486 template <
typename K,
typename P>
493 return s_.find(key)->second;
498 template <
typename K,
typename P>
503 mln_invariant(run_());
504 mln_precondition(k_.find(p) != k_.end());
505 return k_.find(p)->second;
508 template <
typename K,
typename P>
513 mln_invariant(run_());
517 template <
typename K,
typename P>
522 mln_invariant(run_());
526 template <
typename K,
typename P>
534 template <
typename K,
typename P>
537 p_key<K,P>::set_2_(
const K& key)
const
539 mln_precondition(b_.has(key));
540 return s_.find(key)->second;
543 template <
typename K,
typename P>
546 p_key<K,P>::run_()
const
548 if (!
implies(n_ == 0, b_.is_empty()))
550 std::cerr <<
"#1" << std::endl;
554 if (b_.nelements() != s_.size())
557 std::cerr <<
"#2" << std::endl;
564 std::cerr <<
"#3: k_.size=" << k_.size() <<
" n_=" << n_ << std::endl;
569 mln_eiter(util::set<K>) key(b_);
572 typename s_t::const_iterator k_s = s_.find(key);
577 std::cerr <<
"#4" << std::endl;
581 const p_set<P>& s = k_s->second;
586 std::cerr <<
"#5" << std::endl;
592 mln_piter(p_set<P>) p(s);
595 typename k_t::const_iterator p_k = k_.find(p);
600 std::cerr <<
"#6" << std::endl;
604 if (p_k->second != key)
607 std::cerr <<
"#7" << std::endl;
616 std::cerr <<
"#8" << std::endl;
629 template <
typename K,
typename P>
630 std::ostream& operator<<(std::ostream& ostr, const p_key<K,P>& pk)
633 mln_fwd_eiter(util::set<K>) k(pk.keys());
636 ostr <<
' ' << k <<
':';
637 ostr << pk.set_2_(k);
643 # endif // ! MLN_INCLUDE_ONLY
648 #endif // ! MLN_CORE_SITE_SET_P_KEY_HH