Loading...
Searching...
No Matches
Active_witness_iterator.h
1/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2 * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3 * Author(s): Siargey Kachanovich
4 *
5 * Copyright (C) 2016 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
11#ifndef ACTIVE_WITNESS_ACTIVE_WITNESS_ITERATOR_H_
12#define ACTIVE_WITNESS_ACTIVE_WITNESS_ITERATOR_H_
13
14#include <boost/iterator/iterator_facade.hpp>
15#include <list>
16
17namespace Gudhi {
18
19namespace witness_complex {
20
27template< typename Active_witness,
28 typename Id_distance_pair,
29 typename INS_iterator >
31 : public boost::iterator_facade< Active_witness_iterator <Active_witness, Id_distance_pair, INS_iterator>,
32 Id_distance_pair const,
33 boost::forward_traversal_tag,
34 Id_distance_pair const> {
35 friend class boost::iterator_core_access;
36
37 typedef typename std::list<Id_distance_pair>::iterator Pair_iterator;
39 Id_distance_pair,
40 INS_iterator> Iterator;
41
42 Active_witness *aw_;
43 Pair_iterator lh_; // landmark handle
44 bool is_end_; // true only if the pointer is end and there are no more neighbors to add
45
46 public:
48 : aw_(aw), lh_(aw_->nearest_landmark_table_.end()), is_end_(true) {
49 }
50
51 Active_witness_iterator(Active_witness* aw, const Pair_iterator& lh)
52 : aw_(aw), lh_(lh) {
53 is_end_ = false;
54 if (lh_ == aw_->nearest_landmark_table_.end()) {
55 if (aw_->iterator_next_ == aw_->iterator_end_) {
56 is_end_ = true;
57 } else {
58 aw_->nearest_landmark_table_.push_back(*aw_->iterator_next_);
59 lh_ = --aw_->nearest_landmark_table_.end();
60 ++(aw_->iterator_next_);
61 }
62 }
63 }
64
65 private :
66 Id_distance_pair& dereference() const {
67 return *lh_;
68 }
69
70 bool equal(const Iterator& other) const {
71 return (is_end_ == other.is_end_) || (lh_ == other.lh_);
72 }
73
74 void increment() {
75 // the neighbor search can't be at the end iterator of a list
76 GUDHI_CHECK(!is_end_ && lh_ != aw_->nearest_landmark_table_.end(),
77 std::logic_error("Wrong active witness increment."));
78 // if the id of the current landmark is the same as the last one
79
80 lh_++;
81 if (lh_ == aw_->nearest_landmark_table_.end()) {
82 if (aw_->iterator_next_ == aw_->iterator_end_) {
83 is_end_ = true;
84 } else {
85 aw_->nearest_landmark_table_.push_back(*aw_->iterator_next_);
86 lh_ = std::prev(aw_->nearest_landmark_table_.end());
87 ++(aw_->iterator_next_);
88 }
89 }
90 }
91};
92
93} // namespace witness_complex
94} // namespace Gudhi
95
96#endif // ACTIVE_WITNESS_ACTIVE_WITNESS_ITERATOR_H_
Iterator in the nearest landmark list.
Definition: Active_witness_iterator.h:34
Class representing a list of nearest neighbors to a given witness.
Definition: Active_witness.h:27