13 #ifndef SPATIAL_NEIGHBOR_HPP
14 #define SPATIAL_NEIGHBOR_HPP
18 #include "spatial_import_tuple.hpp"
19 #include "../metric.hpp"
20 #include "../traits.hpp"
21 #include "spatial_bidirectional.hpp"
41 template<
typename Ct,
typename Metric>
61 typename Metric::distance_type
distance)
111 template <
typename Ct,
typename Metric =
117 <typename container_traits<Ct>::mode_type,
118 typename container_traits<Ct>::rank_type>
157 (Ct& container_,
const Metric& metric_,
160 typename Metric::distance_type distance_)
161 :
Base(container_.rank(), iter_.node,
162 modulo(iter_.node, container_.rank())),
163 _data(container_.key_comp(), metric_, target_, distance_) { }
190 (Ct& container_,
const Metric& metric_,
194 typename Metric::distance_type distance_)
195 :
Base(container_.rank(), node_, node_dim_),
196 _data(container_.key_comp(), metric_, target_, distance_) { }
225 const Metric& metric_,
229 typename Metric::distance_type distance_)
230 :
Base(rank_, node_, node_dim_),
231 _data(key_comp_, metric_, target_, distance_) { }
339 template<
typename Ct,
typename Metric>
342 <typename container_traits<Ct>::mode_type,
343 typename container_traits<Ct>::rank_type>
347 <
typename container_traits<Ct>::mode_type,
382 (
const Ct& container_,
const Metric& metric_,
385 typename Metric::distance_type distance_)
386 :
Base(container_.rank(), iter_.node,
387 modulo(iter_.node, container_.rank())),
388 _data(container_.key_comp(), metric_, target_, distance_) { }
415 (
const Ct& container_,
const Metric& metric_,
419 typename Metric::distance_type distance_)
420 :
Base(container_.rank(), node_, node_dim_),
421 _data(container_.key_comp(), metric_, target_, distance_) { }
446 const Metric& metric_,
450 typename Metric::distance_type distance_)
451 :
Base(rank_, node_, node_dim_),
452 _data(key_comp_, metric_, target_, distance_) { }
536 template <
typename Ct,
typename Metric>
538 inline typename Metric::distance_type
542 template <
typename Ct,
typename Metric>
545 const typename Metric::distance_type&
distance)
553 template <
typename Ct,
typename Metric>
565 template <
typename Ct,
typename Metric
566 = euclidian<typename details::mutate<Ct>::type,
567 double,
typename details::with_builtin_difference<Ct>
570 : std::pair<neighbor_iterator<Ct, Metric>,
571 neighbor_iterator<Ct, Metric> >
577 typedef std::pair<neighbor_iterator<Ct, Metric>,
597 template <
typename Ct,
typename Metric>
599 : std::pair<neighbor_iterator<const Ct, Metric>,
600 neighbor_iterator<const Ct, Metric> >
606 typedef std::pair<neighbor_iterator<const Ct, Metric>,
622 : Base(p.first, p.second) { }
631 template <
typename Ct,
typename Metric>
633 inline neighbor_iterator<Ct, Metric>
638 (container, metric, target, container.
dimension() - 1,
639 container.end().
node,
typename Metric::distance_type());
642 template <
typename Ct,
typename Metric>
643 inline neighbor_iterator<const Ct, Metric>
648 (container, metric, target, container.dimension() - 1,
649 container.end().node,
typename Metric::distance_type());
652 template <
typename Ct,
typename Metric>
653 inline neighbor_iterator<const Ct, Metric>
658 typename Metric::distance_type());
669 template <
typename Ct>
671 inline typename enable_if<details::is_compare_builtin<Ct>,
672 neighbor_iterator<Ct> >::type
684 template <
typename Ct>
685 inline typename enable_if<details::is_compare_builtin<Ct>,
686 neighbor_iterator<const Ct> >::type
698 template <
typename Ct>
699 inline typename enable_if<details::is_compare_builtin<Ct>,
700 neighbor_iterator<const Ct> >::type
720 template <
typename Ct,
typename Metric>
722 inline neighbor_iterator<Ct, Metric>
726 if (container.empty())
return neighbor_end(container, metric, target);
727 typename Ct::mode_type::node_ptr node = container.end().node->parent;
729 typename Metric::distance_type dist;
730 import::tie(node, dim, dist)
731 = first_neighbor(node, dim, container.rank(), container.key_comp(),
737 template <
typename Ct,
typename Metric>
738 inline neighbor_iterator<const Ct, Metric>
742 if (container.empty())
return neighbor_end(container, metric, target);
743 typename Ct::mode_type::const_node_ptr node = container.end().node->parent;
745 typename Metric::distance_type dist;
746 import::tie(node, dim, dist)
747 = first_neighbor(node, dim, container.rank(), container.key_comp(),
753 template <
typename Ct,
typename Metric>
754 inline neighbor_iterator<const Ct, Metric>
768 template <
typename Ct>
770 inline typename enable_if<details::is_compare_builtin<Ct>,
771 neighbor_iterator<Ct> >::type
783 template <
typename Ct>
784 inline typename enable_if<details::is_compare_builtin<Ct>,
785 neighbor_iterator<const Ct> >::type
797 template <
typename Ct>
798 inline typename enable_if<details::is_compare_builtin<Ct>,
799 neighbor_iterator<const Ct> >::type
822 template <
typename Ct,
typename Metric>
824 inline neighbor_iterator<Ct, Metric>
827 typename Metric::distance_type bound)
829 if (container.empty())
return neighbor_end(container, metric, target);
830 typename Ct::mode_type::node_ptr node = container.end().node->parent;
832 typename Metric::distance_type dist;
833 import::tie(node, dim, dist)
834 = lower_bound_neighbor(node, dim, container.rank(), container.key_comp(),
835 metric, target, bound);
840 template <
typename Ct,
typename Metric>
841 inline neighbor_iterator<const Ct, Metric>
844 typename Metric::distance_type bound)
846 if (container.empty())
return neighbor_end(container, metric, target);
847 typename Ct::mode_type::const_node_ptr node = container.end().node->parent;
849 typename Metric::distance_type dist;
850 import::tie(node, dim, dist)
851 = lower_bound_neighbor(node, dim, container.rank(), container.key_comp(),
852 metric, target, bound);
857 template <
typename Ct,
typename Metric>
858 inline neighbor_iterator<const Ct, Metric>
861 typename Metric::distance_type bound)
876 template <
typename Ct>
878 inline typename enable_if<details::is_compare_builtin<Ct>,
879 neighbor_iterator<Ct> >::type
892 template <
typename Ct>
893 inline typename enable_if<details::is_compare_builtin<Ct>,
894 neighbor_iterator<const Ct> >::type
907 template <
typename Ct>
908 inline typename enable_if<details::is_compare_builtin<Ct>,
909 neighbor_iterator<const Ct> >::type
933 template <
typename Ct,
typename Metric>
935 inline neighbor_iterator<Ct, Metric>
938 typename Metric::distance_type bound)
940 if (container.empty())
return neighbor_end(container, metric, target);
941 typename Ct::mode_type::node_ptr node = container.end().node->parent;
943 typename Metric::distance_type dist;
944 import::tie(node, dim, dist)
945 = upper_bound_neighbor(node, dim, container.rank(), container.key_comp(),
946 metric, target, bound);
951 template <
typename Ct,
typename Metric>
952 inline neighbor_iterator<const Ct, Metric>
955 typename Metric::distance_type bound)
957 if (container.empty())
return neighbor_end(container, metric, target);
958 typename Ct::mode_type::const_node_ptr node = container.end().node->parent;
960 typename Metric::distance_type dist;
961 import::tie(node, dim, dist)
962 = upper_bound_neighbor(node, dim, container.rank(), container.key_comp(),
963 metric, target, bound);
968 template <
typename Ct,
typename Metric>
969 inline neighbor_iterator<const Ct, Metric>
972 typename Metric::distance_type bound)
987 template <
typename Ct>
989 inline typename enable_if<details::is_compare_builtin<Ct>,
990 neighbor_iterator<Ct> >::type
1003 template <
typename Ct>
1004 inline typename enable_if<details::is_compare_builtin<Ct>,
1005 neighbor_iterator<const Ct> >::type
1018 template <
typename Ct>
1019 inline typename enable_if<details::is_compare_builtin<Ct>,
1020 neighbor_iterator<const Ct> >::type
1043 template <
typename Ct,
typename Metric>
1045 inline neighbor_iterator_pair<Ct, Metric>
1054 template <
typename Ct,
typename Metric>
1055 inline neighbor_iterator_pair<const Ct, Metric>
1064 template <
typename Ct,
typename Metric>
1065 inline neighbor_iterator_pair<const Ct, Metric>
1085 template <
typename Ct>
1087 inline typename enable_if<details::is_compare_builtin<Ct>,
1088 neighbor_iterator_pair<Ct> >::type
1096 template <
typename Ct>
1097 inline typename enable_if<details::is_compare_builtin<Ct>,
1098 neighbor_iterator_pair<const Ct> >::type
1106 template <
typename Ct>
1107 inline typename enable_if<details::is_compare_builtin<Ct>,
1108 neighbor_iterator_pair<const Ct> >::type
1119 template <
typename NodePtr,
typename Rank,
typename KeyCompare,
1120 typename Key,
typename Metric>
1122 typename Metric::distance_type>
1124 KeyCompare key_comp,
const Metric& met,
const Key& target,
1125 typename Metric::distance_type best_dist)
1127 SPATIAL_ASSERT_CHECK(dim < rank());
1128 SPATIAL_ASSERT_CHECK(!
header(node));
1129 SPATIAL_ASSERT_CHECK(node != 0);
1140 NodePtr best = node->parent;
1141 dimension_type best_dim = 0;
1144 typename Metric::distance_type test_dist
1145 = met.distance_to_key(rank(), target,
const_key(node));
1146 if (test_dist >= best_dist)
1150 best_dist = test_dist;
1153 import::tie(near, far) = key_comp(dim,
const_key(node), target)
1154 ? import::make_tuple(node->right, node->left)
1155 : import::make_tuple(node->left, node->right);
1158 dimension_type child_dim =
incr_dim(rank, dim);
1162 typename Metric::distance_type>
1164 key_comp, met, target,
1166 if (import::get<0>(triplet) != node)
1167 { import::tie(best, best_dim, best_dist) = triplet; }
1169 node = far; dim = child_dim;
1172 { node = near; dim =
incr_dim(rank, dim); }
1174 {
return import::make_tuple(best, best_dim, best_dist); }
1178 template <
typename NodePtr,
typename Rank,
typename KeyCompare,
1179 typename Key,
typename Metric>
1181 typename Metric::distance_type>
1183 KeyCompare key_comp,
const Metric& met,
const Key& target)
1186 typename Metric::distance_type());
1189 template <
typename NodePtr,
typename Rank,
typename KeyCompare,
1190 typename Key,
typename Metric>
1192 typename Metric::distance_type>
1194 const KeyCompare& key_comp,
const Metric& met,
1196 typename Metric::distance_type best_dist)
1198 SPATIAL_ASSERT_CHECK(dim < rank());
1199 SPATIAL_ASSERT_CHECK(node != 0);
1200 SPATIAL_ASSERT_CHECK(!
header(node));
1202 NodePtr best = node->parent;
1203 dimension_type best_dim = 0;
1206 typename Metric::distance_type test_dist
1207 = met.distance_to_key(rank(), target,
const_key(node));
1208 if (test_dist < best_dist)
1212 best_dist = test_dist;
1215 import::tie(near, far) = key_comp(dim,
const_key(node), target)
1216 ? import::make_tuple(node->right, node->left)
1217 : import::make_tuple(node->left, node->right);
1218 if (far != 0 && (met.distance_to_plane
1219 (rank(), dim, target,
const_key(node)) < best_dist))
1221 dimension_type child_dim =
incr_dim(rank, dim);
1225 typename Metric::distance_type>
1227 key_comp, met, target,
1229 if (import::get<0>(triplet) != node)
1232 if (!(met.distance_to_plane
1234 < import::get<2>(triplet)))
1236 import::tie(best, best_dim, best_dist) = triplet;
1239 node = far; dim = child_dim;
1242 { node = near; dim =
incr_dim(rank, dim); }
1244 {
return import::make_tuple(best, best_dim, best_dist); }
1248 template <
typename NodePtr,
typename Rank,
typename KeyCompare,
1249 typename Key,
typename Metric>
1251 typename Metric::distance_type>
1253 const KeyCompare& key_comp,
const Metric& met,
const Key& target)
1256 (node, dim, rank, key_comp, met, target,
1257 (std::numeric_limits<typename Metric::distance_type>::max)());
1260 template <
typename NodePtr,
typename Rank,
typename KeyCompare,
1261 typename Key,
typename Metric>
1263 typename Metric::distance_type>
1265 KeyCompare key_comp,
const Metric& met,
1267 typename Metric::distance_type bound,
1268 typename Metric::distance_type best_dist)
1271 SPATIAL_ASSERT_CHECK(dim < rank());
1272 SPATIAL_ASSERT_CHECK(node != 0);
1273 SPATIAL_ASSERT_CHECK(!
header(node));
1274 NodePtr best = node->parent;
1275 dimension_type best_dim =
decr_dim(rank, dim);
1278 typename Metric::distance_type test_dist
1279 = met.distance_to_key(rank(), target,
const_key(node));
1280 if (test_dist > bound)
1282 if (test_dist < best_dist)
1286 best_dist = test_dist;
1289 else if (test_dist == bound)
1290 {
return import::make_tuple(node, dim, test_dist); }
1292 import::tie(near, far) = key_comp(dim,
const_key(node), target)
1293 ? import::make_tuple(node->right, node->left)
1294 : import::make_tuple(node->left, node->right);
1295 if (far != 0 && (met.distance_to_plane
1296 (rank(), dim, target,
const_key(node)) < best_dist))
1298 dimension_type child_dim =
incr_dim(rank, dim);
1302 typename Metric::distance_type>
1304 key_comp, met, target,
1306 if (import::get<0>(triplet) != node)
1308 if (import::get<2>(triplet) == bound
1310 || !(met.distance_to_plane
1312 < import::get<2>(triplet)))
1314 import::tie(best, best_dim, best_dist) = triplet;
1317 node = far; dim = child_dim;
1320 { node = near; dim =
incr_dim(rank, dim); }
1322 {
return import::make_tuple(best, best_dim, best_dist); }
1326 template <
typename NodePtr,
typename Rank,
typename KeyCompare,
1327 typename Key,
typename Metric>
1329 typename Metric::distance_type>
1331 KeyCompare key_comp,
const Metric& met,
1333 typename Metric::distance_type bound)
1336 (node, dim, rank, key_comp, met, target, bound,
1337 (std::numeric_limits<typename Metric::distance_type>::max)());
1340 template <
typename NodePtr,
typename Rank,
typename KeyCompare,
1341 typename Key,
typename Metric>
1343 typename Metric::distance_type>
1345 KeyCompare key_comp, Metric met,
const Key& target,
1346 typename Metric::distance_type bound,
1347 typename Metric::distance_type best_dist)
1349 SPATIAL_ASSERT_CHECK(dim < rank());
1350 SPATIAL_ASSERT_CHECK(node != 0);
1351 SPATIAL_ASSERT_CHECK(!
header(node));
1353 NodePtr best = node->parent;
1354 dimension_type best_dim =
decr_dim(rank, dim);
1357 typename Metric::distance_type test_dist
1358 = met.distance_to_key(rank(), target,
const_key(node));
1359 if (test_dist > bound && test_dist < best_dist)
1363 best_dist = test_dist;
1366 import::tie(near, far) = key_comp(dim,
const_key(node), target)
1367 ? import::make_tuple(node->right, node->left)
1368 : import::make_tuple(node->left, node->right);
1369 if (far != 0 && (met.distance_to_plane
1370 (rank(), dim, target,
const_key(node)) < best_dist))
1372 dimension_type child_dim =
incr_dim(rank, dim);
1376 typename Metric::distance_type>
1378 key_comp, met, target,
1380 if (import::get<0>(triplet) != node)
1383 if (!(met.distance_to_plane
1385 < import::get<2>(triplet)))
1387 import::tie(best, best_dim, best_dist) = triplet;
1390 node = far; dim = child_dim;
1393 { node = near; dim =
incr_dim(rank, dim); }
1395 {
return import::make_tuple(best, best_dim, best_dist); }
1399 template <
typename NodePtr,
typename Rank,
typename KeyCompare,
1400 typename Key,
typename Metric>
1402 typename Metric::distance_type>
1404 KeyCompare key_comp,
const Metric& met,
1406 typename Metric::distance_type bound)
1409 (node, dim, rank, key_comp, met, target, bound,
1410 (std::numeric_limits<typename Metric::distance_type>::max)());
1413 template <
typename NodePtr,
typename Rank,
typename KeyCompare,
1414 typename Key,
typename Metric>
1416 typename Metric::distance_type>
1418 KeyCompare key_comp,
const Metric& met,
1420 typename Metric::distance_type node_dist)
1422 SPATIAL_ASSERT_CHECK(dim < rank());
1423 SPATIAL_ASSERT_CHECK(!
header(node));
1424 SPATIAL_ASSERT_CHECK(node != 0);
1425 NodePtr orig = node;
1426 dimension_type orig_dim = dim;
1428 dimension_type best_dim = dim;
1429 typename Metric::distance_type best_dist = node_dist;
1436 import::tie(near, far) = key_comp(dim,
const_key(node), target)
1437 ? import::make_tuple(node->right, node->left)
1438 : import::make_tuple(node->left, node->right);
1440 { node = near; dim =
incr_dim(rank, dim); }
1443 || met.distance_to_plane
1444 (rank(), dim, target,
const_key(node)) < best_dist))
1445 { node = far; dim =
incr_dim(rank, dim); }
1448 NodePtr prev_node = node;
1449 node = node->parent; dim =
decr_dim(rank, dim);
1452 == (far = key_comp(dim,
const_key(node), target)
1453 ? node->left : node->right)
1456 || (met.distance_to_plane
1461 node = node->parent; dim =
decr_dim(rank, dim);
1464 { node = far; dim =
incr_dim(rank, dim); }
1468 typename Metric::distance_type test_dist
1469 = met.distance_to_key(rank(), target,
const_key(node));
1470 if (test_dist == node_dist)
1472 SPATIAL_ASSERT_CHECK(dim < rank());
1473 SPATIAL_ASSERT_CHECK(best == 0 || test_dist < best_dist);
1474 return import::make_tuple(node, dim, test_dist);
1476 else if (test_dist > node_dist
1477 && (best == 0 || test_dist < best_dist))
1481 best_dist = test_dist;
1486 NodePtr prev_node = orig;
1487 dimension_type prev_dim = orig_dim;
1488 node = orig->parent;
1493 import::tie(near, far) = key_comp(dim,
const_key(node), target)
1494 ? import::make_tuple(node->right, node->left)
1495 : import::make_tuple(node->left, node->right);
1496 if (far == prev_node && near != 0)
1502 import::tie(near, far) = key_comp(dim,
const_key(node), target)
1503 ? import::make_tuple(node->right, node->left)
1504 : import::make_tuple(node->left, node->right);
1507 || (met.distance_to_plane(rank(), dim, target,
1510 { node = far; dim =
incr_dim(rank, dim); }
1512 { node = near; dim =
incr_dim(rank, dim); }
1517 typename Metric::distance_type test_dist
1518 = met.distance_to_key(rank(), target,
const_key(node));
1519 if (test_dist > node_dist && (best == 0 || test_dist <= best_dist))
1523 best_dist = test_dist;
1527 node = node->parent;
1530 SPATIAL_ASSERT_CHECK(dim < rank());
1531 SPATIAL_ASSERT_CHECK(node != 0);
1532 if (best != 0) { node = best; dim = best_dim; }
1533 return import::make_tuple(node, dim, best_dist);
1536 template <
typename NodePtr,
typename Rank,
typename KeyCompare,
1537 typename Key,
typename Metric>
1539 typename Metric::distance_type>
1541 KeyCompare key_comp,
const Metric& met,
1543 typename Metric::distance_type node_dist)
1546 {
return last_neighbor(node->parent, 0, rank, key_comp, met, target); }
1547 SPATIAL_ASSERT_CHECK(dim < rank());
1548 SPATIAL_ASSERT_CHECK(node != 0);
1549 NodePtr orig = node;
1550 dimension_type orig_dim = dim;
1552 dimension_type best_dim = dim;
1553 typename Metric::distance_type best_dist = node_dist;
1557 NodePtr prev_node = node;
1558 dimension_type prev_dim = dim;
1559 node = node->parent;
1564 import::tie(near, far) = key_comp(dim,
const_key(node), target)
1565 ? import::make_tuple(node->right, node->left)
1566 : import::make_tuple(node->left, node->right);
1567 if (prev_node == far && near != 0)
1573 import::tie(near, far) = key_comp(dim,
const_key(node), target)
1574 ? import::make_tuple(node->right, node->left)
1575 : import::make_tuple(node->left, node->right);
1577 && (met.distance_to_plane(rank(), dim, target,
1580 { node = far; dim =
incr_dim(rank, dim); }
1582 { node = near; dim =
incr_dim(rank, dim); }
1587 typename Metric::distance_type test_dist
1588 = met.distance_to_key(rank(), target,
const_key(node));
1589 if (test_dist == node_dist)
1591 SPATIAL_ASSERT_CHECK(dim < rank());
1592 SPATIAL_ASSERT_CHECK(best == 0 || test_dist > best_dist);
1593 return import::make_tuple(node, dim, test_dist);
1595 else if (test_dist < node_dist
1596 && (best == 0 || test_dist > best_dist))
1600 best_dist = test_dist;
1604 node = node->parent;
1614 import::tie(near, far) = key_comp(dim,
const_key(node), target)
1615 ? import::make_tuple(node->right, node->left)
1616 : import::make_tuple(node->left, node->right);
1618 { node = near; dim =
incr_dim(rank, dim); }
1620 && (met.distance_to_plane(rank(), dim, target,
1623 { node = far; dim =
incr_dim(rank, dim); }
1627 node = node->parent; dim =
decr_dim(rank, dim);
1630 == (far = key_comp(dim,
const_key(node), target)
1631 ? node->left : node->right)
1633 || !(met.distance_to_plane(rank(), dim, target,
1638 node = node->parent; dim =
decr_dim(rank, dim);
1641 { node = far; dim =
incr_dim(rank, dim); }
1644 typename Metric::distance_type test_dist
1645 = met.distance_to_key(rank(), target,
const_key(node));
1646 if (test_dist < node_dist && (best == 0 || test_dist >= best_dist))
1650 best_dist = test_dist;
1653 SPATIAL_ASSERT_CHECK(dim < rank());
1654 SPATIAL_ASSERT_CHECK(node != 0);
1655 if (best != 0) { node = best; dim = best_dim; }
1656 return import::make_tuple(node, dim, best_dist);
1662 #endif // SPATIAL_NEIGHBOR_HPP
neighbor_iterator_pair()
Empty constructor.
key_type & target_key()
Read/write accessor to the target of the iterator.
neighbor_iterator_pair()
Empty constructor.
std::pair< neighbor_iterator< Ct, Metric >, neighbor_iterator< Ct, Metric > > Base
A pair of iterators that represents a range (that is: a range of elements to iterate, and not an orthogonal range).
Metric::distance_type distance(const neighbor_iterator< Ct, Metric > &iter)
Read/write accessor for neighbor iterators that retrieve the valid calculated distance from the targe...
import::tuple< NodePtr, dimension_type, typename Metric::distance_type > last_neighbor(NodePtr node, dimension_type dim, Rank rank, KeyCompare key_comp, const Metric &met, const Key &target)
This structure defines a pair of constant neighbor iterator.
container_traits< Ct >::key_type key_type
The key type that is used as a target for the nearest neighbor search.
import::tuple< NodePtr, dimension_type, typename Metric::distance_type > increment_neighbor(NodePtr node, dimension_type dim, Rank rank, KeyCompare key_comp, const Metric &met, const Key &target, typename Metric::distance_type node_dist)
neighbor_iterator_pair(const neighbor_iterator_pair< Ct, Metric > &p)
Convert a mutable neighbor iterator pair into a const neighbor iterator pair.
details::Const_bidirectional_iterator< typename container_traits< Ct >::mode_type, typename container_traits< Ct >::rank_type > Base
neighbor_iterator< const Ct, Metric > neighbor_clower_bound(const Ct &container, const Metric &metric, const typename container_traits< Ct >::key_type &target, typename Metric::distance_type bound)
Build a neighbor_iterator pointing to the neighbor closest to target but for which distance to target...
neighbor_iterator< const Ct, Metric > operator++(int)
Increments the iterator but returns the value of the iterator before the increment.
const container_traits< Ct >::key_type & target_key(const neighbor_iterator< Ct, Metric > &iter)
A quick accessor for neighbor iterators that retrive the key that is the target for the nearest neigh...
const rank_type & rank() const
Return the current Rank type used by the iterator.
details::Neighbor_data< Ct, Metric > _data
The related data for the iterator.
neighbor_iterator< const Ct, Metric > operator--(int)
Decrements the iterator but returns the value of the iterator before the decrement.
node_ptr node
The pointer to the current node.
key_compare key_comp() const
Return the key_comparator used by the iterator.
Tp::key_compare key_compare
Comparison functor used to compare two instances of key_type.
key_compare key_comp() const
Return the key_comparator used by the iterator.
dimension_type dimension() const
Return the number of dimensions stored by the Rank of the iterator.
details::Bidirectional_iterator< typename container_traits< Ct >::mode_type, typename container_traits< Ct >::rank_type > Base
import::tuple< NodePtr, dimension_type, typename Metric::distance_type > last_neighbor_sub(NodePtr node, dimension_type dim, Rank rank, KeyCompare key_comp, const Metric &met, const Key &target, typename Metric::distance_type best_dist)
Metric metric_type
The metric type used by the iterator.
const distance_type & distance() const
Read-only accessor to the last valid distance of the iterator.
container_traits< Ct >::key_compare key_compare
Key comparator type transferred from the container.
details::Neighbor_data< Ct, Metric > _data
The related data for the iterator.
neighbor_iterator< const Ct, Metric > & operator--()
Decrements the iterator and returns the decremented value.
neighbor_iterator(const neighbor_iterator< Ct, Metric > &iter)
Convertion of mutable iterator into a constant iterator.
neighbor_iterator_pair< Ct, Metric > neighbor_range(Ct &container, const Metric &metric, const typename container_traits< Ct >::key_type &target)
Returns a neighbor_iterator_pair representing the range of values from the closest to the furthest in...
Metric::distance_type distance_type
The distance type that is read from metric_type.
container_traits< Ct >::key_compare key_compare
Key comparator type transferred from the container.
neighbor_iterator< const Ct, Metric > neighbor_cend(const Ct &container, const Metric &metric, const typename container_traits< Ct >::key_type &target)
Build a past-the-end neighbor iterator with a user-defined Metric.
Ct::key_type key_type
The type representing the key managed by the container.
const Kdtree_link< Value, Value >::key_type & const_key(const Node< Kdtree_link< Value, Value > > *node)
This function converts a pointer on a node into a key for a Kdtree_link type.
neighbor_iterator< Ct, Metric > & operator--()
Decrements the iterator and returns the decremented value.
metric_type metric() const
Return the metric used by the iterator.
dimension_type node_dim
The dimension of the current node.
Metric::distance_type _distance
The last valid computed value of the distance.
bool header(const Node< Link > *x)
Check if node is a header node.
neighbor_iterator_pair(const neighbor_iterator< Ct, Metric > &a, const neighbor_iterator< Ct, Metric > &b)
Regular constructor that builds a neighbor_iterator_pair out of 2 neighbor_iterators.
Neighbor_data()
Build an unintialized neighbor data object.
neighbor_iterator< Ct, Metric > neighbor_lower_bound(Ct &container, const Metric &metric, const typename container_traits< Ct >::key_type &target, typename Metric::distance_type bound)
Build a neighbor_iterator pointing to the neighbor closest to target but for which distance to target...
neighbor_iterator< Ct, Metric > neighbor_end(Ct &container, const Metric &metric, const typename container_traits< Ct >::key_type &target)
Build a past-the-end neighbor iterator with a user-defined Metric.
A spatial iterator for a container Ct that goes through the nearest to the furthest element from a ta...
key_type & target_key()
Read/write accessor to the target of the iterator.
neighbor_iterator< Ct, Metric > & operator++()
Increments the iterator and returns the incremented value.
neighbor_iterator_pair< const Ct, Metric > neighbor_crange(const Ct &container, const Metric &metric, const typename container_traits< Ct >::key_type &target)
Returns a neighbor_iterator_pair representing the range of values from the closest to the furthest in...
The traits type for all containers in the spatial namespace.
std::size_t dimension_type
Defines the type for the dimension as being a size.
neighbor_iterator< const Ct, Metric > neighbor_cbegin(const Ct &container, const Metric &metric, const typename container_traits< Ct >::key_type &target)
Build a neighbor_iterator pointing to the nearest neighbor of target using a user-defined Metric...
neighbor_iterator< Ct, Metric > operator++(int)
Increments the iterator but returns the value of the iterator before the increment.
import::tuple< NodePtr, dimension_type, typename Metric::distance_type > first_neighbor_sub(NodePtr node, dimension_type dim, Rank rank, const KeyCompare &key_comp, const Metric &met, const Key &target, typename Metric::distance_type best_dist)
const key_type & target_key() const
Read-only accessor to the target of the iterator.
Metric metric_type
The metric type used by the iterator.
neighbor_iterator()
Uninitialized iterator.
This structure defines a pair of neighbor iterator.
Defines a metric working on the Euclidian space where distances are expressed in one of C++'s floatin...
neighbor_iterator< const Ct, Metric > & operator++()
Increments the iterator and returns the incremented value.
A spatial iterator for a container Ct that goes through the nearest to the furthest element from a ta...
neighbor_iterator_pair(const neighbor_iterator< const Ct, Metric > &a, const neighbor_iterator< const Ct, Metric > &b)
Regular constructor that builds a neighbor_iterator_pair out of 2 neighbor_iterators.
Uses the empty base class optimization in order to compress a potentially empty base class with a mem...
Extra information needed by the iterator to perform its work.
Compress< Metric, typename container_traits< Ct >::key_type > _target
The target of the iteration; element of the container are iterate from the closest to the element fur...
neighbor_iterator< Ct, Metric > neighbor_upper_bound(Ct &container, const Metric &metric, const typename container_traits< Ct >::key_type &target, typename Metric::distance_type bound)
Build a neighbor_iterator pointing to the neighbor closest to target but for which distance to target...
distance_type distance() const
Read-only accessor to the last valid distance of the iterator.
The main namespace used in the library.
container_traits< Ct >::key_type key_type
The key type that is used as a target for the nearest neighbor search.
import::tuple< NodePtr, dimension_type, typename Metric::distance_type > first_neighbor(NodePtr node, dimension_type dim, Rank rank, const KeyCompare &key_comp, const Metric &met, const Key &target)
distance_type & distance()
Read/write accessor to the last valid distance of the iterator.
neighbor_iterator< Ct, Metric > operator--(int)
Decrements the iterator but returns the value of the iterator before the decrement.
neighbor_iterator()
Constructs an empty, uninitialized object.
dimension_type decr_dim(Rank rank, dimension_type node_dim)
Decrement dimension node_dim, given rank.
const key_type & target_key() const
Read-only accessor to the target of the iterator.
import::tuple< NodePtr, dimension_type, typename Metric::distance_type > lower_bound_neighbor_sub(NodePtr node, dimension_type dim, Rank rank, KeyCompare key_comp, const Metric &met, const Key &target, typename Metric::distance_type bound, typename Metric::distance_type best_dist)
Metric::distance_type distance_type
The distance type that is read from metric_type.
import::tuple< NodePtr, dimension_type, typename Metric::distance_type > upper_bound_neighbor_sub(NodePtr node, dimension_type dim, Rank rank, KeyCompare key_comp, Metric met, const Key &target, typename Metric::distance_type bound, typename Metric::distance_type best_dist)
distance_type & distance()
Read/write accessor to the last valid distance of the iterator.
A common template for constant bidirectional iterators that work on identical modes of linking...
neighbor_iterator< Ct, Metric > neighbor_begin(Ct &container, const Metric &metric, const typename container_traits< Ct >::key_type &target)
Build a neighbor_iterator pointing to the nearest neighbor of target using a user-defined Metric...
import::tuple< NodePtr, dimension_type, typename Metric::distance_type > lower_bound_neighbor(NodePtr node, dimension_type dim, Rank rank, KeyCompare key_comp, const Metric &met, const Key &target, typename Metric::distance_type bound)
neighbor_iterator< const Ct, Metric > neighbor_cupper_bound(const Ct &container, const Metric &metric, const typename container_traits< Ct >::key_type &target, typename Metric::distance_type bound)
Build a neighbor_iterator pointing to the neighbor closest to target but for which distance to target...
import::tuple< NodePtr, dimension_type, typename Metric::distance_type > upper_bound_neighbor(NodePtr node, dimension_type dim, Rank rank, KeyCompare key_comp, const Metric &met, const Key &target, typename Metric::distance_type bound)
A common template for bidirectional iterators that work on identical modes of linking.
The generic helper class to determine if a container uses a built-in compare type.
import::tuple< NodePtr, dimension_type, typename Metric::distance_type > decrement_neighbor(NodePtr node, dimension_type dim, Rank rank, KeyCompare key_comp, const Metric &met, const Key &target, typename Metric::distance_type node_dist)
metric_type metric() const
Return the metric used by the iterator.
std::pair< neighbor_iterator< const Ct, Metric >, neighbor_iterator< const Ct, Metric > > Base
A pair of iterators that represents a range (that is: a range of elements to iterate, and not an orthogonal range).
dimension_type incr_dim(Rank rank, dimension_type node_dim)
Increment dimension node_dim, given rank.