35 #ifndef OPENMS_DATASTRUCTURES_KDTREE_H
36 #define OPENMS_DATASTRUCTURES_KDTREE_H
38 #ifdef KDTREE_DEFINE_OSTREAM_OPERATORS
76 template <
typename _Val>
84 _Node(_Val
const& __VALUE = _Val(),
90 #ifdef KDTREE_DEFINE_OSTREAM_OPERATORS
92 template <
typename Char,
typename Traits>
94 std::basic_ostream<Char, Traits>&
95 operator<<(
typename std::basic_ostream<Char, Traits>& out,
100 out <<
"; left: " << node.
_M_left;
101 out <<
"; right: " << node.
_M_right;
105 template <
typename Char,
typename Traits>
107 std::basic_ostream<Char, Traits>&
108 operator<<(
typename std::basic_ostream<Char, Traits>& out,
109 _Node<_Val>
const& node)
112 out <<
' ' << node._M_value;
113 out <<
"; parent: " << node._M_parent;
114 out <<
"; left: " << node._M_left;
115 out <<
"; right: " << node._M_right;
122 template <
typename _Val,
typename _Acc,
typename _Cmp>
147 template <
typename _ValA,
typename _ValB,
typename _Cmp,
152 const _Cmp& __cmp,
const _Acc& __acc,
153 const _ValA& __a,
const _ValB& __b)
155 return __cmp(__acc(__a, __dim), __acc(__b, __dim));
163 template <
typename _ValA,
typename _ValB,
typename _Dist,
166 typename _Dist::distance_type
168 const _Dist& __dist,
const _Acc& __acc,
169 const _ValA& __a,
const _ValB& __b)
171 return __dist(__acc(__a, __dim), __acc(__b, __dim));
180 template <
typename _ValA,
typename _ValB,
typename _Dist,
183 typename _Dist::distance_type
185 const _Dist& __dist,
const _Acc& __acc,
186 const _ValA& __a,
const _ValB& __b)
188 typename _Dist::distance_type d = 0;
189 for (
size_t i=0; i<__dim; ++i)
190 d += __dist(__acc(__a, i), __acc(__b, i));
199 template <
typename _Val,
typename _Cmp,
typename _Acc,
typename NodeType>
203 const _Cmp& __cmp,
const _Acc& __acc,
204 const _Val& __val,
const NodeType* __node)
207 return static_cast<const NodeType *
>(__node->_M_left);
208 return static_cast<const NodeType *
>(__node->_M_right);
219 template <
class SearchVal,
220 typename NodeType,
typename _Cmp,
221 typename _Acc,
typename _Dist,
224 std::pair<
const NodeType*,
225 std::pair<size_t, typename _Dist::distance_type> >
227 const NodeType* __node,
const _Node_base* __end,
228 const NodeType* __best,
typename _Dist::distance_type __max,
229 const _Cmp& __cmp,
const _Acc& __acc,
const _Dist& __dist,
232 typedef const NodeType* NodePtr;
233 NodePtr pcur = __node;
234 NodePtr cur =
_S_node_descend(__dim % __k, __cmp, __acc, __val, __node);
235 size_t cur_dim = __dim+1;
239 if (__p(cur->_M_value))
241 typename _Dist::distance_type d = 0;
242 for (
size_t i=0; i != __k; ++i)
266 NodePtr pprobe = probe;
269 size_t probe_dim = cur_dim;
270 if (
_S_node_compare(probe_dim % __k, __cmp, __acc, __val, probe->_M_value))
271 near_node =
static_cast<NodePtr
>(probe->_M_right);
273 near_node =
static_cast<NodePtr
>(probe->_M_left);
276 && (std::sqrt(
_S_node_distance(probe_dim % __k, __dist, __acc, __val, probe->_M_value)) <= __max))
285 if (
_S_node_compare(probe_dim % __k, __cmp, __acc, __val, probe->_M_value))
287 near_node =
static_cast<NodePtr
>(probe->_M_left);
288 far_node =
static_cast<NodePtr
>(probe->_M_right);
292 near_node =
static_cast<NodePtr
>(probe->_M_right);
293 far_node =
static_cast<NodePtr
>(probe->_M_left);
295 if (pprobe == probe->_M_parent)
297 if (__p(probe->_M_value))
299 typename _Dist::distance_type d = 0;
300 for (
size_t i=0; i < __k; ++i)
318 std::sqrt(
_S_node_distance(probe_dim % __k, __dist, __acc, __val, probe->_M_value)) <= __max)
325 probe =
static_cast<NodePtr
>(probe->_M_parent);
331 if (pprobe == near_node && far_node
333 && std::sqrt(
_S_node_distance(probe_dim % __k, __dist, __acc, __val, probe->_M_value)) <= __max)
342 probe =
static_cast<NodePtr
>(probe->_M_parent);
348 cur =
static_cast<NodePtr
>(cur->_M_parent);
355 if (pcur == cur->_M_left)
356 near_node =
static_cast<NodePtr
>(cur->_M_right);
358 near_node =
static_cast<NodePtr
>(cur->_M_left);
361 && (std::sqrt(
_S_node_distance(cur_dim % __k, __dist, __acc, __val, cur->_M_value)) <= __max))
368 return std::pair<NodePtr,
369 std::pair<size_t, typename _Dist::distance_type> >
370 (__best, std::pair<size_t, typename _Dist::distance_type>
398 #ifndef INCLUDE_KDTREE_ACCESSOR_HPP
399 #define INCLUDE_KDTREE_ACCESSOR_HPP
405 template <
typename _Val>
417 template <
typename _Tp>
423 template <
typename _Tp,
typename _Dist>
436 template <
typename _Tp,
typename _Dist>
486 #ifndef INCLUDE_KDTREE_ALLOCATOR_HPP
487 #define INCLUDE_KDTREE_ALLOCATOR_HPP
494 template <
typename _Tp,
typename _Alloc>
548 new (__p)
_Node_(__V, __PARENT, __LEFT, __RIGHT);
580 #ifndef INCLUDE_KDTREE_ITERATOR_HPP
581 #define INCLUDE_KDTREE_ITERATOR_HPP
587 template <
typename _Val,
typename _Ref,
typename _Ptr>
590 template<
typename _Val,
typename _Ref,
typename _Ptr>
592 operator==(_Iterator<_Val, _Ref, _Ptr>
const&,
593 _Iterator<_Val, _Ref, _Ptr>
const&);
595 template<
typename _Val>
597 operator==(_Iterator<_Val, const _Val&, const _Val*>
const&,
598 _Iterator<_Val, _Val&, _Val*>
const&);
600 template<
typename _Val>
602 operator==(_Iterator<_Val, _Val&, _Val*>
const&,
603 _Iterator<_Val, const _Val&, const _Val*>
const&);
605 template<
typename _Val,
typename _Ref,
typename _Ptr>
607 operator!=(_Iterator<_Val, _Ref, _Ptr>
const&,
608 _Iterator<_Val, _Ref, _Ptr>
const&);
610 template<
typename _Val>
612 operator!=(_Iterator<_Val, const _Val&, const _Val*>
const&,
613 _Iterator<_Val, _Val&, _Val*>
const&);
615 template<
typename _Val>
617 operator!=(_Iterator<_Val, _Val&, _Val*>
const&,
618 _Iterator<_Val, const _Val&, const _Val*>
const&);
642 while (__p &&
_M_node == __p->_M_right)
663 while (x->_M_right) x = x->_M_right;
669 while (__p &&
_M_node == __p->_M_left)
680 template <
size_t const __K,
typename _Val,
typename _Acc,
681 typename _Dist,
typename _Cmp,
typename _Alloc>
685 template <
typename _Val,
typename _Ref,
typename _Ptr>
778 template<
typename _Val,
typename _Ref,
typename _Ptr>
784 template<
typename _Val>
790 template<
typename _Val>
796 template<
typename _Val,
typename _Ref,
typename _Ptr>
802 template<
typename _Val>
808 template<
typename _Val>
836 #ifndef INCLUDE_KDTREE_REGION_HPP
837 #define INCLUDE_KDTREE_REGION_HPP
844 template <
size_t const __K,
typename _Val,
typename _SubVal,
845 typename _Acc,
typename _Cmp>
856 _Region(_Acc
const& __acc=_Acc(),
const _Cmp& __cmp=_Cmp())
859 template <
typename Val>
861 _Acc
const& __acc=_Acc(),
const _Cmp& __cmp=_Cmp())
864 for (
size_t __i = 0; __i != __K; ++__i)
870 template <
typename Val>
872 _Acc
const& __acc=_Acc(),
const _Cmp& __cmp=_Cmp())
875 for (
size_t __i = 0; __i != __K; ++__i)
885 for (
size_t __i = 0; __i != __K; ++__i)
903 for (
size_t __i = 0; __i != __K; ++__i)
915 for (
size_t __i = 0; __i != __K; ++__i)
1004 #ifndef INCLUDE_KDTREE_KDTREE_HPP
1005 #define INCLUDE_KDTREE_KDTREE_HPP
1014 #define KDTREE_VERSION 701
1019 #define KDTREE_LIB_VERSION "0_7_1"
1024 #ifdef KDTREE_CHECK_PERFORMANCE_COUNTERS
1027 #include <algorithm>
1028 #include <functional>
1030 #ifdef KDTREE_DEFINE_OSTREAM_OPERATORS
1042 #ifdef KDTREE_CHECK_PERFORMANCE
1043 unsigned long long num_dist_calcs = 0;
1046 template <
size_t const __K,
typename _Val,
1047 typename _Acc = _Bracket_accessor<_Val>,
1048 typename _Dist = squared_difference<
typename _Acc::result_type,
1049 typename _Acc::result_type>,
1050 typename _Cmp = std::less<typename _Acc::result_type>,
1051 typename _Alloc = std::allocator<_Node<_Val> > >
1077 KDTree(_Acc
const& __acc = _Acc(), _Dist
const& __dist = _Dist(),
1079 :
_Base(__a), _M_header(),
1080 _M_count(0), _M_acc(__acc), _M_cmp(__cmp), _M_dist(__dist)
1082 _M_empty_initialise();
1086 :
_Base(__x.get_allocator()), _M_header(), _M_count(0),
1087 _M_acc(__x._M_acc), _M_cmp(__x._M_cmp), _M_dist(__x._M_dist)
1089 _M_empty_initialise();
1098 std::vector<value_type> temp;
1099 temp.reserve(__x.size());
1100 std::copy(__x.begin(),__x.end(),std::back_inserter(temp));
1101 _M_optimise(temp.begin(), temp.end(), 0);
1104 template<
typename _InputIterator>
1105 KDTree(_InputIterator __first, _InputIterator __last,
1106 _Acc
const& acc = _Acc(), _Dist
const& __dist = _Dist(),
1108 :
_Base(__a), _M_header(), _M_count(0),
1109 _M_acc(acc), _M_cmp(__cmp), _M_dist(__dist)
1111 _M_empty_initialise();
1120 std::vector<value_type> temp;
1121 temp.reserve(std::distance(__first,__last));
1122 std::copy(__first,__last,std::back_inserter(temp));
1123 _M_optimise(temp.begin(), temp.end(), 0);
1146 _M_optimise(writable_vector.begin(), writable_vector.end(), 0);
1157 _M_dist = __x._M_dist;
1158 _M_cmp = __x._M_cmp;
1167 std::vector<value_type> temp;
1168 temp.reserve(__x.size());
1169 std::copy(__x.begin(),__x.end(),std::back_inserter(temp));
1170 efficient_replace_and_optimise(temp);
1183 return _Base::get_allocator();
1201 return this->size() == 0;
1207 _M_erase_subtree(_M_get_root());
1208 _M_set_leftmost(&_M_header);
1209 _M_set_rightmost(&_M_header);
1210 _M_set_root(
nullptr);
1264 return this->insert(__V);
1272 _Link_type __n = _M_new_node(__V, &_M_header);
1275 _M_set_leftmost(__n);
1276 _M_set_rightmost(__n);
1279 return _M_insert(_M_get_root(), __V, 0);
1282 template <
class _InputIterator>
1283 void insert(_InputIterator __first, _InputIterator __last) {
1284 for (; __first != __last; ++__first)
1285 this->insert(*__first);
1291 for (; __n > 0; --__n)
1292 this->insert(__pos, __x);
1295 template<
typename _InputIterator>
1298 for (; __first != __last; ++__first)
1299 this->insert(__pos, *__first);
1320 this->erase(this->find_exact(__V));
1327 assert(__IT != this->end());
1331 while ((n = _S_parent(n)) != &_M_header)
1333 _M_erase(
const_cast<_Link_type>(target), level );
1334 _M_delete_node(
const_cast<_Link_type>(target) );
1358 template <
class SearchVal>
1362 if (!_M_get_root())
return this->end();
1363 return _M_find(_M_get_root(), __V, 0);
1380 template <
class SearchVal>
1384 if (!_M_get_root())
return this->end();
1385 return _M_find_exact(_M_get_root(), __V, 0);
1392 if (!_M_get_root())
return 0;
1393 _Region_ __region(__V, __R, _M_acc, _M_cmp);
1394 return this->count_within_range(__region);
1400 if (!_M_get_root())
return 0;
1403 return _M_count_within_range(_M_get_root(),
1404 __REGION, __bounds, 0);
1408 template <
typename SearchVal,
class Visitor>
1412 if (!_M_get_root())
return visitor;
1414 return this->visit_within_range(region, visitor);
1417 template <
class Visitor>
1424 return _M_visit_within_range(visitor, _M_get_root(), REGION, bounds, 0);
1439 template <
typename SearchVal,
typename _OutputIterator>
1442 _OutputIterator out)
const
1444 if (!_M_get_root())
return out;
1445 _Region_ region(val, range, _M_acc, _M_cmp);
1446 return this->find_within_range(region, out);
1449 template <
typename _OutputIterator>
1452 _OutputIterator out)
const
1457 out = _M_find_within_range(out, _M_get_root(),
1463 template <
class SearchVal>
1464 std::pair<const_iterator, distance_type>
1469 std::pair<const _Node<_Val>*,
1470 std::pair<size_type, typename _Acc::result_type> >
1472 _M_get_root(), &_M_header, _M_get_root(),
1474 (__K, _M_dist, _M_acc, _M_get_root()->_M_value, __val)),
1475 _M_cmp, _M_acc, _M_dist,
1477 return std::pair<const_iterator, distance_type>
1478 (best.first, best.second.second);
1480 return std::pair<const_iterator, distance_type>(end(), 0);
1483 template <
class SearchVal>
1484 std::pair<const_iterator, distance_type>
1489 bool root_is_candidate =
false;
1493 (__K, _M_dist, _M_acc, _M_get_root()->_M_value, __val));
1494 if (root_dist <= __max)
1496 root_is_candidate =
true;
1500 std::pair<const _Node<_Val>*,
1501 std::pair<size_type, typename _Acc::result_type> >
1503 node, __max, _M_cmp, _M_acc, _M_dist,
1506 if (root_is_candidate || best.first != _M_get_root())
1507 return std::pair<const_iterator, distance_type>
1508 (best.first, best.second.second);
1510 return std::pair<const_iterator, distance_type>(end(), __max);
1513 template <
class SearchVal,
class _Predicate>
1514 std::pair<const_iterator, distance_type>
1516 _Predicate __p)
const
1520 bool root_is_candidate =
false;
1522 if (__p(_M_get_root()->_M_value))
1526 (__K, _M_dist, _M_acc, _M_get_root()->_M_value, __val));
1527 if (root_dist <= __max)
1529 root_is_candidate =
true;
1534 std::pair<const _Node<_Val>*,
1535 std::pair<size_type, typename _Acc::result_type> >
1537 node, __max, _M_cmp, _M_acc, _M_dist, __p);
1539 if (root_is_candidate || best.first != _M_get_root())
1540 return std::pair<const_iterator, distance_type>
1541 (best.first, best.second.second);
1543 return std::pair<const_iterator, distance_type>(end(), __max);
1549 std::vector<value_type> __v(this->begin(),this->end());
1551 _M_optimise(__v.begin(), __v.end(), 0);
1562 _M_check_node(_M_get_root(),0);
1579 _M_check_children(_S_left(child),parent,level,to_the_left);
1580 _M_check_children(_S_right(child),parent,level,to_the_left);
1590 _M_check_children( _S_left(node), node, level,
true );
1592 _M_check_children( _S_right(node), node, level,
false );
1594 _M_check_node( _S_left(node), level+1 );
1595 _M_check_node( _S_right(node), level+1 );
1601 _M_set_leftmost(&_M_header);
1602 _M_set_rightmost(&_M_header);
1603 _M_header._M_parent =
nullptr;
1604 _M_set_root(
nullptr);
1610 _S_set_left(__N, _M_new_node(__V)); ++_M_count;
1611 _S_set_parent( _S_left(__N), __N );
1612 if (__N == _M_get_leftmost())
1613 _M_set_leftmost( _S_left(__N) );
1620 _S_set_right(__N, _M_new_node(__V)); ++_M_count;
1621 _S_set_parent( _S_right(__N), __N );
1622 if (__N == _M_get_rightmost())
1623 _M_set_rightmost( _S_right(__N) );
1634 return _M_insert_left(__N, __V);
1635 return _M_insert(_S_left(__N), __V, __L+1);
1639 if (!_S_right(__N) || __N == _M_get_rightmost())
1640 return _M_insert_right(__N, __V);
1641 return _M_insert(_S_right(__N), __V, __L+1);
1649 _Link_type step_dad = _M_get_erase_replacement(dead_dad, level);
1652 if (dead_dad == _M_get_root())
1653 _M_set_root(step_dad);
1654 else if (_S_left(_S_parent(dead_dad)) == dead_dad)
1655 _S_set_left(_S_parent(dead_dad), step_dad);
1657 _S_set_right(_S_parent(dead_dad), step_dad);
1662 if (dead_dad == _M_get_leftmost())
1663 _M_set_leftmost( (step_dad ? step_dad : _S_parent(dead_dad)) );
1664 if (dead_dad == _M_get_rightmost())
1665 _M_set_rightmost( (step_dad ? step_dad : _S_parent(dead_dad)) );
1670 _S_set_parent(step_dad, _S_parent(dead_dad));
1673 if (_S_left(dead_dad))
1674 _S_set_parent(_S_left(dead_dad), step_dad);
1675 if (_S_right(dead_dad))
1676 _S_set_parent(_S_right(dead_dad), step_dad);
1679 _S_set_left(step_dad, _S_left(dead_dad));
1680 _S_set_right(step_dad, _S_right(dead_dad));
1692 if (_S_is_leaf(node))
1695 std::pair<_Link_type,size_type> candidate;
1698 candidate = _M_get_j_min( std::pair<_Link_type,size_type>(_S_right(node),level), level+1);
1700 else if ((!_S_right(node)))
1701 candidate = _M_get_j_max( std::pair<_Link_type,size_type>(_S_left(node),level), level+1);
1714 if (compare(_S_right(node)->_M_value, _S_left(node)->_M_value))
1716 candidate = _M_get_j_min(std::pair<_Link_type,size_type>(_S_right(node),level), level+1);
1718 candidate = _M_get_j_max( std::pair<_Link_type,size_type>(_S_left(node),level), level+1);
1724 _Link_type parent = _S_parent(candidate.first);
1725 if (_S_left(parent) == candidate.first)
1726 _S_set_left(parent, _M_erase(candidate.first, candidate.second));
1728 _S_set_right(parent, _M_erase(candidate.first, candidate.second));
1730 return candidate.first;
1736 std::pair<_Link_type,size_type>
1739 typedef std::pair<_Link_type,size_type> Result;
1740 if (_S_is_leaf(node.first))
1741 return Result(node.first,level);
1744 Result candidate = node;
1745 if (_S_left(node.first))
1747 Result left = _M_get_j_min(Result(_S_left(node.first), node.second), level+1);
1748 if (compare(left.first->_M_value, candidate.first->_M_value))
1751 if (_S_right(node.first))
1753 Result right = _M_get_j_min( Result(_S_right(node.first),node.second), level+1);
1754 if (compare(right.first->_M_value, candidate.first->_M_value))
1757 if (candidate.first == node.first)
1758 return Result(candidate.first,level);
1766 std::pair<_Link_type,size_type>
1769 typedef std::pair<_Link_type,size_type> Result;
1771 if (_S_is_leaf(node.first))
1772 return Result(node.first,level);
1775 Result candidate = node;
1776 if (_S_left(node.first))
1778 Result left = _M_get_j_max( Result(_S_left(node.first),node.second), level+1);
1779 if (compare(candidate.first->_M_value, left.first->_M_value))
1782 if (_S_right(node.first))
1784 Result right = _M_get_j_max(Result(_S_right(node.first),node.second), level+1);
1785 if (compare(candidate.first->_M_value, right.first->_M_value))
1789 if (candidate.first == node.first)
1790 return Result(candidate.first,level);
1801 _M_erase_subtree(_S_right(__n));
1803 _M_delete_node(__n);
1818 if (!compare(node->
_M_value,value))
1821 if (_M_matches_node(node, value, level))
1824 found = _M_find(_S_left(node), value, level+1);
1826 if ( _S_right(node) && found == this->end() && !compare(value,node->
_M_value))
1827 found = _M_find(_S_right(node), value, level+1);
1841 if (!compare(node->
_M_value,value))
1847 found = _M_find_exact(_S_left(node), value, level+1);
1851 if ( _S_right(node) && found == this->end() && !compare(value,node->
_M_value))
1852 found = _M_find_exact(_S_right(node), value, level+1);
1869 while ((__i = (__i + 1) % __K) != __L % __K)
1870 if (!_M_matches_node_in_d(__N, __V, __i))
return false;
1878 return _M_matches_node_in_d(__N, __V, __L)
1879 && _M_matches_node_in_other_ds(__N, __V, __L);
1888 if (__REGION.
encloses(_S_value(__N)))
1897 count += _M_count_within_range(_S_left(__N),
1898 __REGION, __bounds, __L+1);
1905 count += _M_count_within_range(_S_right(__N),
1906 __REGION, __bounds, __L+1);
1913 template <
class Visitor>
1922 visitor(_S_value(N));
1929 visitor = _M_visit_within_range(visitor, _S_left(N),
1930 REGION, bounds, L+1);
1937 visitor = _M_visit_within_range(visitor, _S_right(N),
1938 REGION, bounds, L+1);
1946 template <
typename _OutputIterator>
1953 if (__REGION.
encloses(_S_value(__N)))
1955 *out++ = _S_value(__N);
1962 out = _M_find_within_range(out, _S_left(__N),
1963 __REGION, __bounds, __L+1);
1970 out = _M_find_within_range(out, _S_right(__N),
1971 __REGION, __bounds, __L+1);
1978 template <
typename _Iter>
1983 if (__A == __B)
return;
1985 _Iter __m = __A + (__B - __A) / 2;
1986 std::nth_element(__A, __m, __B, compare);
1988 if (__m != __A) _M_optimise(__A, __m, __L+1);
1989 if (++__m != __B) _M_optimise(__m, __B, __L+1);
2012 return static_cast<_Link_type>(_M_header._M_left);
2018 _M_header._M_left = a;
2024 return static_cast<_Link_type>( _M_header._M_right );
2030 _M_header._M_right = a;
2039 static _Link_const_type
2063 static _Link_const_type
2081 static _Link_const_type
2090 return !_S_left(N) && !_S_right(N);
2093 static const_reference
2099 static const_reference
2105 static _Link_const_type
2111 static _Link_const_type
2126 _Base::_M_construct_node(new_node, __V, __PARENT, __LEFT, __RIGHT);
2144 _Base::_M_destroy_node(__p);
2145 _Base::_M_deallocate_node(__p);
2155 #ifdef KDTREE_DEFINE_OSTREAM_OPERATORS
2156 friend std::ostream&
2160 o <<
"meta node: " << tree._M_header << std::endl;
2161 o <<
"root node: " << tree._M_root << std::endl;
2164 return o <<
"[empty " << __K <<
"d-tree " << &tree <<
"]";
2166 o <<
"nodes total: " << tree.size() << std::endl;
2167 o <<
"dimensions: " << __K << std::endl;
2170 typedef typename _Tree::_Link_type
_Link_type;
2172 std::stack<_Link_const_type> s;
2173 s.push(tree._M_get_root());
2179 o << *n << std::endl;
2180 if (_Tree::_S_left(n)) s.push(_Tree::_S_left(n));
2181 if (_Tree::_S_right(n)) s.push(_Tree::_S_right(n));
Definition: KDTree.h:1053
static _Link_type _S_left(_Base_ptr N)
Definition: KDTree.h:2058
KDTree(const KDTree &__x)
Definition: KDTree.h:1085
bool _M_matches_node_in_other_ds(_Link_const_type __N, const_reference __V, size_type const __L=0) const
Definition: KDTree.h:1865
iterator insert(iterator, const_reference __V)
Definition: KDTree.h:1262
_OutputIterator find_within_range(SearchVal const &val, subvalue_type const range, _OutputIterator out) const
Definition: KDTree.h:1441
bool _M_matches_node_in_d(_Link_const_type __N, const_reference __V, size_type const __L) const
Definition: KDTree.h:1857
const_reverse_iterator rend() const
Definition: KDTree.h:1259
void efficient_replace_and_optimise(std::vector< value_type > &writable_vector)
Definition: KDTree.h:1143
void erase_exact(const_reference __V)
Definition: KDTree.h:1319
void erase(const_reference __V)
Definition: KDTree.h:1313
_Node_compare< _Val, _Acc, _Cmp > _Node_compare_
Definition: KDTree.h:1063
bool _M_matches_node(_Link_const_type __N, const_reference __V, size_type __L=0) const
Definition: KDTree.h:1875
static _Link_const_type _S_maximum(_Link_const_type __X)
Definition: KDTree.h:2112
Visitor visit_within_range(_Region_ const ®ION, Visitor visitor) const
Definition: KDTree.h:1419
_Link_const_type _M_get_rightmost() const
Definition: KDTree.h:2022
iterator _M_insert_left(_Link_type __N, const_reference __V)
Definition: KDTree.h:1608
static void _S_set_parent(_Base_ptr N, _Base_ptr p)
Definition: KDTree.h:2046
value_type const * const_pointer
Definition: KDTree.h:1069
void check_tree()
Definition: KDTree.h:1560
static _Link_const_type _S_minimum(_Link_const_type __X)
Definition: KDTree.h:2106
static void _S_set_left(_Base_ptr N, _Base_ptr l)
Definition: KDTree.h:2052
const_iterator begin() const
Definition: KDTree.h:1256
void _M_set_root(_Link_type n)
Definition: KDTree.h:2004
_Link_type _M_get_root()
Definition: KDTree.h:1999
iterator _M_insert(_Link_type __N, const_reference __V, size_type const __L)
Definition: KDTree.h:1628
void optimise()
Definition: KDTree.h:1547
void _M_delete_node(_Link_type __p)
Definition: KDTree.h:2142
_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:1948
_Node< _Val > const * _Link_const_type
Definition: KDTree.h:1061
KDTree & operator=(const KDTree &__x)
Definition: KDTree.h:1152
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: KDTree.h:1250
_Link_type _M_get_erase_replacement(_Link_type node, size_type const level)
Definition: KDTree.h:1689
static _Link_const_type _S_parent(_Base_const_ptr N)
Definition: KDTree.h:2040
size_t size_type
Definition: KDTree.h:1074
size_type count_within_range(const_reference __V, subvalue_type const __R) const
Definition: KDTree.h:1390
_Node_base * _Base_ptr
Definition: KDTree.h:1058
std::pair< const_iterator, distance_type > find_nearest(SearchVal const &__val, distance_type __max) const
Definition: KDTree.h:1485
void _M_empty_initialise()
Definition: KDTree.h:1599
size_type size() const
Definition: KDTree.h:1187
_Dist _M_dist
Definition: KDTree.h:2153
bool empty() const
Definition: KDTree.h:1199
void _M_erase_subtree(_Link_type __n)
Definition: KDTree.h:1797
_Node< _Val > * _Link_type
Definition: KDTree.h:1060
value_type const & const_reference
Definition: KDTree.h:1071
allocator_type get_allocator() const
Definition: KDTree.h:1181
_Link_type _M_erase(_Link_type dead_dad, size_type const level)
Definition: KDTree.h:1646
size_type _M_count_within_range(_Link_const_type __N, _Region_ const &__REGION, _Region_ const &__BOUNDS, size_type const __L) const
Definition: KDTree.h:1883
iterator insert(const_reference __V)
Definition: KDTree.h:1268
static _Link_const_type _S_right(_Base_const_ptr N)
Definition: KDTree.h:2082
Visitor visit_within_range(SearchVal const &V, subvalue_type const R, Visitor visitor) const
Definition: KDTree.h:1410
const_iterator find(SearchVal const &__V) const
Definition: KDTree.h:1360
void _M_check_node(_Link_const_type node, size_type const level)
Definition: KDTree.h:1584
void insert(iterator __pos, _InputIterator __first, _InputIterator __last)
Definition: KDTree.h:1297
_Node_base _M_header
Definition: KDTree.h:2149
void _M_optimise(_Iter const &__A, _Iter const &__B, size_type const __L)
Definition: KDTree.h:1980
size_type count_within_range(_Region_ const &__REGION) const
Definition: KDTree.h:1398
_Base::allocator_type allocator_type
Definition: KDTree.h:1056
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:1737
std::reverse_iterator< iterator > reverse_iterator
Definition: KDTree.h:1251
size_type max_size() const
Definition: KDTree.h:1193
~KDTree()
Definition: KDTree.h:1175
_Alloc_base< _Val, _Alloc > _Base
Definition: KDTree.h:1055
static _Link_const_type _S_left(_Base_const_ptr N)
Definition: KDTree.h:2064
std::pair< const_iterator, distance_type > find_nearest(SearchVal const &__val) const
Definition: KDTree.h:1465
_Cmp value_comp() const
Comparator for the values in the KDTree.
Definition: KDTree.h:1220
_Acc _M_acc
Definition: KDTree.h:2151
void erase(const_iterator const &__IT)
Definition: KDTree.h:1325
void insert(iterator __pos, size_type __n, const value_type &__x)
Definition: KDTree.h:1289
void _M_set_leftmost(_Node_base *a)
Definition: KDTree.h:2016
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:1105
void insert(_InputIterator __first, _InputIterator __last)
Definition: KDTree.h:1283
void optimize()
Definition: KDTree.h:1555
_Link_const_type _M_get_leftmost() const
Definition: KDTree.h:2010
_Node_base const * _Base_const_ptr
Definition: KDTree.h:1059
static bool _S_is_leaf(_Base_const_ptr N)
Definition: KDTree.h:2088
_Val value_type
Definition: KDTree.h:1067
const_iterator _M_find(_Link_const_type node, const_reference value, size_type const level) const
Definition: KDTree.h:1809
static const_reference _S_value(_Link_const_type N)
Definition: KDTree.h:2094
value_type & reference
Definition: KDTree.h:1070
void _M_check_children(_Link_const_type child, _Link_const_type parent, size_type const level, bool to_the_left)
Definition: KDTree.h:1567
_Acc value_acc() const
Accessor to the value's elements.
Definition: KDTree.h:1229
_Link_type _M_root
Definition: KDTree.h:2148
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:1915
const _Dist & value_distance() const
Distance calculator between 2 value's element.
Definition: KDTree.h:1239
void clear()
Definition: KDTree.h:1205
const_iterator iterator
Definition: KDTree.h:1249
const_iterator end() const
Definition: KDTree.h:1257
ptrdiff_t difference_type
Definition: KDTree.h:1075
value_type * pointer
Definition: KDTree.h:1068
size_type _M_count
Definition: KDTree.h:2150
_Cmp _M_cmp
Definition: KDTree.h:2152
_Iterator< _Val, const_reference, const_pointer > const_iterator
Definition: KDTree.h:1247
std::pair< const_iterator, distance_type > find_nearest_if(SearchVal const &__val, distance_type __max, _Predicate __p) const
Definition: KDTree.h:1515
iterator _M_insert_right(_Link_type __N, const_reference __V)
Definition: KDTree.h:1618
_Dist & value_distance()
Definition: KDTree.h:1243
static void _S_set_right(_Base_ptr N, _Base_ptr r)
Definition: KDTree.h:2070
_Region< __K, _Val, typename _Acc::result_type, _Acc, _Cmp > _Region_
Definition: KDTree.h:1066
KDTree(_Acc const &__acc=_Acc(), _Dist const &__dist=_Dist(), _Cmp const &__cmp=_Cmp(), const allocator_type &__a=allocator_type())
Definition: KDTree.h:1077
_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:2119
const_iterator find_exact(SearchVal const &__V) const
Definition: KDTree.h:1382
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:1767
_Link_const_type _M_get_root() const
Definition: KDTree.h:1993
const_iterator _M_find_exact(_Link_const_type node, const_reference value, size_type const level) const
Definition: KDTree.h:1832
const_reverse_iterator rbegin() const
Definition: KDTree.h:1258
static _Link_type _S_parent(_Base_ptr N)
Definition: KDTree.h:2034
void _M_set_rightmost(_Node_base *a)
Definition: KDTree.h:2028
static _Link_type _S_right(_Base_ptr N)
Definition: KDTree.h:2076
_Dist::distance_type distance_type
Definition: KDTree.h:1073
_Acc::result_type subvalue_type
Definition: KDTree.h:1072
_OutputIterator find_within_range(_Region_ const ®ion, _OutputIterator out) const
Definition: KDTree.h:1451
static const_reference _S_value(_Base_const_ptr N)
Definition: KDTree.h:2100
_Node_ * new_node
Definition: KDTree.h:515
~NoLeakAlloc()
Definition: KDTree.h:523
void disconnect()
Definition: KDTree.h:521
NoLeakAlloc(_Alloc_base *b)
Definition: KDTree.h:518
_Node_ * get()
Definition: KDTree.h:520
_Alloc_base * base
Definition: KDTree.h:514
_Node_::_Base_ptr _Base_ptr
Definition: KDTree.h:499
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:543
_Node< _Tp > _Node_
Definition: KDTree.h:498
_Alloc_base(allocator_type const &__A)
Definition: KDTree.h:502
allocator_type get_allocator() const
Definition: KDTree.h:506
void _M_deallocate_node(_Node_ *const __P)
Definition: KDTree.h:537
_Alloc allocator_type
Definition: KDTree.h:500
_Node_ * _M_allocate_node()
Definition: KDTree.h:531
void _M_destroy_node(_Node_ *__p)
Definition: KDTree.h:552
allocator_type _M_node_allocator
Definition: KDTree.h:528
void _M_decrement()
Definition: KDTree.h:654
_Base_iterator(_Base_iterator const &__THAT)
Definition: KDTree.h:628
_Node_base::_Base_const_ptr _Base_const_ptr
Definition: KDTree.h:623
_Base_const_ptr _M_node
Definition: KDTree.h:624
_Base_iterator(_Base_const_ptr const __N=nullptr)
Definition: KDTree.h:626
void _M_increment()
Definition: KDTree.h:632
_Iterator< _Val, _Ref, _Ptr > _Self
Definition: KDTree.h:694
std::bidirectional_iterator_tag iterator_category
Definition: KDTree.h:696
_Iterator< _Val, _Val &, _Val * > iterator
Definition: KDTree.h:692
_Self & operator--()
Definition: KDTree.h:739
_Ptr pointer
Definition: KDTree.h:691
_Node< _Val > const * _Link_const_type
Definition: KDTree.h:695
_Self operator++(int)
Definition: KDTree.h:731
_Iterator(_Link_const_type const __N)
Definition: KDTree.h:701
_Link_const_type get_raw_node() const
Definition: KDTree.h:706
_Iterator(iterator const &__THAT)
Definition: KDTree.h:703
_Ref reference
Definition: KDTree.h:690
_Self operator++()
Definition: KDTree.h:724
_Iterator< _Val, _Val const &, _Val const * > const_iterator
Definition: KDTree.h:693
reference operator*() const
Definition: KDTree.h:712
_Val value_type
Definition: KDTree.h:689
_Iterator()
Definition: KDTree.h:699
ptrdiff_t difference_type
Definition: KDTree.h:697
_Self operator--(int)
Definition: KDTree.h:746
pointer operator->() const
Definition: KDTree.h:718
bool operator()(_Val const &__A, _Val const &__B) const
Definition: KDTree.h:130
_Node_compare(size_t const __DIM, _Acc const &acc, _Cmp const &cmp)
Definition: KDTree.h:126
_Acc _M_acc
Definition: KDTree.h:137
_Cmp _M_cmp
Definition: KDTree.h:138
size_t _M_DIM
Definition: KDTree.h:136
bool _S_node_compare(const size_t __dim, const _Cmp &__cmp, const _Acc &__acc, const _ValA &__a, const _ValB &__b)
Definition: KDTree.h:151
const NodeType * _S_node_descend(const size_t __dim, const _Cmp &__cmp, const _Acc &__acc, const _Val &__val, const NodeType *__node)
Definition: KDTree.h:202
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:780
bool operator!=(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:798
_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:184
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:226
_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:167
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:411
_Val::value_type result_type
Definition: KDTree.h:408
_Node_base * _Base_ptr
Definition: KDTree.h:49
_Base_ptr _M_parent
Definition: KDTree.h:52
static _Base_ptr _S_minimum(_Base_ptr __x)
Definition: KDTree.h:62
_Base_ptr _M_right
Definition: KDTree.h:54
_Node_base const * _Base_const_ptr
Definition: KDTree.h:50
static _Base_ptr _S_maximum(_Base_ptr __x)
Definition: KDTree.h:69
_Base_ptr _M_left
Definition: KDTree.h:53
_Node_base(_Base_ptr const __PARENT=nullptr, _Base_ptr const __LEFT=nullptr, _Base_ptr const __RIGHT=nullptr)
Definition: KDTree.h:56
_Node(_Val const &__VALUE=_Val(), _Base_ptr const __PARENT=nullptr, _Base_ptr const __LEFT=nullptr, _Base_ptr const __RIGHT=nullptr)
Definition: KDTree.h:84
_Val _M_value
Definition: KDTree.h:82
_Node * _Link_type
Definition: KDTree.h:80
_Region & set_low_bound(value_type const &__V, size_t const __L)
Definition: KDTree.h:932
bool encloses(value_type const &__V) const
Definition: KDTree.h:913
bool intersects_with(_Region const &__THAT) const
Definition: KDTree.h:901
_Region(_Acc const &__acc=_Acc(), const _Cmp &__cmp=_Cmp())
Definition: KDTree.h:856
_SubVal subvalue_type
Definition: KDTree.h:849
_Region(Val const &__V, subvalue_type const &__R, _Acc const &__acc=_Acc(), const _Cmp &__cmp=_Cmp())
Definition: KDTree.h:871
_Acc _M_acc
Definition: KDTree.h:939
std::pair< _Region, _SubVal > _CenterPt
Definition: KDTree.h:854
_Val value_type
Definition: KDTree.h:848
_Region & set_high_bound(value_type const &__V, size_t const __L)
Definition: KDTree.h:925
subvalue_type _M_low_bounds[__K]
Definition: KDTree.h:938
_Cmp _M_cmp
Definition: KDTree.h:940
bool intersects_with(_CenterPt const &__THAT) const
Definition: KDTree.h:883
subvalue_type _M_high_bounds[__K]
Definition: KDTree.h:938
_Region(Val const &__V, _Acc const &__acc=_Acc(), const _Cmp &__cmp=_Cmp())
Definition: KDTree.h:860
bool operator()(const _Tp &) const
Definition: KDTree.h:420
distance_type operator()(const _Tp &__a, const _Tp &__b) const
Definition: KDTree.h:453
long _M_count
Definition: KDTree.h:461
squared_difference_counted()
Definition: KDTree.h:441
long & count() const
Definition: KDTree.h:449
void reset()
Definition: KDTree.h:445
_Dist distance_type
Definition: KDTree.h:439
distance_type operator()(const _Tp &__a, const _Tp &__b) const
Definition: KDTree.h:429
_Dist distance_type
Definition: KDTree.h:426