Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74620 - in sandbox-branches/geometry/index: boost/geometry/extensions/index boost/geometry/extensions/index/rtree tests
From: adam.wulkiewicz_at_[hidden]
Date: 2011-09-30 18:48:06


Author: awulkiew
Date: 2011-09-30 18:48:01 EDT (Fri, 30 Sep 2011)
New Revision: 74620
URL: http://svn.boost.org/trac/boost/changeset/74620

Log:
added bgi::insert_iterator<> and bgi::inserter() + tests.
Added:
   sandbox-branches/geometry/index/boost/geometry/extensions/index/inserter.hpp (contents, props changed)
Text files modified:
   sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/rtree.hpp | 7 ++-----
   sandbox-branches/geometry/index/tests/additional_sizes_and_times.cpp | 20 ++++++++++++++++++++
   sandbox-branches/geometry/index/tests/rtree_function.hpp | 6 +++++-
   3 files changed, 27 insertions(+), 6 deletions(-)

Added: sandbox-branches/geometry/index/boost/geometry/extensions/index/inserter.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/inserter.hpp 2011-09-30 18:48:01 EDT (Fri, 30 Sep 2011)
@@ -0,0 +1,65 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Boost.SpatialIndex - inserter
+//
+// Copyright 2011 Adam Wulkiewicz.
+// Use, modification and distribution is subject to the Boost Software License,
+// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_GEOMETRY_EXTENSIONS_INDEX_INSERTER_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_INDEX_INSERTER_HPP
+
+#include <iterator>
+
+namespace boost { namespace geometry { namespace index {
+
+template <class Container>
+class insert_iterator :
+ public std::iterator<std::output_iterator_tag, void, void, void, void>
+{
+public:
+ typedef Container container_type;
+
+ inline explicit insert_iterator()
+// : container(0)
+ {}
+
+ inline explicit insert_iterator(Container & c)
+ : container(&c)
+ {}
+
+ insert_iterator & operator=(typename Container::value_type const& value)
+ {
+ index::insert(*container, value);
+ return *this;
+ }
+
+ insert_iterator & operator* ()
+ {
+ return *this;
+ }
+
+ insert_iterator & operator++ ()
+ {
+ return *this;
+ }
+
+ insert_iterator operator++(int)
+ {
+ return *this;
+ }
+
+private:
+ Container * container;
+};
+
+template <typename Container>
+insert_iterator<Container> inserter(Container & c)
+{
+ return insert_iterator<Container>(c);
+}
+
+}}} // namespace boost::geometry::index
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_INSERTER_HPP

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 2011-09-30 18:48:01 EDT (Fri, 30 Sep 2011)
@@ -57,9 +57,6 @@
 // TODO change remove() to erase() or just add erase() ?
 // erase works on iterators of this container so this may be confusing with remove(ValIt, ValIt)
 
-// TODO add third parameter to insert(It, It) - unary_op, like in std::transform
-// transforming It::value_type to rtree::value_type ?
-
 template <
     typename Value,
     typename Parameters,
@@ -355,7 +352,7 @@
     tree.insert(v);
 }
 
-template<typename Iterator, typename Value, typename Options, typename Translator>
+template<typename Value, typename Options, typename Translator, typename Iterator>
 inline void insert(rtree<Value, Options, Translator> & tree, Iterator first, Iterator last)
 {
     tree.insert(first, last);
@@ -367,7 +364,7 @@
     tree.remove(v);
 }
 
-template<typename Iterator, typename Value, typename Options, typename Translator>
+template<typename Value, typename Options, typename Translator, typename Iterator>
 inline void remove(rtree<Value, Options, Translator> & tree, Iterator first, Iterator last)
 {
     tree.remove(first, last);

Modified: sandbox-branches/geometry/index/tests/additional_sizes_and_times.cpp
==============================================================================
--- sandbox-branches/geometry/index/tests/additional_sizes_and_times.cpp (original)
+++ sandbox-branches/geometry/index/tests/additional_sizes_and_times.cpp 2011-09-30 18:48:01 EDT (Fri, 30 Sep 2011)
@@ -11,6 +11,7 @@
 #include <fstream>
 
 #include <boost/geometry/extensions/index/rtree/rtree.hpp>
+#include <boost/geometry/extensions/index/inserter.hpp>
 
 #include <boost/geometry/extensions/index/rtree/visitors/are_boxes_ok.hpp>
 #include <boost/geometry/extensions/index/rtree/visitors/are_levels_ok.hpp>
@@ -137,6 +138,25 @@
         std::cout << "time: " << tim.elapsed() << "s\n";
     }
 
+ // elements inserting test using insert_iterator
+ {
+ RT t;
+
+ std::cout << "rtree inserting time test using insert_iterator<>... ("
+ << values_count << ")\n";
+ bgi::insert_iterator<RT> ii = bgi::inserter(t);
+ tim.restart();
+ for (size_t i = 0 ; i < values_count ; ++i )
+ {
+ float x = coords[i].first;
+ float y = coords[i].second;
+ B b(P(x - 0.5f, y - 0.5f), P(x + 0.5f, y + 0.5f));
+
+ *ii++ = std::make_pair(b, i);
+ }
+ std::cout << "time: " << tim.elapsed() << "s\n";
+ }
+
     std::vector< std::pair<B, size_t> > v;
 
     // elements inserting test

Modified: sandbox-branches/geometry/index/tests/rtree_function.hpp
==============================================================================
--- sandbox-branches/geometry/index/tests/rtree_function.hpp (original)
+++ sandbox-branches/geometry/index/tests/rtree_function.hpp 2011-09-30 18:48:01 EDT (Fri, 30 Sep 2011)
@@ -5,6 +5,7 @@
 
 #include <boost/geometry/extensions/index/rtree/rtree.hpp>
 #include <boost/geometry/extensions/index/translator/index.hpp>
+#include <boost/geometry/extensions/index/inserter.hpp>
 
 #include <boost/geometry/extensions/index/rtree/visitors/print.hpp>
 
@@ -118,10 +119,13 @@
     namespace bg = boost::geometry;
     namespace bgi = bg::index;
 
+ bgi::insert_iterator<Rtree> ii = bgi::inserter(t);
+
     for ( size_t i = 0 ; i < n ; ++i )
     {
         typename Randomizer::value_type v = r();
- bgi::insert(t, v);
+ //bgi::insert(t, v);
+ *ii++ = v;
         c.push_back(v);
     }
 }


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