Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R-tree improvements. #639

Merged
merged 5 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -322,28 +322,31 @@ inline void pick_seeds(Elements const& elements,

// from void split_node(node_pointer const& n, node_pointer& n1, node_pointer& n2) const

template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
struct redistribute_elements<Value, Options, Translator, Box, Allocators, linear_tag>
template <typename MembersHolder>
struct redistribute_elements<MembersHolder, linear_tag>
{
typedef typename Options::parameters_type parameters_type;
typedef typename MembersHolder::box_type box_type;
typedef typename MembersHolder::parameters_type parameters_type;
typedef typename MembersHolder::translator_type translator_type;
typedef typename MembersHolder::allocators_type allocators_type;

typedef typename rtree::node<Value, parameters_type, Box, Allocators, typename Options::node_tag>::type node;
typedef typename rtree::internal_node<Value, parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
typedef typename rtree::leaf<Value, parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
typedef typename MembersHolder::node node;
typedef typename MembersHolder::internal_node internal_node;
typedef typename MembersHolder::leaf leaf;

template <typename Node>
static inline void apply(Node & n,
Node & second_node,
Box & box1,
Box & box2,
box_type & box1,
box_type & box2,
parameters_type const& parameters,
Translator const& translator,
Allocators & allocators)
translator_type const& translator,
allocators_type & allocators)
{
typedef typename rtree::elements_type<Node>::type elements_type;
typedef typename elements_type::value_type element_type;
typedef typename rtree::element_indexable_type<element_type, Translator>::type indexable_type;
typedef typename index::detail::default_content_result<Box>::type content_type;
typedef typename rtree::element_indexable_type<element_type, translator_type>::type indexable_type;
typedef typename index::detail::default_content_result<box_type>::type content_type;

typename index::detail::strategy_type<parameters_type>::type const&
strategy = index::detail::get_strategy(parameters);
Expand Down Expand Up @@ -414,8 +417,8 @@ struct redistribute_elements<Value, Options, Translator, Box, Allocators, linear
else
{
// calculate enlarged boxes and areas
Box enlarged_box1(box1);
Box enlarged_box2(box2);
box_type enlarged_box1(box1);
box_type enlarged_box2(box2);
index::detail::expand(enlarged_box1, indexable, strategy);
index::detail::expand(enlarged_box2, indexable, strategy);
content_type enlarged_content1 = index::detail::content(enlarged_box1);
Expand Down Expand Up @@ -452,7 +455,7 @@ struct redistribute_elements<Value, Options, Translator, Box, Allocators, linear
elements1.clear();
elements2.clear();

rtree::destroy_elements<Value, Options, Translator, Box, Allocators>::apply(elements_copy, allocators);
rtree::destroy_elements<MembersHolder>::apply(elements_copy, allocators);
//elements_copy.clear();

BOOST_RETHROW // RETHROW, BASIC
Expand Down
67 changes: 37 additions & 30 deletions include/boost/geometry/index/detail/rtree/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -102,41 +101,47 @@ inline Box values_box(FwdIter first, FwdIter last, Translator const& tr,
}

// destroys subtree if the element is internal node's element
template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
template <typename MembersHolder>
struct destroy_element
{
typedef typename Options::parameters_type parameters_type;

typedef typename rtree::internal_node<Value, parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
typedef typename rtree::leaf<Value, parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
typedef typename MembersHolder::parameters_type parameters_type;
typedef typename MembersHolder::allocators_type allocators_type;

typedef rtree::subtree_destroyer<Value, Options, Translator, Box, Allocators> subtree_destroyer;
typedef typename MembersHolder::internal_node internal_node;
typedef typename MembersHolder::leaf leaf;

inline static void apply(typename internal_node::elements_type::value_type & element, Allocators & allocators)
inline static void apply(typename internal_node::elements_type::value_type & element,
allocators_type & allocators)
{
subtree_destroyer dummy(element.second, allocators);
detail::rtree::visitors::destroy<MembersHolder>::apply(element.second, allocators);

element.second = 0;
}

inline static void apply(typename leaf::elements_type::value_type &, Allocators &) {}
inline static void apply(typename leaf::elements_type::value_type &,
allocators_type &)
{}
};

// destroys stored subtrees if internal node's elements are passed
template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
template <typename MembersHolder>
struct destroy_elements
{
typedef typename MembersHolder::value_type value_type;
typedef typename MembersHolder::allocators_type allocators_type;

template <typename Range>
inline static void apply(Range & elements, Allocators & allocators)
inline static void apply(Range & elements, allocators_type & allocators)
{
apply(boost::begin(elements), boost::end(elements), allocators);
}

template <typename It>
inline static void apply(It first, It last, Allocators & allocators)
inline static void apply(It first, It last, allocators_type & allocators)
{
typedef boost::mpl::bool_<
boost::is_same<
Value, typename std::iterator_traits<It>::value_type
value_type, typename std::iterator_traits<It>::value_type
>::value
> is_range_of_values;

Expand All @@ -145,37 +150,38 @@ struct destroy_elements

private:
template <typename It>
inline static void apply_dispatch(It first, It last, Allocators & allocators,
inline static void apply_dispatch(It first, It last, allocators_type & allocators,
boost::mpl::bool_<false> const& /*is_range_of_values*/)
{
typedef rtree::subtree_destroyer<Value, Options, Translator, Box, Allocators> subtree_destroyer;

for ( ; first != last ; ++first )
{
subtree_destroyer dummy(first->second, allocators);
detail::rtree::visitors::destroy<MembersHolder>::apply(first->second, allocators);

first->second = 0;
}
}

template <typename It>
inline static void apply_dispatch(It /*first*/, It /*last*/, Allocators & /*allocators*/,
inline static void apply_dispatch(It /*first*/, It /*last*/, allocators_type & /*allocators*/,
boost::mpl::bool_<true> const& /*is_range_of_values*/)
{}
};

// clears node, deletes all subtrees stored in node
template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
/*
template <typename MembersHolder>
struct clear_node
{
typedef typename Options::parameters_type parameters_type;
typedef typename MembersHolder::parameters_type parameters_type;
typedef typename MembersHolder::allocators_type allocators_type;

typedef typename rtree::node<Value, parameters_type, Box, Allocators, typename Options::node_tag>::type node;
typedef typename rtree::internal_node<Value, parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
typedef typename rtree::leaf<Value, parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
typedef typename MembersHolder::node node;
typedef typename MembersHolder::internal_node internal_node;
typedef typename MembersHolder::leaf leaf;

inline static void apply(node & node, Allocators & allocators)
inline static void apply(node & node, allocators_type & allocators)
{
rtree::visitors::is_leaf<Value, Options, Box, Allocators> ilv;
rtree::visitors::is_leaf<MembersHolder> ilv;
rtree::apply_visitor(ilv, node);
if ( ilv.result )
{
Expand All @@ -187,17 +193,18 @@ struct clear_node
}
}

inline static void apply(internal_node & internal_node, Allocators & allocators)
inline static void apply(internal_node & internal_node, allocators_type & allocators)
{
destroy_elements<Value, Options, Translator, Box, Allocators>::apply(rtree::elements(internal_node), allocators);
destroy_elements<MembersHolder>::apply(rtree::elements(internal_node), allocators);
rtree::elements(internal_node).clear();
}

inline static void apply(leaf & leaf, Allocators &)
inline static void apply(leaf & leaf, allocators_type &)
{
rtree::elements(leaf).clear();
}
};
*/

template <typename Container, typename Iterator>
void move_from_back(Container & container, Iterator it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
//
// Copyright (c) 2011-2015 Adam Wulkiewicz, Lodz, Poland.
//
// This file was modified by Oracle on 2019.
// Modifications copyright (c) 2019 Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
//
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
Expand All @@ -17,17 +21,19 @@ namespace boost { namespace geometry { namespace index {

namespace detail { namespace rtree {

template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
template <typename MembersHolder>
class subtree_destroyer
{
typedef typename rtree::node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type node;
typedef typename Allocators::node_pointer pointer;
typedef typename MembersHolder::node node;

typedef typename MembersHolder::allocators_type allocators_type;
typedef typename MembersHolder::node_pointer pointer;

subtree_destroyer(subtree_destroyer const&);
subtree_destroyer & operator=(subtree_destroyer const&);

public:
subtree_destroyer(pointer ptr, Allocators & allocators)
subtree_destroyer(pointer ptr, allocators_type & allocators)
: m_ptr(ptr)
, m_allocators(allocators)
{}
Expand All @@ -41,8 +47,7 @@ class subtree_destroyer
{
if ( m_ptr && m_ptr != ptr )
{
detail::rtree::visitors::destroy<Value, Options, Translator, Box, Allocators> 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;
}
Expand All @@ -69,7 +74,7 @@ class subtree_destroyer

private:
pointer m_ptr;
Allocators & m_allocators;
allocators_type & m_allocators;
};

}} // namespace detail::rtree
Expand Down
Loading