LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
lal::iterators::E_iterator< graph_t, 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_t &g) noexcept
 Constructor.
 
 ~E_iterator ()=default
 Default destructor.
 
bool end () const noexcept
 Returns true if the end of the iteration was reached.
 
const edgeget_edge () const noexcept
 Returns the current edge.
 
edge_t get_edge_t () const noexcept
 Returns the current edge.
 
edge yield_edge () noexcept
 Returns the current edge and advances the iterator.
 
edge_t yield_edge_t () noexcept
 Returns the current edge and advances the iterator.
 
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 Types

typedef std::pair< node, std::size_t > E_pointer
 Useful typedef.
 

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_pointerfind_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_pointerfind_next_edge () const noexcept
 Finds the next edge on an undirected graph.
 

Private Attributes

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

Detailed Description

template<typename graph_t, bool is_directed = std::is_base_of_v<graphs::directed_graph, graph_t>, std::enable_if_t< std::is_base_of_v< graphs::graph, graph_t >, bool > = true>
class lal::iterators::E_iterator< graph_t, 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 initialized with a constant reference to a graph.

A possible usage of this class is the following:

lal::iterators::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:97

or, in a more compact way

lal::iterators::E_iterator it(g); // g is a graph
while (not it.end()) {
const auto [u, v] = it.get_edge();
// ...
}

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

for (lal::iterators::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:117

Constructor & Destructor Documentation

◆ E_iterator()

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

Constructor.

Parameters
gConstant reference to the graph over which we iterate.

Member Function Documentation

◆ find_next_edge() [1/2]

template<typename graph_t , bool is_directed = std::is_base_of_v<graphs::directed_graph, graph_t>, std::enable_if_t< std::is_base_of_v< graphs::graph, graph_t >, bool > = true>
template<bool isdir = is_directed, std::enable_if_t< isdir, bool > = true>
std::pair< bool, E_pointer > lal::iterators::E_iterator< graph_t, is_directed, >::find_next_edge ( ) const
inlinenodiscardprivatenoexcept

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_t , bool is_directed = std::is_base_of_v<graphs::directed_graph, graph_t>, std::enable_if_t< std::is_base_of_v< graphs::graph, graph_t >, 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_t, is_directed, >::find_next_edge ( ) const
inlinenodiscardprivatenoexcept

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: