cheshirekow  v0.1.0
iterators.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
26 #ifndef EDELSBRUNNER96_ITERATORS_H_
27 #define EDELSBRUNNER96_ITERATORS_H_
28 
29 #include <list>
30 #include <edelsbrunner96/simplex.h>
31 
32 namespace edelsbrunner96 {
33 
34 namespace iter {
35 
36 template <class Traits>
37 class BreadthFirst {
38  public:
39  typedef typename Traits::SimplexRef SimplexRef;
40  typedef typename Traits::Storage Storage;
41 
42  BreadthFirst(Storage& storage, std::list<SimplexRef>* queue,
43  typename std::list<SimplexRef>::iterator queue_iter)
44  : storage_(storage), queue_(queue), queue_iter_(queue_iter) {}
45 
47  return queue_iter_ != other.queue_iter_;
48  }
49 
51  return *queue_iter_;
52  }
53 
55 
56  private:
58  std::list<SimplexRef>* queue_;
59  typename std::list<SimplexRef>::iterator queue_iter_;
60 };
61 
62 } // namespace iter
63 
64 template <class Traits>
65 class BreadthFirst {
66  public:
67  typedef typename Traits::SimplexRef SimplexRef;
68  typedef typename Traits::Storage Storage;
69 
70  BreadthFirst(Storage& storage, SimplexRef start_ref)
71  : storage_(storage), start_ref_(start_ref) {
72  storage_[start_ref].marked[simplex::BFS_QUEUED] = true;
73  queue_.push_back(start_ref);
74  }
75 
77  for (auto s_ref : queue_) {
78  storage_[s_ref].marked[simplex::BFS_QUEUED] = false;
79  }
80  }
81 
83  return iter::BreadthFirst<Traits>(storage_, &queue_, queue_.begin());
84  }
85 
87  return iter::BreadthFirst<Traits>(storage_, &queue_, queue_.end());
88  }
89 
90  private:
93  std::list<SimplexRef> queue_;
94 };
95 
96 } // namespace edelsbrunner96
97 
98 #endif // EDELSBRUNNER96_ITERATORS_H_
BreadthFirst(Storage &storage, std::list< SimplexRef > *queue, typename std::list< SimplexRef >::iterator queue_iter)
Definition: iterators.h:42
std::list< SimplexRef > queue_
Definition: iterators.h:93
BreadthFirst< Traits > & operator++()
Definition: iterators.hpp:35
Traits::Storage Storage
Definition: iterators.h:68
std::list< SimplexRef >::iterator queue_iter_
Definition: iterators.h:59
BreadthFirst(Storage &storage, SimplexRef start_ref)
Definition: iterators.h:70
has been queud in breadth-first search
Definition: simplex.h:51
iter::BreadthFirst< Traits > begin()
Definition: iterators.h:82
Traits::SimplexRef SimplexRef
Definition: iterators.h:39
std::list< SimplexRef > * queue_
Definition: iterators.h:58
iter::BreadthFirst< Traits > end()
Definition: iterators.h:86
BinaryKey other(const BinaryKey &key)
Definition: BinaryKey.h:44
Traits::SimplexRef SimplexRef
Definition: iterators.h:67
bool operator!=(const BreadthFirst< Traits > &other)
Definition: iterators.h:46