27 #ifndef MLN_CORE_SITE_SET_P_PRIORITY_HH
28 # define MLN_CORE_SITE_SET_P_PRIORITY_HH
35 # include <mln/core/site_set/p_double.hh>
36 # include <mln/core/internal/site_set_base.hh>
37 # include <mln/util/set.hh>
38 # include <mln/util/ord.hh>
45 template <
typename P,
typename Q>
class p_priority;
52 template <
typename P,
typename Q>
53 struct site_set_< p_priority<P,Q> >
55 typedef trait::site_set::nsites::known
nsites;
56 typedef trait::site_set::bbox::unknown
bbox;
57 typedef trait::site_set::contents::growing
contents;
58 typedef trait::site_set::arity::multiple
arity;
76 template <
typename P,
typename Q>
79 private mlc_is_a(Q, Site_Set)::check_t
93 mln_bkd_eiter(util::
set<P>),
98 mln_fwd_eiter(util::
set<P>),
109 bool has(const psite&) const;
119 void push(const P& priority, const element& e);
125 void insert(const i_element& p_e);
139 const mln_element(Q)&
front() const;
154 const Q& operator()(const P& priority) const;
172 const util::
set<P>& set_1_() const;
173 const Q& set_2_(const P& priority) const;
183 typedef std::map<P, Q, util::ord<P> >
q_type_;
195 template <typename P, typename Q>
196 std::ostream& operator<<(std::ostream& ostr, const
p_priority<P,Q>& pq);
200 # ifndef MLN_INCLUDE_ONLY
202 template <
typename P,
typename Q>
207 mln_invariant(
run_());
210 template <
typename P,
typename Q>
215 mln_invariant(
run_());
220 template <
typename P,
typename Q>
225 mln_invariant(
run_());
229 template <
typename P,
typename Q>
234 mln_invariant(
run_());
238 template <
typename P,
typename Q>
243 mln_invariant(
run_());
245 q_[priority].push(e);
247 mln_invariant(
run_());
250 template <
typename P,
typename Q>
255 this->
push(p_e.first, p_e.second);
258 template <
typename P,
typename Q>
263 mln_invariant(
run_());
264 typename q_type_::const_iterator i;
265 for (i = other.q_.begin(); i != other.q_.end(); ++i)
267 P priority = i->first;
269 const Q& q_p = i->second;
273 mln_invariant(
run_());
276 template <
typename P,
typename Q>
281 mln_precondition(! this->
is_empty());
290 mln_invariant(
run_());
293 template <
typename P,
typename Q>
295 const mln_element(Q)&
298 mln_precondition(! this->
is_empty());
299 q_type_& q__ =
const_cast< q_type_&
>(
q_);
303 template <
typename P,
typename Q>
308 mln_precondition(! this->
is_empty());
310 mln_element(Q) e = this->
front();
315 template <typename P, typename Q>
320 mln_invariant(
run_());
324 mln_invariant(
run_());
327 template <
typename P,
typename Q>
332 mln_invariant(
run_());
333 std::size_t mem_q = 0;
334 typename q_type_::const_iterator i;
335 for (i = q_.begin(); i != q_.end(); ++i)
336 mem_q += i->second.memory_size();
337 return p_.memory_size() +
sizeof(
q_) +
sizeof(n_);
340 template <
typename P,
typename Q>
345 static const Q nil_ = Q();
348 q_type_& mq =
const_cast<q_type_&
>(
q_);
349 mln_assertion(mq[priority].
nsites() > 0);
356 template <
typename P,
typename Q>
361 mln_invariant(
run_());
365 template <
typename P,
typename Q>
370 mln_invariant(
run_());
371 return p_.has(priority);
374 template <
typename P,
typename Q>
379 mln_precondition(! this->
is_empty());
380 return p_.last_element();
383 template <
typename P,
typename Q>
388 mln_precondition(! this->
is_empty());
389 return p_.first_element();
392 template <
typename P,
typename Q>
395 p_priority<P,Q>::set_1_()
const
400 template <
typename P,
typename Q>
403 p_priority<P,Q>::set_2_(
const P& priority)
const
405 mln_precondition(p_.has(priority));
406 q_type_& mq =
const_cast<q_type_&
>(
q_);
407 mln_precondition(mq[priority].
nsites() > 0);
411 template <
typename P,
typename Q>
416 if (!
implies(n_ == 0, p_.is_empty()))
419 if (! (p_.nelements() == q_.size()))
423 mln_eiter(util::set<P>)
p(p_);
425 if (q_.
find(
p) == q_.end())
429 typename std::map<P,Q>::const_iterator i;
430 for (i = q_.begin(); i != q_.end(); ++i)
431 if (! p_.
has(i->first))
441 template <typename P, typename Q>
442 std::ostream& operator<<(std::ostream& ostr, const
p_priority<P,Q>& pq)
448 ostr <<
' ' << p <<
':';
449 ostr << pq.set_2_(p);
455 # endif // ! MLN_INCLUDE_ONLY
460 #endif // ! MLN_CORE_SITE_SET_P_PRIORITY_HH