Improve util::dfs::cycle_iterator
This commit is contained in:
parent
3bfe867cc0
commit
df5e188236
1 changed files with 19 additions and 0 deletions
|
|
@ -20,20 +20,39 @@ namespace psemek::util
|
|||
|
||||
struct cycle_iterator
|
||||
{
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = Index;
|
||||
using reference_type = Index;
|
||||
using pointer = Index *;
|
||||
using difference_type = int;
|
||||
|
||||
dfs * parent;
|
||||
Index i;
|
||||
|
||||
Index operator *() const { return i; }
|
||||
|
||||
cycle_iterator & operator ++()
|
||||
{
|
||||
i = parent->parent_[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
cycle_iterator operator ++(int)
|
||||
{
|
||||
auto copy = *this;
|
||||
i = parent->parent_[i];
|
||||
return copy;
|
||||
}
|
||||
|
||||
friend bool operator == (cycle_iterator const & i1, cycle_iterator const & i2)
|
||||
{
|
||||
return i1.i == i2.i;
|
||||
}
|
||||
|
||||
friend bool operator != (cycle_iterator const & i1, cycle_iterator const & i2)
|
||||
{
|
||||
return i1.i != i2.i;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename CycleCallback>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue