15 #ifndef SPATIAL_REGION_HPP
16 #define SPATIAL_REGION_HPP
19 #include "../traits.hpp"
20 #include "spatial_bidirectional.hpp"
21 #include "spatial_rank.hpp"
22 #include "spatial_except.hpp"
45 template <
typename Key,
typename Compare>
60 bounds(
const Compare& compare,
const Key& lower,
const Key& upper)
71 return (Compare::operator()(dim, key,
_lower)
73 : (Compare::operator()(dim, key,
_upper)
108 template <
typename Tp>
112 (
const Tp& container,
120 (container.key_comp(), lower, upper);
137 template <
typename Ct,
typename Predicate
138 = bounds<typename container_traits<Ct>::key_type,
142 <typename container_traits<Ct>::mode_type,
143 typename container_traits<Ct>::rank_type>
170 : Base(container.rank(), iter.node, modulo(iter.node, container.rank())),
193 :
Base(container.rank(), ptr, dim),
_pred(pred) { }
198 {
return increment_region(*
this); }
205 increment_region(*
this);
212 {
return decrement_region(*
this); }
219 decrement_region(*
this);
245 template <
typename Ct,
typename Predicate>
248 <typename container_traits<Ct>::mode_type,
249 typename container_traits<Ct>::rank_type>
253 <
typename container_traits<Ct>::mode_type,
276 : Base(container.rank(), iter.node, modulo(iter.node, container.rank())),
300 :
Base(container.rank(), ptr, dim),
_pred(pred) { }
304 : Base(iter.rank(), iter.node, iter.node_dim),
_pred(iter.
predicate()) { }
309 {
return increment_region(*
this); }
316 increment_region(*
this);
323 {
return decrement_region(*
this); }
330 decrement_region(*
this);
353 template <
typename Ct,
typename Predicate>
369 template <
typename Ct,
typename Predicate>
383 template <
typename Ct,
typename Predicate>
397 template <
typename Ct,
typename Predicate>
403 template <
typename Ct,
typename Predicate>
404 inline region_iterator<Ct, Predicate>
408 (container, pred, container.dimension() - 1,
409 container.end().node);
412 template <
typename Ct,
typename Predicate>
413 inline region_iterator<const Ct, Predicate>
417 (container, pred, container.dimension() - 1,
418 container.end().node);
421 template <
typename Ct,
typename Predicate>
422 inline region_iterator<const Ct, Predicate>
426 template <
typename Ct>
427 inline region_iterator<Ct>
433 template <
typename Ct>
434 inline region_iterator<const Ct>
440 template <
typename Ct>
441 inline region_iterator<const Ct>
447 template <
typename Ct,
typename Predicate>
448 inline region_iterator<Ct, Predicate>
451 if (container.empty())
return region_end(container, pred);
453 it(container, pred, 0, container.end().node->parent);
457 template <
typename Ct,
typename Predicate>
458 inline region_iterator<const Ct, Predicate>
461 if (container.empty())
return region_end(container, pred);
463 it(container, pred, 0, container.end().node->parent);
467 template <
typename Ct,
typename Predicate>
468 inline region_iterator<const Ct, Predicate>
472 template <
typename Ct>
473 inline region_iterator<Ct>
479 template <
typename Ct>
480 inline region_iterator<const Ct>
486 template <
typename Ct>
487 inline region_iterator<const Ct>
499 template <
typename Ct,
typename Predicate
500 = bounds<typename container_traits<Ct>::key_type,
503 : std::pair<region_iterator<Ct, Predicate>,
504 region_iterator<Ct, Predicate> >
510 typedef std::pair<region_iterator<Ct, Predicate>,
529 template <
typename Ct,
typename Predicate>
531 : std::pair<region_iterator<const Ct, Predicate>,
532 region_iterator<const Ct, Predicate> >
538 typedef std::pair<region_iterator<const Ct, Predicate>,
553 : Base(p.first, p.second) { }
567 template <
typename Ct,
typename Predicate>
569 inline region_iterator_pair<Ct, Predicate>
579 template <
typename Ct,
typename Predicate>
580 inline region_iterator_pair<const Ct, Predicate>
590 template <
typename Ct,
typename Predicate>
591 inline region_iterator_pair<const Ct, Predicate>
599 template <
typename Ct>
600 inline region_iterator_pair<Ct>
606 template <
typename Ct>
607 inline region_iterator_pair<const Ct>
613 template <
typename Ct>
614 inline region_iterator_pair<const Ct>
636 template <
typename Rank,
typename Key,
typename Predicate>
638 match_all(
const Rank& rank,
const Key& key,
const Predicate& predicate)
641 {
if (predicate(i, rank(), key) !=
matching) {
return false; } }
645 template <
typename Container,
typename Predicate>
651 SPATIAL_ASSERT_CHECK(!
header(iter.node));
652 SPATIAL_ASSERT_CHECK(iter.node != 0);
653 SPATIAL_ASSERT_CHECK(iter.node_dim < rank());
656 if (iter.node->right != 0
659 iter.node = iter.node->right;
660 iter.node_dim =
incr_dim(rank, iter.node_dim);
661 while (iter.node->left != 0
662 && pred(iter.node_dim, rank(),
665 iter.node = iter.node->left;
666 iter.node_dim =
incr_dim(rank, iter.node_dim);
673 while (!
header(p) && iter.node == p->right)
676 iter.node_dim =
decr_dim(rank, iter.node_dim);
677 p = iter.node->parent;
680 iter.node_dim =
decr_dim(rank, iter.node_dim);
685 SPATIAL_ASSERT_CHECK(iter.node_dim < rank());
686 SPATIAL_ASSERT_CHECK(iter.node != 0);
690 template <
typename Container,
typename Predicate>
696 SPATIAL_ASSERT_CHECK(iter.node != 0);
697 SPATIAL_ASSERT_CHECK(iter.node_dim < rank());
700 iter.node = iter.node->parent;
706 if (iter.node->left != 0
709 iter.node = iter.node->left;
710 iter.node_dim =
incr_dim(rank, iter.node_dim);
711 while (iter.node->right != 0
712 && pred(iter.node_dim, rank(),
715 iter.node = iter.node->right;
716 iter.node_dim =
incr_dim(rank, iter.node_dim);
723 while (!
header(p) && iter.node == p->left)
726 iter.node_dim =
decr_dim(rank, iter.node_dim);
727 p = iter.node->parent;
730 iter.node_dim =
decr_dim(rank, iter.node_dim);
735 SPATIAL_ASSERT_CHECK(iter.node_dim < rank());
736 SPATIAL_ASSERT_CHECK(iter.node != 0);
740 template <
typename Container,
typename Predicate>
746 SPATIAL_ASSERT_CHECK(iter.node_dim < rank());
747 SPATIAL_ASSERT_CHECK(!
header(iter.node));
748 SPATIAL_ASSERT_CHECK(iter.node != 0);
752 while(iter.node->right != 0
755 iter.node = iter.node->right;
756 iter.node_dim =
incr_dim(rank, iter.node_dim);
758 while(iter.node->left != 0
761 iter.node = iter.node->left;
762 iter.node_dim =
incr_dim(rank, iter.node_dim);
768 if (iter.node->right != 0
769 && pred(iter.node_dim, rank(),
772 iter.node = iter.node->right;
773 iter.node_dim =
incr_dim(rank, iter.node_dim);
774 while (iter.node->left != 0
775 && pred(iter.node_dim, rank(),
778 iter.node = iter.node->left;
779 iter.node_dim =
incr_dim(rank, iter.node_dim);
786 while (p != end && iter.node == p->right)
789 iter.node_dim =
decr_dim(rank, iter.node_dim);
790 p = iter.node->parent;
793 iter.node_dim =
decr_dim(rank, iter.node_dim);
796 while (iter.node != end);
797 SPATIAL_ASSERT_CHECK(iter.node_dim < rank());
798 SPATIAL_ASSERT_CHECK(iter.node != 0);
802 template <
typename Container,
typename Predicate>
808 SPATIAL_ASSERT_CHECK(iter.node != 0);
809 SPATIAL_ASSERT_CHECK(iter.node_dim < rank());
810 SPATIAL_ASSERT_CHECK(!
header(iter.node));
814 while (iter.node->left != 0
817 iter.node = iter.node->left;
818 iter.node_dim =
incr_dim(rank, iter.node_dim);
820 while (iter.node->right != 0
823 iter.node = iter.node->right;
824 iter.node_dim =
incr_dim(rank, iter.node_dim);
830 if (iter.node->left != 0
833 iter.node = iter.node->left;
834 iter.node_dim =
incr_dim(rank, iter.node_dim);
835 while (iter.node->right != 0
836 && pred(iter.node_dim, rank(),
839 iter.node = iter.node->right;
840 iter.node_dim =
incr_dim(rank, iter.node_dim);
847 while (p != end && iter.node == p->left)
850 iter.node_dim =
decr_dim(rank, iter.node_dim);
851 p = iter.node->parent;
854 iter.node_dim =
decr_dim(rank, iter.node_dim);
857 while (iter.node != end);
858 SPATIAL_ASSERT_CHECK(iter.node_dim < rank());
859 SPATIAL_ASSERT_CHECK(iter.node != 0);
866 #endif // SPATIAL_REGION_HPP
relative_order operator()(dimension_type dim, dimension_type, const Key &key) const
The operator that returns true if the key is within the boundaries, false if it isn't.
region_iterator(const Ct &container, const Predicate &pred, typename container_traits< Ct >::const_iterator iter)
Build a region iterator from a container's iterator type.
region_iterator< Ct, Predicate > & decrement_region(region_iterator< Ct, Predicate > &iter)
From iter, returns the previous matching iterator in the region delimited by Predicate, using in-order transversal.
This structure defines a pair of constant region iterator.
Key _upper
The upper bound for the orthogonal region.
region_iterator_pair(const region_iterator_pair< Ct, Predicate > &p)
Convert a mutable region iterator pair into a const region iterator pair.
This type provides both an iterator and a constant iterator to iterate through all elements of a tree...
region_iterator< const Ct, Predicate > operator--(int)
Decrements the iterator but returns the value of the iterator before the decrement.
void check_bounds(const Tp &container, const typename container_traits< Tp >::key_type &lower, const typename container_traits< Tp >::key_type &upper)
Checks if all coordinates of lower are strictly less than these of higher along the same dimensions...
region_iterator_pair()
Empty constructor.
region_iterator< Ct, Predicate > & maximum_region(region_iterator< Ct, Predicate > &iter)
In the children of the node pointed to by iter, find the last matching iterator in the region delimit...
region_iterator(const region_iterator< Ct, Predicate > &iter)
Convertion of an iterator into a const_iterator is permitted.
Tp::key_compare key_compare
Comparison functor used to compare two instances of key_type.
Predicate _pred
The related data for the iterator.
This type provides both an iterator and a constant iterator to iterate through all elements of a tree...
region_iterator< Ct, Predicate > & minimum_region(region_iterator< Ct, Predicate > &iter)
In the children of the node pointed to by iter, find the first matching iterator in the region delimi...
bounds()
The default constructor leaves everything un-initialized.
region_iterator< const Ct, Predicate > region_cend(const Ct &container, const Predicate &pred)
This structure defines a pair of mutable region iterator.
bounds(const Compare &compare, const Key &lower, const Key &upper)
Set the lower and upper boundary for the orthogonal region search.
Tp::key_type key_type
The type representing the key managed by the container.
std::pair< region_iterator< const Ct, Predicate >, region_iterator< const Ct, Predicate > > Base
A pair of iterators that represents a range (that is: a range of elements to iterate, and not an orthogonal range).
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.
region_iterator_pair()
Empty constructor.
region_iterator_pair(const region_iterator< Ct, Predicate > &a, const region_iterator< Ct, Predicate > &b)
Regular constructor that builds a region_iterator_pair out of 2 region_iterators. ...
bool header(const Node< Link > *x)
Check if node is a header node.
region_iterator< const Ct, Predicate > & operator++()
Increments the iterator and returns the incremented value.
Predicate predicate() const
Return the key_comparator used by the iterator.
std::pair< region_iterator< Ct, Predicate >, region_iterator< Ct, Predicate > > Base
A pair of iterators that represents a range (that is: a range of elements to iterate, and not an orthogonal range).
region_iterator< Ct, Predicate > region_begin(Ct &container, const Predicate &pred)
region_iterator_pair< Ct, Predicate > region_range(Ct &container, const Predicate &pred)
Returns a spatial::region_iterator_pair where first points to the first element matching the predicat...
region_iterator_pair(const region_iterator< const Ct, Predicate > &a, const region_iterator< const Ct, Predicate > &b)
Regular constructor that builds a region_iterator_pair out of 2 region_iterators. ...
The traits type for all containers in the spatial namespace.
Predicate predicate() const
Return the key_comparator used by the iterator.
region_iterator< const Ct, Predicate > region_cbegin(const Ct &container, const Predicate &pred)
relative_order
Defines values for relative ordering.
std::size_t dimension_type
Defines the type for the dimension as being a size.
region_iterator< Ct, Predicate > region_end(Ct &container, const Predicate &pred)
region_iterator< const Ct, Predicate > operator++(int)
Increments the iterator but returns the value of the iterator before the increment.
region_iterator< Ct, Predicate > & operator--()
Decrements the iterator and returns the decremented value.
Tp::rank_type rank_type
The type used to represent the rank of the container.
details::Const_bidirectional_iterator< typename container_traits< Ct >::mode_type, typename container_traits< Ct >::rank_type > Base
region_iterator(Ct &container, const Predicate &pred, typename container_traits< Ct >::iterator iter)
Build a region iterator from a container's iterator type.
The main namespace used in the library.
region_iterator_pair< const Ct, Predicate > region_crange(const Ct &container, const Predicate &pred)
This overload works only on constant containers and will return a set of constant iterators...
region_iterator()
Uninitialized iterator.
dimension_type decr_dim(Rank rank, dimension_type node_dim)
Decrement dimension node_dim, given rank.
region_iterator< const Ct, Predicate > & operator--()
Decrements the iterator and returns the decremented value.
region_iterator< Ct, Predicate > operator++(int)
Increments the iterator but returns the value of the iterator before the increment.
region_iterator< Ct, Predicate > & operator++()
Increments the iterator and returns the incremented value.
A common template for constant bidirectional iterators that work on identical modes of linking...
A common template for bidirectional iterators that work on identical modes of linking.
details::Bidirectional_iterator< typename container_traits< Ct >::mode_type, typename container_traits< Ct >::rank_type > Base
Predicate _pred
The related data for the iterator.
bool match_all(const Rank &rank, const Key &key, const Predicate &predicate)
Return a boolean indicating whether all of key's coordinates are within range or not.
region_iterator()
Constructs an empty, uninitialized object.
region_iterator< Ct, Predicate > & increment_region(region_iterator< Ct, Predicate > &iter)
From iter, returns the next matching iterator in the region delimited by Predicate, using in-order transversal.
region_iterator< Ct, Predicate > operator--(int)
Decrements the iterator but returns the value of the iterator before the decrement.
A model of Region Predicate that defines an orthogonal region and checks if a value of type Key is co...
Key _lower
The lower bound for the orthogonal region.
dimension_type incr_dim(Rank rank, dimension_type node_dim)
Increment dimension node_dim, given rank.
bounds< typename container_traits< Tp >::key_type, typename container_traits< Tp >::key_compare > make_bounds(const Tp &container, const typename container_traits< Tp >::key_type &lower, const typename container_traits< Tp >::key_type &upper)
A bounds factory that takes in a container, 2 arguments lower and upper, and returns a fully construc...