[rtree] Simplify node destruction calls.

This commit is contained in:
Adam Wulkiewicz
2019-11-04 23:49:20 +01:00
parent 477627d16a
commit b0e3bd8541
9 changed files with 29 additions and 19 deletions

View File

@@ -31,10 +31,9 @@
#include <boost/geometry/index/detail/rtree/node/variant_dynamic.hpp>
#include <boost/geometry/index/detail/rtree/node/variant_static.hpp>
#include <boost/geometry/index/detail/rtree/node/subtree_destroyer.hpp>
#include <boost/geometry/algorithms/expand.hpp>
#include <boost/geometry/index/detail/rtree/visitors/destroy.hpp>
#include <boost/geometry/index/detail/rtree/visitors/is_leaf.hpp>
#include <boost/geometry/index/detail/algorithms/bounds.hpp>
@@ -114,7 +113,8 @@ struct destroy_element
inline static void apply(typename internal_node::elements_type::value_type & element,
allocators_type & allocators)
{
rtree::subtree_destroyer<MembersHolder> dummy(element.second, allocators);
detail::rtree::visitors::destroy<MembersHolder>::apply(element.second, allocators);
element.second = 0;
}
@@ -155,7 +155,8 @@ private:
{
for ( ; first != last ; ++first )
{
rtree::subtree_destroyer<MembersHolder> dummy(first->second, allocators);
detail::rtree::visitors::destroy<MembersHolder>::apply(first->second, allocators);
first->second = 0;
}
}
@@ -167,6 +168,7 @@ private:
};
// clears node, deletes all subtrees stored in node
/*
template <typename MembersHolder>
struct clear_node
{
@@ -202,6 +204,7 @@ struct clear_node
rtree::elements(leaf).clear();
}
};
*/
template <typename Container, typename Iterator>
void move_from_back(Container & container, Iterator it)

View File

@@ -47,8 +47,7 @@ public:
{
if ( m_ptr && m_ptr != ptr )
{
detail::rtree::visitors::destroy<MembersHolder> del_v(m_ptr, m_allocators);
detail::rtree::apply_visitor(del_v, *m_ptr);
detail::rtree::visitors::destroy<MembersHolder>::apply(m_ptr, m_allocators);
}
m_ptr = ptr;
}

View File

@@ -20,6 +20,7 @@
#include <boost/geometry/algorithms/expand.hpp>
#include <boost/geometry/index/detail/algorithms/bounds.hpp>
#include <boost/geometry/index/detail/algorithms/nth_element.hpp>
#include <boost/geometry/index/detail/rtree/node/subtree_destroyer.hpp>
#include <boost/geometry/algorithms/detail/expand_by_epsilon.hpp>

View File

@@ -394,8 +394,7 @@ struct level_insert
// NOTE: exception-safety
// if the insert fails above, the element won't be stored in the tree, so delete it
rtree::visitors::destroy<MembersHolder> del_v(base::m_element.second, base::m_allocators);
rtree::apply_visitor(del_v, *base::m_element.second);
rtree::visitors::destroy<MembersHolder>::apply(base::m_element.second, base::m_allocators);
BOOST_RETHROW // RETHROW
}

View File

@@ -15,6 +15,8 @@
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_COPY_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_COPY_HPP
#include <boost/geometry/index/detail/rtree/node/subtree_destroyer.hpp>
namespace boost { namespace geometry { namespace index {
namespace detail { namespace rtree { namespace visitors {

View File

@@ -31,8 +31,8 @@ public:
typedef typename MembersHolder::allocators_type allocators_type;
typedef typename MembersHolder::node_pointer node_pointer;
inline destroy(node_pointer root_node, allocators_type & allocators)
: m_current_node(root_node)
inline destroy(node_pointer node, allocators_type & allocators)
: m_current_node(node)
, m_allocators(allocators)
{}
@@ -64,6 +64,12 @@ public:
rtree::destroy_node<allocators_type, leaf>::apply(m_allocators, m_current_node);
}
static inline void apply(node_pointer node, allocators_type & allocators)
{
destroy v(node, allocators);
rtree::apply_visitor(v, *node);
}
private:
node_pointer m_current_node;
allocators_type & m_allocators;

View File

@@ -23,6 +23,8 @@
#include <boost/geometry/index/detail/algorithms/bounds.hpp>
#include <boost/geometry/index/detail/algorithms/content.hpp>
#include <boost/geometry/index/detail/rtree/node/subtree_destroyer.hpp>
namespace boost { namespace geometry { namespace index {
namespace detail { namespace rtree {
@@ -533,8 +535,7 @@ public:
{
// if the insert fails above, the element won't be stored in the tree
rtree::visitors::destroy<MembersHolder> del_v(base::m_element.second, base::m_allocators);
rtree::apply_visitor(del_v, *base::m_element.second);
rtree::visitors::destroy<MembersHolder>::apply(base::m_element.second, base::m_allocators);
BOOST_RETHROW // RETHROW
}

View File

@@ -15,6 +15,7 @@
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_REMOVE_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_VISITORS_REMOVE_HPP
#include <boost/geometry/index/detail/rtree/visitors/destroy.hpp>
#include <boost/geometry/index/detail/rtree/visitors/is_leaf.hpp>
#include <boost/geometry/algorithms/detail/covered_by/interface.hpp>
@@ -283,7 +284,7 @@ private:
// destroy current and remaining nodes
for ( ; it != m_underflowed_nodes.rend() ; ++it )
{
subtree_destroyer dummy(it->second, m_allocators);
rtree::visitors::destroy<MembersHolder>::apply(it->second, m_allocators);
}
//m_underflowed_nodes.clear();
@@ -315,8 +316,7 @@ private:
BOOST_CATCH(...)
{
++it;
rtree::destroy_elements<MembersHolder>
::apply(it, elements.end(), m_allocators);
rtree::destroy_elements<MembersHolder>::apply(it, elements.end(), m_allocators);
elements.clear();
BOOST_RETHROW // RETHROW
}

View File

@@ -1639,8 +1639,7 @@ private:
if ( t.m_members.root )
{
detail::rtree::visitors::destroy<members_holder>
del_v(t.m_members.root, t.m_members.allocators());
detail::rtree::apply_visitor(del_v, *t.m_members.root);
::apply(t.m_members.root, t.m_members.allocators());
t.m_members.root = 0;
}
@@ -1677,8 +1676,8 @@ private:
if ( dst.m_members.root )
{
detail::rtree::visitors::destroy<members_holder>
del_v(dst.m_members.root, dst.m_members.allocators());
detail::rtree::apply_visitor(del_v, *dst.m_members.root);
::apply(dst.m_members.root, dst.m_members.allocators());
dst.m_members.root = 0;
}