35 #ifndef SHARK_ALGORITHMS_NEARESTNEIGHBORS_BINARYTREE_H 36 #define SHARK_ALGORITHMS_NEARESTNEIGHBORS_BINARYTREE_H 44 #include <boost/range/algorithm_ext/iota.hpp> 45 #include <boost/range/iterator_range.hpp> 46 #include <boost/math/special_functions/fpclassify.hpp> 127 template <
class InputT>
131 typedef InputT value_type;
150 mp_indexList =
new std::size_t[m_size];
151 std::iota(mp_indexList,mp_indexList+m_size,0);
157 if (mp_left != NULL)
delete mp_left;
158 if (mp_right != NULL)
delete mp_right;
159 if (mep_parent == NULL)
delete [] mp_indexList;
167 {
return mep_parent; }
170 {
return mep_parent; }
175 {
return (mp_left != NULL); }
180 {
return (mp_left == NULL); }
204 std::size_t
index(std::size_t point)
const{
205 return mp_indexList[point];
225 return funct(point) - m_threshold;
235 bool isLeft(value_type
const& point)
const 236 {
return (funct(point) < m_threshold); }
241 {
return (funct(point) >= m_threshold); }
259 virtual double squaredDistanceLowerBound(value_type
const& point)
const = 0;
296 virtual double funct(value_type
const& point)
const = 0;
305 template<
class Range1,
class Range2>
306 typename Range2::iterator
splitList (Range1& values, Range2& points){
307 std::vector<KeyValuePair<typename Range1::value_type, typename Range2::value_type> > range(values.size());
308 for(std::size_t i = 0; i != range.size(); ++i){
309 range[i].key = values[i];
310 range[i].value = points[i];
315 for(std::size_t i = 0; i != range.size(); ++i){
316 values[i] = range[i].key;
317 points[i] = range[i].value;
320 if (pos == range.end()) {
322 m_threshold = values[0];
323 return points.begin();
330 double maximum = std::max_element(range.begin(), pos)->key;
331 m_threshold = 0.5*(maximum + pos->key);
333 return points.begin() + (pos - range.begin());