1 // Boost.Geometry Index
3 // R-tree visitor collecting basic statistics
5 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
6 // Copyright (c) 2013 Mateusz Loskot, London, UK.
8 // Use, modification and distribution is subject to the Boost Software License,
9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
12 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_STATISTICS_HPP
13 #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_STATISTICS_HPP
16 #include <boost/tuple/tuple.hpp>
18 namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace utilities {
22 template <typename Value, typename Options, typename Box, typename Allocators>
23 struct statistics : public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, true>::type
25 typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
26 typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;
30 , levels(1) // count root
38 inline void operator()(internal_node const& n)
40 typedef typename rtree::elements_type<internal_node>::type elements_type;
41 elements_type const& elements = rtree::elements(n);
43 ++nodes; // count node
45 size_t const level_backup = level;
48 levels += level++ > levels ? 1 : 0; // count level (root already counted)
50 for (typename elements_type::const_iterator it = elements.begin();
51 it != elements.end(); ++it)
53 rtree::apply_visitor(*this, *it->second);
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 ++leaves; // count leaves
66 std::size_t const v = elements.size();
67 // count values spread per node and total
68 values_min = (std::min)(values_min == 0 ? v : values_min, v);
69 values_max = (std::max)(values_max, v);
78 std::size_t values_min;
79 std::size_t values_max;
82 } // namespace visitors
84 template <typename Rtree> inline
85 boost::tuple<std::size_t, std::size_t, std::size_t, std::size_t, std::size_t, std::size_t>
86 statistics(Rtree const& tree)
88 typedef utilities::view<Rtree> RTV;
92 typename RTV::value_type,
93 typename RTV::options_type,
94 typename RTV::box_type,
95 typename RTV::allocators_type
98 rtv.apply_visitor(stats_v);
100 return boost::make_tuple(stats_v.levels, stats_v.nodes, stats_v.leaves, stats_v.values, stats_v.values_min, stats_v.values_max);
103 }}}}}} // namespace boost::geometry::index::detail::rtree::utilities
105 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_UTILITIES_STATISTICS_HPP