|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r82593 - in sandbox-branches/geometry/index: boost/geometry/index tests
From: adam.wulkiewicz_at_[hidden]
Date: 2013-01-24 00:43:58
Author: awulkiew
Date: 2013-01-24 00:43:57 EST (Thu, 24 Jan 2013)
New Revision: 82593
URL: http://svn.boost.org/trac/boost/changeset/82593
Log:
query_expr: implemented push_back_impl operator&& and find_nearest_impl
Text files modified:
sandbox-branches/geometry/index/boost/geometry/index/query_expr.hpp | 100 +++++++++++++++++++++++++++++++++++++--
sandbox-branches/geometry/index/tests/query_expr.cpp | 12 ++++
2 files changed, 106 insertions(+), 6 deletions(-)
Modified: sandbox-branches/geometry/index/boost/geometry/index/query_expr.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/index/query_expr.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/index/query_expr.hpp 2013-01-24 00:43:57 EST (Thu, 24 Jan 2013)
@@ -11,11 +11,14 @@
#ifndef BOOST_GEOMETRY_INDEX_QUERY_EXPR_HPP
#define BOOST_GEOMETRY_INDEX_QUERY_EXPR_HPP
+#include <boost/type_traits/is_same.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/mpl/assert.hpp>
namespace boost { namespace geometry { namespace index { namespace qe {
+namespace detail {
+
// tags
struct intersects_tag {};
@@ -30,7 +33,7 @@
{
typedef Tag tag_type;
predicate(T const& d) : data(d) {}
- T const& data;
+ T data;
};
template <typename T>
@@ -38,22 +41,107 @@
{
typedef nearest_tag tag_type;
predicate(T const& d, size_t k) : data(d), count(k) {}
- T const& data;
+ T data;
size_t count;
};
+template <typename T, typename Tuple, size_t I, size_t N>
+struct push_back_impl
+{
+ typedef
+ boost::tuples::cons<
+ typename boost::tuples::element<I, Tuple>::type,
+ typename push_back_impl<T, Tuple, I+1, N>::type
+ > type;
+
+ static type apply(T const& t, Tuple const& tup)
+ {
+ return
+ type(
+ boost::get<I>(tup),
+ push_back_impl<T, Tuple, I+1, N>::apply(t, tup)
+ );
+ }
+};
+
+template <typename T, typename Tuple, size_t N>
+struct push_back_impl<T, Tuple, N, N>
+{
+ typedef boost::tuples::cons<T, boost::tuples::null_type> type;
+
+ static type apply(T const& t, Tuple const&)
+ {
+ return type(t, boost::tuples::null_type());
+ }
+};
+
+template <typename T1, typename Tag1, typename T2, typename Tag2> inline
+boost::tuples::cons<
+ predicate<T1, Tag1>,
+ boost::tuples::cons<predicate<T2, Tag2>, boost::tuples::null_type>
+>
+operator&&(predicate<T1, Tag1> const& p1, predicate<T2, Tag2> const& p2)
+{
+ return
+ boost::tuples::cons<
+ predicate<T1, Tag1>,
+ boost::tuples::cons<predicate<T2, Tag2>, boost::tuples::null_type>
+ >(
+ p1,
+ boost::tuples::cons<predicate<T2, Tag2>, boost::tuples::null_type>(p2, boost::tuples::null_type())
+ );
+}
+
+template <typename Head, typename Tail, typename T, typename Tag> inline
+typename push_back_impl<
+ predicate<T, Tag>,
+ boost::tuples::cons<Head, Tail>,
+ 0,
+ boost::tuples::length<boost::tuples::cons<Head, Tail> >::value
+>::type
+operator&&(boost::tuples::cons<Head, Tail> const& t, predicate<T, Tag> const& p)
+{
+ return
+ push_back_impl<
+ predicate<T, Tag>,
+ boost::tuples::cons<Head, Tail>,
+ 0,
+ boost::tuples::length<boost::tuples::cons<Head, Tail> >::value
+ >::apply(p, t);
+}
+
+template <typename Tuple, size_t I, size_t N>
+struct find_nearest_impl
+{
+ static const size_t value =
+ boost::is_same<
+ typename boost::tuples::element<I, Tuple>::type::tag_type,
+ nearest_tag
+ >::value ?
+ I :
+ find_nearest_impl<Tuple, I+1, N>::value;
+};
+
+template <typename Tuple, size_t N>
+struct find_nearest_impl<Tuple, N, N>
+{
+ static const size_t value = N;
+};
+
+} // namespace detail
+
// predicates generators
template <typename Geometry>
-predicate<Geometry, intersects_tag> intersects(Geometry const& g)
+detail::predicate<Geometry, detail::intersects_tag> intersects(Geometry const& g)
{
- return predicate<Geometry, intersects_tag>(g);
+ return detail::predicate<Geometry, detail::intersects_tag>(g);
}
template <typename DistancePredicates>
-predicate<DistancePredicates, nearest_tag> nearest(DistancePredicates const& p, size_t k)
+detail::predicate<DistancePredicates, detail::nearest_tag> nearest(DistancePredicates const& p, size_t k)
{
- return predicate<DistancePredicates, nearest_tag>(p, k);
+ return detail::predicate<DistancePredicates, detail::nearest_tag>(p, k);
}
}}}} // namespace boost::geometry::index::qe
Modified: sandbox-branches/geometry/index/tests/query_expr.cpp
==============================================================================
--- sandbox-branches/geometry/index/tests/query_expr.cpp (original)
+++ sandbox-branches/geometry/index/tests/query_expr.cpp 2013-01-24 00:43:57 EST (Thu, 24 Jan 2013)
@@ -136,13 +136,25 @@
return boost::get<0>(t).v + boost::get<1>(t).v + boost::get<2>(t).v;
}
+template <typename T> inline
+void test2(T const& t)
+{
+ using namespace boost::geometry::index::qe;
+ std::cout << detail::find_nearest_impl<T, 0, 3>::value << '\n';
+}
+
int main()
{
using namespace boost::geometry::index::qe;
+ //TEST
+
+ test2(intersects(0) && nearest(0, 0) && intersects(0));
+
boost::timer tim;
size_t count = 200000000;
+ //size_t count = 2000000;
int dummy = 0;
std::ifstream f("blablabla");
f >> dummy;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk