Spatial C++ Library
Generic Multi-Dimensional Containers and Spatial Operations
spatial::neighbor_iterator< Ct, Metric > Class Template Reference

A spatial iterator for a container Ct that goes through the nearest to the furthest element from a target key, with distances applied according to a user-defined geometric space that is a model of Metric. More...

#include <spatial_neighbor.hpp>

Inherits spatial::details::Bidirectional_iterator< container_traits< Ct >::mode_type, container_traits< Ct >::rank_type >.

Public Types

typedef container_traits< Ct >::key_compare key_compare
 Key comparator type transferred from the container. More...
 
typedef Metric metric_type
 The metric type used by the iterator. More...
 
typedef Metric::distance_type distance_type
 The distance type that is read from metric_type. More...
 
typedef container_traits< Ct >::key_type key_type
 The key type that is used as a target for the nearest neighbor search. More...
 
- Public Types inherited from spatial::details::Bidirectional_iterator< container_traits< Ct >::mode_type, container_traits< Ct >::rank_type >
typedef mutate< typename container_traits< Ct >::mode_type::value_type >::type value_type
 The value_type can receive a copy of the reference pointed to be the iterator. More...
 
typedef container_traits< Ct >::mode_type::value_type & reference
 The reference type of the object pointed to by the iterator. More...
 
typedef container_traits< Ct >::mode_type::value_type * pointer
 The pointer type of the object pointed to by the iterator. More...
 
typedef std::ptrdiff_t difference_type
 The difference_type returned by the distance between 2 iterators. More...
 
typedef std::bidirectional_iterator_tag iterator_category
 The iterator category that is always Bidirectional_iterator_tag. More...
 
typedef container_traits< Ct >::mode_type::node_ptr node_ptr
 The type for the node pointed to by the iterator. More...
 
typedef container_traits< Ct >::rank_type rank_type
 The type of rank used by the iterator. More...
 
typedef container_traits< Ct >::mode_type::invariant_category invariant_category
 The invariant category of the the iterator. More...
 

Public Member Functions

 neighbor_iterator ()
 Uninitialized iterator. More...
 
 neighbor_iterator (Ct &container_, const Metric &metric_, const typename container_traits< Ct >::key_type &target_, const typename container_traits< Ct >::iterator &iter_, typename Metric::distance_type distance_)
 The standard way to build this iterator: specify a metric to apply, an iterator on a container, and that container. More...
 
 neighbor_iterator (Ct &container_, const Metric &metric_, const typename container_traits< Ct >::key_type &target_, dimension_type node_dim_, typename container_traits< Ct >::mode_type::node_ptr node_, typename Metric::distance_type distance_)
 When the information of the dimension for the current node being pointed to by the iterator is known, this constructor saves some CPU cycle, by comparison to the other constructor. More...
 
 neighbor_iterator (const typename container_traits< Ct >::rank_type &rank_, const typename container_traits< Ct >::key_compare &key_comp_, const Metric &metric_, const typename container_traits< Ct >::key_type &target_, dimension_type node_dim_, typename container_traits< Ct >::mode_type::node_ptr node_, typename Metric::distance_type distance_)
 Build the iterator with a given rank and key compare functor, if the container is not available. More...
 
neighbor_iterator< Ct, Metric > & operator++ ()
 Increments the iterator and returns the incremented value. More...
 
neighbor_iterator< Ct, Metric > operator++ (int)
 Increments the iterator but returns the value of the iterator before the increment. More...
 
neighbor_iterator< Ct, Metric > & operator-- ()
 Decrements the iterator and returns the decremented value. More...
 
neighbor_iterator< Ct, Metric > operator-- (int)
 Decrements the iterator but returns the value of the iterator before the decrement. More...
 
key_compare key_comp () const
 Return the key_comparator used by the iterator. More...
 
metric_type metric () const
 Return the metric used by the iterator. More...
 
const distance_typedistance () const
 Read-only accessor to the last valid distance of the iterator. More...
 
distance_typedistance ()
 Read/write accessor to the last valid distance of the iterator. More...
 
const key_typetarget_key () const
 Read-only accessor to the target of the iterator. More...
 
key_typetarget_key ()
 Read/write accessor to the target of the iterator. More...
 
- Public Member Functions inherited from spatial::details::Bidirectional_iterator< container_traits< Ct >::mode_type, container_traits< Ct >::rank_type >
 Bidirectional_iterator ()
 Build an uninitialized iterator. More...
 
 Bidirectional_iterator (const container_traits< Ct >::rank_type &rank_, node_ptr node_, dimension_type node_dim_)
 Initialize the node at construction time. More...
 
reference operator* ()
 Returns the reference to the value pointed to by the iterator. More...
 
pointer operator-> ()
 Returns a pointer to the value pointed to by the iterator. More...
 
bool operator== (const Const_node_iterator< container_traits< Ct >::mode_type > &x) const
 A bidirectional iterator can be compared with a node iterator if they work on identical linking modes. More...
 
bool operator!= (const Const_node_iterator< container_traits< Ct >::mode_type > &x) const
 A bidirectional iterator can be compared for inequality with a node iterator if they work on identical linking modes. More...
 
const rank_typerank () const
 Return the current Rank type used by the iterator. More...
 
dimension_type dimension () const
 Return the number of dimensions stored by the Rank of the iterator. More...
 
 operator Node_iterator< container_traits< Ct >::mode_type > () const
 This iterator can be casted silently into a container iterator. More...
 
 operator Const_node_iterator< container_traits< Ct >::mode_type > () const
 This iterator can be casted silently into a container iterator. More...
 

Private Types

typedef details::Bidirectional_iterator< typename container_traits< Ct >::mode_type, typename container_traits< Ct >::rank_typeBase
 

Private Attributes

details::Neighbor_data< Ct, Metric > _data
 The related data for the iterator. More...
 

Additional Inherited Members

- Public Attributes inherited from spatial::details::Bidirectional_iterator< container_traits< Ct >::mode_type, container_traits< Ct >::rank_type >
node_ptr node
 The pointer to the current node. More...
 
dimension_type node_dim
 The dimension of the current node. More...
 

Detailed Description

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
class spatial::neighbor_iterator< Ct, Metric >

A spatial iterator for a container Ct that goes through the nearest to the furthest element from a target key, with distances applied according to a user-defined geometric space that is a model of Metric.

Template Parameters
CtThe container type bound to the iterator.
DistanceTypeThe type used to represent distances.
MetricAn type that is a model of Metric.

The Metric type is a complex type that must be a model of Metric:

struct Metric
{
typedef DistanceType distance_type;
DistanceType
distance_to_key(dimension_type rank,
const Key& origin, const Key& key) const;
DistanceType
distance_to_plane(dimension_type rank, dimension_type dim,
const Key& origin, const Key& key) const;
};

The details of the Metric type are explained in Metric. The library provides ready-made models of Metric such as spatial::euclidian and spatial::manhattan that are designed to work only with C++'s built-in arithmetic types. If more metrics needs to be defined, see the explanation in the Metric concept.

Definition at line 115 of file spatial_neighbor.hpp.

Member Typedef Documentation

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
typedef details::Bidirectional_iterator<typename container_traits<Ct>::mode_type, typename container_traits<Ct>::rank_type> spatial::neighbor_iterator< Ct, Metric >::Base
private

Definition at line 123 of file spatial_neighbor.hpp.

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
typedef Metric::distance_type spatial::neighbor_iterator< Ct, Metric >::distance_type

The distance type that is read from metric_type.

Definition at line 137 of file spatial_neighbor.hpp.

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
typedef container_traits<Ct>::key_compare spatial::neighbor_iterator< Ct, Metric >::key_compare

Key comparator type transferred from the container.

Definition at line 131 of file spatial_neighbor.hpp.

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
typedef container_traits<Ct>::key_type spatial::neighbor_iterator< Ct, Metric >::key_type

The key type that is used as a target for the nearest neighbor search.

Definition at line 140 of file spatial_neighbor.hpp.

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
typedef Metric spatial::neighbor_iterator< Ct, Metric >::metric_type

The metric type used by the iterator.

Definition at line 134 of file spatial_neighbor.hpp.

Constructor & Destructor Documentation

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
spatial::neighbor_iterator< Ct, Metric >::neighbor_iterator ( )

Uninitialized iterator.

Definition at line 143 of file spatial_neighbor.hpp.

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
spatial::neighbor_iterator< Ct, Metric >::neighbor_iterator ( Ct &  container_,
const Metric &  metric_,
const typename container_traits< Ct >::key_type target_,
const typename container_traits< Ct >::iterator &  iter_,
typename Metric::distance_type  distance_ 
)

The standard way to build this iterator: specify a metric to apply, an iterator on a container, and that container.

Parameters
container_The container to iterate.
metric_The Metric applied during the iteration.
target_The target of the neighbor iteration.
iter_An iterator on container.
distance_The distance at which the node pointed by iterator is from target.

Definition at line 157 of file spatial_neighbor.hpp.

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
spatial::neighbor_iterator< Ct, Metric >::neighbor_iterator ( Ct &  container_,
const Metric &  metric_,
const typename container_traits< Ct >::key_type target_,
dimension_type  node_dim_,
typename container_traits< Ct >::mode_type::node_ptr  node_,
typename Metric::distance_type  distance_ 
)

