126# ifndef TPL_CONST_GRAPH_VIEW_H
127# define TPL_CONST_GRAPH_VIEW_H
130# include <type_traits>
141 class Const_Graph_View;
143 namespace const_graph_view_detail
158 return const_cast<T *
>(p);
179 static_assert(std::is_same_v<decltype(std::declval<const Base &>().get_curr()),
181 "GT::Node_Iterator::get_curr() must hand out a Node * by value");
202 :
Base(*view.graph_ptr) {}
231 static_assert(std::is_same_v<decltype(std::declval<const Base &>().get_curr()),
233 "GT::Arc_Iterator::get_curr() must hand out an Arc * by value");
254 :
Base(*view.graph_ptr) {}
315 static_assert(std::is_same_v<decltype(std::declval<const Base &>().get_curr()),
317 "GT::Node_Arc_Iterator::get_curr() must hand out an Arc * by value");
574 if (not op(it.get_curr_ne()))
589 if (not op(it.get_curr_ne()))
605 if (not op(it.get_curr_ne()))
618 op(it.get_curr_ne());
629 op(it.get_curr_ne());
641 op(it.get_curr_ne());
687 if (
Node *p = it.get_curr_ne(); op(p))
701 if (
Arc *a = it.get_curr_ne(); op(a))
716 if (
Arc *a = it.get_curr_ne(); op(a))
729 if (it.get_tgt_node_ne() == tgt)
730 return it.get_curr_ne();
740 return search_node([&info] (
Node *p) {
return p->get_info() == info; });
749 return search_arc([&info] (
Arc *a) {
return a->get_info() == info; });
796 if (op(it.get_curr_ne()))
811 if (op(it.get_curr_ne()))
824 ret.
append(it.get_curr_ne());
836 ret.
append(it.get_curr_ne());
849 ret.
append(it.get_curr_ne());
862 ret.
append(it.get_tgt_node_ne());
877 if (
Node *p = it.get_curr_ne(); op(p))
893 if (
Arc *a = it.get_curr_ne(); op(a))
910 if (
Arc *a = it.get_curr_ne(); op(a))
923 template <
typename T = Node_Type,
class Op>
924 requires std::is_invocable_r_v<T, Op &, Node *>
941 template <
typename T = Arc_Type,
class Op>
942 requires std::is_invocable_r_v<T, Op &, Arc *>
958 template <
typename T = Node_Type,
class Op>
959 requires std::is_invocable_r_v<T, Op &, const T &, Node *>
975 template <
typename T = Arc_Type,
class Op>
976 requires std::is_invocable_r_v<T, Op &, const T &, Arc *>
998 template <AlephGraph GT>
1005 template <AlephGraph GT>
C++20 concepts hub: comparison, BST policy, and Aleph container concepts.
C++20 concepts for the protocol shared by graph algorithms.
STL-compatible iterator adapters for Aleph containers.
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
Read-only iterator on the arcs of a graph.
Item_Type get_current_arc() const
The current arc.
const GT::Node * get_src_node_ne() const noexcept
get_src_node() without checking that there is a current arc.
const GT::Node * get_tgt_node_ne() const noexcept
get_tgt_node() without checking that there is a current arc.
Const_Arc_Iterator()=default
An iterator with no current arc.
const GT::Node * get_src_node() const
The source node of the current arc.
const GT::Node * get_tgt_node() const
The target node of the current arc.
Item_Type get_current_arc_ne() const noexcept
get_current_arc() without checking that there is a current arc.
const typename GT::Arc * Item_Type
The type of the items: a pointer to a constant arc.
Const_Arc_Iterator(const GT &g)
Iterator positioned on the first arc of g.
Const_Arc_Iterator(const Const_Graph_View< GT > &view)
Iterator positioned on the first arc seen through view.
Strict read-only view of a graph.
Node_Iterator get_node_it() const
Iterator positioned on the first node.
size_t degree(Node *p) const noexcept
Degree of a node: the number of its arcs.
size_t get_num_nodes() const noexcept
Total number of nodes.
Const_Node_Arc_Iterator< GT > Node_Arc_Iterator
Read-only iterator on the arcs of a node.
Arc_Iterator get_arc_it() const
Iterator positioned on the first arc.
Node * find_node(const Node_Type &info) const
Search a node by its information.
void for_each_arc(Node *p, Op &&op) const
Visit every arc of a node.
bool traverse_arcs(Op &&op) const
Visit the arcs while an operation answers true.
bool is_empty() const noexcept
true if the graph has no nodes.
bool exists_arc(Node *p, Op &&op) const
true if some arc of a node satisfies a condition.
bool all_nodes(Op &&op) const
true if every node satisfies a condition.
bool traverse_arcs(Node *p, Op &&op) const
Visit the arcs of a node while an operation answers true.
const typename GT::Arc Arc
The constant arc type.
Arc * search_arc(Op &&op) const
Linear search of an arc.
Arc * find_arc(const Arc_Type &info) const
Search an arc by its information.
bool all_arcs(Node *p, Op &&op) const
true if every arc of a node satisfies a condition.
Const_Graph_View(const GT &&)=delete
A view of a temporary graph would dangle.
size_t count_nodes(Op &&op) const
Number of nodes satisfying a condition.
Const_Node_Iterator< GT > Node_Iterator
Read-only iterator on the nodes.
Const_Arc_Iterator< GT > Arc_Iterator
Read-only iterator on the arcs.
bool all_arcs(Op &&op) const
true if every arc satisfies a condition.
Node * get_src_node(Arc *a) const noexcept
The source node of an arc.
Arc * search_arc(Node *p, Op &&op) const
Linear search among the arcs of a node.
bool traverse_nodes(Op &&op) const
Visit the nodes while an operation answers true.
DynList< Arc * > arcs() const
The arcs of the graph.
bool exists_node(Op &&op) const
true if some node satisfies a condition.
Node * get_connected_node(Arc *a, Node *p) const noexcept
The node at the other end of an arc.
DynList< T > nodes_map(Op op) const
Map the nodes to a list.
size_t esize() const noexcept
Synonym of get_num_arcs().
bool is_digraph() const noexcept
true if the graph is directed.
DynList< Node * > nodes() const
The nodes of the graph.
Arc * get_first_arc(Node *p) const
Any arc of a node.
Node * get_first_node() const
Any node of the graph.
static constexpr bool filter_iterator_keeps_a_copy
A Filter_Iterator on a view keeps a copy of it: the view is small, and it is often a temporary.
DynList< T > arcs_map(Op op) const
Map the arcs to a list.
Const_Graph_View(const GT &g) noexcept
View of the graph g.
Node * get_tgt_node(Arc *a) const noexcept
The target node of an arc.
T foldl_nodes(const T &init, Op op) const
Fold the nodes from the left.
Arc * get_first_arc() const
Any arc of the graph.
void for_each_node(Op &&op) const
Visit every node.
Node * search_node(Op &&op) const
Linear search of a node.
DynList< Arc * > filter_arcs(Op &&op) const
The arcs satisfying a condition.
size_t get_num_arcs() const noexcept
Total number of arcs.
size_t vsize() const noexcept
Synonym of get_num_nodes().
const typename GT::Node Node
The constant node type.
typename GT::Node_Type Node_Type
The type of the information stored in a node.
T foldl_arcs(const T &init, Op op) const
Fold the arcs from the left.
constexpr Const_Graph_View() noexcept
DynList< Arc * > filter_arcs(Node *p, Op &&op) const
The arcs of a node satisfying a condition.
bool exists_arc(Op &&op) const
true if some arc satisfies a condition.
void for_each_arc(Op &&op) const
Visit every arc.
Node_Arc_Iterator get_arc_it(Node *p) const
Iterator positioned on the first arc of a node.
size_t get_num_arcs(Node *p) const noexcept
Number of arcs of a node, as the graph counts them.
DynList< Arc * > arcs(Node *p) const
The arcs of a node.
static constexpr T * as_graph_item(const T *p) noexcept
DynList< Node * > adjacent_nodes(Node *p) const
The nodes connected to a node.
typename GT::Arc_Type Arc_Type
The type of the information stored in an arc.
Arc * search_arc(Node *src, Node *tgt) const noexcept
Search an arc connecting two nodes.
DynList< Node * > filter_nodes(Op &&op) const
The nodes satisfying a condition.
bool is_null_view() const noexcept
size_t count_arcs(Op &&op) const
Number of arcs satisfying a condition.
Read-only view of an Aleph iterator: the iterator of a constant container.
GT::Arc_Iterator & underlying() const noexcept
The underlying iterator, for the views that extend the reading protocol with members of their own (th...
auto has_curr() const noexcept(noexcept(std::declval< I & >().has_curr())) -> decltype(std::declval< I & >().has_curr())
true if there is a current item.
auto get_curr_ne() const noexcept(noexcept(std::declval< I & >().get_curr_ne())) -> const_iterator_detail::const_item_t< decltype(std::declval< I & >().get_curr_ne())>
get_curr() without the checks of the underlying iterator.
auto get_curr() const noexcept(noexcept(std::declval< I & >().get_curr())) -> const_iterator_detail::const_item_t< decltype(std::declval< I & >().get_curr())>
The current item, read-only.
Read-only iterator on the arcs of a node.
Item_Type get_current_arc_ne() const noexcept
get_current_arc() without checking that there is a current arc.
const typename GT::Node * Set_Type
The type of what is iterated: a constant node.
const GT::Node * get_tgt_node_ne() const noexcept
get_tgt_node() without checking that there is a current arc.
const typename GT::Arc * Item_Type
The type of the items: a pointer to a constant arc.
Const_Node_Arc_Iterator(const typename GT::Node *p)
Iterator positioned on the first arc of the node p.
Const_Node_Arc_Iterator()=default
An iterator with no current arc.
const GT::Node * get_tgt_node() const
The node at the other end of the current arc.
Item_Type get_current_arc() const
The current arc.
Read-only iterator on the nodes of a graph.
Const_Node_Iterator()=default
An iterator with no current node.
Item_Type get_current_node() const
The current node.
Const_Node_Iterator(const GT &g)
Iterator positioned on the first node of g.
const typename GT::Node * Item_Type
The type of the items: a pointer to a constant node.
Item_Type get_current_node_ne() const noexcept
get_current_node() without checking that there is a current node.
Const_Node_Iterator(const Const_Graph_View< GT > &view)
Iterator positioned on the first node seen through view.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
Generic filter iterator wrapper.
Node * get_first_node() const
Return any node in the graph.
Arc * get_first_arc(Node *node) const
Return any arc adjacent to a node.
typename Node::Node_Type Node_Type
The arc class type.
Graph_Node< Node_Info > Node
The graph type.
Graph_Arc< Arc_Info > Arc
The node class type.
typename Arc::Arc_Type Arc_Type
The type of data stored in the arc.
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
bool is_digraph() const noexcept
Return true if the graph this is directed.
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
constexpr size_t get_num_arcs() const noexcept
Return the number of arcs of the graph.
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
f(args...) is a valid call expression, exactly as written.
f(args...) is a valid call whose result is usable as a condition.
Const_Graph_View< GT > const_view(const GT &g) noexcept
Strict read-only view of a graph.
Singly linked list implementations with head-tail access.
constexpr T * as_graph_item(const T *p) noexcept
Hands a node or an arc read through a view back to the graph.
Main namespace for Aleph-w library functions.
std::decay_t< typename HeadC::Item_Type > T
static std::atomic< bool > init
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Filtered iterator of adjacent arcs of a node.