https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Make tests on some queue types pass.
* tests/core/site_set/p_queue_fast.cc: Update.
* tests/core/site_set/p_queue.cc: Likewise.
* tests/core/site_set/p_priority_queue.cc
(operator[]): De-activate since priority queues do not (cannot)
have such a method.
(has): Likewise; replace the calls to this method by calling...
* mln/set/has.hh: ...this new procedure.
It is useful when a site set is not "point-wise" random
accessible.
* mln/core/site_set/p_priority.hh (Q): New static check.
mln/core/site_set/p_priority.hh | 14 +++--
mln/set/has.hh | 85 ++++++++++++++++++++++++++++++++
tests/core/site_set/p_priority_queue.cc | 55 +++++++++++---------
tests/core/site_set/p_queue.cc | 14 ++---
tests/core/site_set/p_queue_fast.cc | 14 ++---
5 files changed, 139 insertions(+), 43 deletions(-)
Index: tests/core/site_set/p_queue_fast.cc
--- tests/core/site_set/p_queue_fast.cc (revision 2238)
+++ tests/core/site_set/p_queue_fast.cc (working copy)
@@ -32,6 +32,8 @@
#include <mln/core/alias/point2d.hh>
#include <mln/core/site_set/p_queue_fast.hh>
+#include <mln/geom/bbox.hh>
+#include <mln/make/box2d.hh>
@@ -40,18 +42,16 @@
using namespace mln;
p_queue_fast<point2d> q;
- q
- .push(make::point2d(6, 9))
- .push(make::point2d(5, 1))
- .push(make::point2d(4, 2));
+ q.push(point2d(6, 9));
+ q.push(point2d(5, 1));
+ q.push(point2d(4, 2));
mln_assertion(q.nsites() == 3);
- std::cout << q.bbox() << std::endl;
- std::cout << q << std::endl;
+ mln_assertion(geom::bbox(q) == make::box2d(4,1, 6,9));
q.pop();
mln_assertion(q.nsites() == 2);
point2d p = q.front();
mln_assertion(q.nsites() == 2);
- mln_assertion(p == make::point2d(5, 1));
+ mln_assertion(p == point2d(5, 1));
}
Index: tests/core/site_set/p_queue.cc
--- tests/core/site_set/p_queue.cc (revision 2238)
+++ tests/core/site_set/p_queue.cc (working copy)
@@ -32,6 +32,8 @@
#include <mln/core/alias/point2d.hh>
#include <mln/core/site_set/p_queue.hh>
+#include <mln/geom/bbox.hh>
+#include <mln/make/box2d.hh>
@@ -40,18 +42,16 @@
using namespace mln;
p_queue<point2d> q;
- q
- .push(make::point2d(6, 9))
- .push(make::point2d(5, 1))
- .push(make::point2d(4, 2));
+ q.push(point2d(6, 9));
+ q.push(point2d(5, 1));
+ q.push(point2d(4, 2));
mln_assertion(q.nsites() == 3);
- std::cout << q.bbox() << std::endl;
- std::cout << q << std::endl;
+ mln_assertion(geom::bbox(q) == make::box2d(4,1, 6,9));
q.pop();
mln_assertion(q.nsites() == 2);
point2d p = q.front();
mln_assertion(q.nsites() == 2);
- mln_assertion(p == make::point2d(5, 1));
+ mln_assertion(p == point2d(5, 1));
}
Index: tests/core/site_set/p_priority_queue.cc
--- tests/core/site_set/p_priority_queue.cc (revision 2238)
+++ tests/core/site_set/p_priority_queue.cc (working copy)
@@ -32,12 +32,18 @@
#include <mln/core/alias/point2d.hh>
#include <mln/core/site_set/p_priority.hh>
+#include <mln/core/site_set/p_queue.hh>
+#include <mln/geom/bbox.hh>
+#include <mln/make/box2d.hh>
+#include <mln/set/has.hh>
+
int main ()
{
using namespace mln;
- p_priority<point2d, unsigned> q;
+ typedef p_queue<point2d> Q;
+ p_priority<unsigned, Q> q;
point2d p1 (6, 9);
point2d p2 (5, 1);
point2d p3 (4, 2);
@@ -46,53 +52,52 @@
mln_assertion (q.nsites() == 0);
- q.push_force (p3);
- q.push_force (p1, 3);
- q.push_force (p2, 5);
+ q.push(0, p3);
+ q.push(3, p1);
+ q.push(5, p2);
- std::cout << q.bbox () << std::endl;
- std::cout << q << std::endl;
+ mln_assertion(geom::bbox(q) == make::box2d(4,1, 6,9));
mln_assertion (!q.is_empty ());
- mln_assertion (q.has (p1));
- mln_assertion (q.has (p2));
- mln_assertion (q.has (p3));
+ mln_assertion(set::has(q, p1));
+ mln_assertion(set::has(q, p2));
+ mln_assertion(set::has(q, p3));
mln_assertion (q.nsites() == 3);
mln_assertion (q.front () == p2);
q.pop ();
- mln_assertion (q.has (p1));
- mln_assertion (!q.has (p2));
- mln_assertion (q.has (p3));
+ mln_assertion(set::has(q, p1));
+ mln_assertion(! set::has(q, p2));
+ mln_assertion(set::has(q, p3));
mln_assertion (q.nsites() == 2);
mln_assertion (q.front () == p1);
q.pop ();
- mln_assertion (!q.has (p1));
- mln_assertion (!q.has (p2));
- mln_assertion (q.has (p3));
+ mln_assertion(! set::has(q, p1));
+ mln_assertion(! set::has(q, p2));
+ mln_assertion(set::has(q, p3));
mln_assertion (q.nsites() == 1);
mln_assertion (q.front () == p3);
q.pop ();
- mln_assertion (!q.has (p1));
- mln_assertion (!q.has (p2));
- mln_assertion (!q.has (p3));
+ mln_assertion(! set::has(q, p1));
+ mln_assertion(! set::has(q, p2));
+ mln_assertion(! set::has(q, p3));
mln_assertion (q.nsites() == 0);
mln_assertion (q.is_empty ());
- q.push_force (p3);
- q.push_force (p2, 5);
- q.push_force (p1, 3);
-
- mln_assertion (q[2] == p3);
- mln_assertion (q[1] == p1);
- mln_assertion (q[0] == p2);
+ q.push(0, p3);
+ q.push(5, p2);
+ q.push(3, p1);
+
+// mln_assertion(q[2] == p3);
+// mln_assertion(q[1] == p1);
+// mln_assertion(q[0] == p2);
q.clear ();
mln_assertion (q.is_empty ());
}
Index: mln/core/site_set/p_priority.hh
--- mln/core/site_set/p_priority.hh (revision 2238)
+++ mln/core/site_set/p_priority.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -68,11 +68,16 @@
/*! \brief Priority queue class.
*
- * FIXME
+ * The parameter \p P is the type of the priorities (for instance
+ * unsigned).
+ *
+ * The parameter \p Q is a type of queue (for instance
+ * p_queue<point2d>).
*/
template <typename P, typename Q>
class p_priority : public internal::site_set_base_< mln_site(Q),
- p_priority<P,Q> >
+ p_priority<P,Q> >,
+ private mlc_is_a(Q, Site_Set)::check_t
{
typedef p_priority<P,Q> self_;
public:
@@ -267,7 +272,8 @@
p_priority<P,Q>::front() const
{
mln_precondition(! this->is_empty()); // Also test invariants.
- return q_[highest_priority()].front();
+ std::map<P,Q>& q__ = const_cast< std::map<P,Q>& >(q_);
+ return q__[highest_priority()].front();
}
template <typename P, typename Q>
Index: mln/set/has.hh
--- mln/set/has.hh (revision 0)
+++ mln/set/has.hh (revision 0)
@@ -0,0 +1,85 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_SET_HAS_HH
+# define MLN_SET_HAS_HH
+
+/*! \file mln/set/has.hh
+ *
+ * \brief Algorithm that tests if a site set has a given site.
+ *
+ * \todo Layout and specialize.
+ */
+
+# include <mln/core/concept/site_set.hh>
+
+
+
+namespace mln
+{
+
+ namespace set
+ {
+
+ /// FIXME
+ template <typename S>
+ bool
+ has(const Site_Set<S>& s, const mln_site(S)& e);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S>
+ bool
+ has(const Site_Set<S>& s_, const mln_site(S)& e)
+ {
+ trace::entering("set::has");
+ const S& s = exact(s_);
+
+ mln_precondition(s.is_valid());
+ bool found = false;
+
+ mln_piter(S) p(s);
+ for_all(p)
+ if (p == e)
+ {
+ found = true;
+ break;
+ }
+
+ trace::exiting("set::has");
+ return found;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::set
+
+} // end of namespace mln
+
+
+#endif // ! MLN_SET_HAS_HH