Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82371 - in sandbox-branches/geometry/index: boost/geometry/extensions/index/rtree boost/geometry/extensions/index/rtree/visitors test/rtree tests
From: adam.wulkiewicz_at_[hidden]
Date: 2013-01-05 19:58:54


Author: awulkiew
Date: 2013-01-05 19:58:54 EST (Sat, 05 Jan 2013)
New Revision: 82371
URL: http://svn.boost.org/trac/boost/changeset/82371

Log:
Fixed error in nearest_query() - for Iterator which is not an inserter - operator++ call added.
Text files modified:
   sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/rtree.hpp | 9 +++++----
   sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/nearest_query.hpp | 22 +++++++++++-----------
   sandbox-branches/geometry/index/test/rtree/test_rtree.hpp | 6 ++++++
   sandbox-branches/geometry/index/tests/additional_speed.cpp | 18 +++++++++++++++++-
   4 files changed, 39 insertions(+), 16 deletions(-)

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/rtree.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/rtree.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/rtree.hpp 2013-01-05 19:58:54 EST (Sat, 05 Jan 2013)
@@ -938,7 +938,7 @@
 
         detail::rtree::apply_visitor(nearest_v, *m_root);
 
- return result.get(v);
+ return result.finish();
     }
 
     /*!
@@ -958,10 +958,11 @@
         typedef detail::rtree::visitors::nearest_query_result_k<
             value_type,
             translator_type,
- point_type
+ point_type,
+ OutIter
> result_type;
 
- result_type result(k);
+ result_type result(k, out_it);
 
         detail::rtree::visitors::nearest_query<
             value_type,
@@ -976,7 +977,7 @@
 
         detail::rtree::apply_visitor(nearest_v, *m_root);
 
- return result.get(out_it);
+ return result.finish();
     }
 
     translator_type m_translator;

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/nearest_query.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/nearest_query.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/nearest_query.hpp 2013-01-05 19:58:54 EST (Sat, 05 Jan 2013)
@@ -33,7 +33,7 @@
         typename translator::indexable_type<Translator>::type
>::type distance_type;
 
- inline nearest_query_result_one(Value const& value)
+ inline nearest_query_result_one(Value & value)
         : m_value(value)
         , m_comp_dist((std::numeric_limits<distance_type>::max)())
     {}
@@ -57,18 +57,17 @@
         return m_comp_dist;
     }
 
- inline size_t get(Value & v)
+ inline size_t finish()
     {
- v = m_value;
         return is_comparable_distance_valid() ? 1 : 0;
     }
 
 private:
- Value m_value;
+ Value & m_value;
     distance_type m_comp_dist;
 };
 
-template <typename Value, typename Translator, typename Point>
+template <typename Value, typename Translator, typename Point, typename OutIt>
 struct nearest_query_result_k
 {
 public:
@@ -77,8 +76,8 @@
         typename translator::indexable_type<Translator>::type
>::type distance_type;
 
- inline explicit nearest_query_result_k(size_t k)
- : m_count(k)
+ inline explicit nearest_query_result_k(size_t k, OutIt out_it)
+ : m_count(k), m_out_it(out_it)
     {
         BOOST_GEOMETRY_INDEX_ASSERT(0 < m_count, "Number of neighbors should be greater than 0");
 
@@ -122,12 +121,11 @@
             : m_neighbors.front().first;
     }
 
- template <typename OutIter>
- inline size_t get(OutIter & out_it)
+ inline size_t finish()
     {
         typedef typename std::vector< std::pair<distance_type, Value> >::const_iterator neighbors_iterator;
- for ( neighbors_iterator it = m_neighbors.begin() ; it != m_neighbors.end() ; ++it )
- *out_it = it->second;
+ for ( neighbors_iterator it = m_neighbors.begin() ; it != m_neighbors.end() ; ++it, ++m_out_it )
+ *m_out_it = it->second;
 
         return m_neighbors.size();
     }
@@ -141,6 +139,8 @@
     }
 
     size_t m_count;
+ OutIt m_out_it;
+
     std::vector< std::pair<distance_type, Value> > m_neighbors;
     distance_type m_biggest_comp_dist;
 };

Modified: sandbox-branches/geometry/index/test/rtree/test_rtree.hpp
==============================================================================
--- sandbox-branches/geometry/index/test/rtree/test_rtree.hpp (original)
+++ sandbox-branches/geometry/index/test/rtree/test_rtree.hpp 2013-01-05 19:58:54 EST (Sat, 05 Jan 2013)
@@ -857,6 +857,12 @@
     }
 
     test_exactly_the_same_outputs(rtree, output, rtree | bgi::adaptors::nearest_queried(pt, k));
+
+ std::vector<Value> output2(k, generate_value_default<Value>::apply());
+ size_t found_count = rtree.nearest_query(pt, k, output2.begin());
+ output2.resize(found_count, generate_value_default<Value>::apply());
+
+ test_exactly_the_same_outputs(rtree, output, output2);
 }
 
 // rtree nearest not found

Modified: sandbox-branches/geometry/index/tests/additional_speed.cpp
==============================================================================
--- sandbox-branches/geometry/index/tests/additional_speed.cpp (original)
+++ sandbox-branches/geometry/index/tests/additional_speed.cpp 2013-01-05 19:58:54 EST (Sat, 05 Jan 2013)
@@ -94,6 +94,7 @@
 
         std::vector<B> result;
         result.reserve(100);
+ B result_one;
 
         // query test
         {
@@ -117,7 +118,7 @@
 
         // searching test
         {
- std::cout << "nearest 5 searching time test... ("
+ std::cout << "nearest 10 searching time test... ("
                 << queries_count / 10 << ")\n";
             tim.restart();
             size_t temp = 0;
@@ -131,6 +132,21 @@
             std::cout << "time: " << tim.elapsed() << "s\n";
             std::cout << "found: " << temp << "\n";
         }
+
+ {
+ std::cout << "nearest 1 searching time test... ("
+ << queries_count / 10 << ")\n";
+ tim.restart();
+ size_t temp = 0;
+ for (size_t i = 0 ; i < queries_count / 10 ; ++i )
+ {
+ float x = coords[i].first + 100;
+ float y = coords[i].second + 100;
+ temp += t.nearest_query(P(x, y), result_one);
+ }
+ std::cout << "time: " << tim.elapsed() << "s\n";
+ std::cout << "found: " << temp << "\n";
+ }
     }
 
     return 0;


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