13 #ifndef SPATIAL_ORDERED_ITERATOR_HPP
14 #define SPATIAL_ORDERED_ITERATOR_HPP
17 #include "spatial.hpp"
18 #include "bits/spatial_ordered.hpp"
28 template <
typename Ct>
30 : std::pair<ordered_iterator<Ct>, ordered_iterator<Ct> >
53 template <
typename Ct>
55 : std::pair<ordered_iterator<const Ct>, ordered_iterator<const Ct> >
76 :
Base(p.first, p.second) { }
94 template <
typename Container>
95 inline ordered_iterator_pair<Container>
118 template <
typename Container>
119 inline ordered_iterator_pair<const Container>
126 template <
typename Container>
127 inline ordered_iterator_pair<const Container>
159 template <
typename Container>
160 ordered_iterator<Container>&
162 (ordered_iterator<Container>& iter,
163 const typename container_traits<Container>::key_type& bound);
187 template <
typename Container>
188 ordered_iterator<Container>&
190 (ordered_iterator<Container>& iter,
191 const typename container_traits<Container>::key_type& bound);
215 template <
typename Container>
216 inline ordered_iterator<Container>
221 if (container.empty())
return ordered_end(container);
223 (container, 0, container.end().node->parent);
243 template <
typename Container>
244 inline ordered_iterator<const Container>
246 (
const Container& container,
249 if (container.empty())
return ordered_end(container);
251 (container, 0, container.end().node->parent);
255 template <
typename Container>
256 inline ordered_iterator<const Container>
258 (
const Container& container,
285 template <
typename Container>
286 inline ordered_iterator<Container>
288 (Container& container,
291 if (container.empty())
return ordered_end(container);
293 (container, 0, container.end().
node->parent);
314 template <
typename Container>
315 inline ordered_iterator<const Container>
317 (
const Container& container,
320 if (container.empty())
return ordered_end(container);
322 (container, 0, container.end().
node->parent);
326 template <
typename Container>
327 inline ordered_iterator<const Container>
329 (
const Container& container,
337 template <
typename Cmp,
typename Key>
340 const Key& a,
const Key& b)
344 if (cmp(d, a, b))
return true;
345 if (cmp(d, b, a))
return false;
352 template<
typename Container>
364 SPATIAL_ASSERT_CHECK(iter.
node != 0);
365 SPATIAL_ASSERT_CHECK(iter.
node_dim < rank());
367 node_ptr end = iter.
node->parent;
377 while (node->left != 0
378 && (node_dim > set_dim
379 || !cmp(node_dim,
const_key(node), bound)))
380 { node = node->left; node_dim =
incr_dim(rank, node_dim); }
382 { best = node; best_dim = node_dim; }
386 && (node_dim > set_dim || best == 0
390 node_dim =
incr_dim(rank, node_dim);
391 while (node->left != 0
392 && (node_dim > set_dim
393 || !cmp(node_dim,
const_key(node), bound)))
396 node_dim =
incr_dim(rank, node_dim);
402 { best = node; best_dim = node_dim; }
406 node_ptr p = node->parent;
407 while (p != end && p->right == node)
410 node_dim =
decr_dim(rank, node_dim);
414 node_dim =
decr_dim(rank, node_dim);
419 { best = node; best_dim = node_dim; }
421 }
while (node != end);
422 }
while (++set_dim < rank());
423 if (best != 0) { iter.
node = best; iter.
node_dim = best_dim; }
425 SPATIAL_ASSERT_CHECK(iter.
node_dim < rank());
426 SPATIAL_ASSERT_CHECK(iter.
node != 0);
432 template<
typename Container>
444 SPATIAL_ASSERT_CHECK(iter.
node != 0);
445 SPATIAL_ASSERT_CHECK(iter.
node_dim < rank());
447 node_ptr end = iter.
node->parent;
457 while (node->left != 0
458 && (node_dim > set_dim
460 || cmp(node_dim, bound,
const_key(node))))
461 { node = node->left; node_dim =
incr_dim(rank, node_dim); }
463 { best = node; best_dim = node_dim; }
467 && (node_dim > set_dim || best == 0
471 node_dim =
incr_dim(rank, node_dim);
472 while (node->left != 0
473 && (node_dim > set_dim
475 || cmp(node_dim, bound,
const_key(node))))
478 node_dim =
incr_dim(rank, node_dim);
484 { best = node; best_dim = node_dim; }
488 node_ptr p = node->parent;
489 while (p != end && p->right == node)
492 node_dim =
decr_dim(rank, node_dim);
496 node_dim =
decr_dim(rank, node_dim);
501 { best = node; best_dim = node_dim; }
503 }
while (node != end);
504 }
while (++set_dim < rank());
505 if (best != 0) { iter.
node = best; iter.
node_dim = best_dim; }
507 SPATIAL_ASSERT_CHECK(iter.
node_dim < rank());
508 SPATIAL_ASSERT_CHECK(iter.
node != 0);
512 template <
typename Container>
525 template <
typename Container>
537 SPATIAL_ASSERT_CHECK(iter.
node != 0);
538 SPATIAL_ASSERT_CHECK(iter.
node_dim < rank());
540 node_ptr end = iter.
node->parent;
550 while (node->left != 0
551 && (node_dim > set_dim
552 || !cmp(node_dim,
const_key(node), bound)))
553 { node = node->left; node_dim =
incr_dim(rank, node_dim); }
555 { best = node; best_dim = node_dim; }
559 && (node_dim > set_dim || best == 0
563 node_dim =
incr_dim(rank, node_dim);
564 while (node->left != 0
565 && (node_dim > set_dim
566 || !cmp(node_dim,
const_key(node), bound)))
569 node_dim =
incr_dim(rank, node_dim);
575 { best = node; best_dim = node_dim; }
579 node_ptr p = node->parent;
580 while (p != end && p->right == node)
583 node_dim =
decr_dim(rank, node_dim);
587 node_dim =
decr_dim(rank, node_dim);
593 { best = node; best_dim = node_dim; }
595 }
while (node != end);
596 }
while (++set_dim < rank());
597 if (best != 0) { iter.
node = best; iter.
node_dim = best_dim; }
599 SPATIAL_ASSERT_CHECK(iter.
node_dim < rank());
600 SPATIAL_ASSERT_CHECK(iter.
node != 0);
606 template <
typename Container>
618 SPATIAL_ASSERT_CHECK(iter.
node != 0);
619 SPATIAL_ASSERT_CHECK(iter.
node_dim < rank());
621 node_ptr end = iter.
node->parent;
631 while (node->left != 0
632 && (node_dim > set_dim
634 || cmp(node_dim, bound,
const_key(node))))
635 { node = node->left; node_dim =
incr_dim(rank, node_dim); }
637 { best = node; best_dim = node_dim; }
641 && (node_dim > set_dim || best == 0
645 node_dim =
incr_dim(rank, node_dim);
646 while (node->left != 0
647 && (node_dim > set_dim
649 || cmp(node_dim, bound,
const_key(node))))
652 node_dim =
incr_dim(rank, node_dim);
658 { best = node; best_dim = node_dim; }
662 node_ptr p = node->parent;
663 while (p != end && p->right == node)
666 node_dim =
decr_dim(rank, node_dim);
670 node_dim =
decr_dim(rank, node_dim);
676 { best = node; best_dim = node_dim; }
678 }
while (node != end);
679 }
while (++set_dim < rank());
680 if (best != 0) { iter.
node = best; iter.
node_dim = best_dim; }
682 SPATIAL_ASSERT_CHECK(iter.
node_dim < rank());
683 SPATIAL_ASSERT_CHECK(iter.
node != 0);
687 template <
typename Container>
700 #endif // SPATIAL_ORDERED_ITERATOR_HPP
ordered_iterator_pair< Container > ordered_range(Container &container)
Returns a pair of iterator on the first and the last value in the range that can be iterated...
ordered_iterator< const Container > ordered_cupper_bound(const Container &container, const typename container_traits< Container >::key_type &bound)
Finds the value with the largest coordinate along the ordered dimension that is stricly less than bou...
All elements returned by this iterator are ordered from the smallest to the largest value of their ke...
const rank_type & rank() const
Return the current Rank type used by the iterator.
Link::invariant_category invariant_category(const Node< Link > *)
For a given node, this function returns the invariant category of the node.
bool order_ref(const Cmp &cmp, const Rank &rank, const Key &a, const Key &b)
node_ptr node
The pointer to the current node.
Tp::key_compare key_compare
Comparison functor used to compare two instances of key_type.
ordered_iterator< Container > & upper_bound_ordered(ordered_iterator< Container > &iter, const typename container_traits< Container >::key_type &bound)
Move the iterator given in parameter to the value with the largest coordinate strictly lower than bou...
key_compare key_comp() const
Return the key_comparator used by the iterator.
ordered_iterator_pair()
Constructs an empty, uninitialized object.
ordered_iterator< Container > ordered_begin(Container &container)
Finds the value in container for which its key has the smallest coordinate over the dimension ordered...
Tp::key_type key_type
The type representing the key managed by the container.
All elements returned by this iterator are ordered from the smallest to the largest value of their ke...
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.
dimension_type node_dim
The dimension of the current node.
bool header(const Node< Link > *x)
Check if node is a header node.
This structure defines a pair of mutable spatial::ordered_iterator.
ordered_iterator_pair(const ordered_iterator< Ct > &a, const ordered_iterator< Ct > &b)
Regular constructor that builds a ordered_iterator_pair out of 2 spatial::ordered_iterator.
ordered_iterator< Container > & lower_bound_ordered(ordered_iterator< Container > &iter, const typename container_traits< Container >::key_type &bound)
Move the iterator given in parameter to the value with the smallest coordinate greater or equal to bo...
ordered_iterator_pair< const Container > ordered_crange(const Container &container)
Returns a pair of constant iterator on the first and the last value in the range that can be iterated...
ordered_iterator< Container > ordered_end(Container &container)
Finds the past-the-end position in container for this constant iterator.
container_traits< Ct >::mode_type::node_ptr node_ptr
The type for the node pointed to by the iterator.
Tp::mode_type mode_type
The Link Mode type that is associated with the container.
std::size_t dimension_type
Defines the type for the dimension as being a size.
ordered_iterator< Container > ordered_upper_bound(Container &container, const typename container_traits< Container >::key_type &bound)
Finds the value with the largest coordinate along the ordered dimension that is stricly less than bou...
bool order_less(const Cmp &cmp, dimension_type set_dim, const Key &a, const Key &b)
Tp::rank_type rank_type
The type used to represent the rank of the container.
ordered_iterator_pair(const ordered_iterator< const Ct > &a, const ordered_iterator< const Ct > &b)
Regular constructor that builds a ordered_iterator_pair out of 2 spatial::ordered_iterator.
The category of invariants for a k-d tree node: strict or relaxed.
std::pair< ordered_iterator< Ct >, ordered_iterator< Ct > > Base
A pair of iterators that represents a range (that is: a range of elements to iterate, and not an orthogonal range).
The main namespace used in the library.
ordered_iterator_pair()
Constructs an empty, uninitialized object.
dimension_type decr_dim(Rank rank, dimension_type node_dim)
Decrement dimension node_dim, given rank.
std::pair< ordered_iterator< const Ct >, ordered_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).
ordered_iterator< Container > ordered_lower_bound(Container &container, const typename container_traits< Container >::key_type &bound)
Finds the value with the smallest coordinate along the ordered dimension that is greater or equal to ...
ordered_iterator< const Container > ordered_clower_bound(const Container &container, const typename container_traits< Container >::key_type &bound)
Finds the value with the smallest coordinate along the ordered dimension that is greater or equal to ...
ordered_iterator_pair(const ordered_iterator_pair< Ct > &p)
Convert a mutable ordered iterator pair into a const ordered iterator pair.
dimension_type incr_dim(Rank rank, dimension_type node_dim)
Increment dimension node_dim, given rank.