35 #ifndef OPENMS_DATASTRUCTURES_KDTREE_H
36 #define OPENMS_DATASTRUCTURES_KDTREE_H
38 #ifdef KDTREE_DEFINE_OSTREAM_OPERATORS
77 template <
typename _Val>
85 _Node(_Val
const& __VALUE = _Val(),
91 #ifdef KDTREE_DEFINE_OSTREAM_OPERATORS
93 template <
typename Char,
typename Traits>
95 std::basic_ostream<Char, Traits>&
96 operator<<(
typename std::basic_ostream<Char, Traits>& out,
101 out <<
"; left: " << node.
_M_left;
102 out <<
"; right: " << node.
_M_right;
106 template <
typename Char,
typename Traits>
108 std::basic_ostream<Char, Traits>&
109 operator<<(
typename std::basic_ostream<Char, Traits>& out,
110 _Node<_Val>
const& node)
113 out <<
' ' << node._M_value;
114 out <<
"; parent: " << node._M_parent;
115 out <<
"; left: " << node._M_left;
116 out <<
"; right: " << node._M_right;
123 template <
typename _Val,
typename _Acc,
typename _Cmp>
148 template <
typename _ValA,
typename _ValB,
typename _Cmp,
153 const _Cmp& __cmp,
const _Acc& __acc,
154 const _ValA& __a,
const _ValB& __b)
156 return __cmp(__acc(__a, __dim), __acc(__b, __dim));
164 template <
typename _ValA,
typename _ValB,
typename _Dist,
167 typename _Dist::distance_type
169 const _Dist& __dist,
const _Acc& __acc,
170 const _ValA& __a,
const _ValB& __b)
172 return __dist(__acc(__a, __dim), __acc(__b, __dim));
181 template <
typename _ValA,
typename _ValB,
typename _Dist,
184 typename _Dist::distance_type
186 const _Dist& __dist,
const _Acc& __acc,
187 const _ValA& __a,
const _ValB& __b)
189 typename _Dist::distance_type d = 0;
190 for (
size_t i=0; i<__dim; ++i)
191 d += __dist(__acc(__a, i), __acc(__b, i));
200 template <
typename _Val,
typename _Cmp,
typename _Acc,
typename NodeType>
204 const _Cmp& __cmp,
const _Acc& __acc,
205 const _Val& __val,
const NodeType* __node)
208 return static_cast<const NodeType *
>(__node->_M_left);
209 return static_cast<const NodeType *
>(__node->_M_right);
220 template <
class SearchVal,
221 typename NodeType,
typename _Cmp,
222 typename _Acc,
typename _Dist,
225 std::pair<
const NodeType*,
226 std::pair<size_t, typename _Dist::distance_type> >
228 const NodeType* __node,
const _Node_base* __end,
229 const NodeType* __best,
typename _Dist::distance_type __max,
230 const _Cmp& __cmp,
const _Acc& __acc,
const _Dist& __dist,
233 typedef const NodeType* NodePtr;
234 NodePtr pcur = __node;
235 NodePtr cur =
_S_node_descend(__dim % __k, __cmp, __acc, __val, __node);
236 size_t cur_dim = __dim+1;
240 if (__p(cur->_M_value))
242 typename _Dist::distance_type d = 0;
243 for (
size_t i=0; i != __k; ++i)
267 NodePtr pprobe = probe;
270 size_t probe_dim = cur_dim;
271 if (
_S_node_compare(probe_dim % __k, __cmp, __acc, __val, probe->_M_value))
272 near_node =
static_cast<NodePtr
>(probe->_M_right);
274 near_node =
static_cast<NodePtr
>(probe->_M_left);
277 && (std::sqrt(
_S_node_distance(probe_dim % __k, __dist, __acc, __val, probe->_M_value)) <= __max))
286 if (
_S_node_compare(probe_dim % __k, __cmp, __acc, __val, probe->_M_value))
288 near_node =
static_cast<NodePtr
>(probe->_M_left);
289 far_node =
static_cast<NodePtr
>(probe->_M_right);
293 near_node =
static_cast<NodePtr
>(probe->_M_right);
294 far_node =
static_cast<NodePtr
>(probe->_M_left);
296 if (pprobe == probe->_M_parent)
298 if (__p(probe->_M_value))
300 typename _Dist::distance_type d = 0;
301 for (
size_t i=0; i < __k; ++i)
319 std::sqrt(
_S_node_distance(probe_dim % __k, __dist, __acc, __val, probe->_M_value)) <= __max)
326 probe =
static_cast<NodePtr
>(probe->_M_parent);
332 if (pprobe == near_node && far_node
334 && std::sqrt(
_S_node_distance(probe_dim % __k, __dist, __acc, __val, probe->_M_value)) <= __max)
343 probe =
static_cast<NodePtr
>(probe->_M_parent);
349 cur =
static_cast<NodePtr
>(cur->_M_parent);
356 if (pcur == cur->_M_left)
357 near_node =
static_cast<NodePtr
>(cur->_M_right);
359 near_node =
static_cast<NodePtr
>(cur->_M_left);
362 && (std::sqrt(
_S_node_distance(cur_dim % __k, __dist, __acc, __val, cur->_M_value)) <= __max))
369 return std::pair<NodePtr,
370 std::pair<size_t, typename _Dist::distance_type> >
371 (__best, std::pair<size_t, typename _Dist::distance_type>
399 #ifndef INCLUDE_KDTREE_ACCESSOR_HPP
400 #define INCLUDE_KDTREE_ACCESSOR_HPP
406 template <
typename _Val>
418 template <
typename _Tp>
424 template <
typename _Tp,
typename _Dist>
437 template <
typename _Tp,
typename _Dist>
487 #ifndef INCLUDE_KDTREE_ALLOCATOR_HPP
488 #define INCLUDE_KDTREE_ALLOCATOR_HPP
495 template <
typename _Tp,
typename _Alloc>
549 new (__p)
_Node_(__V, __PARENT, __LEFT, __RIGHT);
581 #ifndef INCLUDE_KDTREE_ITERATOR_HPP
582 #define INCLUDE_KDTREE_ITERATOR_HPP
588 template <
typename _Val,
typename _Ref,
typename _Ptr>
591 template<
typename _Val,
typename _Ref,
typename _Ptr>
593 operator==(_Iterator<_Val, _Ref, _Ptr>
const&,
594 _Iterator<_Val, _Ref, _Ptr>
const&);
596 template<
typename _Val>
598 operator==(_Iterator<_Val, const _Val&, const _Val*>
const&,
599 _Iterator<_Val, _Val&, _Val*>
const&);
601 template<
typename _Val>
603 operator==(_Iterator<_Val, _Val&, _Val*>
const&,
604 _Iterator<_Val, const _Val&, const _Val*>
const&);
606 template<
typename _Val,
typename _Ref,
typename _Ptr>
608 operator!=(_Iterator<_Val, _Ref, _Ptr>
const&,
609 _Iterator<_Val, _Ref, _Ptr>
const&);
611 template<
typename _Val>
613 operator!=(_Iterator<_Val, const _Val&, const _Val*>
const&,
614 _Iterator<_Val, _Val&, _Val*>
const&);
616 template<
typename _Val>
618 operator!=(_Iterator<_Val, _Val&, _Val*>
const&,
619 _Iterator<_Val, const _Val&, const _Val*>
const&);
643 while (__p &&
_M_node == __p->_M_right)
664 while (x->_M_right) x = x->_M_right;
670 while (__p &&
_M_node == __p->_M_left)
681 template <
size_t const __K,
typename _Val,
typename _Acc,
682 typename _Dist,
typename _Cmp,
typename _Alloc>
686 template <
typename _Val,
typename _Ref,
typename _Ptr>
779 template<
typename _Val,
typename _Ref,
typename _Ptr>
785 template<
typename _Val>
791 template<
typename _Val>
797 template<
typename _Val,
typename _Ref,
typename _Ptr>
803 template<
typename _Val>
809 template<
typename _Val>
837 #ifndef INCLUDE_KDTREE_REGION_HPP
838 #define INCLUDE_KDTREE_REGION_HPP
845 template <
size_t const __K,
typename _Val,
typename _SubVal,
846 typename _Acc,
typename _Cmp>
857 _Region(_Acc
const& __acc=_Acc(),
const _Cmp& __cmp=_Cmp())
860 template <
typename Val>
862 _Acc
const& __acc=_Acc(),
const _Cmp& __cmp=_Cmp())
865 for (
size_t __i = 0; __i != __K; ++__i)
871 template <
typename Val>
873 _Acc
const& __acc=_Acc(),
const _Cmp& __cmp=_Cmp())
876 for (
size_t __i = 0; __i != __K; ++__i)
886 for (
size_t __i = 0; __i != __K; ++__i)
904 for (
size_t __i = 0; __i != __K; ++__i)
916 for (
size_t __i = 0; __i != __K; ++__i)
1005 #ifndef INCLUDE_KDTREE_KDTREE_HPP
1006 #define INCLUDE_KDTREE_KDTREE_HPP
1015 #define KDTREE_VERSION 701
1020 #define KDTREE_LIB_VERSION "0_7_1"
1025 #ifdef KDTREE_CHECK_PERFORMANCE_COUNTERS
1028 #include <algorithm>
1029 #include <functional>
1031 #ifdef KDTREE_DEFINE_OSTREAM_OPERATORS
1043 #ifdef KDTREE_CHECK_PERFORMANCE
1044 unsigned long long num_dist_calcs = 0;
1047 template <
size_t const __K,
typename _Val,
1048 typename _Acc = _Bracket_accessor<_Val>,
1049 typename _Dist = squared_difference<
typename _Acc::result_type,
1050 typename _Acc::result_type>,
1051 typename _Cmp = std::less<typename _Acc::result_type>,
1052 typename _Alloc = std::allocator<_Node<_Val> > >
1078 KDTree(_Acc
const& __acc = _Acc(), _Dist
const& __dist = _Dist(),
1080 :
_Base(__a), _M_header(),
1081 _M_count(0), _M_acc(__acc), _M_cmp(__cmp), _M_dist(__dist)
1083 _M_empty_initialise();
1087 :
_Base(__x.get_allocator()), _M_header(), _M_count(0),
1088 _M_acc(__x._M_acc), _M_cmp(__x._M_cmp), _M_dist(__x._M_dist)
1090 _M_empty_initialise();
1099 std::vector<value_type> temp;
1100 temp.reserve(__x.size());
1101 std::copy(__x.begin(),__x.end(),std::back_inserter(temp));
1102 _M_optimise(temp.begin(), temp.end(), 0);
1105 template<
typename _InputIterator>
1106 KDTree(_InputIterator __first, _InputIterator __last,
1107 _Acc
const& acc = _Acc(), _Dist
const& __dist = _Dist(),
1109 :
_Base(__a), _M_header(), _M_count(0),
1110 _M_acc(acc), _M_cmp(__cmp), _M_dist(__dist)
1112 _M_empty_initialise();
1121 std::vector<value_type> temp;
1122 temp.reserve(std::distance(__first,__last));
1123 std::copy(__first,__last,std::back_inserter(temp));
1124 _M_optimise(temp.begin(), temp.end(), 0);
1147 _M_optimise(writable_vector.begin(), writable_vector.end(), 0);
1158 _M_dist = __x._M_dist;
1159 _M_cmp = __x._M_cmp;
1168 std::vector<value_type> temp;
1169 temp.reserve(__x.size());
1170 std::copy(__x.begin(),__x.end(),std::back_inserter(temp));
1171 efficient_replace_and_optimise(temp);
1184 return _Base::get_allocator();
1202 return this->size() == 0;
1208 _M_erase_subtree(_M_get_root());
1209 _M_set_leftmost(&_M_header);
1210 _M_set_rightmost(&_M_header);
1211 _M_set_root(
nullptr);
1265 return this->insert(__V);
1273 _Link_type __n = _M_new_node(__V, &_M_header);
1276 _M_set_leftmost(__n);
1277 _M_set_rightmost(__n);
1280 return _M_insert(_M_get_root(), __V, 0);
1283 template <
class _InputIterator>
1284 void insert(_InputIterator __first, _InputIterator __last) {
1285 for (; __first != __last; ++__first)
1286 this->insert(*__first);
1292 for (; __n > 0; --__n)
1293 this->insert(__pos, __x);
1296 template<
typename _InputIterator>
1299 for (; __first != __last; ++__first)
1300 this->insert(__pos, *__first);
1321 this->erase(this->find_exact(__V));
1328 assert(__IT != this->end());
1332 while ((n = _S_parent(n)) != &_M_header)
1334 _M_erase(
const_cast<_Link_type>(target), level );
1335 _M_delete_node(
const_cast<_Link_type>(target) );
1359 template <
class SearchVal>
1363 if (!_M_get_root())
return this->end();
1364 return _M_find(_M_get_root(), __V, 0);
1381 template <
class SearchVal>
1385 if (!_M_get_root())
return this->end();
1386 return _M_find_exact(_M_get_root(), __V, 0);
1393 if (!_M_get_root())
return 0;
1394 _Region_ __region(__V, __R, _M_acc, _M_cmp);
1395 return this->count_within_range(__region);
1401 if (!_M_get_root())
return 0;
1404 return _M_count_within_range(_M_get_root(),
1405 __REGION, __bounds, 0);
1409 template <
typename SearchVal,
class Visitor>
1413 if (!_M_get_root())
return visitor;
1415 return this->visit_within_range(region, visitor);
1418 template <
class Visitor>
1425 return _M_visit_within_range(visitor, _M_get_root(), REGION, bounds, 0);
1440 template <
typename SearchVal,
typename _OutputIterator>
1443 _OutputIterator out)
const
1445 if (!_M_get_root())
return out;
1446 _Region_ region(val, range, _M_acc, _M_cmp);
1447 return this->find_within_range(region, out);
1450 template <
typename _OutputIterator>
1453 _OutputIterator out)
const
1458 out = _M_find_within_range(out, _M_get_root(),
1464 template <
class SearchVal>
1465 std::pair<const_iterator, distance_type>
1470 std::pair<const _Node<_Val>*,
1471 std::pair<size_type, typename _Acc::result_type> >
1473 _M_get_root(), &_M_header, _M_get_root(),
1475 (__K, _M_dist, _M_acc, _M_get_root()->_M_value, __val)),
1476 _M_cmp, _M_acc, _M_dist,
1478 return std::pair<const_iterator, distance_type>
1479 (best.first, best.second.second);
1481 return std::pair<const_iterator, distance_type>(end(), 0);
1484 template <
class SearchVal>
1485 std::pair<const_iterator, distance_type>
1490 bool root_is_candidate =
false;
1494 (__K, _M_dist, _M_acc, _M_get_root()->_M_value, __val));
1495 if (root_dist <= __max)
1497 root_is_candidate =
true;
1501 std::pair<const _Node<_Val>*,
1502 std::pair<size_type, typename _Acc::result_type> >
1504 node, __max, _M_cmp, _M_acc, _M_dist,
1507 if (root_is_candidate || best.first != _M_get_root())
1508 return std::pair<const_iterator, distance_type>
1509 (best.first, best.second.second);
1511 return std::pair<const_iterator, distance_type>(end(), __max);
1514 template <
class SearchVal,
class _Predicate>
1515 std::pair<const_iterator, distance_type>
1517 _Predicate __p)
const
1521 bool root_is_candidate =
false;
1523 if (__p(_M_get_root()->_M_value))
1527 (__K, _M_dist, _M_acc, _M_get_root()->_M_value, __val));
1528 if (root_dist <= __max)
1530 root_is_candidate =
true;
1535 std::pair<const _Node<_Val>*,
1536 std::pair<size_type, typename _Acc::result_type> >
1538 node, __max, _M_cmp, _M_acc, _M_dist, __p);
1540 if (root_is_candidate || best.first != _M_get_root())
1541 return std::pair<const_iterator, distance_type>
1542 (best.first, best.second.second);
1544 return std::pair<const_iterator, distance_type>(end(), __max);
1550 std::vector<value_type> __v(this->begin(),this->end());
1552 _M_optimise(__v.begin(), __v.end(), 0);
1563 _M_check_node(_M_get_root(),0);
1580 _M_check_children(_S_left(child),parent,level,to_the_left);
1581 _M_check_children(_S_right(child),parent,level,to_the_left);
1591 _M_check_children( _S_left(node), node, level,
true );
1593 _M_check_children( _S_right(node), node, level,
false );
1595 _M_check_node( _S_left(node), level+1 );
1596 _M_check_node( _S_right(node), level+1 );
1602 _M_set_leftmost(&_M_header);
1603 _M_set_rightmost(&_M_header);
1604 _M_header._M_parent =
nullptr;
1605 _M_set_root(
nullptr);
1611 _S_set_left(__N, _M_new_node(__V)); ++_M_count;
1612 _S_set_parent( _S_left(__N), __N );
1613 if (__N == _M_get_leftmost())
1614 _M_set_leftmost( _S_left(__N) );
1621 _S_set_right(__N, _M_new_node(__V)); ++_M_count;
1622 _S_set_parent( _S_right(__N), __N );
1623 if (__N == _M_get_rightmost())
1624 _M_set_rightmost( _S_right(__N) );
1635 return _M_insert_left(__N, __V);
1636 return _M_insert(_S_left(__N), __V, __L+1);
1640 if (!_S_right(__N) || __N == _M_get_rightmost())
1641 return _M_insert_right(__N, __V);
1642 return _M_insert(_S_right(__N), __V, __L+1);
1650 _Link_type step_dad = _M_get_erase_replacement(dead_dad, level);
1653 if (dead_dad == _M_get_root())
1654 _M_set_root(step_dad);
1655 else if (_S_left(_S_parent(dead_dad)) == dead_dad)
1656 _S_set_left(_S_parent(dead_dad), step_dad);
1658 _S_set_right(_S_parent(dead_dad), step_dad);
1663 if (dead_dad == _M_get_leftmost())
1664 _M_set_leftmost( (step_dad ? step_dad : _S_parent(dead_dad)) );
1665 if (dead_dad == _M_get_rightmost())
1666 _M_set_rightmost( (step_dad ? step_dad : _S_parent(dead_dad)) );
1671 _S_set_parent(step_dad, _S_parent(dead_dad));
1674 if (_S_left(dead_dad))
1675 _S_set_parent(_S_left(dead_dad), step_dad);
1676 if (_S_right(dead_dad))
1677 _S_set_parent(_S_right(dead_dad), step_dad);
1680 _S_set_left(step_dad, _S_left(dead_dad));
1681 _S_set_right(step_dad, _S_right(dead_dad));
1693 if (_S_is_leaf(node))
1696 std::pair<_Link_type,size_type> candidate;
1699 candidate = _M_get_j_min( std::pair<_Link_type,size_type>(_S_right(node),level), level+1);
1701 else if ((!_S_right(node)))
1702 candidate = _M_get_j_max( std::pair<_Link_type,size_type>(_S_left(node),level), level+1);
1715 if (compare(_S_right(node)->_M_value, _S_left(node)->_M_value))
1717 candidate = _M_get_j_min(std::pair<_Link_type,size_type>(_S_right(node),level), level+1);
1719 candidate = _M_get_j_max( std::pair<_Link_type,size_type>(_S_left(node),level), level+1);
1725 _Link_type parent = _S_parent(candidate.first);
1726 if (_S_left(parent) == candidate.first)
1727 _S_set_left(parent, _M_erase(candidate.first, candidate.second));
1729 _S_set_right(parent, _M_erase(candidate.first, candidate.second));
1731 return candidate.first;
1737 std::pair<_Link_type,size_type>
1740 typedef std::pair<_Link_type,size_type> Result;
1741 if (_S_is_leaf(node.first))
1742 return Result(node.first,level);
1745 Result candidate = node;
1746 if (_S_left(node.first))
1748 Result left = _M_get_j_min(Result(_S_left(node.first), node.second), level+1);
1749 if (compare(left.first->_M_value, candidate.first->_M_value))
1752 if (_S_right(node.first))
1754 Result right = _M_get_j_min( Result(_S_right(node.first),node.second), level+1);
1755 if (compare(right.first->_M_value, candidate.first->_M_value))
1758 if (candidate.first == node.first)
1759 return Result(candidate.first,level);
1767 std::pair<_Link_type,size_type>
1770 typedef std::pair<_Link_type,size_type> Result;
1772 if (_S_is_leaf(node.first))
1773 return Result(node.first,level);
1776 Result candidate = node;
1777 if (_S_left(node.first))
1779 Result left = _M_get_j_max( Result(_S_left(node.first),node.second), level+1);
1780 if (compare(candidate.first->_M_value, left.first->_M_value))
1783 if (_S_right(node.first))
1785 Result right = _M_get_j_max(Result(_S_right(node.first),node.second), level+1);
1786 if (compare(candidate.first->_M_value, right.first->_M_value))
1790 if (candidate.first == node.first)
1791 return Result(candidate.first,level);
1802 _M_erase_subtree(_S_right(__n));
1804 _M_delete_node(__n);
1819 if (!compare(node->
_M_value,value))
1822 if (_M_matches_node(node, value, level))
1825 found = _M_find(_S_left(node), value, level+1);
1827 if ( _S_right(node) && found == this->end() && !compare(value,node->
_M_value))
1828 found = _M_find(_S_right(node), value, level+1);
1842 if (!compare(node->
_M_value,value))
1848 found = _M_find_exact(_S_left(node), value, level+1);
1852 if ( _S_right(node) && found == this->end() && !compare(value,node->
_M_value))
1853 found = _M_find_exact(_S_right(node), value, level+1);
1870 while ((__i = (__i + 1) % __K) != __L % __K)
1871 if (!_M_matches_node_in_d(__N, __V, __i))
return false;
1879 return _M_matches_node_in_d(__N, __V, __L)
1880 && _M_matches_node_in_other_ds(__N, __V, __L);
1889 if (__REGION.
encloses(_S_value(__N)))
1898 count += _M_count_within_range(_S_left(__N),
1899 __REGION, __bounds, __L+1);
1906 count += _M_count_within_range(_S_right(__N),
1907 __REGION, __bounds, __L+1);
1914 template <
class Visitor>
1923 visitor(_S_value(N));
1930 visitor = _M_visit_within_range(visitor, _S_left(N),
1931 REGION, bounds, L+1);
1938 visitor = _M_visit_within_range(visitor, _S_right(N),
1939 REGION, bounds, L+1);
1947 template <
typename _OutputIterator>
1954 if (__REGION.
encloses(_S_value(__N)))
1956 *out++ = _S_value(__N);
1963 out = _M_find_within_range(out, _S_left(__N),
1964 __REGION, __bounds, __L+1);
1971 out = _M_find_within_range(out, _S_right(__N),
1972 __REGION, __bounds, __L+1);
1979 template <
typename _Iter>
1984 if (__A == __B)
return;
1986 _Iter __m = __A + (__B - __A) / 2;
1987 std::nth_element(__A, __m, __B, compare);
1989 if (__m != __A) _M_optimise(__A, __m, __L+1);
1990 if (++__m != __B) _M_optimise(__m, __B, __L+1);
2013 return static_cast<_Link_type>(_M_header._M_left);
2019 _M_header._M_left = a;
2025 return static_cast<_Link_type>( _M_header._M_right );
2031 _M_header._M_right = a;
2040 static _Link_const_type
2064 static _Link_const_type
2082 static _Link_const_type
2091 return !_S_left(N) && !_S_right(N);
2094 static const_reference
2100 static const_reference
2106 static _Link_const_type
2112 static _Link_const_type
2127 _Base::_M_construct_node(new_node, __V, __PARENT, __LEFT, __RIGHT);
2145 _Base::_M_destroy_node(__p);
2146 _Base::_M_deallocate_node(__p);
2156 #ifdef KDTREE_DEFINE_OSTREAM_OPERATORS
2157 friend std::ostream&
2161 o <<
"meta node: " << tree._M_header << std::endl;
2162 o <<
"root node: " << tree._M_root << std::endl;
2165 return o <<
"[empty " << __K <<
"d-tree " << &tree <<
"]";
2167 o <<
"nodes total: " << tree.size() << std::endl;
2168 o <<
"dimensions: " << __K << std::endl;
2171 typedef typename _Tree::_Link_type
_Link_type;
2173 std::stack<_Link_const_type> s;
2174 s.push(tree._M_get_root());
2180 o << *n << std::endl;
2181 if (_Tree::_S_left(n)) s.push(_Tree::_S_left(n));
2182 if (_Tree::_S_right(n)) s.push(_Tree::_S_right(n));
Definition: KDTree.h:1054
static _Link_type _S_left(_Base_ptr N)
Definition: KDTree.h:2059
KDTree(const KDTree &__x)
Definition: KDTree.h:1086
bool _M_matches_node_in_other_ds(_Link_const_type __N, const_reference __V, size_type const __L=0) const
Definition: KDTree.h:1866
iterator insert(iterator, const_reference __V)
Definition: KDTree.h:1263
_OutputIterator find_within_range(SearchVal const &val, subvalue_type const range, _OutputIterator out) const
Definition: KDTree.h:1442
bool _M_matches_node_in_d(_Link_const_type __N, const_reference __V, size_type const __L) const
Definition: KDTree.h:1858
const_reverse_iterator rend() const
Definition: KDTree.h:1260
void efficient_replace_and_optimise(std::vector< value_type > &writable_vector)
Definition: KDTree.h:1144
void erase_exact(const_reference __V)
Definition: KDTree.h:1320
void erase(const_reference __V)
Definition: KDTree.h:1314
_Node_compare< _Val, _Acc, _Cmp > _Node_compare_
Definition: KDTree.h:1064
bool _M_matches_node(_Link_const_type __N, const_reference __V, size_type __L=0) const
Definition: KDTree.h:1876
static _Link_const_type _S_maximum(_Link_const_type __X)
Definition: KDTree.h:2113
Visitor visit_within_range(_Region_ const ®ION, Visitor visitor) const
Definition: KDTree.h:1420
_Link_const_type _M_get_rightmost() const
Definition: KDTree.h:2023
iterator _M_insert_left(_Link_type __N, const_reference __V)
Definition: KDTree.h:1609
static void _S_set_parent(_Base_ptr N, _Base_ptr p)
Definition: KDTree.h:2047
value_type const * const_pointer
Definition: KDTree.h:1070
void check_tree()
Definition: KDTree.h:1561
static _Link_const_type _S_minimum(_Link_const_type __X)
Definition: KDTree.h:2107
static void _S_set_left(_Base_ptr N, _Base_ptr l)
Definition: KDTree.h:2053
const_iterator begin() const
Definition: KDTree.h:1257
void _M_set_root(_Link_type n)
Definition: KDTree.h:2005
_Link_type _M_get_root()
Definition: KDTree.h:2000
iterator _M_insert(_Link_type __N, const_reference __V, size_type const __L)
Definition: KDTree.h:1629
void optimise()
Definition: KDTree.h:1548
void _M_delete_node(_Link_type __p)
Definition: KDTree.h:2143
_OutputIterator _M_find_within_range(_OutputIterator out, _Link_const_type __N, _Region_ const &__REGION, _Region_ const &__BOUNDS, size_type const __L) const
Definition: KDTree.h:1949
_Node< _Val > const * _Link_const_type
Definition: KDTree.h:1062
KDTree & operator=(const KDTree &__x)
Definition: KDTree.h:1153
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: KDTree.h:1251
_Link_type _M_get_erase_replacement(_Link_type node, size_type const level)
Definition: KDTree.h:1690
static _Link_const_type _S_parent(_Base_const_ptr N)
Definition: KDTree.h:2041
size_t size_type
Definition: KDTree.h:1075
size_type count_within_range(const_reference __V, subvalue_type const __R) const
Definition: KDTree.h:1391
_Node_base * _Base_ptr
Definition: KDTree.h:1059
std::pair< const_iterator, distance_type > find_nearest(SearchVal const &__val, distance_type __max) const
Definition: KDTree.h:1486
void _M_empty_initialise()
Definition: KDTree.h:1600
size_type size() const
Definition: KDTree.h:1188
_Dist _M_dist
Definition: KDTree.h:2154
bool empty() const
Definition: KDTree.h:1200
void _M_erase_subtree(_Link_type __n)
Definition: KDTree.h:1798
_Node< _Val > * _Link_type
Definition: KDTree.h:1061
value_type const & const_reference
Definition: KDTree.h:1072
allocator_type get_allocator() const
Definition: KDTree.h:1182
_Link_type _M_erase(_Link_type dead_dad, size_type const level)
Definition: KDTree.h:1647
size_type _M_count_within_range(_Link_const_type __N, _Region_ const &__REGION, _Region_ const &__BOUNDS, size_type const __L) const
Definition: KDTree.h:1884
iterator insert(const_reference __V)
Definition: KDTree.h:1269
static _Link_const_type _S_right(_Base_const_ptr N)
Definition: KDTree.h:2083
Visitor visit_within_range(SearchVal const &V, subvalue_type const R, Visitor visitor) const
Definition: KDTree.h:1411
const_iterator find(SearchVal const &__V) const
Definition: KDTree.h:1361
void _M_check_node(_Link_const_type node, size_type const level)
Definition: KDTree.h:1585
void insert(iterator __pos, _InputIterator __first, _InputIterator __last)
Definition: KDTree.h:1298
_Node_base _M_header
Definition: KDTree.h:2150
void _M_optimise(_Iter const &__A, _Iter const &__B, size_type const __L)
Definition: KDTree.h:1981
size_type count_within_range(_Region_ const &__REGION) const
Definition: KDTree.h:1399
_Base::allocator_type allocator_type
Definition: KDTree.h:1057
std::pair< _Link_type, size_type > _M_get_j_min(std::pair< _Link_type, size_type > const node, size_type const level)
Definition: KDTree.h:1738
std::reverse_iterator< iterator > reverse_iterator
Definition: KDTree.h:1252
size_type max_size() const
Definition: KDTree.h:1194
~KDTree()
Definition: KDTree.h:1176
_Alloc_base< _Val, _Alloc > _Base
Definition: KDTree.h:1056
static _Link_const_type _S_left(_Base_const_ptr N)
Definition: KDTree.h:2065
std::pair< const_iterator, distance_type > find_nearest(SearchVal const &__val) const
Definition: KDTree.h:1466
_Cmp value_comp() const
Comparator for the values in the KDTree.
Definition: KDTree.h:1221
_Acc _M_acc
Definition: KDTree.h:2152
void erase(const_iterator const &__IT)
Definition: KDTree.h:1326
void insert(iterator __pos, size_type __n, const value_type &__x)
Definition: KDTree.h:1290
void _M_set_leftmost(_Node_base *a)
Definition: KDTree.h:2017
KDTree(_InputIterator __first, _InputIterator __last, _Acc const &acc=_Acc(), _Dist const &__dist=_Dist(), _Cmp const &__cmp=_Cmp(), const allocator_type &__a=allocator_type())
Definition: KDTree.h:1106
void insert(_InputIterator __first, _InputIterator __last)
Definition: KDTree.h:1284
void optimize()
Definition: KDTree.h:1556
_Link_const_type _M_get_leftmost() const
Definition: KDTree.h:2011
_Node_base const * _Base_const_ptr
Definition: KDTree.h:1060
static bool _S_is_leaf(_Base_const_ptr N)
Definition: KDTree.h:2089
_Val value_type
Definition: KDTree.h:1068
const_iterator _M_find(_Link_const_type node, const_reference value, size_type const level) const
Definition: KDTree.h:1810
static const_reference _S_value(_Link_const_type N)
Definition: KDTree.h:2095
value_type & reference
Definition: KDTree.h:1071
void _M_check_children(_Link_const_type child, _Link_const_type parent, size_type const level, bool to_the_left)
Definition: KDTree.h:1568
_Acc value_acc() const
Accessor to the value's elements.
Definition: KDTree.h:1230
_Link_type _M_root
Definition: KDTree.h:2149
Visitor _M_visit_within_range(Visitor visitor, _Link_const_type N, _Region_ const ®ION, _Region_ const &BOUNDS, size_type const L) const
Definition: KDTree.h:1916
const _Dist & value_distance() const
Distance calculator between 2 value's element.
Definition: KDTree.h:1240
void clear()
Definition: KDTree.h:1206
const_iterator iterator
Definition: KDTree.h:1250
const_iterator end() const
Definition: KDTree.h:1258
ptrdiff_t difference_type
Definition: KDTree.h:1076
value_type * pointer
Definition: KDTree.h:1069
size_type _M_count
Definition: KDTree.h:2151
_Cmp _M_cmp
Definition: KDTree.h:2153
_Iterator< _Val, const_reference, const_pointer > const_iterator
Definition: KDTree.h:1248
std::pair< const_iterator, distance_type > find_nearest_if(SearchVal const &__val, distance_type __max, _Predicate __p) const
Definition: KDTree.h:1516
iterator _M_insert_right(_Link_type __N, const_reference __V)
Definition: KDTree.h:1619
_Dist & value_distance()
Definition: KDTree.h:1244
static void _S_set_right(_Base_ptr N, _Base_ptr r)
Definition: KDTree.h:2071
_Region< __K, _Val, typename _Acc::result_type, _Acc, _Cmp > _Region_
Definition: KDTree.h:1067
KDTree(_Acc const &__acc=_Acc(), _Dist const &__dist=_Dist(), _Cmp const &__cmp=_Cmp(), const allocator_type &__a=allocator_type())
Definition: KDTree.h:1078
_Link_type _M_new_node(const_reference __V, _Base_ptr const __PARENT=nullptr, _Base_ptr const __LEFT=nullptr, _Base_ptr const __RIGHT=nullptr)
Definition: KDTree.h:2120
const_iterator find_exact(SearchVal const &__V) const
Definition: KDTree.h:1383
std::pair< _Link_type, size_type > _M_get_j_max(std::pair< _Link_type, size_type > const node, size_type const level)
Definition: KDTree.h:1768
_Link_const_type _M_get_root() const
Definition: KDTree.h:1994
const_iterator _M_find_exact(_Link_const_type node, const_reference value, size_type const level) const
Definition: KDTree.h:1833
const_reverse_iterator rbegin() const
Definition: KDTree.h:1259
static _Link_type _S_parent(_Base_ptr N)
Definition: KDTree.h:2035
void _M_set_rightmost(_Node_base *a)
Definition: KDTree.h:2029
static _Link_type _S_right(_Base_ptr N)
Definition: KDTree.h:2077
_Dist::distance_type distance_type
Definition: KDTree.h:1074
_Acc::result_type subvalue_type
Definition: KDTree.h:1073
_OutputIterator find_within_range(_Region_ const ®ion, _OutputIterator out) const
Definition: KDTree.h:1452
static const_reference _S_value(_Base_const_ptr N)
Definition: KDTree.h:2101
_Node_ * new_node
Definition: KDTree.h:516
~NoLeakAlloc()
Definition: KDTree.h:524
void disconnect()
Definition: KDTree.h:522
NoLeakAlloc(_Alloc_base *b)
Definition: KDTree.h:519
_Node_ * get()
Definition: KDTree.h:521
_Alloc_base * base
Definition: KDTree.h:515
_Node_::_Base_ptr _Base_ptr
Definition: KDTree.h:500
void _M_construct_node(_Node_ *__p, _Tp const __V=_Tp(), _Base_ptr const __PARENT=NULL, _Base_ptr const __LEFT=NULL, _Base_ptr const __RIGHT=NULL)
Definition: KDTree.h:544
_Node< _Tp > _Node_
Definition: KDTree.h:499
_Alloc_base(allocator_type const &__A)
Definition: KDTree.h:503
allocator_type get_allocator() const
Definition: KDTree.h:507
void _M_deallocate_node(_Node_ *const __P)
Definition: KDTree.h:538
_Alloc allocator_type
Definition: KDTree.h:501
_Node_ * _M_allocate_node()
Definition: KDTree.h:532
void _M_destroy_node(_Node_ *__p)
Definition: KDTree.h:553
allocator_type _M_node_allocator
Definition: KDTree.h:529
void _M_decrement()
Definition: KDTree.h:655
_Base_iterator(_Base_iterator const &__THAT)
Definition: KDTree.h:629
_Node_base::_Base_const_ptr _Base_const_ptr
Definition: KDTree.h:624
_Base_const_ptr _M_node
Definition: KDTree.h:625
_Base_iterator(_Base_const_ptr const __N=nullptr)
Definition: KDTree.h:627
void _M_increment()
Definition: KDTree.h:633
_Iterator< _Val, _Ref, _Ptr > _Self
Definition: KDTree.h:695
std::bidirectional_iterator_tag iterator_category
Definition: KDTree.h:697
_Iterator< _Val, _Val &, _Val * > iterator
Definition: KDTree.h:693
_Self & operator--()
Definition: KDTree.h:740
_Ptr pointer
Definition: KDTree.h:692
_Node< _Val > const * _Link_const_type
Definition: KDTree.h:696
_Self operator++(int)
Definition: KDTree.h:732
_Iterator(_Link_const_type const __N)
Definition: KDTree.h:702
_Link_const_type get_raw_node() const
Definition: KDTree.h:707
_Iterator(iterator const &__THAT)
Definition: KDTree.h:704
_Ref reference
Definition: KDTree.h:691
_Self operator++()
Definition: KDTree.h:725
_Iterator< _Val, _Val const &, _Val const * > const_iterator
Definition: KDTree.h:694
reference operator*() const
Definition: KDTree.h:713
_Val value_type
Definition: KDTree.h:690
_Iterator()
Definition: KDTree.h:700
ptrdiff_t difference_type
Definition: KDTree.h:698
_Self operator--(int)
Definition: KDTree.h:747
pointer operator->() const
Definition: KDTree.h:719
bool operator()(_Val const &__A, _Val const &__B) const
Definition: KDTree.h:131
_Node_compare(size_t const __DIM, _Acc const &acc, _Cmp const &cmp)
Definition: KDTree.h:127
_Acc _M_acc
Definition: KDTree.h:138
_Cmp _M_cmp
Definition: KDTree.h:139
size_t _M_DIM
Definition: KDTree.h:137
bool _S_node_compare(const size_t __dim, const _Cmp &__cmp, const _Acc &__acc, const _ValA &__a, const _ValB &__b)
Definition: KDTree.h:152
const NodeType * _S_node_descend(const size_t __dim, const _Cmp &__cmp, const _Acc &__acc, const _Val &__val, const NodeType *__node)
Definition: KDTree.h:203
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:781
bool operator!=(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:799
_Dist::distance_type _S_accumulate_node_distance(const size_t __dim, const _Dist &__dist, const _Acc &__acc, const _ValA &__a, const _ValB &__b)
Definition: KDTree.h:185
std::pair< const NodeType *, std::pair< size_t, typename _Dist::distance_type > > _S_node_nearest(const size_t __k, size_t __dim, SearchVal const &__val, const NodeType *__node, const _Node_base *__end, const NodeType *__best, typename _Dist::distance_type __max, const _Cmp &__cmp, const _Acc &__acc, const _Dist &__dist, _Predicate __p)
Definition: KDTree.h:227
_Dist::distance_type _S_node_distance(const size_t __dim, const _Dist &__dist, const _Acc &__acc, const _ValA &__a, const _ValB &__b)
Definition: KDTree.h:168
const double R
Definition: Constants.h:149
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
result_type operator()(_Val const &V, size_t const N) const
Definition: KDTree.h:412
_Val::value_type result_type
Definition: KDTree.h:409
_Node_base * _Base_ptr
Definition: KDTree.h:50
_Base_ptr _M_parent
Definition: KDTree.h:53
static _Base_ptr _S_minimum(_Base_ptr __x)
Definition: KDTree.h:63
_Base_ptr _M_right
Definition: KDTree.h:55
_Node_base const * _Base_const_ptr
Definition: KDTree.h:51
static _Base_ptr _S_maximum(_Base_ptr __x)
Definition: KDTree.h:70
_Base_ptr _M_left
Definition: KDTree.h:54
_Node_base(_Base_ptr const __PARENT=nullptr, _Base_ptr const __LEFT=nullptr, _Base_ptr const __RIGHT=nullptr)
Definition: KDTree.h:57
_Node(_Val const &__VALUE=_Val(), _Base_ptr const __PARENT=nullptr, _Base_ptr const __LEFT=nullptr, _Base_ptr const __RIGHT=nullptr)
Definition: KDTree.h:85
_Val _M_value
Definition: KDTree.h:83
_Node * _Link_type
Definition: KDTree.h:81
_Region & set_low_bound(value_type const &__V, size_t const __L)
Definition: KDTree.h:933
bool encloses(value_type const &__V) const
Definition: KDTree.h:914
bool intersects_with(_Region const &__THAT) const
Definition: KDTree.h:902
_Region(_Acc const &__acc=_Acc(), const _Cmp &__cmp=_Cmp())
Definition: KDTree.h:857
_SubVal subvalue_type
Definition: KDTree.h:850
_Region(Val const &__V, subvalue_type const &__R, _Acc const &__acc=_Acc(), const _Cmp &__cmp=_Cmp())
Definition: KDTree.h:872
_Acc _M_acc
Definition: KDTree.h:940
std::pair< _Region, _SubVal > _CenterPt
Definition: KDTree.h:855
_Val value_type
Definition: KDTree.h:849
_Region & set_high_bound(value_type const &__V, size_t const __L)
Definition: KDTree.h:926
subvalue_type _M_low_bounds[__K]
Definition: KDTree.h:939
_Cmp _M_cmp
Definition: KDTree.h:941
bool intersects_with(_CenterPt const &__THAT) const
Definition: KDTree.h:884
subvalue_type _M_high_bounds[__K]
Definition: KDTree.h:939
_Region(Val const &__V, _Acc const &__acc=_Acc(), const _Cmp &__cmp=_Cmp())
Definition: KDTree.h:861
bool operator()(const _Tp &) const
Definition: KDTree.h:421
distance_type operator()(const _Tp &__a, const _Tp &__b) const
Definition: KDTree.h:454
long _M_count
Definition: KDTree.h:462
squared_difference_counted()
Definition: KDTree.h:442
long & count() const
Definition: KDTree.h:450
void reset()
Definition: KDTree.h:446
_Dist distance_type
Definition: KDTree.h:440
distance_type operator()(const _Tp &__a, const _Tp &__b) const
Definition: KDTree.h:430
_Dist distance_type
Definition: KDTree.h:427