When the information of the dimension for the current node being pointed to by the iterator is known, this constructor saves some CPU cycle, by comparison to the other constructor.

Parameters
container_The container to iterate.
metric_The metric applied during the iteration.
target_The target of the neighbor iteration.
node_dim_The dimension of the node pointed to by iterator.
node_Use the value of node as the start point for the iteration.
distance_The distance between node_ and target_ according to metric_.

In order to iterate through nodes in the k-d tree built in the container, the algorithm must know at each node which dimension is used to partition the space. Some algorithms will provide this dimension, such as the function spatial::details::modulo().

Attention
Specifying the incorrect dimension value for the node will result in unknown behavior. It is recommended that you do not use this constructor if you are not sure about this dimension, and use the other constructors instead.

Definition at line 190 of file spatial_neighbor.hpp.

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
spatial::neighbor_iterator< Ct, Metric >::neighbor_iterator ( const typename container_traits< Ct >::rank_type rank_,
const typename container_traits< Ct >::key_compare key_comp_,
const Metric &  metric_,
const typename container_traits< Ct >::key_type target_,
dimension_type  node_dim_,
typename container_traits< Ct >::mode_type::node_ptr  node_,
typename Metric::distance_type  distance_ 
)

Build the iterator with a given rank and key compare functor, if the container is not available.

In order to iterate through nodes in the k-d tree built in the container, the algorithm must know at each node which dimension is used to partition the space. Some algorithms will provide this dimension, such as the function spatial::details::modulo().

Attention
Specifying the incorrect dimension value for the node will result in unknown behavior. It is recommended that you do not use this constructor if you are not sure about this dimension, and use the other constructors instead.
Parameters
rank_The rank of the container being iterated.
key_comp_The key compare functor associated with the iterator.
metric_The metric applied during the iteration.
target_The target of the neighbor iteration.
node_dim_The dimension of the node pointed to by iterator.
node_Use the value of node as the start point for the iteration.
distance_The distance between node_ and target_ according to metric_.

Definition at line 223 of file spatial_neighbor.hpp.

Member Function Documentation

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
const distance_type& spatial::neighbor_iterator< Ct, Metric >::distance ( ) const

Read-only accessor to the last valid distance of the iterator.

Definition at line 285 of file spatial_neighbor.hpp.

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
distance_type& spatial::neighbor_iterator< Ct, Metric >::distance ( )

Read/write accessor to the last valid distance of the iterator.

Definition at line 289 of file spatial_neighbor.hpp.

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
key_compare spatial::neighbor_iterator< Ct, Metric >::key_comp ( ) const

Return the key_comparator used by the iterator.

Definition at line 277 of file spatial_neighbor.hpp.

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
metric_type spatial::neighbor_iterator< Ct, Metric >::metric ( ) const

Return the metric used by the iterator.

Definition at line 281 of file spatial_neighbor.hpp.

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
neighbor_iterator<Ct, Metric>& spatial::neighbor_iterator< Ct, Metric >::operator++ ( )

Increments the iterator and returns the incremented value.

Prefer to use this form in for loops.

Definition at line 235 of file spatial_neighbor.hpp.

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
neighbor_iterator<Ct, Metric> spatial::neighbor_iterator< Ct, Metric >::operator++ ( int  )

Increments the iterator but returns the value of the iterator before the increment.

Prefer to use the other form in for loops.

Definition at line 245 of file spatial_neighbor.hpp.

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
neighbor_iterator<Ct, Metric>& spatial::neighbor_iterator< Ct, Metric >::operator-- ( )

Decrements the iterator and returns the decremented value.

Prefer to use this form in for loops.

Definition at line 256 of file spatial_neighbor.hpp.

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
neighbor_iterator<Ct, Metric> spatial::neighbor_iterator< Ct, Metric >::operator-- ( int  )

Decrements the iterator but returns the value of the iterator before the decrement.

Prefer to use the other form in for loops.

Definition at line 266 of file spatial_neighbor.hpp.

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
const key_type& spatial::neighbor_iterator< Ct, Metric >::target_key ( ) const

Read-only accessor to the target of the iterator.

Definition at line 293 of file spatial_neighbor.hpp.

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
key_type& spatial::neighbor_iterator< Ct, Metric >::target_key ( )

Read/write accessor to the target of the iterator.

Definition at line 297 of file spatial_neighbor.hpp.

Member Data Documentation

template<typename Ct, typename Metric = euclidian<typename details::mutate<Ct>::type, double, typename details::with_builtin_difference<Ct>::type>>
details::Neighbor_data<Ct, Metric> spatial::neighbor_iterator< Ct, Metric >::_data
private

The related data for the iterator.

Definition at line 301 of file spatial_neighbor.hpp.


The documentation for this class was generated from the following file: