13 #ifndef SPATIAL_MAPPING_ITERATOR_HPP
14 #define SPATIAL_MAPPING_ITERATOR_HPP
17 #include "spatial.hpp"
19 #include "bits/spatial_bidirectional.hpp"
20 #include "bits/spatial_rank.hpp"
21 #include "bits/spatial_except.hpp"
22 #include "bits/spatial_assign.hpp"
23 #include "bits/spatial_mapping.hpp"
41 template <
typename Container>
59 typename Container::key_compare
key_comp()
const
60 {
return static_cast<typename Container::key_compare
>(*this); }
95 <typename container_traits<Ct>::mode_type,
96 typename container_traits<Ct>::rank_type>
154 : Base(container.
rank(), ptr, dim),
247 template<
typename Ct>
250 <typename container_traits<Ct>::mode_type,
251 typename container_traits<Ct>::rank_type>
313 :
Base(container.rank(), ptr, dim),
314 _data(container.key_comp(), mapping_dim)
400 template <
typename Container>
410 template <
typename Container>
441 template <
typename Container>
443 inline mapping_iterator<Container>
448 (container, mapping_dim, container.dimension() - 1,
449 container.end().node);
452 template <
typename Container>
453 inline mapping_iterator<const Container>
478 template <
typename Container>
480 inline mapping_iterator<Container>
483 if (container.empty())
return mapping_end(container, mapping_dim);
486 = container.end().node->parent;
489 minimum_mapping(node, 0,
490 container.rank(), mapping_dim,
491 container.key_comp()));
495 template <
typename Container>
496 inline mapping_iterator<const Container>
507 template <
typename Ct>
509 : std::pair<mapping_iterator<Ct>, mapping_iterator<Ct> >
532 template <
typename Ct>
534 : std::pair<mapping_iterator<const Ct>, mapping_iterator<const Ct> >
555 : Base(p.first, p.second) { }
594 template <
typename Container>
595 inline mapping_iterator_pair<Container>
634 template <
typename Container>
635 inline mapping_iterator_pair<const Container>
643 template <
typename Container>
644 inline mapping_iterator_pair<const Container>
677 template <
typename Container>
679 inline mapping_iterator<Container>
684 if (container.empty())
return mapping_end(container, mapping_dim);
687 = container.end().node->parent;
690 lower_bound_mapping(node, 0, container.rank(), mapping_dim,
691 container.key_comp(), bound));
695 template <
typename Container>
696 inline mapping_iterator<const Container>
727 template <
typename Container>
729 inline mapping_iterator<Container>
734 if (container.empty())
return mapping_end(container, mapping_dim);
737 = container.end().node->parent;
740 upper_bound_mapping(node, 0, container.rank(), mapping_dim,
741 container.key_comp(), bound));
745 template <
typename Container>
746 inline mapping_iterator<const Container>
759 template <
typename KeyCompare,
typename Key>
765 {
return key_comp(map, x, y); }
767 template <
typename KeyCompare,
typename Key>
772 {
return !key_comp(map, y, x); }
800 template <
typename NodePtr,
typename Rank,
typename KeyCompare>
801 inline std::pair<NodePtr, dimension_type>
806 SPATIAL_ASSERT_CHECK(dim < rank());
807 SPATIAL_ASSERT_CHECK(!
header(node));
817 && (dim != map || best == 0
820 node = node->right; dim =
incr_dim(rank, dim);
821 while (node->left != 0
826 { node = node->left; dim =
incr_dim(rank, dim); }
830 NodePtr prev_node = node;
831 node = node->parent; dim =
decr_dim(rank, dim);
833 && prev_node == node->right)
836 node = node->parent; dim =
decr_dim(rank, dim);
843 { best = node; best_dim = dim; }
847 SPATIAL_ASSERT_CHECK(dim < rank());
848 SPATIAL_ASSERT_CHECK(!
header(node));
849 return std::make_pair(node, dim);
852 SPATIAL_ASSERT_CHECK(dim == rank() - 1);
853 SPATIAL_ASSERT_CHECK(
header(node));
863 node = node->left; dim =
incr_dim(rank, dim);
864 while (node->right != 0
865 && (dim != map || best == 0
867 { node = node->right; dim =
incr_dim(rank, dim); }
871 NodePtr prev_node = node;
872 node = node->parent; dim =
decr_dim(rank, dim);
874 && prev_node == node->left)
877 node = node->parent; dim =
decr_dim(rank, dim);
884 { best = node; best_dim = dim; }
887 { node = best; dim = best_dim; }
888 SPATIAL_ASSERT_CHECK(dim < rank());
889 SPATIAL_ASSERT_CHECK((best == 0 &&
header(node))
890 || (best != 0 && !
header(node)));
891 return std::make_pair(node, dim);
922 template <
typename NodePtr,
typename Rank,
typename KeyCompare>
923 inline std::pair<NodePtr, dimension_type>
928 SPATIAL_ASSERT_CHECK(dim < rank());
940 && (dim != map || best == 0
943 node = node->left; dim =
incr_dim(rank, dim);
944 while (node->right != 0
947 { node = node->right; dim =
incr_dim(rank, dim); }
951 NodePtr prev_node = node;
952 node = node->parent; dim =
decr_dim(rank, dim);
954 && prev_node == node->left)
957 node = node->parent; dim =
decr_dim(rank, dim);
964 { best = node; best_dim = dim; }
968 SPATIAL_ASSERT_CHECK(dim < rank());
969 SPATIAL_ASSERT_CHECK(!
header(node));
970 return std::make_pair(node, dim);
973 SPATIAL_ASSERT_CHECK(dim == rank() - 1);
974 SPATIAL_ASSERT_CHECK(
header(node));
984 node = node->right; dim =
incr_dim(rank, dim);
985 while (node->left != 0
986 && (dim != map || best == 0
988 { node = node->left; dim =
incr_dim(rank, dim); }
992 NodePtr prev_node = node;
993 node = node->parent; dim =
decr_dim(rank, dim);
995 && prev_node == node->right)
998 node = node->parent; dim =
decr_dim(rank, dim);
1005 { best = node; best_dim = dim; }
1008 { node = best; dim = best_dim; }
1009 SPATIAL_ASSERT_CHECK(dim < rank());
1010 SPATIAL_ASSERT_CHECK((best == 0 &&
header(node))
1011 || (best != 0 && !
header(node)));
1012 return std::make_pair(node, dim);
1043 template <
typename NodePtr,
typename Rank,
typename KeyCompare,
1045 inline std::pair<NodePtr, dimension_type>
1048 KeyCompare key_comp,
const KeyType& bound)
1050 SPATIAL_ASSERT_CHECK(map < rank());
1051 SPATIAL_ASSERT_CHECK(dim < rank());
1052 SPATIAL_ASSERT_CHECK(!
header(node));
1053 while (node->left != 0
1057 { node = node->left; dim =
incr_dim(rank, dim); }
1060 if (!key_comp(map,
const_key(node), bound))
1061 { best = node; best_dim = dim; }
1064 if (node->right != 0 && (dim != map || best == 0))
1068 while (node->left != 0
1073 { node = node->left; dim =
incr_dim(rank, dim); }
1077 NodePtr prev_node = node;
1078 node = node->parent;
1081 && prev_node == node->right)
1084 node = node->parent; dim =
decr_dim(rank, dim);
1088 if (!key_comp(map,
const_key(node), bound)
1090 { best = node; best_dim = dim; }
1092 SPATIAL_ASSERT_CHECK(dim == rank() - 1);
1093 SPATIAL_ASSERT_CHECK(best != node);
1094 SPATIAL_ASSERT_CHECK(
header(node));
1096 { best = node; best_dim = dim; }
1097 return std::make_pair(best, best_dim);
1128 template <
typename NodePtr,
typename Rank,
typename KeyCompare,
1130 inline std::pair<NodePtr, dimension_type>
1133 KeyCompare key_comp,
const KeyType& bound)
1135 SPATIAL_ASSERT_CHECK(map < rank());
1136 SPATIAL_ASSERT_CHECK(dim < rank());
1137 SPATIAL_ASSERT_CHECK(!
header(node));
1138 while (node->left != 0
1140 || key_comp(map, bound,
const_key(node))))
1141 { node = node->left; dim =
incr_dim(rank, dim); }
1144 if (key_comp(map, bound,
const_key(node)))
1145 { best = node; best_dim = dim; }
1148 if (node->right != 0 && (dim != map || best == 0))
1152 while (node->left != 0
1154 || key_comp(map, bound,
const_key(node))))
1155 { node = node->left; dim =
incr_dim(rank, dim); }
1159 NodePtr prev_node = node;
1160 node = node->parent;
1163 && prev_node == node->right)
1166 node = node->parent; dim =
decr_dim(rank, dim);
1170 if (key_comp(map, bound,
const_key(node))
1172 { best = node; best_dim = dim; }
1174 SPATIAL_ASSERT_CHECK(dim == rank() - 1);
1175 SPATIAL_ASSERT_CHECK(best != node);
1176 SPATIAL_ASSERT_CHECK(
header(node));
1178 { best = node; best_dim = dim; }
1179 return std::make_pair(best, best_dim);
1185 #endif // SPATIAL_MAPPING_ITERATOR_HPP
details::Mapping< Ct > _data
The related data for the iterator.
details::Mapping< Ct > _data
The related data for the iterator.
dimension_type mapping_dimension() const
Accessor to the mapping dimension used by the iterator.
mapping_iterator< const Container > mapping_clower_bound(const Container &container, dimension_type mapping_dim, const typename container_traits< Container >::key_type &bound)
Finds the value with the smallest coordinate along the mapping dimension that is greater or equal to ...
mapping_iterator(Ct &container, dimension_type mapping_dim, dimension_type dim, typename container_traits< Ct >::mode_type::node_ptr ptr)
When the information of the dimension for the current node being pointed to by the iterator is known...
mapping_iterator_pair< Container > mapping_range(Container &container, dimension_type mapping_dim)
Returns a pair of iterator on the first and the last value in the range that can be iterated...
container_traits< Ct >::key_compare key_compare
mapping_iterator(const Ct &container, dimension_type mapping_dim, typename container_traits< Ct >::const_iterator iter)
The standard way to build this iterator: specify a mapping dimension, an iterator on a container...
mapping_iterator< Container > mapping_upper_bound(Container &container, dimension_type mapping_dim, const typename container_traits< Container >::key_type &bound)
Finds the value with the largest coordinate along the mapping dimension that is stricly less than bou...
This structure defines a pair of mutable mapping iterator.
const rank_type & rank() const
Return the current Rank type used by the iterator.
dimension_type mapping_dim
The current dimension of iteration.
Link::invariant_category invariant_category(const Node< Link > *)
For a given node, this function returns the invariant category of the node.
std::pair< NodePtr, dimension_type > decrement_mapping(NodePtr node, dimension_type dim, Rank rank, dimension_type map, KeyCompare key_comp)
Move the pointer given in parameter to the previous element in the ordered iteration of values along ...
node_ptr node
The pointer to the current node.
mapping_iterator< Ct > operator--(int)
Decrements the iterator but returns the value of the iterator before the decrement.
void check_dimension(dimension_type rank, dimension_type dimension)
Checks that dimension is not greater or equal to rank.
This iterator walks through all items in the container in order from the lowest to the highest value ...
mapping_iterator< const Container > mapping_cupper_bound(const Container &container, dimension_type mapping_dim, const typename container_traits< Container >::key_type &bound)
Finds the value with the largest coordinate along the mapping dimension that is stricly less than bou...
dimension_type dimension() const
Return the number of dimensions stored by the Rank of the iterator.
std::pair< mapping_iterator< Ct >, mapping_iterator< Ct > > Base
A pair of iterators that represents a range (that is: a range of elements to iterate, and not an orthogonal range).
std::pair< mapping_iterator< const Ct >, mapping_iterator< const Ct > > Base
A pair of iterators that represents a range (that is: a range of elements to iterate, and not an orthogonal range).
mapping_iterator_pair< const Container > mapping_crange(const Container &container, dimension_type mapping_dim)
Returns a pair of constant iterator on the first and the last value in the range that can be iterated...
dimension_type mapping_dimension() const
Accessor to the mapping dimension used by the iterator.
mapping_iterator< Container > mapping_end(Container &container, dimension_type mapping_dim)
Finds the past-the-end position in container for this constant iterator.
key_compare key_comp() const
Return the key_comparator used by the iterator.
Tp::key_type key_type
The type representing the key managed by the container.
mapping_iterator< const Ct > & operator--()
Decrements the iterator and returns the decremented value.
container_traits< Ct >::key_compare key_compare
Alias for the key_compare type used by the iterator.
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.
mapping_iterator()
Build an uninitialized iterator.
dimension_type node_dim
The dimension of the current node.
bool header(const Node< Link > *x)
Check if node is a header node.
key_compare key_comp() const
Return the key_comparator used by the iterator.
Container::key_compare key_comp() const
std::pair< NodePtr, dimension_type > lower_bound_mapping(NodePtr node, dimension_type dim, Rank rank, dimension_type map, KeyCompare key_comp, const KeyType &bound)
Move the iterator given in parameter to the value with the smallest coordinate greater or equal to bo...
mapping_iterator_pair(const mapping_iterator_pair< Ct > &p)
Convert a mutable mapping iterator pair into a const mapping iterator pair.
details::Const_bidirectional_iterator< typename container_traits< Ct >::mode_type, typename container_traits< Ct >::rank_type > Base
mapping_iterator< const Container > mapping_cbegin(const Container &container, dimension_type mapping_dim)
Finds the value in container for which its key has the smallest coordinate over the dimension mapping...
mapping_iterator< Container > mapping_lower_bound(Container &container, dimension_type mapping_dim, const typename container_traits< Container >::key_type &bound)
Finds the value with the smallest coordinate along the mapping dimension that is greater or equal to ...
mapping_iterator< Ct > & operator++()
Increments the iterator and returns the incremented value.
mapping_iterator< const Ct > & operator++()
Increments the iterator and returns the incremented value.
mapping_iterator< Ct > & operator--()
Decrements the iterator and returns the decremented value.
The traits type for all containers in the spatial namespace.
container_traits< Ct >::mode_type::node_ptr node_ptr
The type for the node pointed to by the iterator.
std::size_t dimension_type
Defines the type for the dimension as being a size.
mapping_iterator_pair()
Empty constructor.
mapping_iterator< const Ct > operator--(int)
Decrements the iterator but returns the value of the iterator before the decrement.
dimension_type & mapping_dimension()
Accessor to the mapping dimension used by the iterator.
mapping_iterator_pair(const mapping_iterator< const Ct > &a, const mapping_iterator< const Ct > &b)
Regular constructor that builds a mapping_iterator_pair out of 2 mapping_iterators.
The category of invariants for a k-d tree node: strict or relaxed.
void assign(Type1 &first, Type2 &second, const std::pair< Type1, Type2 > &pair)
details::Bidirectional_iterator< typename container_traits< Ct >::mode_type, typename container_traits< Ct >::rank_type > Base
std::pair< NodePtr, dimension_type > maximum_mapping(NodePtr node, dimension_type dim, Rank rank, dimension_type map, KeyCompare key_comp)
Move the iterator given in parameter to the maximum value along the iterator's mapping dimension but ...
The main namespace used in the library.
std::pair< NodePtr, dimension_type > upper_bound_mapping(NodePtr node, dimension_type dim, Rank rank, dimension_type map, KeyCompare key_comp, const KeyType &bound)
Move the iterator given in parameter to the value with the largest coordinate strictly lower than bou...
dimension_type decr_dim(Rank rank, dimension_type node_dim)
Decrement dimension node_dim, given rank.
mapping_iterator_pair(const mapping_iterator< Ct > &a, const mapping_iterator< Ct > &b)
Regular constructor that builds a mapping_iterator_pair out of 2 mapping_iterators.
mapping_iterator(const mapping_iterator< Ct > &iter)
Convertion of mutable iterator into a constant iterator is permitted.
mapping_iterator(Ct &container, dimension_type mapping_dim, typename container_traits< Ct >::iterator iter)
The standard way to build this iterator: specify a mapping dimension, an iterator on a container...
A common template for constant bidirectional iterators that work on identical modes of linking...
std::pair< NodePtr, dimension_type > increment_mapping(NodePtr node, dimension_type dim, Rank rank, dimension_type map, KeyCompare key_comp)
Move the pointer given in parameter to the next element in the ordered iteration of values along the ...
A common template for bidirectional iterators that work on identical modes of linking.
bool left_compare_mapping(KeyCompare key_comp, dimension_type map, const Key &x, const Key &y, strict_invariant_tag)
This function provides a common interface for the two k-d tree invariants.
Mapping()
Build an uninitialized mapping data object.
Extra information needed by the iterator to perform its work.
mapping_iterator_pair()
Empty constructor.
mapping_iterator< const Ct > operator++(int)
Increments the iterator but returns the value of the iterator before the increment.
mapping_iterator< Container > mapping_begin(Container &container, dimension_type mapping_dim)
Finds the value in container for which its key has the smallest coordinate over the dimension mapping...
mapping_iterator()
Uninitialized iterator.
This iterator walks through all items in the container in order from the lowest to the highest value ...
mapping_iterator< Ct > operator++(int)
Increments the iterator but returns the value of the iterator before the increment.
dimension_type mapping_dimension(const mapping_iterator< Container > &it)
Return the mapping dimension of the iterator.
dimension_type & mapping_dimension()
Accessor to the mapping dimension used by the iterator.
dimension_type incr_dim(Rank rank, dimension_type node_dim)
Increment dimension node_dim, given rank.
mapping_iterator< const Container > mapping_cend(const Container &container, dimension_type mapping_dim)
Finds the past-the-end position in container for this constant iterator.