26 #ifndef MLN_CORE_SITE_SET_P_PRIORITY_HH
27 # define MLN_CORE_SITE_SET_P_PRIORITY_HH
34 # include <mln/core/site_set/p_double.hh>
35 # include <mln/core/internal/site_set_base.hh>
36 # include <mln/util/set.hh>
37 # include <mln/util/ord.hh>
44 template <
typename P,
typename Q>
class p_priority;
51 template <
typename P,
typename Q>
52 struct site_set_< p_priority<P,Q> >
54 typedef trait::site_set::nsites::known
nsites;
55 typedef trait::site_set::bbox::unknown bbox;
56 typedef trait::site_set::contents::growing contents;
57 typedef trait::site_set::arity::multiple arity;
75 template <
typename P,
typename Q>
76 class p_priority :
public internal::site_set_base_< mln_site(Q),
78 private mlc_is_a(Q, Site_Set)::check_t
91 typedef p_double_piter< self_,
92 mln_bkd_eiter(util::
set<P>),
96 typedef p_double_piter< self_,
97 mln_fwd_eiter(util::
set<P>),
108 bool has(const psite&) const;
118 void push(const P& priority, const element& e);
124 void insert(const i_element& p_e);
138 const mln_element(Q)&
front() const;
153 const Q& operator()(const P& priority) const;
171 const util::
set<P>& set_1_() const;
172 const Q& set_2_(const P& priority) const;
181 typedef std::map<P, Q, util::ord<P> > q_type_;
193 template <typename P, typename Q>
194 std::ostream& operator<<(std::ostream& ostr, const
p_priority<P,Q>& pq);
198 # ifndef MLN_INCLUDE_ONLY
200 template <
typename P,
typename Q>
205 mln_invariant(run_());
208 template <
typename P,
typename Q>
213 mln_invariant(run_());
218 template <
typename P,
typename Q>
223 mln_invariant(run_());
227 template <
typename P,
typename Q>
232 mln_invariant(run_());
236 template <
typename P,
typename Q>
241 mln_invariant(run_());
243 q_[priority].push(e);
245 mln_invariant(run_());
248 template <
typename P,
typename Q>
253 this->
push(p_e.first, p_e.second);
256 template <
typename P,
typename Q>
261 mln_invariant(run_());
262 typename q_type_::const_iterator i;
263 for (i = other.q_.begin(); i != other.q_.end(); ++i)
265 P priority = i->first;
267 const Q& q_p = i->second;
271 mln_invariant(run_());
274 template <
typename P,
typename Q>
279 mln_precondition(! this->is_empty());
282 if (q_[prior].is_empty())
288 mln_invariant(run_());
291 template <
typename P,
typename Q>
293 const mln_element(Q)&
296 mln_precondition(! this->is_empty());
297 q_type_& q__ =
const_cast< q_type_&
>(q_);
301 template <
typename P,
typename Q>
306 mln_precondition(! this->is_empty());
308 mln_element(Q) e = this->
front();
313 template <
typename P,
typename Q>
318 mln_invariant(run_());
322 mln_invariant(run_());
325 template <
typename P,
typename Q>
330 mln_invariant(run_());
331 std::size_t mem_q = 0;
332 typename q_type_::const_iterator i;
333 for (i = q_.begin(); i != q_.end(); ++i)
334 mem_q += i->second.memory_size();
335 return p_.memory_size() +
sizeof(q_) +
sizeof(n_);
338 template <
typename P,
typename Q>
343 static const Q nil_ = Q();
346 q_type_& mq =
const_cast<q_type_&
>(q_);
347 mln_assertion(mq[priority].
nsites() > 0);
354 template <
typename P,
typename Q>
359 mln_invariant(run_());
363 template <
typename P,
typename Q>
368 mln_invariant(run_());
369 return p_.has(priority);
372 template <
typename P,
typename Q>
377 mln_precondition(! this->is_empty());
378 return p_.last_element();
381 template <
typename P,
typename Q>
386 mln_precondition(! this->is_empty());
387 return p_.first_element();
390 template <
typename P,
typename Q>
398 template <
typename P,
typename Q>
401 p_priority<P,Q>::set_2_(
const P& priority)
const
403 mln_precondition(p_.has(priority));
404 q_type_& mq =
const_cast<q_type_&
>(q_);
405 mln_precondition(mq[priority].
nsites() > 0);
409 template <
typename P,
typename Q>
412 p_priority<P,Q>::run_()
const
414 if (!
implies(n_ == 0, p_.is_empty()))
417 if (! (p_.nelements() == q_.size()))
421 mln_eiter(util::set<P>) p(p_);
423 if (q_.find(p) == q_.end())
427 typename std::map<P,Q>::const_iterator i;
428 for (i = q_.begin(); i != q_.end(); ++i)
429 if (! p_.
has(i->first))
439 template <typename P, typename Q>
440 std::ostream& operator<<(std::ostream& ostr, const
p_priority<P,Q>& pq)
443 mln_bkd_eiter(util::set<P>) p(pq.
priorities());
446 ostr <<
' ' << p <<
':';
447 ostr << pq.set_2_(p);
453 # endif // ! MLN_INCLUDE_ONLY
458 #endif // ! MLN_CORE_SITE_SET_P_PRIORITY_HH