69 template <
class GT,
class D>
72 using type =
decltype(std::declval<typename concepts_detail::defer<GT, D>::type::Node_Iterator &>().
get_curr());
79 template <
class GT,
class D>
82 using type =
decltype(std::declval<typename concepts_detail::defer<GT, D>::type::Arc_Iterator &>().
get_curr());
89 template <
class GT,
class D>
92 using type =
decltype(std::declval<typename concepts_detail::defer<GT, D>::type::Node_Arc_Iterator &>().
get_curr());
107 [[gnu::always_inline]]
inline decltype(
auto)
curr_ne(
It & it)
131 template <
class GT,
class SA>
151 for (;
arcs->has_curr();
arcs->next_ne())
160 for (;
arcs->has_curr();
arcs->prev())
191 "In_Iterator(p) does not see the arcs into p on a digraph, whose list of p "
192 "holds only the arcs that leave p: use In_Iterator(g, p), or In_Arcs_Index "
197 [[nodiscard]]
bool has_curr() const noexcept {
return arcs->has_curr(); }
255 if (not
arcs->has_curr())
392template <
typename It>
395 { cit.has_curr() } -> std::convertible_to<bool>;
396 { it.
next() } -> std::same_as<void>;
412template <
typename It>
431template <
typename It,
typename Node>
434 { cit.get_curr() } -> std::convertible_to<Node*>;
450template <
typename It,
typename Arc>
453 { cit.get_curr() } -> std::convertible_to<Arc*>;
474template <
typename It,
typename Node,
typename Arc>
477 { cit.get_tgt_node() } -> std::convertible_to<Node*>;
518 return static_cast<Node *
>(Dlink::Iterator::get_curr_ne());
558 : Dlink::Iterator(head)
565 return static_cast<Arc *
>(Dlink::Iterator::get_curr_ne());
569 Arc *
get_curr()
const {
return static_cast<Arc *
>(Dlink::Iterator::get_curr()); }
607template <
class GT,
class Cmp>
630 noexcept(
noexcept(
static_cast<bool>(std::declval<Cmp &>()(std::declval<Node *&>(),
631 std::declval<Node *&>()))))
635 return static_cast<bool>(
cmp(p1, p2));
643template <
class GT,
class Cmp>
666 noexcept(
noexcept(
static_cast<bool>(std::declval<Cmp &>()(std::declval<Arc *&>(),
667 std::declval<Arc *&>()))))
669 Arc *arc1 =
static_cast<Arc *
>(d1);
670 Arc *arc2 =
static_cast<Arc *
>(d2);
671 return static_cast<bool>(
cmp(arc1, arc2));
692template <
typename NodeInfo>
785template <
typename ArcInfo>
840 arc_info = std::move(other.arc_info);
875template <
class GT,
class Node,
class Arc>
878 GT *
me() {
return static_cast<GT *
>(
this); }
891 ~Guard() {
delete arc; }
926 std::swap(
cookie, g.cookie);
1019 return static_cast<Node *
>(arc->src_node);
1025 return static_cast<Node *
>(arc->tgt_node);
1060 return static_cast<Node *
>(arc->get_connected_node(node));
1070 return node->num_arcs;
1279 template <
class N1,
class N2 = N1>
1283 assert(p !=
nullptr and q !=
nullptr);
1310 template <
class A1,
class A2 = A1>
1314 assert(p !=
nullptr and q !=
nullptr);
1451 template <
typename... Args>
1533 template <
typename... Args>
1585 template <
class Operation>
1590 if (not op(graph_dry_detail::curr_ne(it)))
1596 template <
class Operation>
1652 template <
class Operation>
1657 if (not op(graph_dry_detail::curr_ne(it)))
1663 template <
class Operation>
1721 template <
class Operation>
1725 for (
typename GT::Node_Arc_Iterator it(p); it.
has_curr(); it.
next_ne())
1726 if (not op(graph_dry_detail::curr_ne(it)))
1732 template <
class Operation>
1763 template <
class Operation>
1768 operation(graph_dry_detail::curr_ne(it));
1772 template <
class Operation>
1803 template <
class Operation>
1808 op(graph_dry_detail::curr_ne(it));
1812 template <
class Operation>
1852 template <
class Operation>
1856 for (
typename GT::Node_Arc_Iterator it(p); it.
has_curr(); it.
next_ne())
1857 op(graph_dry_detail::curr_ne(it));
1861 template <
class Operation>
1897 template <
class Operation>
1905 template <
class Operation>
1941 template <
class Operation>
1949 template <
class Operation>
1988 template <
class Operation>
1996 template <
class Operation>
2042 template <
typename T = Node_Type,
class Op>
2043 requires std::is_invocable_r_v<T, Op &, Node *>
2090 template <
typename T = Arc_Type,
class Op>
2091 requires std::is_invocable_r_v<T, Op &, Arc *>
2142 template <
typename T = Arc_Type,
class Op>
2143 requires std::is_invocable_r_v<T, Op &, Arc *>
2188 template <
typename T = Node_Type,
class Op>
2189 requires std::is_invocable_r_v<T, Op &, const T &, Node *>
2231 template <
typename T = Arc_Type,
class Op>
2232 requires std::is_invocable_r_v<T, Op &, const T &, Arc *>
2275 template <
typename T = Arc_Type,
class Op>
2276 requires std::is_invocable_r_v<T, Op &, const T &, Arc *>
2310 DynList<Node *> ret;
2438 template <
class Operation>
2446 template <
class Operation>
2471 template <
class Operation>
2479 template <
class Operation>
2508 template <
class Operation>
2516 template <
class Operation>
2537 template <
class Operation>
2545 template <
class Operation>
2566 template <
class Operation>
2574 template <
class Operation>
2588 template <
class Operation>
2596 template <
class Operation>
2619 template <
class Operation = std::function<
bool(Node*)>>
2644 template <
class Operation = std::function<
bool(Arc*)>>
2659 template <
class Operation = std::function<
bool(Arc*)>>
2684 template <
typename T =
double,
class Extract>
2685 requires requires(
T &
sum, Extract &extract,
Arc *a) {
sum += extract(a); }
2694 template <
typename T =
double>
2698 for_each_arc(p, [&sum](
Arc *a) { sum +=
static_cast<T
>(a->get_info()); });
2717 template <
class Compare = std::function<
bool(Arc*, Arc*)>>
2720 return a->get_info() < b->get_info();
2723 Arc* result =
nullptr;
2725 if (result ==
nullptr or
cmp(a, result))
2746 template <
class Compare = std::function<
bool(Arc*, Arc*)>>
2749 return a->get_info() < b->get_info();
2752 Arc* result =
nullptr;
2754 if (result ==
nullptr or
cmp(result, a))
2765 template <
class Compare = std::function<
bool(Arc*, Arc*)>>
2768 return a->get_info() < b->get_info();
2771 Arc* result =
nullptr;
2773 if (result ==
nullptr or
cmp(a, result))
2784 template <
class Compare = std::function<
bool(Arc*, Arc*)>>
2787 return a->get_info() < b->get_info();
2790 Arc* result =
nullptr;
2792 if (result ==
nullptr or
cmp(result, a))
2813 template <
class Operation>
2817 DynList<Node*> yes, no;
2824 return {std::move(yes), std::move(no)};
2837 template <
class Operation>
2841 DynList<Arc*> yes, no;
2848 return {std::move(yes), std::move(no)};
2866 DynList<Node*> result;
2922 noexcept(
noexcept(
static_cast<bool>(std::declval<Node_Type &>() == std::declval<const Node_Type &>())))
2924 return search_node([&info](
auto p) {
return static_cast<bool>(p->get_info() == info); });
2976 noexcept(
noexcept(
static_cast<bool>(std::declval<Arc_Type &>() == std::declval<const Arc_Type &>())))
2978 return search_arc([&info](
auto a) {
return static_cast<bool>(a->get_info() == info); });
2999 template <
class Operation>
3003 for (
typename GT::Node_Arc_Iterator it(p); it.
has_curr(); it.
next_ne())
3013 template <
class Operation>
3045 for (
typename GT::Node_Arc_Iterator it(src); it.
has_curr(); it.
next_ne())
3046 if (it.get_tgt_node_ne() == tgt)
3124 return typename GT::Node_Iterator(*
const_me());
3146 return typename GT::Arc_Iterator(*
const_me());
3169 return typename GT::Node_Arc_Iterator(p);
3218 return a->tgt_node ==
tgt;
3225 return (
typename GT::Node *) a->src_node;
3275 return a->src_node ==
src;
3282 return (
Node *) a->tgt_node;
3311 template <
class Filter>
3314 using Itor = Filter_Iterator<Node *, typename GT::Node_Arc_Iterator, Filter>;
3323 static constexpr bool shows_ne =
noexcept(std::declval<Itor &>().next_ne());
3375 return filt.get_node(a);
3440 <<
"In_Iterator(g, p): the graph says that it is directed, so that its arcs into p "
3441 <<
"are not in the list of p: use the in_ methods of the graph, or In_Arcs_Index";
3542 if (it.get_tgt_node() == tgt)
3543 return it.get_curr();
3558 for (
typename GT::Arc_Iterator it(*
const_me()); it.has_curr(); it.next_ne())
3559 if (
Arc *a = it.get_curr_ne(); a->tgt_node == p and not op(a))
3569 for (
typename GT::Arc_Iterator it(*
const_me()); it.has_curr(); it.next_ne())
3570 if (it.get_curr_ne()->tgt_node == p)
3589 DynList<Node *> ret;
3594 ret.append(
static_cast<Node *
>(a->src_node));
3600 ret.
append(it.get_node());
3616 DynList<Node *> ret;
3618 ret.
append(it.get_node_ne());
3635 ret.
append(it.get_curr());
3661 ret.
append(it.get_curr());
3683 DynList<ArcPair> ret;
3688 auto q = (
Node *) a->get_connected_node(p);
3689 ret.append(std::make_tuple(a, q));
3696 auto a = it.get_curr();
3697 ret.append(std::make_tuple(a, (
Node *) a->get_connected_node(p)));
3716 DynList<ArcPair> ret;
3719 auto a = it.get_curr();
3720 ret.append(std::make_tuple(a, (
Node *) a->get_connected_node(p)));
3791 template <
class Itor,
class Operation>
3795 for (Itor it(p); it.has_curr(); it.next_ne())
3796 if (not op(graph_dry_detail::curr_ne(it)))
3802 template <
class Itor,
class Operation>
3806 for (Itor it(p); it.has_curr(); it.next_ne())
3807 op(graph_dry_detail::curr_ne(it));
3819 return traverse_arcs<In_Iterator, Op>(p, op);
3843 for_each_arc<In_Iterator>(p, op);
3926 template <
typename T,
class Op>
3927 requires std::is_invocable_r_v<T, Op &, Arc *>
3942 template <
typename T = Arc_Type,
class Op>
3943 requires std::is_invocable_r_v<T, Op &, const T &, Arc *>
3983 return traverse_arcs<Out_Iterator>(p, op);
3997 for_each_arc<Out_Iterator>(p, op);
4052 typename GT::Arc *ret =
nullptr;
4080 template <
typename T = Arc_Type,
class Op>
4081 requires std::is_invocable_r_v<T, Op &, Arc *>
4090 template <
typename T = Arc_Type,
class Op>
4091 requires std::is_invocable_r_v<T, Op &, const T &, Arc *>
4145 template <
class Predicate>
4148 DynList<Arc*> result;
4149 for (
typename GT::Arc_Iterator it(*
const_me()); it.has_curr(); it.next_ne())
4150 if (
pred(it.get_curr_ne()))
4151 result.
append(it.get_curr_ne());
4176 template <
class Predicate>
4190 requires(U & u) { { u.get_node_dlink() } -> std::same_as<Dlink&>; };
4194 requires(U & u) { { u.get_arc_dlink() } -> std::same_as<Dlink&>; };
4199 template <
class Compare,
class T>
4201 noexcept(
static_cast<bool>(std::declval<Compare &>()(std::declval<T *&>(),
4202 std::declval<T *&>())));
4224 template <
class Compare>
4226 requires(has_node_dlink_v<GT>)
4229 mergesort(
me()->get_node_dlink(), c);
4233 template <
class Compare>
4260 template <
class Compare>
4262 requires(has_arc_dlink_v<GT>)
4265 mergesort(
me()->get_arc_dlink(), c);
4269 template <
class Compare>
4311#define ALEPH_GRAPH_COPY_MOVE_CTORS(GraphClass) \
4313 GraphClass(const GraphClass & g) \
4315 copy_graph(*this, g); \
4319 GraphClass(GraphClass && g) noexcept \
4327 GraphClass & operator=(const GraphClass & g) \
4332 copy.digraph = this->digraph; \
4333 copy_graph(copy, g); \
4334 copy.cookie = this->cookie; \
4340 GraphClass & operator=(GraphClass && g) noexcept \
4377template <
class BaseGraph>
4378class Digraph :
public BaseGraph
4382 using Node =
typename BaseGraph::Node;
4383 using Arc =
typename BaseGraph::Arc;
4391 this->digraph =
true;
4403 this->digraph =
true;
4416 this->digraph =
true;
4433 void swap(BaseGraph & g) =
delete;
4479 copy.cookie = this->cookie;
4495 this->digraph =
true;
C++20 concepts hub: comparison, BST policy, and Aleph container concepts.
#define ah_domain_error()
Throws std::domain_error unconditionally.
C++20 concepts for the protocol shared by graph algorithms.
WeightedDigraph::Node Node
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
size_t size_t int32_t value
Generic directed graph (digraph) wrapper template.
In_Iterator get_in_it(Node *p) const
Return an iterator on the arcs that go into p: those of the arcs of the digraph whose target is p,...
Digraph & operator=(const Digraph &g)
Copy assignment operator.
typename BaseGraph::Arc Arc
typename BaseGraph::Node Node
void swap(Digraph &g) noexcept
Swap in constant time this digraph with g.
Digraph() noexcept
Default constructor.
T & get_curr() const
Return the current item.
T & get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
void next()
Advances the iterator to the next filtered element.
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
void reset_first()
Resets the iterator to the first filtered element.
bool has_curr() const noexcept
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.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
virtual void remove_arc(Arc *arc) noexcept
Remove an arc from the graph and free it.
Graph_Node< Node_Info > Node
The graph type.
Graph_Arc< Arc_Info > Arc
The node class type.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
The iterator on the arcs into a node of a digraph type, which In_Iterator is on a type built with the...
std::optional< Arc_Itor > arcs
static constexpr bool goes_to_last
Whether the walk goes to its last arc, which reset_last() needs.
Node * get_node_ne() const noexcept
Return the source of the current arc, which must exist.
void prev_ne() noexcept(shows_ne)
prev() without its exception: nothing if there is no current arc; noexcept when the filter is,...
In_Arcs_Walk(const GT &g, Node *p, SA sa=SA())
The arcs of g into p that sa shows, from the first one.
void end() noexcept
Put the walk past the last arc.
void reset_last()
Put the walk on the last arc.
void prev()
Move to the previous arc.
Node * get_node(Arc *a) const noexcept
Return the source of a.
Arc * get_current_arc() const
See get_curr().
void next()
Move to the next arc.
static constexpr bool shows_ne
void reset_first()
Put the walk on the first arc.
In_Arcs_Walk(Node *, SA sa=SA())
The form that takes only the node, which does not compile: the list of a node of a digraph holds only...
bool has_curr() const noexcept
Return true if there is a current arc.
typename GT::Arc_Iterator Arc_Itor
Node * get_tgt_node_ne() const noexcept
Alias of get_node_ne().
Node * get_node() const
Return the source of the current arc.
Arc * Item_Type
The type of the items: arcs.
static constexpr bool goes_back
Whether the walk moves back: the arc iterators of List_SGraph and List_SDigraph go only forward.
Arc * get_curr_ne() const noexcept
Return the current arc, which must exist.
Node * get_tgt_node() const
Alias of get_node().
Arc * get_curr() const
Return the current arc. Throws overflow_error if there is none.
Arc * get_current_arc_ne() const noexcept
See get_curr_ne().
void next_ne() noexcept(shows_ne)
Move to the next arc, which must exist; noexcept when the filter is, else what the filter throws goes...
void for_each(Operation &operation) const
Traverse all the container and performs an operation on each element.
Common methods for the arc of a graph.
GTArcCommon() noexcept=default
data contained in arc
ArcInfo & get_info() noexcept
Return a modifiable reference to the arc data.
void * tgt_node
Please don't use.
void * get_connected_node(void *node) noexcept
GTArcCommon(const GTArcCommon &other)
Copy constructor.
GTArcCommon(void *src, void *tgt, const ArcInfo &data)
Construct with endpoints and info (copy)
const ArcInfo & get_info() const noexcept
Return a constant reference to the arc data.
GTArcCommon(GTArcCommon &&other) noexcept
Move constructor.
Graph_Attr attrs
Please don't use.
GTArcCommon(ArcInfo &&info)
Construct from info value (move)
GTArcCommon & operator=(const GTArcCommon &other)
Copy assignment operator.
void set_state(unsigned int s) noexcept
Set the state of arc to value s
void * get_img_node(void *node) noexcept
GTArcCommon(void *src, void *tgt, ArcInfo &&data=ArcInfo())
Construct with endpoints and info (move)
unsigned int state() const noexcept
Return the state of arc.
GTArcCommon & operator=(GTArcCommon &&other) noexcept
Move assignment operator.
Common attributes and methods for nodes (vertexes) belonging to graphs.
const NodeInfo & get_info() const noexcept
Return a constant reference to the data contained in the node.
GTNodeCommon() noexcept=default
another alias for set type
GTNodeCommon & operator=(const GTNodeCommon &other)
Copy assignment operator.
GTNodeCommon(NodeInfo &&info)
Move constructor from info value.
Graph_Attr attrs
Attributes of node.
unsigned int state() const noexcept
Return the state's value.
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
NodeInfo Node_Type
The node.
GTNodeCommon & operator=(GTNodeCommon &&other) noexcept
Move assignment operator.
GTNodeCommon(GTNodeCommon &&other) noexcept
Move constructor.
GTNodeCommon(const GTNodeCommon &other)
Copy constructor.
void set_state(unsigned int s) noexcept
Set the state to value s
size_t num_arcs
data associated to the node. Access it with get_info()
Special iterator for distinguishing input arcs of output ones.
static constexpr bool goes_to_last
Whether the iterator goes to its last arc, which reset_last() needs.
typename Itor::Item_Type Item_Type
void next()
Advance to next arc.
void reset_first() noexcept(shows_ne)
Reset the iterator to first arc.
Digraph_Iterator(Node *p)
Instantiate an filtered iterator for arcs on the node p
void next_ne() noexcept(shows_ne)
next() without its check: the current arc must exist.
static constexpr bool shows_ne
Whether what the filter says of an arc cannot throw, nor its conversion to bool: the moves without ch...
void prev_ne()
prev() without exceptions. Only where the iterator moves back
Filter_Iterator< Node *, typename GT::Node_Arc_Iterator, Filter > Itor
GT::Arc * get_curr_ne() const noexcept
void prev()
back to previous item.
GT::Arc * get_curr() const
Return the current arc.
GT::Node * get_node(typename GT::Arc *a) const noexcept
Return the node connected to p (passed during construction) and linked through a
Itor Iterator_Type
the type of items (Arc*)
void reset_last() noexcept(shows_ne)
Reset the iterator to last arc.
auto get_current_arc() const
See get_curr().
static constexpr bool goes_back
Whether the iterator moves back: the iterators of the lists of List_SGraph go only forward,...
auto get_tgt_node_ne() const noexcept
Backward-compatible alias: return target node (same as get_node_ne()).
auto get_current_arc_ne() const noexcept
GT::Node * get_node_ne() const noexcept
Return the node connected to p (passed during construction) and linked through the current arc.
bool has_curr() const noexcept
Return true is the iterator has a current arc.
auto get_tgt_node() const
Backward-compatible alias: return target node (same as get_node()).
GT::Node * get_node() const
Common methods to the Aleph-w ( ) graph classes.
void sort_arcs(Compare &cmp) noexcept(nothrow_cmp_v< Compare, Arc >)
Sort all the arcs of the graph according to a specific criteria.
void sort_nodes(Compare &cmp) noexcept(nothrow_cmp_v< Compare, Node >)
Sort all the nodes of the graph according to a specific criteria.
Arc * min_arc(Node *p, Compare cmp=[](Arc *a, Arc *b) { return a->get_info()< b->get_info();}) const
Find the minimum arc adjacent to a node.
In_Iterator get_in_it(Node *p) const
Return an input iterator on the incoming arcs to p
void for_each_arc(Node *p, Operation &op) const
Unconditionally traverse all the arcs adjacnt to a node and on each one perform an operation.
void reset_bit_nodes(int bit) const noexcept
Reset bit to zero for all the nodes of graph.
auto out_arcs_map(Node *p, Op op) const
Return a list of outcoming arcs of a node mapped to items of type given by transformation op.
typename Arc::Arc_Type Arc_Type
auto search_in_arc(Node *p, Op &op) const
Search an incoming arc to a node satisfaying a condition.
T sum_arcs(Node *p, Extract extract) const
Sum values derived from arcs adjacent to a node.
void for_each_out_arc(Node *p, Op &op) const
Perform op on each outcoming arc of node p
auto filter_arcs(Node *p, Op &&op) const
Overload of filter_arcs(Node*, Op&) that accepts rvalues.
Node * find_node(const Node_Type &info) const noexcept(noexcept(static_cast< bool >(std::declval< Node_Type & >()==std::declval< const Node_Type & >())))
Find a node mathing a content.
T foldl_arcs(Node *p, const T &init, Op op) const
Folding of arcs of a node.
bool exists_in_arc(Node *p, Op &op) const
Return true if it exists a incoming arc to p returning true for op
void for_each_arc(Node *p, Operation &&op=Operation()) const
Overload of for_each_arc(Node*, Operation&) that accepts rvalues.
void * get_cookie() const noexcept
Return a constant reference to graph's cookie.
Arc * emplace_arc(Node *src, Node *tgt, Args &&... args)
Insert a new arc in the graph by constructing its associated data in-place with the given args.
void reset_arcs() const
Reset all the arcs of graph (the control bits, the state, the counter and the cookie)
bool all_arcs(Node *p, Operation &&op=Operation()) const
Overload of all_arcs(Node*, Operation&) that accepts rvalues.
auto filter_in_arcs(Node *p, Op &&op=Op()) const
Overload of filter_in_arcs(Node*, Op&) that accepts rvalues.
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
void reset_cookie_arcs() const noexcept
Reset all the cookies to `nullptr for all the arcs of graph.
bool traverse_digraph_arcs_into(Node *p, Op op) const
Container< Arc * > arcs() const
Return a container with all the arcs of the graph.
int get_bit(Arc *arc, int bit) const noexcept
Get the control bit of arc
size_t get_num_arcs(Node *node) const noexcept
Return the total of arcs of a node.
void for_each_arc(Operation &op) const
Unconditionally traverse all the arcs of graph and on each one perform an operation.
bool all_nodes(Operation &&op=Operation()) const
Overload of all_nodes(Operation&) that accepts rvalues.
bool exists_out_arc(Node *p, Op &op) const
Return true if it exists a outcoming arc to p returning true for op
void for_each_in_arc(Node *p, Op &op) const
Perform op on each incoming arc of node p; on a digraph, among the arcs of the graph,...
auto get_arc_it() const noexcept
Obtains an iterator to the arc of graph.
void reset_counter(Node *node) const noexcept
Reset the node counter to zero.
void for_each_out_arc(Node *p, Op &&op=Op()) const
Overload of for_each_out_arc(Node*, Op&) that accepts rvalues.
Node * insert_node(Node_Type &&node_info=Node_Type())
Allocate a new node, set by moving its data content and insert it into the graph.
void sort_nodes(Compare &&cmp=Compare()) noexcept(nothrow_cmp_v< Compare, Node >)
See sort_nodes(Compare & cmp).
Node * insert_node(const Node_Type &node_info)
Allocate a new node, set by copy its data content and insert it into the graph.
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Node * get_node() const
Return any node in the graph.
Out_Iterator get_out_it(Node *p) const noexcept
Return an output iterator on the incoming nodes to p
auto search_out_arc(Node *p, Op &op) const
Search an outcoming arc to a node satisfaying a condition.
std::tuple< Arc *, Node * > ArcPair
Pair of arc and node (topologically related)
DynList< Node * > in_nodes(Node *p) const
Return a list with the incoming nodes to p
void for_each_arc(Node *p, Operation &op) const
Perform op on each arc of node p
bool traverse_nodes(Operation &op) const
Conditioned traversal of all the nodes of a graph.
T foldl_in_arcs(Node *p, const T &init, Op op) const
Fold the incoming arcs of a node.
Arc * search_arc(Op &&op) const
Overload of search_arc(Op&) that accepts rvalues.
bool traverse_arcs(Node *p, Operation &op) const
Conditioned traversal of all the adjacent arcs of a node.
bool traverse_in_arcs(Node *p, Op &&op=Op()) const
Overload of traverse_in_arcs(Node*, Op&) that accepts rvalues.
void reset_bit_nodes() const noexcept
Reset all the bits for all the nodes of graph.
bool exists_arc(Node *p, Operation &op) const
Determine if exists at least a arc adjacent to a node satisfying a condition.
auto search_in_arc(Node *p, Op &&op=Op()) const
Overload of search_in_arc(Node*, Op&) that accepts rvalues.
auto search_out_arc(Node *p, Op &&op=Op()) const
Overload of search_out_arc(Node*, Op&) that accepts rvalues.
void for_each_in_arc(Node *p, Op &&op=Op()) const
Overload of for_each_in_arc(Node*, Op&) that accepts rvalues.
T sum_arcs(Node *p) const
Overload of sum_arcs(Node*, Extract) using the arc info as extractor.
Arc * max_arc(Compare cmp=[](Arc *a, Arc *b) { return a->get_info()< b->get_info();}) const
Find the maximum arc in the entire graph.
Arc * insert_new_arc(Node *src, Node *tgt, Arc *arc)
Arc * insert_arc(Node *src, Node *tgt, Arc_Type &&arc_info=Arc_Type())
Create and insert a new arc linking two nodes and moving the received data.
bool none_arc(Node *p, Operation &&op) const
Overload of none_arc(Node*, Operation&) that accepts rvalues.
bool none_node(Operation &&op) const
Overload of none_node(Operation&) that accepts rvalues.
void set_bit(Node *node, int bit, int value) const noexcept
Set the control bit of node to value
DynList< Arc * > out_arcs(Node *p) const
Return a list with the outcoming arcs to p`.
bool exists_in_arc(Node *p, Op &&op=Op()) const
Overload of exists_in_arc(Node*, Op&) that accepts rvalues.
void set_bit(Arc *arc, int bit, int value) const noexcept
Set the control bit of arc to value
Arc * search_arc(Node *p, Operation &op) const
Linear search of an arc.
bool is_digraph() const noexcept
Return true if the graph this is directed.
void reset_cookie_nodes() const noexcept
Reset all the cookies to `nullptr for all the nodes of graph.
void reset_counter(Arc *arc) const noexcept
Reset the acr counter to zero.
T foldl_nodes(const T &init, Op op) const
Folding of nodes on a graph.
auto filter_arcs(Node *p, Op &op) const
Filter the arcs adjacent to a node satisfying a condition.
void set_digraph(bool val)
Temporal indication for preventing to other algorithms that an graph must be treated as a directed gr...
bool traverse_out_arcs(Node *p, Op &&op=Op()) const
Overload of traverse_out_arcs(Node*, Op&) that accepts rvalues.
bool traverse_arcs(Node *p, Operation &&op=Operation()) const
Overload of traverse_arcs(Node*, Operation&) that accepts rvalues.
bool all_arcs(Operation &op) const
Check if all the arcs of graph satisfy a boolean condition.
auto nodes_map(Op op) const
Map the nodes of a graph to a specific range.
void *& get_cookie() noexcept
Return a modifiable reference to graph's cookie.
T foldl_arcs(const T &init, Op op) const
Folding of arcs on a graph.
bool all_nodes(Operation &op) const
Check if all the nodes of graph satisfy an boolean condition.
DynList< Arc * > filter_in_arcs(Node *p, Op &op) const
Filter the incoming arcs of a node.
auto arcs_map(Op operation) const
Map the arcs of a graph to a specific range.
bool all_in_arcs(Node *p, Op &op) const
Return true if op is true for all the incoming arcs to node p
void reset_bit_arcs() const noexcept
Reset all the bits for all the arcs of graph.
Arc * get_arc() const
Return any arc in the graph.
static void map_arcs(A1 *p, A2 *q) noexcept
Map the arcs through their cookies.
auto in_pairs(Node *p) const
Return a list of pair incoming arcs and nodes.
void reset_counter_nodes() const noexcept
Reset all the counters to zero for all the nodes of graph.
Arc * search_arc(Node *src, Node *tgt) const noexcept
Search an arc linking two nodes.
bool traverse_in_arcs(Node *p, Op &op) const
Traverse the incoming arcs of node p executing the conditioned operation.
size_t digraph_in_degree(Node *p) const noexcept
typename Node::Node_Type Node_Type
size_t count_arcs(Node *p, Operation op=[](Arc *) { return true;}) const
Count arcs adjacent to a node satisfying a condition.
auto arcs_map(Node *p, Op operation) const
Map the adjacent arcs of a node to a specific range.
DynList< Arc * > in_arcs(Node *p) const
Return a list with the incoming arcs to p
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
bool traverse_out_arcs(Node *p, Op &op) const
Traverse the outcoming arcs of node p executing the conditioned operation
void common_swap(GT &g) noexcept
std::pair< DynList< Node * >, DynList< Node * > > partition_nodes(Operation op) const
Partition nodes into two groups based on a predicate.
constexpr bool is_empty() const noexcept
Checks if the graph is empty (has no nodes).
Arc * find_arc(const Arc_Type &info) const noexcept(noexcept(static_cast< bool >(std::declval< Arc_Type & >()==std::declval< const Arc_Type & >())))
Find an arc mathing a content.
bool exists_arc(Operation &&op=Operation()) const
Overload of exists_arc(Operation&) that accepts rvalues.
long & get_counter(Node *node) const noexcept
Get a modifiable reference to the counter of node
bool traverse_arcs(Node *p, Operation &op) const
Traverse of arcs of a node according to specific arcs iterator.
bool all_out_arcs(Node *p, Op &op) const
Return true if op is true for all the outcoming arcs to node p
void reset_bit(Node *node, int bit) const noexcept
Reset the bit of node (to zero)
auto filter_nodes(Op &&op) const
Overload of filter_nodes(Op&) that accepts rvalues.
void reset_bit_arcs(int bit) const noexcept
Reset bit to zero for all the arcs of graph.
size_t out_degree(Node *p) const noexcept
Compute the output degree of a node.
Node * emplace_node(Args &&... args)
Insert a new node in the graph by constructing it in-place with the given args.
Arc * insert_arc(Node *src, Node *tgt, const Arc_Type &arc_info)
Create and insert a new arc linking two nodes and copying data.
void for_each_node(Operation &operation) const
Unconditionally traverse all the nodes of graph and on each one perform an operation.
void reset_node_counters() const noexcept
Reset all the node counters of graph to zero.
Arc * max_arc(Node *p, Compare cmp=[](Arc *a, Arc *b) { return a->get_info()< b->get_info();}) const
Find the maximum arc adjacent to a node.
bool none_node(Operation &op) const
Determine if no node satisfies a condition.
bool traverse_nodes(Operation &&op=Operation()) const
Overload of traverse_nodes(Operation&) that accepts rvalues.
Bit_Fields & get_control_bits(Node *node) const noexcept
Return a reference to control fields of node
constexpr size_t get_num_arcs() const noexcept
Return the number of arcs of the graph.
size_t degree(Node *p) const noexcept
Return the total of arcs (or degree) of a node.
Arc * search_arc(Op &op) const
Linear search of an arc.
void reset_counter_arcs() const noexcept
Reset all the counters to zero for all the arcs of graph.
constexpr size_t vsize() const noexcept
See get_num_nodes().
void reset_bits(Node *node) const noexcept
Reset all the control bits of node
bool all_out_arcs(Node *p, Op &&op=Op()) const
Overload of all_out_arcs(Node*, Op&) that accepts rvalues.
Arc * search_directed_arc(Node *src, Node *tgt) const noexcept
Search a directed arc linking two nodes.
long & get_counter(Arc *arc) const noexcept
Get a modifiable reference to the counter of arc
bool traverse_arcs(Operation &&op=Operation()) const
Overload of traverse_arcs(Operation&) that accepts rvalues.
bool all_arcs(Node *p, Operation &op) const
Check if all the arcs adjacent to a node satisfy an boolean condition.
const GT * const_me() const
size_t esize() const noexcept
Return the total of arcs of graph.
void reset_arc(Arc *arc) const noexcept
Reset all the control attributes of arc.
void reset_nodes() const
Reset all the nodes of graph (the control bits, the state, the counter and the cookie)
Arc * get_arc(Node *p) const
Return any arc adjacent to a node.
void reset_node(Node *p) const noexcept
Reset all the control attributes of node p.
auto in_arcs_map(Node *p, Op op) const
Return a list of incoming arcs of a node mapped to items of type given by transformation op.
size_t in_degree(Node *p) const noexcept
Compute the input degree of a node.
auto filter_arcs(Op &op) const
Filter the arcs of graph satisfying a condition.
auto get_node_it() const noexcept
Obtains an iterator to the nodes of graph.
Arc * search_arc(Node *p, Operation &&op=Operation()) const
Overload of search_arc(Node*, Operation&) that accepts rvalues.
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
auto filter_out_arcs(Node *p, Op &&op=Op()) const
Overload of filter_out_arcs(Node*, Op&) that accepts rvalues.
DynList< Arc * > collect_arcs_if(Predicate pred) const
Collect all arcs matching a predicate.
void for_each_arc(Operation &&operation=Operation()) const
Overload of for_each_arc(Operation&) that accepts rvalues.
bool all_in_arcs(Node *p, Op &&op=Op()) const
Overload of all_in_arcs(Node*, Op&) that accepts rvalues.
void reset_bits(Arc *arc) const noexcept
Reset all the control bits of arc
bool exists_node(Operation &op) const
Determine if exists at least a node satisfying a condition.
auto get_arc_it(Node *p) const noexcept
Obtains an iterator to the adjacent arcs of a node.
DynList< Node * > out_nodes(Node *p) const
Return a list with the outcoming nodes to p
void *& get_cookie(Arc *arc) const noexcept
Get a modifiable reference to the cookie pointer of arc
Container< Node * > nodes() const
Return a container with all the nodes of the graph.
static void map_nodes(N1 *p, N2 *q) noexcept
Map the nodes through their cookies.
std::pair< DynList< Arc * >, DynList< Arc * > > partition_arcs(Operation op) const
Partition arcs into two groups based on a predicate.
Container< Arc * > arcs(Node *p) const
Return a container with all the arcs adjacent to a node.
static constexpr bool nothrow_cmp_v
void sort_arcs(Compare &&cmp=Compare()) noexcept(nothrow_cmp_v< Compare, Arc >)
See sort_arcs(Compare & cmp).
void reset_arc_counters() const noexcept
Reset all the arc counters of graph to zero.
void reset_bit(Arc *arc, int bit) const noexcept
Reset the bit of arc to zero.
auto filter_nodes(Op &op) const
Filter the nodes satisfying a condition.
bool all_arcs(Operation &&op=Operation()) const
Overload of all_arcs(Operation&) that accepts rvalues.
Node * search_node(Op &op) const
Linear search of a node.
Node * search_node(Op &&op) const
Overload of search_node(Op&) that accepts rvalues.
Bit_Fields & get_control_bits(Arc *arc) const noexcept
Return a reference to the control bits of arc
DynList< Arc * > filter_out_arcs(Node *p, Op &op) const
Filter the outcoming arcs of a node.
bool traverse_arcs(Operation &op) const
Conditioned traversal of all the arcs of a graph.
DynList< Node * > adjacent_nodes(Node *p) const
Get all adjacent nodes (neighbors) of a node.
bool none_arc(Operation &&op) const
Overload of none_arc(Operation&) that accepts rvalues.
auto filter_arcs(Op &&op) const
Overload of filter_arcs(Op&) that accepts rvalues.
static constexpr bool has_arc_dlink_v
void remove_arcs_if(Predicate pred)
Remove all arcs matching a predicate.
bool none_arc(Node *p, Operation &op) const
Determine if no arc adjacent to a node satisfies a condition.
void *& get_cookie(Node *node) const noexcept
Get a modifiable reference to the cookie pointer of node
bool exists_node(Operation &&op=Operation()) const
Overload of exists_node(Operation&) that accepts rvalues.
size_t count_arcs(Operation op=[](Arc *) { return true;}) const
Count the arcs satisfying a condition.
void for_each_node(Operation &&operation=Operation()) const
Overload of for_each_node(Operation&) that accepts rvalues.
T foldl_out_arcs(Node *p, const T &init, Op op) const
Fold-left over outcoming arcs of a node.
Arc * min_arc(Compare cmp=[](Arc *a, Arc *b) { return a->get_info()< b->get_info();}) const
Find the minimum arc in the entire graph.
bool exists_out_arc(Node *p, Op &&op=Op()) const
Overload of exists_out_arc(Node*, Op&) that accepts rvalues.
static constexpr bool has_node_dlink_v
Whether U::get_node_dlink() returns a Dlink &.
auto out_pairs(Node *p) const
Return a list of pair outcoming arcs and nodes.
int get_bit(Node *node, int bit) const noexcept
Get the control bit of node
bool none_arc(Operation &op) const
Determine if no arc satisfies a condition.
bool exists_arc(Node *p, Operation &&op=Operation()) const
Overload of exists_arc(Node*, Operation&) that accepts rvalues.
bool exists_arc(Operation &op) const
Determine if exists at least a arc satisfying a condition.
size_t count_nodes(Operation op=[](Node *) { return true;}) const
Count the nodes satisfying a condition.
An AlephIterator whose get_curr_ne() gives what get_curr() gives, without its check.
f(args...) is a valid call expression, exactly as written.
A graph type built with the Digraph template.
PredicateWith<F, Args...>, and neither the call nor the conversion of its result to bool can throw.
f(args...) is a valid call whose result is usable as a condition.
Concept for basic graph iterators.
Concept for graph arc iterators.
Concept for graph node iterators.
Concept for node adjacency iterators.
Concept for resettable graph iterators.
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
List_Digraph< Node, Arc > Digraph
#define ARC_COOKIE(p)
Return the arc cookie
#define NODE_COUNTER(p)
Get the counter of a node.
#define ARC_COUNTER(p)
Return the counter of arc p.
#define ARC_BITS(p)
Return the control bits of arc p.
#define NODE_COOKIE(p)
Return the node cookie
#define NODE_BITS(p)
Get the control bits of a node.
void copy_graph(GT >gt, const GT &gsrc, bool cookie_map=false)
Explicit copy of graph.
Freq_Node * pred
Predecessor node in level-order traversal.
decltype(auto) curr_ne(It &it)
The current item of it, which must have one.
Main namespace for Aleph-w library functions.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
std::decay_t< typename HeadC::Item_Type > T
auto get_curr() const
Return the current tuple (bounds-checked).
and
Check uniqueness with explicit hash + equality functors.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
Iterator on the arcs that go into a node of the digraph.
Empty placeholder class with no data members.
The filter of a walk that shows every arc.
bool operator()(Arc *) const noexcept
Every arc is shown.
What GT::Arc_Iterator::get_curr() yields, deferred on D.
decltype(std::declval< typename concepts_detail::defer< GT, D >::type::Arc_Iterator & >().get_curr()) type
What GT::Node_Arc_Iterator::get_curr() yields, deferred on D.
decltype(std::declval< typename concepts_detail::defer< GT, D >::type::Node_Arc_Iterator & >().get_curr()) type
What GT::Node_Iterator::get_curr() yields, deferred on D.
decltype(std::declval< typename concepts_detail::defer< GT, D >::type::Node_Iterator & >().get_curr()) type
Used internally for some graphs for compare their arcs.
Cmp_Dlink_Arc(Cmp &__cmp) noexcept
Cmp_Dlink_Arc(Cmp &&)=delete
bool operator()(Dlink *d1, Dlink *d2) const noexcept(noexcept(static_cast< bool >(std::declval< Cmp & >()(std::declval< Arc *& >(), std::declval< Arc *& >()))))
Whether cmp puts the arc of d1 before the arc of d2.
Used internally for some graphs for compare their nodes.
Cmp_Dlink_Node(Cmp &__cmp) noexcept
bool operator()(Dlink *d1, Dlink *d2) const noexcept(noexcept(static_cast< bool >(std::declval< Cmp & >()(std::declval< Node *& >(), std::declval< Node *& >()))))
Whether cmp puts the node of d1 before the node of d2.
Cmp_Dlink_Node(Cmp &&)=delete
Common arc iterator for graph having its arcs derived from Dlink class.
Arc * get_curr() const
Return current arc.
Arc * Item_Type
The type of item that returns the iterator.
Arc * get_curr_ne() const noexcept
Return current arc without exception.
Node * get_tgt_node() const
Return the target node of current arc (if it is a directed graph)
Arc * get_current_arc() const
Return the current arc.
Node * get_src_node_ne() const noexcept
Return the source node of current arc (if it is a directed graph)
Arc * get_current_arc_ne() const noexcept
Return the current arc without exception.
Node * get_tgt_node_ne() const noexcept
Return the target node of current arc (if it is a directed graph)
Node * get_src_node() const
Return the source node of current arc (if it is a directed graph)
GTArcIterator(Dlink &head) noexcept
Build a iterator for all the arcs of g.
Common node iterator for graph having its node derived from Dlink class.
GTNodeIterator() noexcept
Node * Item_Type
The type of item that returns the iterator.
Node * get_current_node() const
Return the current node.
GTNodeIterator(Dlink &head) noexcept
Build a iterator for all the nodes of g.
Node * get_curr_ne() const noexcept
Return the current node without exception.
Node * get_current_node_ne() const
Node * get_curr() const
Return the current node.
Filter for input arcs of a node.
Node * get_node(Arc *a) const noexcept
Return the source node of arc a
In_Filt(Node *__tgt=nullptr) noexcept
target node of iteration
bool operator()(Arc *a) const noexcept
Return true if the arc a is incoming arc to tgt; false otherwise.
Alias for Digraph_Iterator
In_Iterator(Node *p)
Iterator on the list of p, which holds the arcs into p only in a graph that is not directed.
In_Iterator(const GT &g, Node *p)
Iterator on the arcs into p of g, a graph that is not directed: those of the list of p.
static Node * of_lists(const GT &g, Node *p)
static void refuse_a_digraph()
Filter for output arcs of a node.
Out_Filt(Node *__src) noexcept
source node of iteration
Node * get_node(Arc *a) const noexcept
Return the source node of arc a (whose target is tgt)
bool operator()(Arc *a) const noexcept
Return true if a is a outcoming arc from src; false otherwise.