diff --git a/index/example/Jamfile.v2 b/index/example/Jamfile.v2 index 2067e8d7c..065f49b98 100644 --- a/index/example/Jamfile.v2 +++ b/index/example/Jamfile.v2 @@ -44,6 +44,7 @@ if $(GLUT_ROOT) } exe random_test : random_test.cpp ; +link serialize.cpp /boost//serialization : ; link benchmark.cpp /boost//chrono : multi ; link benchmark2.cpp /boost//chrono : multi ; link benchmark3.cpp /boost//chrono : multi ; diff --git a/index/example/serialize.cpp b/index/example/serialize.cpp index 504667a26..ff988246c 100644 --- a/index/example/serialize.cpp +++ b/index/example/serialize.cpp @@ -7,51 +7,146 @@ // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// WARNING! This code is not fully functional! - #include #include #define BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL #include +#include #include #include +#include #include +#include -namespace boost { namespace serialization { +template ::value> +struct print_tuple +{ + template + static inline Os & apply(Os & os, T const& t) + { + os << boost::get(t) << ", "; + return print_tuple::apply(os, t); + } +}; - - -}} // namespace boost::serialization +template +struct print_tuple +{ + template + static inline Os & apply(Os & os, T const&) + { + return os; + } +}; int main() { namespace bg = boost::geometry; namespace bgi = bg::index; + typedef boost::tuple S; + typedef bg::model::point P; typedef bg::model::box

B; - typedef bgi::rtree > RT; - //typedef bgi::rtree > RT; - //typedef bgi::rtree > RT; + typedef B V; + //typedef bgi::rtree > RT; + //typedef bgi::rtree > RT; + //typedef bgi::rtree > RT; + typedef bgi::rtree RT; - RT tree; + //RT tree; + RT tree(bgi::dynamic_linear(16)); + std::vector vect; + + boost::timer t; //insert values { - for ( double x = 0 ; x < 100 ; x += 10 ) - for ( double y = 0 ; y < 100 ; y += 10 ) - tree.insert(B(P(x, y), P(x+1, y+1))); + for ( double x = 0 ; x < 1000 ; x += 1 ) + for ( double y = 0 ; y < 1000 ; y += 1 ) + vect.push_back(B(P(x, y), P(x+0.5, y+0.5))); + RT tmp(vect, tree.parameters()); + tree = boost::move(tmp); } + B q(P(5, 5), P(6, 6)); + S s; + + std::cout << "vector and tree created in: " << t.elapsed() << std::endl; + + std::cout << "before save" << std::endl; + print_tuple::apply(std::cout, bgi::detail::rtree::utilities::statistics(tree)) << std::endl; + std::cout << boost::get<0>(s) << std::endl; + BOOST_FOREACH(V const& v, tree | bgi::adaptors::queried(bgi::intersects(q))) + std::cout << bg::wkt(v) << std::endl; // save { - std::ofstream ofs("filename", std::ios::binary); + std::ofstream ofs("serialized_vector.bin", std::ios::binary | std::ios::trunc); boost::archive::binary_oarchive oa(ofs); - oa << tree; + t.restart(); + oa << vect; + std::cout << "vector saved in: " << t.elapsed() << std::endl; } + { + std::ofstream ofs("serialized_tree.bin", std::ios::binary | std::ios::trunc); + boost::archive::binary_oarchive oa(ofs); + t.restart(); + oa << tree; + std::cout << "tree saved in: " << t.elapsed() << std::endl; + } + + std::cout << "after save" << std::endl; + print_tuple::apply(std::cout, bgi::detail::rtree::utilities::statistics(tree)) << std::endl; + BOOST_FOREACH(V const& v, tree | bgi::adaptors::queried(bgi::intersects(q))) + std::cout << bg::wkt(v) << std::endl; + + t.restart(); + vect.clear(); + std::cout << "vector cleared in: " << t.elapsed() << std::endl; + + t.restart(); + tree.clear(); + std::cout << "tree cleared in: " << t.elapsed() << std::endl; + + // levels number is 1 because of error in statistics() + std::cout << "before load" << std::endl; + print_tuple::apply(std::cout, bgi::detail::rtree::utilities::statistics(tree)) << std::endl; + BOOST_FOREACH(V const& v, tree | bgi::adaptors::queried(bgi::intersects(q))) + std::cout << bg::wkt(v) << std::endl; + + // load + { + std::ifstream ifs("serialized_vector.bin", std::ios::binary); + boost::archive::binary_iarchive ia(ifs); + t.restart(); + ia >> vect; + std::cout << "vector loaded in: " << t.elapsed() << std::endl; + t.restart(); + RT tmp(vect, tree.parameters()); + tree = boost::move(tmp); + std::cout << "tree rebuilt from vector in: " << t.elapsed() << std::endl; + } + + t.restart(); + tree.clear(); + std::cout << "tree cleared in: " << t.elapsed() << std::endl; + + { + std::ifstream ifs("serialized_tree.bin", std::ios::binary); + boost::archive::binary_iarchive ia(ifs); + t.restart(); + ia >> tree; + std::cout << "tree loaded in: " << t.elapsed() << std::endl; + } + + std::cout << "after load" << std::endl; + print_tuple::apply(std::cout, bgi::detail::rtree::utilities::statistics(tree)) << std::endl; + BOOST_FOREACH(V const& v, tree | bgi::adaptors::queried(bgi::intersects(q))) + std::cout << bg::wkt(v) << std::endl; + return 0; }