LAL: Linear Arrangement Library 21.07.01
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
lal::iterators::E_iterator< GRAPH, is_directed, > Class Template Reference

Iterator over the set of edges of a graph. More...

#include <E_iterator.hpp>

Public Member Functions

 E_iterator (const GRAPH &g) noexcept
 Constructor.
 
 ~E_iterator ()=default
 Default destructor.
 
bool end () const noexcept
 Returns true if the end of the iteration was reached.
 
edge get_edge () const noexcept
 Returns the current edge.
 
void next () noexcept
 Moves the iterator to the next edge.
 
void reset () noexcept
 Sets the iterator at the beginning of the set of edges.
 

Private Member Functions

void __reset () noexcept
 Sets the iterator at the beginning of the set of edges.
 
edge make_current_edge () const noexcept
 Returns the edge pointed by m_cur.
 
template<bool isdir = is_directed, std::enable_if_t< isdir, bool > = true>
std::pair< bool, E_pointer > find_next_edge () const noexcept
 Finds the next edge on a directed graph.
 
template<bool isdir = is_directed, std::enable_if_t< not isdir, bool > = true>
std::pair< bool, E_pointer > find_next_edge () const noexcept
 Finds the next edge on an undirected graph.
 

Private Attributes

const GRAPH & m_G
 The graph whose edges have to be iterated on.
 
E_pointer m_cur
 Pointer to the next edge.
 
bool m_exists_next = true
 Is there a next edge to iterate over?
 
bool m_reached_end = false
 Has the end of the iteration been reached?
 
edge m_cur_edge
 Copy of the current edge.
 

Detailed Description

template<typename GRAPH, bool is_directed = std::is_base_of_v<graphs::directed_graph, GRAPH>, std::enable_if_t< std::is_base_of_v< graphs::directed_graph, GRAPH >||std::is_base_of_v< graphs::undirected_graph, GRAPH >, bool > = true>
class lal::iterators::E_iterator< GRAPH, is_directed, >

Iterator over the set of edges of a graph.

This class is used to easily iterate over the edges of a graph \(E\). For undirected graphs, the edge returned is an edge \((u,v)\) so that the inequality \(u < v\) always holds. For directed graphs, the edge returned always has left-to-right orientation, therefore said inequality need not always hold.

This class has to be initialised with a constant reference to a graph.

A possible usage of this class is the following:

E_iterator it(g); // g is a graph
while (not it.end()) {
const auto [u,v] = it.get_edge();
// ...
it.next();
}
Iterator over the set of edges of a graph.
Definition E_iterator.hpp:93

Alternatively, the lal::iterators::E_iterator object can be used in a for loop:

for (E_iterator it(g); not it.end(); it.next()) {
const auto [u,v] = it.get_edge();
// ...
}
bool end() const noexcept
Returns true if the end of the iteration was reached.
Definition E_iterator.hpp:110

Constructor & Destructor Documentation

◆ E_iterator()

template<typename GRAPH , bool is_directed = std::is_base_of_v<graphs::directed_graph, GRAPH>, std::enable_if_t< std::is_base_of_v< graphs::directed_graph, GRAPH >||std::is_base_of_v< graphs::undirected_graph, GRAPH >, bool > = true>
lal::iterators::E_iterator< GRAPH, is_directed, >::E_iterator ( const GRAPH & g)
inlinenoexcept

Constructor.

Parameters
gConstant reference to the graph over which we iterate.

Member Function Documentation

◆ find_next_edge() [1/2]

template<typename GRAPH , bool is_directed = std::is_base_of_v<graphs::directed_graph, GRAPH>, std::enable_if_t< std::is_base_of_v< graphs::directed_graph, GRAPH >||std::is_base_of_v< graphs::undirected_graph, GRAPH >, bool > = true>
template<bool isdir = is_directed, std::enable_if_t< isdir, bool > = true>
std::pair< bool, E_pointer > lal::iterators::E_iterator< GRAPH, is_directed, >::find_next_edge ( ) const
inlineprivatenoexcept

Finds the next edge on a directed graph.

Returns
A pair of a Boolean indicating if the next edge is valid, and pointers to the next edge.
Precondition
Starts at the values in m_cur.

◆ find_next_edge() [2/2]

template<typename GRAPH , bool is_directed = std::is_base_of_v<graphs::directed_graph, GRAPH>, std::enable_if_t< std::is_base_of_v< graphs::directed_graph, GRAPH >||std::is_base_of_v< graphs::undirected_graph, GRAPH >, bool > = true>
template<bool isdir = is_directed, std::enable_if_t< not isdir, bool > = true>
std::pair< bool, E_pointer > lal::iterators::E_iterator< GRAPH, is_directed, >::find_next_edge ( ) const
inlineprivatenoexcept

Finds the next edge on an undirected graph.

Returns
A pair of a Boolean indicating if the next edge is valid, and pointers to the next edge.
Precondition
Starts at the values in m_cur.

The documentation for this class was generated from the following file: