searching time tests related code added

[SVN r71664]
This commit is contained in:
Adam Wulkiewicz
2011-05-02 12:14:44 +00:00
parent bff387c631
commit d121f4e9e9
4 changed files with 131 additions and 73 deletions

View File

@@ -1,8 +1,7 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
//
// Boost.Index - R-tree details
// Boost.Index - R-tree default nodes
//
// Copyright 2008 Federico J. Fernandez.
// 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

View File

@@ -72,7 +72,9 @@ public:
template <typename Geometry, typename OutIter>
inline void find(Geometry const& geom, OutIter out_it) const
{
detail::rtree::visitors::find<value_type, translator_type, box_type, tag_type, Geometry, OutIter> find_v(m_translator, geom, out_it);
detail::rtree::visitors::find<value_type, translator_type, box_type, tag_type, Geometry, OutIter>
find_v(m_translator, geom, out_it);
boost::apply_visitor(find_v, *m_root);
}

View File

@@ -20,17 +20,88 @@ namespace boost { namespace geometry { namespace index {
namespace detail { namespace rtree { namespace visitors {
//template <size_t N, typename T>
//class array
//{
//public:
// inline array()
// : arr_elements(0)
// {}
//
// inline void push(T const& v)
// {
// arr[arr_elements++] = v;
// }
//
// inline T pop()
// {
// assert(0 < arr_elements);
// return arr[--arr_elements];
// }
//
// inline bool empty() const
// {
// return 0 == arr_elements;
// }
//
// inline size_t size() const
// {
// return arr_elements;
// }
//
//private:
// boost::array<T, N> arr;
// size_t arr_elements;
//};
//
//template <typename Cont>
//class dynamic
//{
//public:
// typedef typename Cont::value_type value_type;
//
// inline void push(value_type const& v)
// {
// cont.push_back(v);
// }
//
// inline value_type pop()
// {
// value_type v = cont.back();
// cont.pop_back();
// return v;
// }
//
// inline bool empty() const
// {
// return cont.empty();
// }
//
// inline size_t size() const
// {
// return cont.size();
// }
//
// inline void clear()
// {
// cont.clear();
// }
//
//private:
// Cont cont;
//};
//
//template <size_t N, typename Cont>
//class array_semi_dynamic
//{
//public:
// typedef typename Cont::value_type value_type;
//
// array_semi_dynamic()
// inline array_semi_dynamic()
// : arr_elements(0)
// {}
//
// void push_back(value_type const& v)
// inline void push(value_type const& v)
// {
// if ( arr_elements < N )
// arr[arr_elements++] = v;
@@ -38,46 +109,27 @@ namespace detail { namespace rtree { namespace visitors {
// cont.push_back(v);
// }
//
// void pop_back()
// inline value_type pop()
// {
// if ( !cont.empty() )
// {
// value_type v = cont.back();
// cont.pop_back();
// return v;
// }
// else
// {
// assert(0 < arr_elements);
// --arr_elements;
// return arr[--arr_elements];
// }
// }
//
// value_type & back()
// inline bool empty() const
// {
// if ( !cont.empty() )
// return cont.back();
// else
// {
// assert(0 < arr_elements);
// return arr[arr_elements - 1];
// }
// return cont.empty() && 0 == arr_elements;
// }
//
// value_type const& back() const
// {
// if ( !cont.empty() )
// return cont.back();
// else
// {
// assert(0 < arr_elements);
// return arr[arr_elements - 1];
// }
// }
//
// bool empty() const
// {
// assert(cont.empty());
// return 0 == arr_elements;
// }
//
// size_t size() const
// inline size_t size() const
// {
// return arr_elements + cont.size();
// }
@@ -103,42 +155,43 @@ struct find : public boost::static_visitor<>
inline void operator()(internal_node const& n)
{
/*typedef typename internal_node::children_type children_type;
//typedef typename internal_node::children_type children_type;
array_semi_dynamic<512, std::deque<node*> > nodes;
for (typename children_type::const_iterator it = n.children.begin();
it != n.children.end(); ++it)
{
if ( geometry::intersects(it->first, geom) )
{
nodes.push_back(it->second);
}
}
//array_semi_dynamic<1024, std::deque<node*> > nodes;
////array<1024, node*> nodes;
////dynamic< std::deque<node*> > nodes;
//
//for (typename children_type::const_iterator it = n.children.begin();
// it != n.children.end(); ++it)
//{
// if ( geometry::intersects(it->first, geom) )
// {
// nodes.push(it->second);
// }
//}
while ( !nodes.empty() )
{
node *n = nodes.back();
nodes.pop_back();
//while ( !nodes.empty() )
//{
// node *n = nodes.pop();
if ( !boost::apply_visitor(visitors::is_leaf<Value, Box, Tag>(), *n) )
{
internal_node &in = boost::get<internal_node>(*n);
// if ( !boost::apply_visitor(visitors::is_leaf<Value, Box, Tag>(), *n) )
// {
// internal_node &in = boost::get<internal_node>(*n);
for (typename children_type::const_iterator it = in.children.begin();
it != in.children.end(); ++it)
{
if ( geometry::intersects(it->first, geom) )
{
nodes.push_back(it->second);
}
}
}
else
{
operator()(boost::get<leaf>(*n));
}
}*/
// for (typename children_type::const_iterator it = in.children.begin();
// it != in.children.end(); ++it)
// {
// if ( geometry::intersects(it->first, geom) )
// {
// nodes.push(it->second);
// }
// }
// }
// else
// {
// operator()(boost::get<leaf>(*n));
// }
//}
typedef typename internal_node::children_type children_type;

View File

@@ -12,8 +12,12 @@ int main()
{
boost::timer tim;
typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
typedef boost::geometry::model::box<P> B;
namespace bg = boost::geometry;
namespace bgi = bg::index;
typedef bg::model::point<float, 2, bg::cs::cartesian> P;
typedef bg::model::box<P> B;
typedef bgi::rtree<std::pair<B, size_t>, bgi::default_parameter, bgi::linear_tag> RT;
std::ifstream file_cfg("config.txt");
size_t max_elems = 4;
@@ -41,7 +45,7 @@ int main()
std::cout << "inserting time test...\n";
tim.restart();
boost::geometry::index::rtree< std::pair<B, size_t> > t(max_elems, min_elems);
RT t(max_elems, min_elems);
for (size_t i = 0 ; i < values_count ; ++i )
{
float x = coords[i].first;
@@ -78,11 +82,11 @@ int main()
std::cout << "saving...\n";
std::ofstream file("save_new.txt", std::ofstream::trunc);
file << std::fixed;
boost::geometry::index::detail::rtree::visitors::save<
boost::geometry::index::rtree< std::pair<B, size_t> >::value_type,
boost::geometry::index::rtree< std::pair<B, size_t> >::translator_type,
boost::geometry::index::rtree< std::pair<B, size_t> >::box_type,
boost::geometry::index::rtree< std::pair<B, size_t> >::tag_type
bgi::detail::rtree::visitors::save<
RT::value_type,
RT::translator_type,
RT::box_type,
RT::tag_type
> saving_v(file, t.get_translator());
t.apply_visitor(saving_v);
std::cout << "saved...\n";