151template <
typename It>
154 { cit.has_curr() } -> std::convertible_to<bool>;
155 { it.next() } -> std::same_as<void>;
171template <
typename It>
174 { it.reset_first() } -> std::same_as<void>;
190template <
typename It,
typename Node>
193 { cit.get_curr() } -> std::convertible_to<Node*>;
209template <
typename It,
typename Arc>
212 { cit.get_curr() } -> std::convertible_to<Arc*>;
233template <
typename It,
typename Node,
typename Arc>
236 { cit.get_tgt_node() } -> std::convertible_to<Node*>;
277 return static_cast<Node *
>(Dlink::Iterator::get_curr_ne());
317 : Dlink::Iterator(head)
324 return static_cast<Arc *
>(Dlink::Iterator::get_curr_ne());
328 Arc *
get_curr()
const {
return static_cast<Arc *
>(Dlink::Iterator::get_curr()); }
366template <
class GT,
class Cmp>
393template <
class GT,
class Cmp>
410 Arc *arc1 =
static_cast<Arc *
>(d1);
411 Arc *arc2 =
static_cast<Arc *
>(d2);
412 return cmp(arc1, arc2);
433template <
typename NodeInfo>
526template <
typename ArcInfo>
581 arc_info = std::move(other.arc_info);
616template <
class GT,
class Node,
class Arc>
619 GT *
me() {
return static_cast<GT *
>(
this); }
646 std::swap(
cookie, g.cookie);
733 return static_cast<Node *
>(arc->src_node);
739 return static_cast<Node *
>(arc->tgt_node);
774 return static_cast<Node *
>(arc->get_connected_node(node));
784 return node->num_arcs;
993 template <
class N1,
class N2 = N1>
997 assert(p !=
nullptr and q !=
nullptr);
1024 template <
class A1,
class A2 = A1>
1028 assert(p !=
nullptr and q !=
nullptr);
1165 template <
typename... Args>
1195 std::unique_ptr<Arc> arc(
new Arc(arc_info));
1197 return arc.release();
1225 std::unique_ptr<Arc> arc(
new Arc(std::forward<Arc_Type>(arc_info)));
1227 return arc.release();
1251 template <
typename... Args>
1303 template <
class Operation>
1306 for (
typename GT::Node_Iterator it(*
const_me()); it.has_curr(); it.next_ne())
1307 if (not op(it.get_curr()))
1313 template <
class Operation>
1368 template <
class Operation>
1371 for (
typename GT::Arc_Iterator it(*
const_me()); it.has_curr(); it.next_ne())
1372 if (not op(it.get_curr()))
1378 template <
class Operation>
1435 template <
class Operation>
1438 for (
typename GT::Node_Arc_Iterator it(p); it.has_curr(); it.next_ne())
1439 if (not op(it.get_curr()))
1445 template <
class Operation>
1475 template <
class Operation>
1478 for (
typename GT::Node_Iterator it(*
const_me()); it.has_curr(); it.next_ne())
1479 operation(it.get_curr());
1483 template <
class Operation>
1513 template <
class Operation>
1516 for (
typename GT::Arc_Iterator it(*
const_me()); it.has_curr(); it.next_ne())
1521 template <
class Operation>
1560 template <
class Operation>
1563 for (
typename GT::Node_Arc_Iterator it(p); it.has_curr(); it.next_ne())
1568 template <
class Operation>
1603 template <
class Operation>
1610 template <
class Operation>
1645 template <
class Operation>
1652 template <
class Operation>
1690 template <
class Operation>
1697 template <
class Operation>
1742 template <
typename T = Node_Type>
1789 template <
typename T = Arc_Type>
1795 ret_val.append(operation(p));
1840 template <
typename T = Arc_Type>
1846 ret_val.append(operation(a));
1885 template <
typename T = Node_Type>
1887 std::function<T(
const T &,
Node *)> op)
const
1927 template <
typename T = Arc_Type>
1929 std::function<T(
const T &,
Arc *)> op)
const
1970 template <
typename T = Arc_Type>
1972 std::function<T(
const T &,
Arc *)> op)
const
2003 DynList<Node *> ret;
2126 template <
class Operation>
2133 template <
class Operation>
2157 template <
class Operation>
2164 template <
class Operation>
2192 template <
class Operation>
2199 template <
class Operation>
2219 template <
class Operation>
2226 template <
class Operation>
2246 template <
class Operation>
2253 template <
class Operation>
2266 template <
class Operation>
2273 template <
class Operation>
2295 template <
class Operation = std::function<
bool(Node*)>>
2319 template <
class Operation = std::function<
bool(Arc*)>>
2333 template <
class Operation = std::function<
bool(Arc*)>>
2357 template <
typename T =
double,
class Extract>
2366 template <
typename T =
double>
2370 for_each_arc(p, [&sum](
Arc *a) { sum +=
static_cast<T
>(a->get_info()); });
2389 template <
class Compare = std::function<
bool(Arc*, Arc*)>>
2391 return a->get_info() < b->get_info();
2394 Arc* result =
nullptr;
2396 if (result ==
nullptr or
cmp(a, result))
2417 template <
class Compare = std::function<
bool(Arc*, Arc*)>>
2419 return a->get_info() < b->get_info();
2422 Arc* result =
nullptr;
2424 if (result ==
nullptr or
cmp(result, a))
2435 template <
class Compare = std::function<
bool(Arc*, Arc*)>>
2437 return a->get_info() < b->get_info();
2440 Arc* result =
nullptr;
2442 if (result ==
nullptr or
cmp(a, result))
2453 template <
class Compare = std::function<
bool(Arc*, Arc*)>>
2455 return a->get_info() < b->get_info();
2458 Arc* result =
nullptr;
2460 if (result ==
nullptr or
cmp(result, a))
2481 template <
class Operation>
2484 DynList<Node*> yes, no;
2491 return {std::move(yes), std::move(no)};
2504 template <
class Operation>
2507 DynList<Arc*> yes, no;
2514 return {std::move(yes), std::move(no)};
2532 DynList<Node*> result;
2558 for (
typename GT::Node_Iterator it(*
const_me()); it.has_curr(); it.next_ne())
2560 auto p = it.get_curr();
2587 return search_node([&info](
auto p) {
return p->get_info() == info; });
2609 for (
typename GT::Arc_Iterator it(*
const_me()); it.has_curr(); it.next_ne())
2611 auto a = it.get_curr();
2638 return search_arc([&info](
auto a) {
return a->get_info() == info; });
2659 template <
class Operation>
2662 for (
typename GT::Node_Arc_Iterator it(p); it.has_curr(); it.next_ne())
2664 Arc *arc = it.get_curr();
2672 template <
class Operation>
2703 for (
typename GT::Node_Arc_Iterator it(src); it.has_curr(); it.next_ne())
2704 if (it.get_tgt_node_ne() == tgt)
2705 return it.get_curr();
2782 return typename GT::Node_Iterator(*
const_me());
2804 return typename GT::Arc_Iterator(*
const_me());
2827 return typename GT::Node_Arc_Iterator(p);
2876 return a->tgt_node ==
tgt;
2883 return (
typename GT::Node *) a->src_node;
2933 return a->src_node ==
src;
2940 return (
Node *) a->tgt_node;
2969 template <
class Filter>
2972 using Itor = Filter_Iterator<Node *, typename GT::Node_Arc_Iterator, Filter>;
3018 return filt.get_node(a);
3114 if (it.get_tgt_node() == tgt)
3115 return it.get_curr();
3131 DynList<Node *> ret;
3133 ret.
append(it.get_node());
3149 DynList<Node *> ret;
3151 ret.
append(it.get_node_ne());
3168 ret.
append(it.get_curr());
3184 ret.
append(it.get_curr());
3205 DynList<ArcPair> ret;
3208 auto a = it.get_curr();
3209 ret.append(std::make_tuple(a, (
Node *) a->get_connected_node(p)));
3228 DynList<ArcPair> ret;
3231 auto a = it.get_curr();
3232 ret.append(std::make_tuple(a, (
Node *) a->get_connected_node(p)));
3299 template <
class Itor,
class Operation>
3302 for (Itor it(p); it.has_curr(); it.next_ne())
3303 if (not op(it.get_curr()))
3309 template <
class Itor,
class Operation>
3312 for (Itor it(p); it.has_curr(); it.next_ne())
3321 return traverse_arcs<In_Iterator, Op>(p, op);
3335 for_each_arc<In_Iterator>(p, op);
3418 template <
typename T>
3433 template <
typename T = Arc_Type>
3435 std::function<T(
const T &,
Arc *)> op)
const
3473 return traverse_arcs<Out_Iterator>(p, op);
3487 for_each_arc<Out_Iterator>(p, op);
3542 typename GT::Arc *ret =
nullptr;
3570 template <
typename T = Arc_Type>
3579 template <
typename T = Arc_Type>
3581 std::function<T(
const T &,
Arc *)> op)
const
3633 template <
class Predicate>
3636 DynList<Arc*> result;
3637 for (
typename GT::Arc_Iterator it(*
const_me()); it.has_curr(); it.next_ne())
3638 if (
pred(it.get_curr_ne()))
3639 result.
append(it.get_curr_ne());
3664 template <
class Predicate>
3695 requires(U & u) { { u.get_node_dlink() } -> std::same_as<Dlink&>; };
3699 requires(U & u) { { u.get_arc_dlink() } -> std::same_as<Dlink&>; };
3701 template <
class Compare>
3703 requires(has_node_dlink_v<GT>)
3706 mergesort(
me()->get_node_dlink(), c);
3710 template <
class Compare>
3735 template <
class Compare>
3737 requires(has_arc_dlink_v<GT>)
3740 mergesort(
me()->get_arc_dlink(), c);
3744 template <
class Compare>
3786#define ALEPH_GRAPH_COPY_MOVE_CTORS(GraphClass) \
3788 GraphClass(const GraphClass & g) \
3790 copy_graph(*this, g); \
3794 GraphClass(GraphClass && g) noexcept \
3800 GraphClass & operator=(const GraphClass & g) \
3804 copy_graph(*this, g); \
3809 GraphClass & operator=(GraphClass && g) noexcept \
3846template <
class BaseGraph>
3851 using Node =
typename BaseGraph::Node;
3852 using Arc =
typename BaseGraph::Arc;
3860 this->digraph =
true;
3872 this->digraph =
true;
3885 this->digraph =
true;
3902 this->digraph =
true;
3918 this->digraph =
true;
WeightedDigraph::Node Node
Generic directed graph (digraph) wrapper template.
Digraph(const Digraph &dg)
Copy constructor.
Digraph(Digraph &&dg) noexcept
Move constructor.
Digraph & operator=(const Digraph &g)
Copy assignment operator.
typename BaseGraph::Arc Arc
typename BaseGraph::Node Node
Digraph() noexcept
Default constructor.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
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< int > Node
The graph type.
Graph_Arc< int > Arc
The node class type.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
void for_each(Operation &operation)
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.
void prev()
back to previous item.
typename Itor::Item_Type Item_Type
void next()
Advance to next arc.
Digraph_Iterator(Node *p)
Instantiate an filtered iterator for arcs on the node p
void reset_last() noexcept
Reset the iterator to last arc.
Filter_Iterator< Node *, typename GT::Node_Arc_Iterator, Filter > Itor
GT::Arc * get_curr_ne() const noexcept
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*)
auto get_current_arc() const
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.
void reset_first() noexcept
Reset the iterator to first 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.
T foldl_nodes(const T &init, std::function< T(const T &, Node *)> op) const
Folding of nodes on a graph.
void reset_bit_nodes(int bit) const noexcept
Reset bit to zero for all the nodes of graph.
Node * search_node(Op &&op) const
Overload of search_node(Op&) that accepts rvalues.
typename Arc::Arc_Type Arc_Type
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.
auto search_in_arc(Node *p, Op &op) const
Search an incoming arc to a node satisfaying a condition.
size_t count_nodes(Operation op=[](Node *) { return true;}) const
Count the nodes satisfying a condition.
T foldl_arcs(Node *p, const T &init, std::function< T(const T &, Arc *)> op) const
Folding of arcs of a node.
void for_each_out_arc(Node *p, Op &op) const
Perform op on each outcoming arc of node p
bool exists_arc(Operation &&op=Operation()) const
Overload of exists_arc(Operation&) that accepts rvalues.
bool exists_in_arc(Node *p, Op &op) const
Return true if it exists a incoming arc to p returning true for op
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.
bool traverse_arcs(Node *p, Operation &op) const
Conditioned traversal of all the adjacent arcs of a node.
void reset_arcs() const
Reset all the arcs of graph (the control bits, the state, the counter and the cookie)
T foldl_arcs(const T &init, std::function< T(const T &, Arc *)> op) const
Folding of arcs on a graph.
auto filter_in_arcs(Node *p, Op &&op=Op()) const
Overload of filter_in_arcs(Node*, Op&) that accepts rvalues.
void reset_cookie_arcs() const noexcept
Reset all the cookies to `nullptr for all the arcs of graph.
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
Arc * find_arc(const Arc_Type &info) const noexcept
Find an arc mathing a content.
size_t get_num_arcs(Node *node) const noexcept
Return the total of arcs of a node.
Node * find_node(const Node_Type &info) const noexcept
Find a node mathing a content.
Arc * search_arc(Node *p, Operation &&op=Operation()) const
Overload of search_arc(Node*, Operation&) that accepts rvalues.
bool none_node(Operation &op) const
Determine if no node satisfies a condition.
bool all_arcs(Operation &&op=Operation()) const
Overload of all_arcs(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
Arc * search_arc(Op &&op) const
Overload of search_arc(Op&) that accepts rvalues.
void for_each_in_arc(Node *p, Op &op) const
Perform op on each incoming arc of node p
auto arcs_map(Node *p, std::function< T(Arc *)> operation) const
Map the adjacent arcs of a node to a specific range.
auto get_arc_it() const noexcept
Obtains an iterator to the arc of graph.
auto filter_arcs(Op &op) const
Filter the arcs of graph satisfying a condition.
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.
bool none_arc(Node *p, Operation &op) const
Determine if no arc adjacent to a node satisfies a condition.
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.
In_Iterator get_in_it(Node *p) const noexcept
Return an input iterator on the incoming arcs to p
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)
bool traverse_arcs(Operation &op) const
Conditioned traversal of all the arcs of a graph.
DynList< Node * > in_nodes(Node *p) const
Return a list with the incoming nodes to p
T foldl_out_arcs(Node *p, const T &init, std::function< T(const T &, Arc *)> op) const
Fold-left over outcoming arcs of a node.
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
auto filter_arcs(Node *p, Op &op) const
Filter the arcs adjacent to a node satisfying a condition.
Arc * search_arc(Node *p, Operation &op) const
Linear search of an arc.
auto out_arcs_map(Node *p, std::function< T(Arc *)> op) const
Return a list of outcoming arcs of a node mapped to items of type given by transformation op.
auto filter_nodes(Op &&op) const
Overload of filter_nodes(Op&) that accepts rvalues.
bool traverse_in_arcs(Node *p, Op &&op=Op()) const
Overload of traverse_in_arcs(Node*, Op&) that accepts rvalues.
bool all_nodes(Operation &op) const
Check if all the nodes of graph satisfy an boolean condition.
void reset_bit_nodes() const noexcept
Reset all the bits for all the nodes of graph.
auto search_in_arc(Node *p, Op &&op=Op()) const
Overload of search_in_arc(Node*, Op&) that accepts rvalues.
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.
bool traverse_arcs(Node *p, Operation &&op=Operation()) const
Overload of traverse_arcs(Node*, Operation&) 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 * 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.
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
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.
bool none_arc(Operation &&op) const
Overload of none_arc(Operation&) that accepts rvalues.
auto arcs_map(std::function< T(Arc *)> operation) const
Map the arcs of a graph to a specific range.
void set_digraph(bool val)
Temporal indication for preventing to other algorithms that an graph must be treated as a directed gr...
bool all_nodes(Operation &&op=Operation()) const
Overload of all_nodes(Operation&) that accepts rvalues.
bool traverse_out_arcs(Node *p, Op &&op=Op()) const
Overload of traverse_out_arcs(Node*, Op&) that accepts rvalues.
void *& get_cookie() noexcept
Return a modifiable reference to graph's cookie.
void for_each_arc(Node *p, Operation &op) const
Perform op on each arc of node p
size_t degree(Node *p) const noexcept
Return the total of arcs (or degree) of a node.
bool exists_arc(Node *p, Operation &op) const
Determine if exists at least a arc adjacent to a node satisfying a condition.
void for_each_node(Operation &&operation=Operation()) const
Overload of for_each_node(Operation&) that accepts rvalues.
bool exists_node(Operation &op) const
Determine if exists at least a node satisfying a condition.
DynList< Arc * > filter_in_arcs(Node *p, Op &op) const
Filter the incoming arcs of a node.
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.
void for_each_arc(Operation &&operation=Operation()) const
Overload of for_each_arc(Operation&) that accepts rvalues.
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
bool none_node(Operation &&op) const
Overload of none_node(Operation&) that accepts rvalues.
typename Node::Node_Type Node_Type
void for_each_arc(Node *p, Operation &&op=Operation()) const
Overload of for_each_arc(Node*, Operation&) that accepts rvalues.
void sort_arcs(Compare &cmp) noexcept
Sort all the arcs of the graph according to a specific criteria.
DynList< Arc * > in_arcs(Node *p) const
Return a list with the incoming arcs to p`.
auto filter_arcs(Op &&op) const
Overload of filter_arcs(Op&) that accepts rvalues.
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.
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
size_t count_arcs(Operation op=[](Arc *) { return true;}) const
Count the arcs satisfying a condition.
void common_swap(GT &g) noexcept
auto in_arcs_map(Node *p, std::function< T(Arc *)> op) const
Return a list of incoming arcs of a node mapped to items of type given by transformation op.
bool all_arcs(Node *p, Operation &&op=Operation()) const
Overload of all_arcs(Node*, 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.
long & get_counter(Node *node) const noexcept
Get a modifiable reference to the counter of node
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)
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.
void for_each_arc(Operation &op) const
Unconditionally traverse all the arcs of graph and on each one perform an operation.
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 reset_node_counters() const noexcept
Reset all the node counters of graph to zero.
Bit_Fields & get_control_bits(Node *node) const noexcept
Return a reference to control fields of node
Node * get_arc(Node *p)
Return any arc adjacent to a node.
constexpr size_t get_num_arcs() const noexcept
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.
void sort_arcs(Compare &&cmp=Compare()) noexcept
constexpr size_t vsize() const noexcept
bool none_arc(Operation &op) const
Determine if no arc satisfies a condition.
bool none_arc(Node *p, Operation &&op) const
Overload of none_arc(Node*, Operation&) that accepts rvalues.
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
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)
bool exists_arc(Node *p, Operation &&op=Operation()) const
Overload of exists_arc(Node*, Operation&) that accepts rvalues.
bool all_arcs(Operation &op) const
Check if all the arcs of graph satisfy a boolean condition.
void reset_node(Node *p) const noexcept
Reset all the control attributes of node p.
size_t in_degree(Node *p) const noexcept
Compute the input degree of a node.
auto get_node_it() const noexcept
Obtains an iterator to the nodes of graph.
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Node * get_arc() const
Return any arc in the graph.
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.
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
auto get_arc_it(Node *p) const noexcept
Obtains an iterator to the adjacent arcs of a node.
auto nodes_map(std::function< T(Node *)> op) const
Map the nodes of a graph to a specific range.
bool traverse_nodes(Operation &&op=Operation()) const
Overload of traverse_nodes(Operation&) that accepts rvalues.
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.
Container< Arc * > arcs(Node *p) const
Return a container with all the arcs adjacent to a node.
bool exists_arc(Operation &op) const
Determine if exists at least a arc satisfying a condition.
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.
bool exists_node(Operation &&op=Operation()) const
Overload of exists_node(Operation&) that accepts rvalues.
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.
Node * search_node(Op &op) const
Linear search of a node.
auto filter_nodes(Op &op) const
Filter the nodes satisfying a condition.
void reset_arc_counters() const noexcept
Reset all the arc counters of graph to zero.
auto filter_arcs(Node *p, Op &&op) const
Overload of filter_arcs(Node*, Op&) that accepts rvalues.
void reset_bit(Arc *arc, int bit) const noexcept
Reset the bit of arc to zero.
void sort_nodes(Compare &cmp) noexcept
T sum_arcs(Node *p, Extract extract) const
Sum values derived from arcs adjacent to a node.
T foldl_in_arcs(Node *p, const T &init, std::function< T(const T &, Arc *)> op) const
Fold the incoming arcs of a node.
std::pair< DynList< Node * >, DynList< Node * > > partition_nodes(Operation op) const
Partition nodes into two groups based on a predicate.
Bit_Fields & get_control_bits(Arc *arc) const noexcept
Return a reference to the control bits of arc
bool traverse_arcs(Node *p, Operation &op) const
Traverse of arcs of a node according to specific arcs iterator.
DynList< Arc * > filter_out_arcs(Node *p, Op &op) const
Filter the outcoming arcs of a node.
void sort_nodes(Compare &&cmp=Compare()) noexcept
DynList< Node * > adjacent_nodes(Node *p) const
Get all adjacent nodes (neighbors) of a node.
void for_each_node(Operation &operation) const
Unconditionally traverse all the nodes of graph and on each one perform an operation.
static constexpr bool has_arc_dlink_v
void remove_arcs_if(Predicate pred)
Remove all arcs matching a predicate.
bool traverse_nodes(Operation &op) const
Conditioned traversal of all the nodes of a graph.
void *& get_cookie(Node *node) const noexcept
Get a modifiable reference to the cookie pointer of node
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
Sort all the nodes of the graph according to a specific criteria.
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
size_t count_arcs(Node *p, Operation op=[](Arc *) { return true;}) const
Count arcs adjacent to a node satisfying a condition.
bool traverse_arcs(Operation &&op=Operation()) const
Overload of traverse_arcs(Operation&) that accepts rvalues.
std::pair< DynList< Arc * >, DynList< Arc * > > partition_arcs(Operation op) const
Partition arcs into two groups based on a predicate.
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.
List_Graph< Graph_Node< int >, Graph_Arc< int > > GT
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
#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.
Main namespace for Aleph-w library functions.
T & swap(T &t1, T &t2)
Generic swap using object's swap method.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Empty placeholder class with no data members.
Arc of graph implemented with double-linked adjacency lists.
Used internally for some graphs for compare their arcs.
Cmp_Dlink_Arc(Cmp &__cmp) noexcept
bool operator()(Dlink *d1, Dlink *d2) const noexcept
Cmp_Dlink_Arc(Cmp &&__cmp=Cmp()) noexcept
Used internally for some graphs for compare their nodes.
Cmp_Dlink_Node(Cmp &__cmp) noexcept
bool operator()(Dlink *d1, Dlink *d2) const noexcept
Cmp_Dlink_Node(Cmp &&__cmp=Cmp()) noexcept
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
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.