diff --git a/include/boost/geometry/index/detail/rtree/visitors/is_leaf.hpp b/include/boost/geometry/index/detail/rtree/visitors/is_leaf.hpp index 6d21afd99..dd2159c71 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/is_leaf.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/is_leaf.hpp @@ -2,7 +2,7 @@ // // R-tree leaf node checking visitor implementation // -// Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland. +// Copyright (c) 2011-2015 Adam Wulkiewicz, Lodz, Poland. // // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -21,9 +21,13 @@ struct is_leaf : public rtree::visitor::type internal_node; typedef typename rtree::leaf::type leaf; + is_leaf() + : result(false) + {} + inline void operator()(internal_node const&) { - result = false; + // result = false; } inline void operator()(leaf const&) diff --git a/include/boost/geometry/index/detail/rtree/visitors/remove.hpp b/include/boost/geometry/index/detail/rtree/visitors/remove.hpp index c96b0952b..a55f5d3fe 100644 --- a/include/boost/geometry/index/detail/rtree/visitors/remove.hpp +++ b/include/boost/geometry/index/detail/rtree/visitors/remove.hpp @@ -2,7 +2,7 @@ // // R-tree removing visitor implementation // -// Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland. +// Copyright (c) 2011-2015 Adam Wulkiewicz, Lodz, Poland. // // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -222,6 +222,13 @@ private: return elements.size() < m_parameters.get_min_elements(); } + static inline bool is_leaf(node const& n) + { + visitors::is_leaf ilv; + rtree::apply_visitor(ilv, n); + return ilv.result; + } + void reinsert_removed_nodes_elements() { typename UnderflowNodes::reverse_iterator it = m_underflowed_nodes.rbegin(); @@ -232,9 +239,11 @@ private: // begin with levels closer to the root for ( ; it != m_underflowed_nodes.rend() ; ++it ) { - is_leaf ilv; - rtree::apply_visitor(ilv, *it->second); - if ( ilv.result ) + // it->first is an index of a level of a node, not children + // counted from the leafs level + bool const node_is_leaf = it->first == 1; + BOOST_GEOMETRY_INDEX_ASSERT(node_is_leaf == is_leaf(*it->second), "unexpected condition"); + if ( node_is_leaf ) { reinsert_node_elements(rtree::get(*it->second), it->first); // MAY THROW (V, E: alloc, copy, N: alloc)