16 #ifndef PAAL_SIMPLE_CYCLE_HPP
17 #define PAAL_SIMPLE_CYCLE_HPP
26 namespace data_structures {
36 template <
typename CycleEl,
typename IdxT =
int>
class simple_cycle {
38 using cycle_el_pair = std::pair<CycleEl, CycleEl>;
39 using cycle_element = CycleEl;
53 std::size_t
size = std::distance(begin, end);
60 for (; begin != end; ++begin) {
61 IdxT lastIdx =
add(*begin);
62 link(prev_idx, lastIdx);
65 link(prev_idx, firstIdx);
70 void flip(
const CycleEl &begin,
const CycleEl &end) {
95 CycleEl
next(
const CycleEl &ce)
const {
104 :
public std::iterator<std::forward_iterator_tag, CycleEl, ptrdiff_t,
105 CycleEl *, const CycleEl &> {
115 : m_cycle(&cm), m_idx(m_cycle->
to_idx(ce)), m_first(m_idx) {}
128 m_idx = next_idx(m_idx);
130 if (m_idx == m_first) {
189 IdxT next_idx(IdxT i)
const {
return m_cycle->
next_idx(i); }
196 using vertices = boost::iterator_range<vertex_iterator>;
248 :
public std::iterator<std::forward_iterator_tag, cycle_el_pair,
249 ptrdiff_t, cycle_el_pair *, const cycle_el_pair &> {
258 : m_cycle(&cm), m_idx(m_cycle->
to_idx(ce)), m_first(m_idx) {
274 m_idx = next_idx(m_idx);
277 if (m_idx == m_first) {
318 const cycle_el_pair *
const operator->()
const {
return &m_curr; }
325 const cycle_el_pair &
operator*()
const {
return m_curr; }
332 m_curr.first = m_cycle->
from_idx(m_idx);
333 m_curr.second = m_cycle->
from_idx(next_idx(m_idx));
343 IdxT next_idx(IdxT i)
const {
return m_cycle->
next_idx(i); }
348 cycle_el_pair m_curr;
351 using edges = boost::iterator_range<edge_iterator>;
447 IdxT
add(
const CycleEl &el) {
456 using SorsMap = std::vector<IdxT>;
470 template <
typename CycleEl,
typename IdxT =
int>
482 template <
typename Iter>
484 :
Base(b, e), m_last_id(0) {}
492 void flip(
const CycleEl &begin,
const CycleEl &end) {
514 #endif // PAAL_SIMPLE_CYCLE_HPP
SorsMap m_successor_map
successors
IdxT next_idx(IdxT i) const
returns next idx in the cycle
This is the simplest implementation of the Cycle concept based on the list.
const CycleEl & operator*() const
operator*()
bool operator==(vertex_iterator ei) const
operator==
vertex_iterator(const simple_cycle &cm, CycleEl ce)
constructor
Base::vertex_iterator vbegin() const
vbegin starts from last flip position
Idx get_idx(const T &t) const
gets index of element t
void flip(const CycleEl &begin, const CycleEl &end)
IdxT prev_idx(IdxT i) const
returns previous idx
edge_iterator & operator++()
operator++()
edges get_edge_range() const
returns edges range
vertex_iterator & operator++()
operator++()
const T & get_val(Idx i) const
get value for index i
IdxT add(const CycleEl &el)
ads new element to cycle data structures
edge_iterator(const simple_cycle &cm, CycleEl ce)
constructor
const CycleEl *const operator->() const
operator->()
Computes size of TypesVector.
vertices get_vertices_range(const CycleEl &el) const
returns range of vertices starting at el
bool operator!=(edge_iterator ei) const
operator!=
vertices get_vertices_range() const
returns range of vertices
Idx add(const T &t)
adds element to collection
CycleEl next(const CycleEl &ce) const
next element in the cycle
iterator over vertices of the cycle
void link(IdxT x, IdxT y)
connects two vertices represented by ids
this class adapts Simple cycle to start from last changed position
Simplecycle_start_from_last_change(Iter b, Iter e)
constructor
edge_iterator()
default constructor
const cycle_el_pair & operator*() const
operator*()
vertex_iterator operator++(int)
operator++(int)
bool operator==(edge_iterator ei) const
operator==
void flip(const CycleEl &begin, const CycleEl &end)
flip remembers last changed position
bool operator!=(vertex_iterator ei) const
operator!=
IdxT to_idx(const CycleEl &ce) const
vertex to idx
edges get_edge_range(const CycleEl &el) const
returns edges range starting at el
const CycleEl & from_idx(IdxT i) const
idx to vertex
vertex_iterator()
default constructor
vertex_iterator vend() const
end of the vertices range
vertex_iterator vbegin(const CycleEl &el) const
begin of the vertices range starting at el
simple_cycle(Iter begin, Iter end)
constructor
void partial_reverse(IdxT x, IdxT y)
after this operation links from x to y are connected i reverse order, after this function call cycle ...
const cycle_el_pair *const operator->() const
operator->
edge_iterator operator++(int)
operator++(int)
vertex_iterator vbegin() const
begin of the vertices range
bimap< CycleEl, IdxT > m_cycle_idx
mapping from elements to indexes
SorsMap m_predecessor_map
predecessors
std::size_t size() const
number of elements in the cycle