1 // Boost.Geometry Index
3 // R-tree nodes elements numbers validating visitor implementation
5 // Copyright (c) 2011-2015 Adam Wulkiewicz, Lodz, Poland.
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_COUNTS_OK_HPP
12 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_COUNTS_OK_HPP
14 #include <boost/geometry/index/detail/rtree/node/node.hpp>
16 namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace utilities {
20 template <typename Value, typename Options, typename Box, typename Allocators>
22 : public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
24 typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
25 typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
26 typedef typename Options::parameters_type parameters_type;
29 inline are_counts_ok(parameters_type const& parameters)
30 : result(true), m_current_level(0), m_parameters(parameters)
33 inline void operator()(internal_node const& n)
35 typedef typename rtree::elements_type<internal_node>::type elements_type;
36 elements_type const& elements = rtree::elements(n);
38 // root internal node shouldn't contain 0 elements
40 || !check_count(elements) )
46 size_t current_level_backup = m_current_level;
49 for ( typename elements_type::const_iterator it = elements.begin();
50 it != elements.end() && result == true ;
53 rtree::apply_visitor(*this, *it->second);
56 m_current_level = current_level_backup;
59 inline void operator()(leaf const& n)
61 typedef typename rtree::elements_type<leaf>::type elements_type;
62 elements_type const& elements = rtree::elements(n);
64 // empty leaf in non-root node
65 if ( ( m_current_level > 0 && elements.empty() )
66 || !check_count(elements) )
75 template <typename Elements>
76 bool check_count(Elements const& elements)
78 // root may contain count < min but should never contain count > max
79 return elements.size() <= m_parameters.get_max_elements()
80 && ( elements.size() >= m_parameters.get_min_elements()
81 || m_current_level == 0 );
84 size_t m_current_level;
85 parameters_type const& m_parameters;
88 } // namespace visitors
90 template <typename Rtree> inline
91 bool are_counts_ok(Rtree const& tree)
93 typedef utilities::view<Rtree> RTV;
96 visitors::are_counts_ok<
97 typename RTV::value_type,
98 typename RTV::options_type,
99 typename RTV::box_type,
100 typename RTV::allocators_type
101 > v(tree.parameters());
103 rtv.apply_visitor(v);
108 }}}}}} // namespace boost::geometry::index::detail::rtree::utilities
110 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_ARE_COUNTS_OK_HPP