From 456b9fd283255d153235186dcb2eef7df26b22a1 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Mon, 3 Oct 2011 20:30:53 +0000 Subject: [PATCH] Allocators used in nodes children containers creation. [SVN r74675] --- .../rtree/linear/redistribute_elements.hpp | 10 +- .../extensions/index/rtree/node/node.hpp | 28 +++ .../index/rtree/node/node_default.hpp | 194 +++++++++--------- .../index/rtree/node/node_default_static.hpp | 91 +++++++- .../node/node_default_static_variant.hpp | 112 ++++++++-- .../index/rtree/node/node_default_variant.hpp | 164 ++++++++------- .../rtree/quadratic/redistribute_elements.hpp | 10 +- .../index/rtree/rstar/choose_next_node.hpp | 10 +- .../extensions/index/rtree/rstar/insert.hpp | 30 +-- .../rtree/rstar/redistribute_elements.hpp | 10 +- .../geometry/extensions/index/rtree/rtree.hpp | 20 +- .../index/rtree/visitors/are_boxes_ok.hpp | 18 +- .../index/rtree/visitors/are_levels_ok.hpp | 18 +- .../index/rtree/visitors/children_box.hpp | 8 +- .../extensions/index/rtree/visitors/copy.hpp | 8 +- .../index/rtree/visitors/destroy.hpp | 8 +- .../index/rtree/visitors/gl_draw.hpp | 27 +-- .../index/rtree/visitors/insert.hpp | 42 ++-- .../index/rtree/visitors/is_leaf.hpp | 8 +- .../index/rtree/visitors/nearest.hpp | 9 +- .../extensions/index/rtree/visitors/print.hpp | 24 ++- .../extensions/index/rtree/visitors/query.hpp | 10 +- .../index/rtree/visitors/remove.hpp | 10 +- 23 files changed, 536 insertions(+), 333 deletions(-) diff --git a/include/boost/geometry/extensions/index/rtree/linear/redistribute_elements.hpp b/include/boost/geometry/extensions/index/rtree/linear/redistribute_elements.hpp index 2e0e1d93f..a8d1ba090 100644 --- a/include/boost/geometry/extensions/index/rtree/linear/redistribute_elements.hpp +++ b/include/boost/geometry/extensions/index/rtree/linear/redistribute_elements.hpp @@ -168,12 +168,12 @@ struct pick_seeds // from void split_node(node_pointer const& n, node_pointer& n1, node_pointer& n2) const -template -struct redistribute_elements +template +struct redistribute_elements { - typedef typename rtree::node::type node; - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::node::type node; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; typedef typename Options::parameters_type parameters_type; diff --git a/include/boost/geometry/extensions/index/rtree/node/node.hpp b/include/boost/geometry/extensions/index/rtree/node/node.hpp index 7e3a05b5b..2f5c9a943 100644 --- a/include/boost/geometry/extensions/index/rtree/node/node.hpp +++ b/include/boost/geometry/extensions/index/rtree/node/node.hpp @@ -16,4 +16,32 @@ #include #include +#include + +namespace boost { namespace geometry { namespace index { + +namespace detail { namespace rtree { + +// elements box + +template +inline Box elements_box(FwdIter first, FwdIter last, Translator const& tr) +{ + BOOST_GEOMETRY_INDEX_ASSERT(first != last, "Can't calculate element's box"); + + Box result; + + geometry::convert(element_indexable(*first, tr), result); + ++first; + + for ( ; first != last ; ++first ) + geometry::expand(result, element_indexable(*first, tr)); + + return result; +} + +}} // namespace detail::rtree + +}}} // namespace boost::geometry::index + #endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_NODE_NODE_HPP diff --git a/include/boost/geometry/extensions/index/rtree/node/node_default.hpp b/include/boost/geometry/extensions/index/rtree/node/node_default.hpp index 0b7e036ad..a7f01533e 100644 --- a/include/boost/geometry/extensions/index/rtree/node/node_default.hpp +++ b/include/boost/geometry/extensions/index/rtree/node/node_default.hpp @@ -12,81 +12,91 @@ #include -#include - namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { // visitor forward declaration -template +template struct visitor_poly; // nodes types -template +template struct node_poly { virtual ~node_poly() {} - virtual void apply_visitor(visitor_poly &) = 0; - virtual void apply_visitor(visitor_poly &) const = 0; + virtual void apply_visitor(visitor_poly &) = 0; + virtual void apply_visitor(visitor_poly &) const = 0; }; -template -struct internal_node_poly : public node_poly +template +struct internal_node_poly : public node_poly { typedef std::vector< - std::pair *> + std::pair *>, + typename Allocators::internal_node_elements_allocator_type > elements_type; - void apply_visitor(visitor_poly & v) { v(*this); } - void apply_visitor(visitor_poly & v) const { v(*this); } + inline internal_node_poly(typename Allocators::internal_node_elements_allocator_type & al) + : elements(al) + {} + + void apply_visitor(visitor_poly & v) { v(*this); } + void apply_visitor(visitor_poly & v) const { v(*this); } elements_type elements; }; -template -struct leaf_poly : public node_poly +template +struct leaf_poly : public node_poly { - typedef std::vector elements_type; + typedef std::vector< + Value, + typename Allocators::leaf_elements_allocator_type + > elements_type; - void apply_visitor(visitor_poly & v) { v(*this); } - void apply_visitor(visitor_poly & v) const { v(*this); } + inline leaf_poly(typename Allocators::leaf_elements_allocator_type & al) + : elements(al) + {} + + void apply_visitor(visitor_poly & v) { v(*this); } + void apply_visitor(visitor_poly & v) const { v(*this); } elements_type elements; }; // nodes traits -template +template struct node { - typedef node_poly type; + typedef node_poly type; }; -template +template struct internal_node { - typedef internal_node_poly type; + typedef internal_node_poly type; }; -template +template struct leaf { - typedef leaf_poly type; + typedef leaf_poly type; }; // nodes conversion -template -inline Derived & get(node_poly & n) +template +inline Derived & get(node_poly & n) { assert(dynamic_cast(&n)); return static_cast(n); } -template -inline Derived * get(node_poly * n) +template +inline Derived * get(node_poly * n) { assert(dynamic_cast(n)); return static_cast(n); @@ -94,11 +104,11 @@ inline Derived * get(node_poly * n) // visitor -template -struct visitor_poly +template +struct visitor_poly { - typedef typename internal_node::type internal_node; - typedef typename leaf::type leaf; + typedef typename internal_node::type internal_node; + typedef typename leaf::type leaf; virtual ~visitor_poly() {} @@ -106,11 +116,11 @@ struct visitor_poly virtual void operator()(leaf const&) = 0; }; -template -struct visitor_poly +template +struct visitor_poly { - typedef typename internal_node::type internal_node; - typedef typename leaf::type leaf; + typedef typename internal_node::type internal_node; + typedef typename leaf::type leaf; virtual ~visitor_poly() {} @@ -120,10 +130,10 @@ struct visitor_poly // visitor traits -template +template struct visitor { - typedef visitor_poly type; + typedef visitor_poly type; }; template @@ -140,9 +150,9 @@ struct element_indexable_type typedef typename Translator::indexable_type type; }; -template +template struct element_indexable_type< - std::pair *>, + std::pair *>, Translator > { @@ -158,10 +168,10 @@ element_indexable(Value const& el, Translator const& tr) return tr(el); } -template +template inline Box const& element_indexable( - std::pair< Box, node_poly *> const& el, + std::pair< Box, node_poly *> const& el, Translator const&) { return el.first; @@ -189,79 +199,73 @@ elements(Node const& n) return n.elements; } -// elements box - -template -inline Box elements_box(FwdIter first, FwdIter last, Translator const& tr) -{ - BOOST_GEOMETRY_INDEX_ASSERT(first != last, "Can't calculate element's box"); - - Box result; - - geometry::convert(element_indexable(*first, tr), result); - ++first; - - for ( ; first != last ; ++first ) - geometry::expand(result, element_indexable(*first, tr)); - - return result; -} - // allocators -template +template struct allocators_poly { typedef Allocator allocator_type; typedef typename allocator_type::size_type size_type; typedef typename allocator_type::template rebind< - typename internal_node::type + typename internal_node::type >::other internal_node_allocator_type; typedef typename allocator_type::template rebind< - typename leaf::type + typename leaf::type >::other leaf_allocator_type; + typedef typename allocator_type::template rebind< + std::pair *> + >::other internal_node_elements_allocator_type; + + typedef typename allocator_type::template rebind< + Value + >::other leaf_elements_allocator_type; + inline explicit allocators_poly(Allocator alloc) : allocator(alloc) , internal_node_allocator(allocator) , leaf_allocator(allocator) + , internal_node_elements_allocator(allocator) + , leaf_elements_allocator(allocator) {} allocator_type allocator; internal_node_allocator_type internal_node_allocator; leaf_allocator_type leaf_allocator; + internal_node_elements_allocator_type internal_node_elements_allocator; + leaf_elements_allocator_type leaf_elements_allocator; }; // allocators -template +template struct allocators { - typedef allocators_poly type; + typedef allocators_poly type; }; -// create_node_poly +// create_node_impl -template +template struct create_node_poly { - template - static inline RetNode * apply(Allocator & allocator) + template + static inline RetNode * apply(AllocNode & alloc_node, AllocElems & alloc_elems) { - Node * p = allocator.allocate(1); + Node * p = alloc_node.allocate(1); if ( 0 == p ) throw std::bad_alloc(); try { - allocator.construct(p, Node()); + alloc_node.construct(p, Node(alloc_elems)); } catch(...) { - allocator.deallocate(p, 1); + alloc_node.deallocate(p, 1); throw; } @@ -269,17 +273,17 @@ struct create_node_poly } }; -// destroy_node_poly +// destroy_node_impl -template +template struct destroy_node_poly { - template - static inline void apply(Allocator & allocator, BaseNode * n) + template + static inline void apply(AllocNode & alloc_node, BaseNode * n) { Node * p = rtree::get(n); - allocator.destroy(p); - allocator.deallocate(p, 1); + alloc_node.destroy(p); + alloc_node.deallocate(p, 1); } }; @@ -297,34 +301,34 @@ struct create_node template struct create_node< Allocators, - internal_node_poly + internal_node_poly > { - static inline typename node::type * apply(Allocators & allocators) + static inline typename node::type * + apply(Allocators & allocators) { return create_node_poly< - typename Allocators::internal_node_allocator_type, - internal_node_poly + internal_node_poly >::template apply< - typename node::type - >(allocators.internal_node_allocator); + typename node::type + >(allocators.internal_node_allocator, allocators.internal_node_elements_allocator); } }; template struct create_node< Allocators, - leaf_poly + leaf_poly > { - static inline typename node::type * apply(Allocators & allocators) + static inline typename node::type * + apply(Allocators & allocators) { return create_node_poly< - typename Allocators::leaf_allocator_type, - leaf_poly + leaf_poly >::template apply< - typename node::type - >(allocators.leaf_allocator); + typename node::type + >(allocators.leaf_allocator, allocators.leaf_elements_allocator); } }; @@ -342,14 +346,13 @@ struct destroy_node template struct destroy_node< Allocators, - internal_node_poly + internal_node_poly > { - static inline void apply(Allocators & allocators, typename node::type * n) + static inline void apply(Allocators & allocators, typename node::type * n) { destroy_node_poly< - typename Allocators::internal_node_allocator_type, - internal_node_poly + internal_node_poly >::apply(allocators.internal_node_allocator, n); } }; @@ -357,14 +360,13 @@ struct destroy_node< template struct destroy_node< Allocators, - leaf_poly + leaf_poly > { - static inline void apply(Allocators & allocators, typename node::type * n) + static inline void apply(Allocators & allocators, typename node::type * n) { destroy_node_poly< - typename Allocators::leaf_allocator_type, - leaf_poly + leaf_poly >::apply(allocators.leaf_allocator, n); } }; diff --git a/include/boost/geometry/extensions/index/rtree/node/node_default_static.hpp b/include/boost/geometry/extensions/index/rtree/node/node_default_static.hpp index 458817996..854680811 100644 --- a/include/boost/geometry/extensions/index/rtree/node/node_default_static.hpp +++ b/include/boost/geometry/extensions/index/rtree/node/node_default_static.hpp @@ -16,36 +16,105 @@ namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { -template -struct internal_node_poly - : public node_poly +template +struct internal_node_poly + : public node_poly { typedef index::pushable_array< std::pair< Box, - node_poly * + node_poly * >, Parameters::max_elements + 1 > elements_type; - void apply_visitor(visitor_poly & v) { v(*this); } - void apply_visitor(visitor_poly & v) const { v(*this); } + template + inline internal_node_poly(Dummy) {} + + void apply_visitor(visitor_poly & v) { v(*this); } + void apply_visitor(visitor_poly & v) const { v(*this); } elements_type elements; }; -template -struct leaf_poly - : public node_poly +template +struct leaf_poly + : public node_poly { typedef index::pushable_array elements_type; - void apply_visitor(visitor_poly & v) { v(*this); } - void apply_visitor(visitor_poly & v) const { v(*this); } + template + inline leaf_poly(Dummy) {} + + void apply_visitor(visitor_poly & v) { v(*this); } + void apply_visitor(visitor_poly & v) const { v(*this); } elements_type elements; }; +// allocators_poly + +template +struct allocators_poly +{ + typedef Allocator allocator_type; + typedef typename allocator_type::size_type size_type; + + typedef typename allocator_type::template rebind< + typename internal_node::type + >::other internal_node_allocator_type; + + typedef typename allocator_type::template rebind< + typename leaf::type + >::other leaf_allocator_type; + + inline explicit allocators_poly(Allocator alloc) + : allocator(alloc) + , internal_node_allocator(allocator) + , leaf_allocator(allocator) + {} + + allocator_type allocator; + internal_node_allocator_type internal_node_allocator; + leaf_allocator_type leaf_allocator; +}; + +// create_node + +template +struct create_node< + Allocators, + internal_node_poly +> +{ + static inline typename node::type * + apply(Allocators & allocators) + { + return create_node_poly< + internal_node_poly + >::template apply< + typename node::type + >(allocators.internal_node_allocator, allocators.internal_node_allocator); + } +}; + +template +struct create_node< + Allocators, + leaf_poly +> +{ + static inline typename node::type * + apply(Allocators & allocators) + { + return create_node_poly< + leaf_poly + >::template apply< + typename node::type + >(allocators.leaf_allocator, allocators.leaf_allocator); + } +}; + }} // namespace detail::rtree }}} // namespace boost::geometry::index diff --git a/include/boost/geometry/extensions/index/rtree/node/node_default_static_variant.hpp b/include/boost/geometry/extensions/index/rtree/node/node_default_static_variant.hpp index 5af462646..ba7a6dba0 100644 --- a/include/boost/geometry/extensions/index/rtree/node/node_default_static_variant.hpp +++ b/include/boost/geometry/extensions/index/rtree/node/node_default_static_variant.hpp @@ -19,64 +19,136 @@ namespace detail { namespace rtree { // nodes default types -template -struct internal_node_variant +template +struct internal_node_variant { typedef index::pushable_array< std::pair< Box, - typename node::type * + typename node::type * >, Parameters::max_elements + 1 > elements_type; + template + inline internal_node_variant(Dummy) {} + elements_type elements; }; -template -struct leaf_variant +template +struct leaf_variant { typedef index::pushable_array elements_type; + + template + inline leaf_variant(Dummy) {} + elements_type elements; }; // nodes traits -template -struct node +template +struct node { typedef boost::variant< - leaf_variant, - internal_node_variant + leaf_variant, + internal_node_variant > type; }; -template -struct internal_node +template +struct internal_node { - typedef internal_node_variant type; + typedef internal_node_variant type; }; -template -struct leaf +template +struct leaf { - typedef leaf_variant type; + typedef leaf_variant type; }; // visitor traits -template -struct visitor +template +struct visitor { typedef static_visitor<> type; }; +// allocators_variant + +template +struct allocators_variant +{ + typedef Allocator allocator_type; + typedef typename allocator_type::size_type size_type; + + typedef typename allocator_type::template rebind< + typename node::type + >::other node_allocator_type; + + typedef typename allocator_type::template rebind< + std::pair *> + >::other internal_node_elements_allocator_type; + + typedef typename allocator_type::template rebind< + Value + >::other leaf_elements_allocator_type; + + inline explicit allocators_variant(Allocator alloc) + : allocator(alloc) + , node_allocator(allocator) + {} + + allocator_type allocator; + node_allocator_type node_allocator; +}; + // allocators -template -struct allocators +template +struct allocators { - typedef allocators_variant type; + typedef allocators_variant type; +}; + +// create_node + +template +struct create_node< + Allocators, + internal_node_variant +> +{ + static inline typename node::type * + apply(Allocators & allocators) + { + return create_node_variant< + internal_node_variant + >::template apply< + typename node::type + >(allocators.node_allocator, allocators.node_allocator); + } +}; + +template +struct create_node< + Allocators, + leaf_variant +> +{ + static inline typename node::type * + apply(Allocators & allocators) + { + return create_node_variant< + leaf_variant + >::template apply< + typename node::type + >(allocators.node_allocator, allocators.node_allocator); + } }; }} // namespace detail::rtree diff --git a/include/boost/geometry/extensions/index/rtree/node/node_default_variant.hpp b/include/boost/geometry/extensions/index/rtree/node/node_default_variant.hpp index 3d081eb7e..b5fff6942 100644 --- a/include/boost/geometry/extensions/index/rtree/node/node_default_variant.hpp +++ b/include/boost/geometry/extensions/index/rtree/node/node_default_variant.hpp @@ -19,67 +19,80 @@ namespace detail { namespace rtree { // nodes default types -template +template struct internal_node_variant { typedef std::vector< std::pair< Box, - typename node::type * - > + typename node::type * + >, + typename Allocators::internal_node_elements_allocator_type > elements_type; + inline internal_node_variant(typename Allocators::internal_node_elements_allocator_type & al) + : elements(al) + {} + elements_type elements; }; -template +template struct leaf_variant { - typedef std::vector elements_type; + typedef std::vector< + Value, + typename Allocators::leaf_elements_allocator_type + > elements_type; + + inline leaf_variant(typename Allocators::leaf_elements_allocator_type & al) + : elements(al) + {} + elements_type elements; }; // nodes traits -template -struct node +template +struct node { typedef boost::variant< - leaf_variant, - internal_node_variant + leaf_variant, + internal_node_variant > type; }; -template -struct internal_node +template +struct internal_node { - typedef internal_node_variant type; + typedef internal_node_variant type; }; -template -struct leaf +template +struct leaf { - typedef leaf_variant type; + typedef leaf_variant type; }; // nodes conversion -template +template inline V & get( boost::variant< - leaf_variant, - internal_node_variant + leaf_variant, + internal_node_variant > &v ) { return boost::get(v); } -template +template inline V * get( boost::variant< - leaf_variant, - internal_node_variant + leaf_variant, + internal_node_variant > *v ) { @@ -88,27 +101,27 @@ inline V * get( // visitor traits -template -struct visitor +template +struct visitor { typedef static_visitor<> type; }; -template +template inline void apply_visitor(Visitor & v, boost::variant< - leaf_variant, - internal_node_variant + leaf_variant, + internal_node_variant > & n) { boost::apply_visitor(v, n); } -template +template inline void apply_visitor(Visitor & v, boost::variant< - leaf_variant, - internal_node_variant + leaf_variant, + internal_node_variant > const& n) { boost::apply_visitor(v, n); @@ -116,13 +129,13 @@ inline void apply_visitor(Visitor & v, // element's indexable type -template +template struct element_indexable_type< std::pair< Box, boost::variant< - leaf_variant, - internal_node_variant + leaf_variant, + internal_node_variant > * >, Translator @@ -133,13 +146,13 @@ struct element_indexable_type< // element's indexable getter -template +template inline Box const& element_indexable(std::pair< Box, boost::variant< - leaf_variant, - internal_node_variant + leaf_variant, + internal_node_variant > * > const& el, Translator const&) @@ -149,53 +162,65 @@ element_indexable(std::pair< // allocators -template +template struct allocators_variant { typedef Allocator allocator_type; typedef typename allocator_type::size_type size_type; typedef typename allocator_type::template rebind< - typename node::type + typename node::type >::other node_allocator_type; + typedef typename allocator_type::template rebind< + std::pair *> + >::other internal_node_elements_allocator_type; + + typedef typename allocator_type::template rebind< + Value + >::other leaf_elements_allocator_type; + inline explicit allocators_variant(Allocator alloc) : allocator(alloc) , node_allocator(allocator) + , internal_node_elements_allocator(allocator) + , leaf_elements_allocator(allocator) {} allocator_type allocator; node_allocator_type node_allocator; + internal_node_elements_allocator_type internal_node_elements_allocator; + leaf_elements_allocator_type leaf_elements_allocator; }; // allocators -template -struct allocators +template +struct allocators { - typedef allocators_variant type; + typedef allocators_variant type; }; // create_node_variant -template +template struct create_node_variant { - template - static inline RetNode * apply(Allocator & allocator) + template + static inline RetNode * apply(AllocNode & alloc_node, AllocElems & alloc_elems) { - RetNode * p = allocator.allocate(1); + RetNode * p = alloc_node.allocate(1); if ( 0 == p ) throw std::bad_alloc(); try { - allocator.construct(p, Node()); + alloc_node.construct(p, Node(alloc_elems)); } catch(...) { - allocator.deallocate(p, 1); + alloc_node.deallocate(p, 1); throw; } @@ -205,14 +230,14 @@ struct create_node_variant // destroy_node_variant -template +template struct destroy_node_variant { - template - static inline void apply(Allocator & allocator, BaseNode * n) + template + static inline void apply(AllocNode & alloc_node, BaseNode * n) { - allocator.destroy(n); - allocator.deallocate(n, 1); + alloc_node.destroy(n); + alloc_node.deallocate(n, 1); } }; @@ -221,35 +246,34 @@ struct destroy_node_variant template struct create_node< Allocators, - internal_node_variant + internal_node_variant > { - static inline typename node::type * + static inline typename node::type * apply(Allocators & allocators) { return create_node_variant< - typename Allocators::node_allocator_type, - internal_node_variant + internal_node_variant >::template apply< - typename node::type - >(allocators.node_allocator); + typename node::type + >(allocators.node_allocator, allocators.internal_node_elements_allocator); } }; template struct create_node< Allocators, - leaf_variant + leaf_variant > { - static inline typename node::type * apply(Allocators & allocators) + static inline typename node::type * + apply(Allocators & allocators) { return create_node_variant< - typename Allocators::node_allocator_type, - leaf_variant + leaf_variant >::template apply< - typename node::type - >(allocators.node_allocator); + typename node::type + >(allocators.node_allocator, allocators.leaf_elements_allocator); } }; @@ -258,14 +282,13 @@ struct create_node< template struct destroy_node< Allocators, - internal_node_variant + internal_node_variant > { - static inline void apply(Allocators & allocators, typename node::type * n) + static inline void apply(Allocators & allocators, typename node::type * n) { destroy_node_variant< - typename Allocators::node_allocator_type, - internal_node_variant + internal_node_variant >::apply(allocators.node_allocator, n); } }; @@ -273,14 +296,13 @@ struct destroy_node< template struct destroy_node< Allocators, - leaf_variant + leaf_variant > { - static inline void apply(Allocators & allocators, typename node::type * n) + static inline void apply(Allocators & allocators, typename node::type * n) { destroy_node_variant< - typename Allocators::node_allocator_type, - leaf_variant + leaf_variant >::apply(allocators.node_allocator, n); } }; diff --git a/include/boost/geometry/extensions/index/rtree/quadratic/redistribute_elements.hpp b/include/boost/geometry/extensions/index/rtree/quadratic/redistribute_elements.hpp index df14cb154..f7cec8b47 100644 --- a/include/boost/geometry/extensions/index/rtree/quadratic/redistribute_elements.hpp +++ b/include/boost/geometry/extensions/index/rtree/quadratic/redistribute_elements.hpp @@ -75,14 +75,14 @@ struct pick_seeds } // namespace quadratic -template -struct redistribute_elements +template +struct redistribute_elements { typedef typename Options::parameters_type parameters_type; - typedef typename rtree::node::type node; - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::node::type node; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; typedef typename index::default_content_result::type content_type; diff --git a/include/boost/geometry/extensions/index/rtree/rstar/choose_next_node.hpp b/include/boost/geometry/extensions/index/rtree/rstar/choose_next_node.hpp index dab689d1a..caf86f030 100644 --- a/include/boost/geometry/extensions/index/rtree/rstar/choose_next_node.hpp +++ b/include/boost/geometry/extensions/index/rtree/rstar/choose_next_node.hpp @@ -27,12 +27,12 @@ namespace detail { namespace rtree { namespace visitors { namespace detail { -template -class choose_next_node +template +class choose_next_node { - typedef typename rtree::node::type node; - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::node::type node; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; typedef typename rtree::elements_type::type children_type; typedef typename children_type::value_type child_type; diff --git a/include/boost/geometry/extensions/index/rtree/rstar/insert.hpp b/include/boost/geometry/extensions/index/rtree/rstar/insert.hpp index 2130c9bfc..2aad1f797 100644 --- a/include/boost/geometry/extensions/index/rtree/rstar/insert.hpp +++ b/include/boost/geometry/extensions/index/rtree/rstar/insert.hpp @@ -20,13 +20,13 @@ namespace detail { namespace rstar { -template +template class remove_elements_to_reinsert { public: - typedef typename rtree::node::type node; - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::node::type node; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; typedef typename Options::parameters_type parameters_type; @@ -103,19 +103,19 @@ private: } }; -template +template struct level_insert_elements_type { typedef typename rtree::elements_type< - typename rtree::internal_node::type + typename rtree::internal_node::type >::type type; }; -template -struct level_insert_elements_type<0, Value, Value, Options, Box> +template +struct level_insert_elements_type<0, Value, Value, Options, Box, Allocators> { typedef typename rtree::elements_type< - typename rtree::leaf::type + typename rtree::leaf::type >::type type; }; @@ -128,7 +128,7 @@ struct level_insert_base typedef typename base::internal_node internal_node; typedef typename base::leaf leaf; - typedef typename level_insert_elements_type::type elements_type; + typedef typename level_insert_elements_type::type elements_type; typedef typename Options::parameters_type parameters_type; inline level_insert_base(node* & root, @@ -154,7 +154,7 @@ struct level_insert_base // node isn't root node if ( base::m_parent ) { - rstar::remove_elements_to_reinsert::apply( + rstar::remove_elements_to_reinsert::apply( result_elements, n, base::m_parent, base::m_current_child_index, base::m_tr); @@ -355,13 +355,13 @@ struct level_insert<0, Value, Value, Options, Translator, Box, Allocators> // R*-tree insert visitor template class insert - : public rtree::visitor::type + : public rtree::visitor::type , index::nonassignable { private: - typedef typename rtree::node::type node; - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::node::type node; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; public: inline insert(node* & root, diff --git a/include/boost/geometry/extensions/index/rtree/rstar/redistribute_elements.hpp b/include/boost/geometry/extensions/index/rtree/rstar/redistribute_elements.hpp index 60676b45c..b1c024f7c 100644 --- a/include/boost/geometry/extensions/index/rtree/rstar/redistribute_elements.hpp +++ b/include/boost/geometry/extensions/index/rtree/rstar/redistribute_elements.hpp @@ -308,12 +308,12 @@ struct partial_sort } // namespace rstar -template -struct redistribute_elements +template +struct redistribute_elements { - typedef typename rtree::node::type node; - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::node::type node; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; typedef typename Options::parameters_type parameters_type; diff --git a/include/boost/geometry/extensions/index/rtree/rtree.hpp b/include/boost/geometry/extensions/index/rtree/rtree.hpp index d07a6487a..1ea7fd367 100644 --- a/include/boost/geometry/extensions/index/rtree/rtree.hpp +++ b/include/boost/geometry/extensions/index/rtree/rtree.hpp @@ -59,8 +59,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 delete unneeded nodes types (using vectors) and change the name of currently used one to node_default - template < typename Value, typename Parameters, @@ -75,18 +73,18 @@ public: typedef Translator translator_type; typedef typename translator_type::indexable_type indexable_type; typedef typename index::default_box_type::type box_type; - + typedef typename detail::rtree::options_type::type options_type; typedef typename options_type::node_tag node_tag; - typedef typename detail::rtree::node::type node; - typedef typename detail::rtree::internal_node::type internal_node; - typedef typename detail::rtree::leaf::type leaf; - typedef Allocator allocator_type; - typedef typename detail::rtree::allocators::type allocators_type; + typedef typename detail::rtree::allocators::type allocators_type; typedef typename allocators_type::size_type size_type; + typedef typename detail::rtree::node::type node; + typedef typename detail::rtree::internal_node::type internal_node; + typedef typename detail::rtree::leaf::type leaf; + inline explicit rtree(translator_type const& translator = translator_type(), Allocator allocator = std::allocator()) : m_values_count(0) , m_root(0) @@ -220,7 +218,7 @@ public: template inline size_type query(Predicates const& pred, OutIter out_it) const { - detail::rtree::visitors::query + detail::rtree::visitors::query find_v(m_translator, pred, out_it); detail::rtree::apply_visitor(find_v, *m_root); @@ -277,7 +275,7 @@ public: return result; } - detail::rtree::visitors::children_box + detail::rtree::visitors::children_box children_box_v(m_translator); detail::rtree::apply_visitor(children_box_v, *m_root); @@ -356,6 +354,7 @@ private: options_type, translator_type, box_type, + allocators_type, DistancesPredicates, Predicates, result_type @@ -385,6 +384,7 @@ private: options_type, translator_type, box_type, + allocators_type, DistancesPredicates, Predicates, result_type diff --git a/include/boost/geometry/extensions/index/rtree/visitors/are_boxes_ok.hpp b/include/boost/geometry/extensions/index/rtree/visitors/are_boxes_ok.hpp index 94408eaf7..0c12b170f 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/are_boxes_ok.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/are_boxes_ok.hpp @@ -17,13 +17,13 @@ namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace visitors { -template +template class are_boxes_ok - : public rtree::visitor::type + : public rtree::visitor::type , index::nonassignable { - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; public: inline are_boxes_ok(Translator const& tr) @@ -109,15 +109,17 @@ private: }}} // namespace detail::rtree::visitors -template -bool are_boxes_ok(rtree const& tree) +template +bool are_boxes_ok(rtree const& tree) { - typedef rtree rt; + typedef rtree rt; detail::rtree::visitors::are_boxes_ok< typename rt::value_type, typename rt::options_type, typename rt::translator_type, - typename rt::box_type> v(tree.translator()); + typename rt::box_type, + typename rt::allocators_type + > v(tree.translator()); tree.apply_visitor(v); diff --git a/include/boost/geometry/extensions/index/rtree/visitors/are_levels_ok.hpp b/include/boost/geometry/extensions/index/rtree/visitors/are_levels_ok.hpp index b9394dd24..946a4303c 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/are_levels_ok.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/are_levels_ok.hpp @@ -16,13 +16,13 @@ namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace visitors { -template +template class are_levels_ok - : public rtree::visitor::type + : public rtree::visitor::type , index::nonassignable { - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; public: inline are_levels_ok(Translator const& tr) @@ -87,15 +87,17 @@ private: }}} // namespace detail::rtree::visitors -template -bool are_levels_ok(rtree const& tree) +template +bool are_levels_ok(rtree const& tree) { - typedef rtree rt; + typedef rtree rt; detail::rtree::visitors::are_levels_ok< typename rt::value_type, typename rt::options_type, typename rt::translator_type, - typename rt::box_type> v(tree.translator()); + typename rt::box_type, + typename rt::allocators_type + > v(tree.translator()); tree.apply_visitor(v); diff --git a/include/boost/geometry/extensions/index/rtree/visitors/children_box.hpp b/include/boost/geometry/extensions/index/rtree/visitors/children_box.hpp index 34f493323..626553643 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/children_box.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/children_box.hpp @@ -16,13 +16,13 @@ namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace visitors { -template +template class children_box - : public rtree::visitor::type + : public rtree::visitor::type , index::nonassignable { - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; public: inline children_box(Translator const& tr) diff --git a/include/boost/geometry/extensions/index/rtree/visitors/copy.hpp b/include/boost/geometry/extensions/index/rtree/visitors/copy.hpp index 31ea2b783..12fa86435 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/copy.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/copy.hpp @@ -18,13 +18,13 @@ namespace detail { namespace rtree { namespace visitors { template class copy - : public rtree::visitor::type + : public rtree::visitor::type , boost::noncopyable { public: - typedef typename rtree::node::type node; - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::node::type node; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; explicit inline copy(Allocators & allocators) : result(0) diff --git a/include/boost/geometry/extensions/index/rtree/visitors/destroy.hpp b/include/boost/geometry/extensions/index/rtree/visitors/destroy.hpp index 15fe5b126..eac919b6d 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/destroy.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/destroy.hpp @@ -18,13 +18,13 @@ namespace detail { namespace rtree { namespace visitors { template class destroy - : public rtree::visitor::type + : public rtree::visitor::type , boost::noncopyable { public: - typedef typename rtree::node::type node; - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::node::type node; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; inline destroy(node * root_node, Allocators & allocators) : m_current_node(root_node) diff --git a/include/boost/geometry/extensions/index/rtree/visitors/gl_draw.hpp b/include/boost/geometry/extensions/index/rtree/visitors/gl_draw.hpp index 1d4e9feb7..9b51e51a1 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/gl_draw.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/gl_draw.hpp @@ -93,11 +93,11 @@ inline void gl_draw_indexable(Indexable const& i, typename index::traits::coordi } // namespace detail -template -struct gl_draw : public rtree::visitor::type +template +struct gl_draw : public rtree::visitor::type { - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; inline gl_draw(Translator const& t, size_t level_first = 0, @@ -186,21 +186,24 @@ struct gl_draw : public rtree::visitor -void gl_draw(rtree const& tree, +template +void gl_draw(rtree const& tree, size_t level_first = 0, size_t level_last = std::numeric_limits::max(), typename index::traits::coordinate_type< - typename rtree::box_type + typename rtree::box_type >::type z_coord_level_multiplier = 1 ) { - typedef typename rtree::value_type value_type; - typedef typename rtree::options_type options_type; - typedef typename rtree::translator_type translator_type; - typedef typename rtree::box_type box_type; + typedef rtree rtree_type; - detail::rtree::visitors::gl_draw + typedef typename rtree_type::value_type value_type; + typedef typename rtree_type::options_type options_type; + typedef typename rtree_type::translator_type translator_type; + typedef typename rtree_type::box_type box_type; + typedef typename rtree_type::allocators_type allocators_type; + + detail::rtree::visitors::gl_draw gl_draw_v(tree.translator(), level_first, level_last, z_coord_level_multiplier); tree.apply_visitor(gl_draw_v); diff --git a/include/boost/geometry/extensions/index/rtree/visitors/insert.hpp b/include/boost/geometry/extensions/index/rtree/visitors/insert.hpp index c164186c3..97c5a242f 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/insert.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/insert.hpp @@ -21,15 +21,15 @@ namespace detail { namespace rtree { namespace visitors { namespace detail { // Default choose_next_node -template +template struct choose_next_node; -template -struct choose_next_node +template +struct choose_next_node { - typedef typename rtree::node::type node; - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::node::type node; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; typedef typename rtree::elements_type::type children_type; @@ -80,28 +80,28 @@ struct choose_next_node // ----------------------------------------------------------------------- // // Not implemented here -template +template struct redistribute_elements; // ----------------------------------------------------------------------- // // Split algorithm -template +template class split; // Default split algorithm -template -class split +template +class split { protected: - typedef typename rtree::node::type node; - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::node::type node; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; typedef typename Options::parameters_type parameters_type; public: - template + template static inline void apply(node* & root_node, size_t & leafs_level, Node & n, @@ -116,7 +116,7 @@ public: // redistribute elements Box box1, box2; - redistribute_elements:: + redistribute_elements:: apply(n, n2, box1, box2, tr); // check numbers of elements @@ -157,13 +157,13 @@ public: // Default insert visitor template class insert - : public rtree::visitor::type + : public rtree::visitor::type , index::nonassignable { protected: - typedef typename rtree::node::type node; - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::node::type node; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; typedef typename Options::parameters_type parameters_type; @@ -196,7 +196,7 @@ protected: inline void traverse(Visitor & visitor, internal_node & n) { // choose next node - size_t choosen_node_index = detail::choose_next_node:: + size_t choosen_node_index = detail::choose_next_node:: apply(n, rtree::element_indexable(m_element, m_tr), m_leafs_level - m_current_level); // expand the node to contain value @@ -248,7 +248,7 @@ protected: template inline void split(Node & n) const { - detail::split::apply(m_root_node, m_leafs_level, n, m_parent, m_current_child_index, m_tr, m_allocators); + detail::split::apply(m_root_node, m_leafs_level, n, m_parent, m_current_child_index, m_tr, m_allocators); } // TODO: awulkiew - implement dispatchable split::apply to enable additional nodes creation diff --git a/include/boost/geometry/extensions/index/rtree/visitors/is_leaf.hpp b/include/boost/geometry/extensions/index/rtree/visitors/is_leaf.hpp index 529bd99c8..f07bc7d15 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/is_leaf.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/is_leaf.hpp @@ -16,11 +16,11 @@ namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace visitors { -template -struct is_leaf : public rtree::visitor::type +template +struct is_leaf : public rtree::visitor::type { - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; inline void operator()(internal_node const&) { diff --git a/include/boost/geometry/extensions/index/rtree/visitors/nearest.hpp b/include/boost/geometry/extensions/index/rtree/visitors/nearest.hpp index 2796bd480..913653619 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/nearest.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/nearest.hpp @@ -141,18 +141,19 @@ template < typename Options, typename Translator, typename Box, + typename Allocators, typename DistancesPredicates, typename Predicates, typename Result > class nearest - : public rtree::visitor::type + : public rtree::visitor::type , index::nonassignable { public: - typedef typename rtree::node::type node; - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::node::type node; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; typedef index::detail::distances_calc node_distances_calc; typedef typename node_distances_calc::result_type node_distances_type; diff --git a/include/boost/geometry/extensions/index/rtree/visitors/print.hpp b/include/boost/geometry/extensions/index/rtree/visitors/print.hpp index 45928e1e0..71d7658d4 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/print.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/print.hpp @@ -111,11 +111,11 @@ inline void print_indexable(std::ostream & os, Indexable const& i) } // namespace detail -template -struct print : public rtree::visitor::type +template +struct print : public rtree::visitor::type { - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; inline print(std::ostream & o, Translator const& t) : os(o), tr(t), level(0) @@ -178,14 +178,16 @@ struct print : public rtree::visitor -std::ostream & operator<<(std::ostream & os, rtree const& tree) +template +std::ostream & operator<<(std::ostream & os, rtree const& tree) { - typedef typename rtree::value_type value_type; - typedef typename rtree::options_type options_type; - typedef typename rtree::translator_type translator_type; - typedef typename rtree::box_type box_type; - detail::rtree::visitors::print print_v(os, tree.translator()); + typedef rtree rtree_type; + typedef typename rtree_type::value_type value_type; + typedef typename rtree_type::options_type options_type; + typedef typename rtree_type::translator_type translator_type; + typedef typename rtree_type::box_type box_type; + typedef typename rtree_type::allocators_type allocators_type; + detail::rtree::visitors::print print_v(os, tree.translator()); tree.apply_visitor(print_v); return os; } diff --git a/include/boost/geometry/extensions/index/rtree/visitors/query.hpp b/include/boost/geometry/extensions/index/rtree/visitors/query.hpp index 39a12a345..9b420e54b 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/query.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/query.hpp @@ -16,14 +16,14 @@ namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace visitors { -template +template struct query - : public rtree::visitor::type + : public rtree::visitor::type , index::nonassignable { - typedef typename rtree::node::type node; - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::node::type node; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; inline query(Translator const& t, Predicates const& p, OutIter out_it) : tr(t), pred(p), out_iter(out_it), found_count(0) diff --git a/include/boost/geometry/extensions/index/rtree/visitors/remove.hpp b/include/boost/geometry/extensions/index/rtree/visitors/remove.hpp index 3a743585e..db267702b 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/remove.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/remove.hpp @@ -23,12 +23,12 @@ namespace detail { namespace rtree { namespace visitors { // Default remove algorithm template class remove - : public rtree::visitor::type + : public rtree::visitor::type , index::nonassignable { - typedef typename rtree::node::type node; - typedef typename rtree::internal_node::type internal_node; - typedef typename rtree::leaf::type leaf; + typedef typename rtree::node::type node; + typedef typename rtree::internal_node::type internal_node; + typedef typename rtree::leaf::type leaf; typedef typename Options::parameters_type parameters_type; @@ -114,7 +114,7 @@ public: for ( typename std::vector< std::pair >::reverse_iterator it = m_underflowed_nodes.rbegin(); it != m_underflowed_nodes.rend() ; ++it ) { - is_leaf ilv; + is_leaf ilv; rtree::apply_visitor(ilv, *it->second); if ( ilv.result ) {