mirror of
https://github.com/boostorg/geometry.git
synced 2026-02-12 12:12:10 +00:00
added bgi::insert_iterator<> and bgi::inserter() + tests.
[SVN r74620]
This commit is contained in:
65
include/boost/geometry/extensions/index/inserter.hpp
Normal file
65
include/boost/geometry/extensions/index/inserter.hpp
Normal file
@@ -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
|
||||
@@ -57,9 +57,6 @@ namespace boost { namespace geometry { namespace index {
|
||||
// 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 @@ inline void insert(rtree<Value, Options, Translator> & tree, Value const& v)
|
||||
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 @@ inline void remove(rtree<Value, Options, Translator> & tree, Value const& v)
|
||||
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);
|
||||
|
||||
@@ -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 @@ int main()
|
||||
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
|
||||
|
||||
@@ -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 @@ void random_insert(Rtree & t, Cont & c, size_t n, Randomizer r)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user