67 template <
typename Node_Info>
70 template <
typename Arc_Info>
78 template <
typename __Graph_Node,
typename __Graph_Arc>
87 template <
typename MT,
typename Entry_Info,
typename Copy>
117 template <
typename __Node_Info = Empty_Class>
218 template <
typename _Arc_Info = Empty_Class>
423 template <
typename _Graph_Node = Graph_Node<
unsigned long>,
424 typename _Graph_Arc = Graph_Arc<
unsigned long>>
426 :
public GraphCommon<List_Graph<_Graph_Node, _Graph_Arc>,
427 _Graph_Node, _Graph_Arc>
456 return static_cast<Node *
>(p);
461 return static_cast<Arc *
>(p);
600 return reinterpret_cast<Arc *
>(arc);
606 assert(src_node !=
nullptr and tgt_node !=
nullptr and a !=
nullptr);
607 Arc *arc =
static_cast<Arc *
>(a);
608 arc->src_node = src_node;
609 arc->tgt_node = tgt_node;
612 std::unique_ptr<Arc_Node> src_arc_node = std::make_unique<Arc_Node>(arc);
617 if (src_node == tgt_node)
618 arc->tgt_arc_node = src_arc_node.get();
621 std::unique_ptr<Arc_Node> tgt_arc_node = std::make_unique<Arc_Node>(arc);
624 arc->tgt_arc_node = tgt_arc_node.get();
625 tgt_node->arc_list.append(tgt_arc_node.get());
626 ++tgt_node->num_arcs;
627 tgt_arc_node.release();
632 arc->src_arc_node = src_arc_node.get();
633 src_node->arc_list.append(src_arc_node.get());
634 ++src_node->num_arcs;
638 src_arc_node.release();
654 Arc_Node *src_arc_node = arc->src_arc_node;
657 --src_node->num_arcs;
663 if (src_node != tgt_node)
665 Arc_Node *tgt_arc_node = arc->tgt_arc_node;
667 --tgt_node->num_arcs;
703 Arc_Node *src_arc_node = arc->src_arc_node;
705 --src_node->num_arcs;
710 if (src_node != tgt_node)
712 Arc_Node *tgt_arc_node = arc->tgt_arc_node;
714 --tgt_node->num_arcs;
738 Arc_Node *src_arc_node = arc->src_arc_node;
739 Arc_Node *tgt_arc_node = arc->tgt_arc_node;
743 if (src_node != tgt_node)
745 tgt_node->arc_list.
append(tgt_arc_node);
746 ++tgt_node->num_arcs;
750 src_node->arc_list.append(src_arc_node);
751 ++src_node->num_arcs;
1114 template <
class GT,
class Show_Arc = Dft_Show_Arc<GT>>
1117 typename GT::Node_Arc_Iterator,
1121 typename GT::Node_Arc_Iterator,
1125 typename GT::Node_Arc_Iterator,
1161 template <
class GT,
class Show_Arc = Dft_Show_Arc<GT>>
1203 template <
class GT,
class Show_Node = Dft_Show_Node<GT>>
1237 template <
class GT,
class SN = Dft_Show_Node<GT>>
1255 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1274 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1295 template <
class GT,
class SN = Dft_Show_Node<GT>>
1297 std::function<
bool (
typename GT::Node *)> cond,
1301 if (
not cond(it.get_curr()))
1316 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1318 std::function<
bool (
typename GT::Arc *)> cond,
1322 if (
not cond(it.get_curr()))
1337 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1339 std::function<
bool (
typename GT::Arc *)> cond,
1343 if (
not cond(it.get_curr()))
1362 template <
class GT,
typename T,
1390 template <
class GT,
typename T,
1425 template <
class GT,
typename T,
1451 template <
class GT,
typename T,
class SN = Dft_Show_Node<GT>>
1473 template <
class GT,
typename T,
class SA = Dft_Show_Arc<GT>>
1496 template <
class GT,
typename T,
class SA = Dft_Show_Arc<GT>>
1530 template <
typename __Graph_Node = Graph_Node<
int>,
1531 typename __Graph_Arc = Graph_Arc<
int>>
1541 using ArcPair = std::tuple<typename GT::Arc *, typename GT::Node *>;
1563 return a->src_node ==
src;
1593 return a->tgt_node ==
tgt;
1607 template <
class GT,
class Filter>
1611 typename GT::Node_Arc_Iterator,
Filter>;
1647 return it.has_curr();
1654 return it.get_curr();
1661 return it.get_curr_ne();
1675 return filt.get_node(a);
1748 template <
class GT,
class Show_Arc = Dft_Show_Arc<GT>>
1793 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1838 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1855 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1871 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1887 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1902 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1917 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1923 typename GT::Arc *a = it.get_curr();
1936 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1942 typename GT::Arc *a = it.get_curr();
1957 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1985 template <
class GT,
class SA = Dft_Show_Arc<GT>>
2025 template <
class GT,
class Itor,
class Operation>
2029 for (Itor it(p); it.has_curr(); it.next_ne())
2030 if (
not op(it.get_curr()))
2052 template <
class GT,
class Itor,
class Operation>
2056 for (Itor it(p); it.has_curr(); it.next_ne())
2072 template <
class GT,
class Op>
2085 template <
class GT,
class Op>
2102 template <
class GT,
class Op>
2122 template <
class GT,
class Op>
2143 template <
class GT,
class Op>
2173 template <
class GT,
typename T>
2201 template <
class GT,
typename T>
2204 std::function<
T (
const T &,
typename GT::Arc *)> op)
2220 template <
class GT,
class Op>
2245 template <
class GT,
class Op>
2258 template <
class GT,
class Op>
2275 template <
class GT,
class Op>
2295 template <
class GT,
class Op>
2316 template <
class GT,
class Op>
2346 template <
class GT,
typename T>
2374 template <
class GT,
typename T>
2377 std::function<
T (
const T &,
typename GT::Arc *)> op)
2393 template <
class GT,
class Op>
2419 template <
class GT,
class SA = Dft_Show_Arc<GT>>
2425 assert(src !=
nullptr and tgt !=
nullptr);
2428 std::swap(tgt, src);
2431 if (
itor.get_tgt_node_ne() == tgt)
2432 return itor.get_current_arc_ne();
2447 template <
class GT,
class SA = Dft_Show_Arc<GT>>
2454 assert(src !=
nullptr and tgt !=
nullptr);
2457 if (
typename GT::Arc *a = it.get_curr(); a->src_node == src
and a->tgt_node == tgt)
2481 template <
class GTSRC,
class GTTGT>
2488 template <
class GTSRC,
class GTTGT>
2489 typename GTTGT::Arc *
mapped_arc(
typename GTSRC::Arc *a)
noexcept
2533 template <
class GT,
class Operation,
class SN = Dft_Show_Node<GT>>
2553 op(g, it.get_curr());
2564 op(g, it.get_curr());
2578 template <
class GT,
class Operation,
class SA = Dft_Show_Arc<GT>>
2598 op(g, it.get_curr());
2604 op(g, it.get_curr());
2617 op(g, it.get_current_arc_ne());
2624 op(g, it.get_current_arc_ne());
2694 if (
not (
node->get_info() == r.node->get_info()))
2698 return r.arc ==
nullptr;
2700 if (r.arc ==
nullptr)
2703 return arc->get_info() == r.arc->get_info();
2733 return list.all([
this](
auto d)
2823 list.remove_first();
2847 std::swap(
g, path.g);
2848 list.swap(path.list);
2875 <<
"arc has not link to last node of path";
2902 if (
list.is_empty())
2912 <<
"There is no an arc connecting to the node";
2941 if (
list.is_empty())
2987 <<
"The arc does not connect the last node";
3018 <<
"arc has not link to first node of path";
3043 if (
list.is_empty())
3080 if (
list.is_empty())
3118 <<
"The arc does not connect the first node";
3127 return list.get_first().node;
3143 return list.get_first().arc;
3151 <<
"Path with only a node (without any arc)";
3172 auto d =
list.remove_last();
3173 list.get_last().arc =
nullptr;
3184 auto d =
list.remove_first();
3191 std::swap(
g, path.g);
3192 list.swap(path.list);
3330 template <
class Operation>
3334 op(it.get_current_node_ne());
3341 template <
class Operation>
3345 op(it.get_current_arc_ne());
3352 if (it.get_current_node_ne() == node)
3361 if (it.get_current_arc_ne() == arc)
3400 return eq(this->list, p.list);
3406 return not eq(this->list, p.list);
3479 auto arc = it.get_current_arc_ne();
3503 template <
class GTS,
class GTT>
3504 void map_nodes(
typename GTS::Node *p,
typename GTT::Node *q)
noexcept
3531 template <
class GTS,
class GTT>
3532 void map_arcs(
typename GTS::Arc *p,
typename GTT::Arc *q)
noexcept
3551 for (
typename GT::Arc_Iterator it(g); it.has_curr();)
3553 typename GT::Arc *arc = it.get_curr_ne();
3558 for (
typename GT::Node_Iterator it(g); it.has_curr();)
3560 typename GT::Node *p = it.get_curr_ne();
3575 for (
typename GT::Node_Iterator it(
gsrc); it.has_curr(); it.next_ne())
3577 typename GT::Node *src_node = it.get_current_node_ne();
3578 std::unique_ptr<typename GT::Node>
3580 map.
insert(src_node, tgt_node.get());
3582 typename GT::Node *tgt = tgt_node.release();
3584 gtgt.insert_node(tgt);
3594 for (
typename GT::Arc_Iterator it(
gsrc); it.has_curr(); it.next_ne())
3621 template <
class GTT,
class GTS>
3624 void operator()(
typename GTT::Node *tgt,
typename GTS::Node *src)
noexcept
3634 template <
class GTT,
class GTS>
3639 tgt->get_info() = src->get_info();
3651 template <
class GTT,
class GTS,
3662 for (
typename GTS::Node_Iterator it(
gsrc); it.has_curr(); it.next_ne())
3664 typename GTS::Node *src_node = it.get_current_node_ne();
3665 std::unique_ptr<typename GTT::Node> tgt_node(
new typename GTT::Node);
3667 map.
insert(src_node, tgt_node.get());
3669 typename GTT::Node *tgt = tgt_node.release();
3670 gtgt.insert_node(tgt);
3680 for (
typename GTS::Arc_Iterator it(
gsrc); it.has_curr(); it.next_ne())
3682 typename GTS::Arc *
src_arc = it.get_current_arc_ne();
3685 typename GTT::Node *src_node = map[
gsrc.get_src_node(
src_arc)];
3686 typename GTT::Node *tgt_node = map[
gsrc.get_tgt_node(
src_arc)];
3687 typename GTT::Arc *
tgt_arc =
gtgt.insert_arc(src_node, tgt_node);
3714 template <
class GT,
class SN = Dft_Show_Node<GT>,
class SA = Dft_Show_Arc<GT>>
3742 typename GT::Node *src_node = it.get_curr();
3743 std::unique_ptr<typename GT::Node>
3744 tgt_node(
new typename GT::Node(src_node));
3745 map.
insert(src_node, tgt_node.get());
3747 typename GT::Node *tgt = tgt_node.release();
3748 gtgt.insert_node(tgt);
3764 gtgt.insert_arc(src_node, tgt_node,
src_arc->get_info());
3801 template <
class GT,
class Distance>
3879 template <
class,
class>
class Tree =
Treap>
3896 for (
typename GT::Node_Iterator it(src); it.has_curr(); it.next_ne())
3898 Node *src_node = it.get_curr();
3904 for (
typename GT::Arc_Iterator it(src); it.has_curr(); it.next_ne())
4007 <<
"Node not found in mapping (not from original graph?)";
4025 return ptr ? ptr->second :
nullptr;
4069 template <
typename Op>
4128 if (
pair.second == node)
4130 original_node = pair.first;
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
#define ah_range_error_if(C)
Throws std::range_error if condition holds.
Simplified graph interface for common use cases.
void put_itor_at_the_end(Itor &it) noexcept
Space-efficient bit array implementation.
Arc_Node(void *__arc) noexcept
Copy_Graph(SA __sa=SA(), SN __sn=SN())
Constructor.
void copy(GT >gt, const GT &gsrc, const bool cookie_map)
void operator()(GT >gt, GT &gsrc, const bool cookie_map=true)
Perform the copy from gsrc to gtgt.
Filtered iterator on directed graphs.
GT::Arc * get_curr_ne() const noexcept
Return the current arc.
void reset_last() noexcept
Reset the iterator to the last arc.
void reset_first() noexcept
Reset the iterator to the first arc.
GT::Node * get_node_ne() const noexcept
Return the connected node to current arc.
GT::Node * get_node() const
Return the connected node to current arc.
GT::Arc * get_curr() const
Return the current arc.
Digraph_Iterator(typename GT::Node *p)
Iterator type.
Filter_Iterator< typename GT::Node *, typename GT::Node_Arc_Iterator, Filter > Itor
auto get_tgt_node_ne() const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
void end() noexcept
Put the iterator in end state.
auto get_tgt_node() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool has_curr() const noexcept
Return true the iterator has an current arc.
auto get_current_arc() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
GT::Node * get_node(typename GT::Arc *a) const noexcept
Return the connected node to arc.
void prev()
Move the iterator one position backward.
typename Itor::Item_Type Item_Type
void next()
Move the iterator one position forward.
Generic directed graph (digraph) wrapper template.
bool is_in_last() const noexcept
Return true if the iterator is positiones on the last item.
bool has_curr() const noexcept
Return true if the iterator has current item.
Dlink * get_curr() const
Return the current node of iterator.
Dlink * get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Doubly linked circular list node.
void append(Dlink *node) noexcept
Insert node before this.
Dlink * del() noexcept
Remove this from the list. this must not be a header node.
void swap(Dlink *link) noexcept
Swap this with list whose header is link.
void insert(Dlink *node) noexcept
Insert node after this.
T & get_curr() const
Return the current item; throw overflow_error if there is no current item.
void reset_last() noexcept
Reset the iterator to the last item.
void prev()
Move the iterator one item backward.
T & get_curr_ne() const noexcept
Dynamic doubly linked list with O(1) size and bidirectional access.
Dynamic singly linked list with functional programming support.
T & insert(const T &item)
Insert a new item by copy.
T & append(const T &item)
Append a new item by copy.
T & get_last() const
Return the last item of the list.
T & get_first() const
Return the first item of the list.
Dynamic map implemented with an AVL tree.
Generic key-value map implemented on top of a binary search tree.
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
Generic filter iterator wrapper.
void next()
Advances the iterator to the next filtered element.
void next_ne() noexcept
Advances the iterator to the next filtered element (noexcept version).
void reset_last()
Resets the iterator to the last filtered element.
void prev()
Moves the iterator backward to the previous filtered element.
typename It::Item_Type Item_Type
The type of element returned by get_curr()
void reset_first()
Resets the iterator to the first filtered element.
Graph copy with explicit node mapping.
Node * search_copy(Node *orig) const noexcept
Search for the copy of an original node (no exception).
typename GT::Arc_Type Arc_Type
bool has_copy(Node *orig) const noexcept
Check if an original node is in the mapping.
GraphCopyWithMapping & operator=(const GraphCopyWithMapping &)=delete
Node * insert_unmapped_node(Node_Type &&info)
Insert a new node into the copied graph (not mapped, move version).
void build_copy(const GT &src)
Build the copy and mapping.
GraphCopyWithMapping()=default
Default constructor.
const GT & get_graph() const noexcept
Get the copied graph (const version).
DynMapTree< Node *, Node *, Tree > node_map
void remove_node(Node *node)
Remove a node from the copied graph.
Node * get_copy(Node *orig) const
Get the copy of an original node.
void clear()
Clear the copied graph and mapping.
Arc * insert_arc(Node *src, Node *tgt, const Arc_Type &info=Arc_Type())
Insert an arc into the copied graph.
GraphCopyWithMapping(const GT &src)
Construct a copy of the given graph with node mapping.
void remove_arc(Arc *arc)
Remove an arc from the copied graph.
void for_each_mapping(Op op) const
Apply a function to each (original, copy) node pair.
size_t num_arcs() const noexcept
Get the number of arcs in the copied graph.
Node * insert_unmapped_node(const Node_Type &info=Node_Type())
Insert a new node into the copied graph (not mapped).
typename GT::Node_Type Node_Type
GraphCopyWithMapping(GraphCopyWithMapping &&other) noexcept=default
Move constructor.
size_t num_nodes() const noexcept
Get the number of mapped nodes.
GT & get_graph() noexcept
Get the copied graph.
GraphCopyWithMapping(const GraphCopyWithMapping &)=delete
GraphCopyWithMapping & operator=(GraphCopyWithMapping &&other) noexcept=default
Move assignment operator.
constexpr bool is_empty() const noexcept
Return true if list is empty.
size_t size() const noexcept
Count the number of elements of the list.
bool is_unitarian_or_empty() const noexcept
Return true if list contains one element or is empty.
Filtered iterator for incoming arcs of a node.
typename GT::Arc * Item_Type
In_Iterator(typename GT::Node *p, SA sa=SA())
Iterator on the arcs of a graph.
Node_Arc_Iterator(Node *src) noexcept
Constructs an iterator on the node src.
Node * get_node_ne() const noexcept
Node * get_tgt_node_ne() const noexcept
Arc_Node * get_current_arc_node() const
Arc * get_current_arc() const
Return the current arc.
Arc * get_curr_ne() const noexcept
Node_Arc_Iterator()=default
The container type (a node)
Arc_Node * get_current_arc_node_ne() const noexcept
Arc * get_current_arc_ne() const noexcept
Node * Set_Type
The type of data of set.
Node * get_tgt_node() const
Return the connected node to source node (src passed in construction time) through the current arc.
Graph implemented with double-linked adjacency lists.
Dlink & get_node_dlink() noexcept
Return a reference to the internal node Dlink for sorting.
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.
Dlink & get_arc_dlink() noexcept
Return a reference to the internal arc Dlink for sorting.
void swap(List_Graph &g) noexcept
Swap in constant time this with g
Arc * get_first_arc() const
Return any arc in the graph.
static Arc * dlink_to_arc(Dlink *p) noexcept
static Arc_Node * dlink_to_arc_node(Dlink *p) noexcept
virtual void remove_node(Node *node) noexcept
Remove a node from the graph and free its memory.
static Node * dlink_to_node(Dlink *p) noexcept
virtual Arc * connect_arc(Arc *arc) noexcept
Connect a previously disconnected arc to the graph.
typename Node::Node_Type Node_Type
The arc class type.
virtual void remove_arc(Arc *arc) noexcept
Remove an arc from the graph and free it.
static Arc * void_to_arc(Arc_Node *arc_node) noexcept
_Graph_Node Node
The graph type.
virtual void disconnect_arc(Arc *arc) noexcept
Disconnect an arc from graph.
_Graph_Arc Arc
The node class type.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
List_Graph()=default
Construct an empty graph.
typename Arc::Arc_Type Arc_Type
The type of data stored in the arc.
Filtered iterator on the nodes of a graph.
typename Itor::Item_Type Item_Type
typename Itor::Set_Type Set_Type
The element type: Node*.
Node_Iterator()=default
The set: the arcs of a graph.
Node_Iterator(const GT &g, Show_Node sn=Show_Node())
Construct a iterator with filter sn
Functor that traverses the arcs of a graph and performs an operation.
void operator()(const GT &g, typename GT::Node *p, Operation op=Operation()) const
Call to `op on each arc of a node.
void operator()(GT &g, Operation op=Operation()) const
void operator()(const GT &g, Operation op=Operation()) const
Call to `op on each arc.
Operate_On_Arcs(SA __sa=SA())
Initialize the functor with the filter sa
void operator()(GT &g, typename GT::Node *p, Operation op=Operation()) const
Functor that traverses the nodes of a graph and performs an operation.
Operate_On_Nodes(SN __sn=SN())
Initialize the functor with the filter sa
void operator()(const GT &g, Operation op=Operation())
Call to operation on each node.
void operator()(GT &g, Operation op=Operation())
Call to operation on each node.
Filtered iterator for outcoming arcs of a node.
Out_Iterator(typename GT::Node *p, Show_Arc sa=Show_Arc())
typename GT::Arc * Item_Type
Iterator on nodes and arcs of a path.
Node * get_current_node_ne() const noexcept
std::tuple< Node *, Arc * > get_tuple() const
Return a tuple with the current node and arc.
Node * get_current_node() const
Return the current node of a path.
std::tuple< Node *, Arc * > get_tuple_ne() const noexcept
Node * get_curr_ne() const noexcept
Arc * get_current_arc_ne() const noexcept
Arc * get_current_arc() const
Return the current arc of a path.
Iterator(const Path &path) noexcept
Create an iterator on the first node of path
Path_Desc & get_curr_path_desc() const
bool has_current_node() const noexcept
Return true if the iterator has a current node.
Path_Desc & get_curr_path_desc_ne() const noexcept
std::pair< Node *, Arc * > get_pair() const
Return a pair with the current node and arc.
bool has_current_arc() const noexcept
Return true if iterator has current arc.
bool is_cycle() const
Return true if this is a cycle; throws if path is empty.
void insert(Arc *arc)
Insert an arc as the first of a path.
void for_each_node(Operation op=Operation()) const
Execute an operation on each node of path.
void empty()
Clean the path: all the nodes and arc are removed.
Path & operator=(const Path &path)
Copy assignment.
DynList< Arc * > arcs() const
Return a list with the arcs of a path (order, according to the path)
typename GT::Arc_Type Arc_Type
The type of data stored in the arc.
void init(Node *start_node)
Set the first node of a path.
void append(Node *node)
Append a node to the path.
Path & operator=(Path &&path) noexcept
Move assignment.
size_t size() const noexcept
Return the path length in nodes.
bool check_directed() const
Return true if the directed path is consistent.
bool contains_node(Node *node) const noexcept
Return true if node belongs to the path.
void insert_directed(Node *p)
Append a node to a directed path.
Node * get_first_node() const
Return the first node of path; throws overflow_error if path is empty.
bool operator==(const Path &p) const noexcept
Return true if this is equal to p,.
bool operator!=(const Path &p) const noexcept
Return true if this is not equal to p,.
Iterator get_it() const
Returns an iterator on the path.
Path(Path &&path) noexcept
Move constructor.
bool is_empty() const noexcept
Return true if the path is empty.
typename GT::Node_Type Node_Type
The type of data stored in the nodes.
bool check() const
Return true if the path is consistent.
bool inside_graph(const GT &gr) const noexcept
Return true if this is on graph gr
Arc * get_last_arc() const
Return the last arc of a path; throws overflow_error if the path is empty.
Path(const GT &__g) noexcept
Construct a empty path on graph __g
bool contains_arc(Arc *arc) const noexcept
Return true if arc belongs to the path.
void swap(Path &path) noexcept
Fast swap between two paths (constant time)
void set_graph(const GT &__g, Node *start_node=nullptr)
Set the graph of the path.
Node * remove_first_node()
Remove the first node of a path.
Arc * get_first_arc() const
Return the first arc of path; throws overflow_error if path is empty.
DynDlist< Path_Desc > list
void append(Arc *arc)
Append an arc to the path.
void append_directed(Node *p)
Append a node to a directed path.
void insert_directed(Arc *arc)
Append an arc to a directed path.
Path(const GT &_g, Node *start_node)
Construct a path starting from a given node.
DynList< Node * > nodes() const
Return a list with the nodes of path (order according to the path)
Node * get_last_node() const
Return the last node of path; throws overflow_error if path is empty.
Path(const Path &path)
Copy constructor.
Node * remove_last_node()
Remove the last node of path.
void insert(Node *node)
Insert a node to the path.
const GT & get_graph() const noexcept
Get a constant reference to the graph.
void for_each_arc(Operation op=Operation()) const
Execute an operation on each arc of path.
void append_directed(Arc *arc)
Append an arc to a directed path.
Filter the incoming arcs.
bool operator()(typename GT::Arc *a) const noexcept
GT::Node * get_node(typename GT::Arc *a) const noexcept
__In_Filt(typename GT::Node *__tgt) noexcept
Filter the outcoming arcs.
bool operator()(typename GT::Arc *a) const noexcept
GT::Node * get_node(typename GT::Arc *a) const noexcept
__Out_Filt(typename GT::Node *__src) noexcept
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Common methods for the arc of a graph.
void * get_connected_node(void *node) noexcept
Common attributes and methods for nodes (vertexes) belonging to graphs.
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
size_t num_arcs
data associated to the node. Access it with get_info()
Common methods to the Aleph-w ( ) graph classes.
void reset_bit_nodes(int bit) const noexcept
Reset bit to zero for all the nodes of graph.
auto get_arc_it() const noexcept
Obtains an iterator to the arc of graph.
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)
bool is_digraph() const noexcept
Return true if the graph this is directed.
static void map_arcs(A1 *p, A2 *q) noexcept
Map the arcs through their cookies.
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
void common_swap(GT &g) noexcept
void reset_bit_arcs(int bit) const noexcept
Reset bit to zero for all the arcs of graph.
Arc * insert_arc(Node *src, Node *tgt, const Arc_Type &arc_info)
Create and insert a new arc linking two nodes and copying data.
constexpr size_t get_num_arcs() const noexcept
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
static void map_nodes(N1 *p, N2 *q) noexcept
Map the nodes through their cookies.
void remove_arcs_if(Predicate pred)
Remove all arcs matching a predicate.
Generic filter iterator wrapper for Aleph containers.
List_Graph< Graph_Node< int >, Graph_Arc< int > > GT
Graph base classes and common utilities via CRTP.
DynArray< Graph::Arc * > arcs
T foldl_arcs(GT &g, const T &init, std::function< T(const T &, typename GT::Arc *)> operation, SA sa=SA())
Fold the filtered arcs of a graph.
T foldl_nodes(GT &g, const T &init, std::function< T(const T &, typename GT::Node *)> operation, SN sn=SN())
Fold the filtered nodes of a graph.
DynList< typename GT::Node * > in_nodes(typename GT::Node *p, SA sa=SA())
Return the nodes connected to the filtered incoming arcs to p.
void for_each_out_arc(typename GT::Node *p, Op op=Op())
Traverse the outcoming arcs of a node and executes an operation.
#define ARC_COOKIE(p)
Return the arc cookie
void map_arcs(typename GTS::Arc *p, typename GTT::Arc *q) noexcept
Map two arcs of different types of graphs through their cookies.
Container< T > nodes_map(GT &g, std::function< T(typename GT::Node *)> transformation, SN sn=SN())
Map the filtered nodes of a graph to a transformed type.
bool traverse_in_arcs(typename GT::Node *p, Op op=Op())
Conditioned traversal of incoming arcs of a node.
DynList< ArcPair< GT > > out_pairs(typename GT::Node *p, SA sa=SA())
Return the filtered outcoming pairs of (arc,node) related to node p
void for_each_arc(const GT &g, std::function< void(typename GT::Arc *)> operation, SA sa=SA())
Traverse all the arcs of graph filtering some ones according to a condition and executing an operatio...
bool traverse_arcs(typename GT::Node *p, Operation op=Operation())
Generic arcs traverse of a node.
bool traverse_out_arcs(typename GT::Node *p, Op op=Op())
Conditioned traversal of outcoming arcs of a node.
#define ALEPH_GRAPH_COPY_MOVE_CTORS(GraphClass)
Macro to generate copy/move constructors and assignment operators.
#define IS_NODE_VISITED(p, bit)
Determine whether the control bit is set or not to one.
bool forall_node(const GT &g, std::function< bool(typename GT::Node *)> cond, SN sn=SN())
Return true if condition cond is met on every filtered node of the graph.
void inter_copy_graph(GTT >gt, const GTS &gsrc, const bool cookie_map=false)
Copy between different types of graphs.
#define ARC_BITS(p)
Return the control bits of arc p.
size_t out_degree(typename GT::Node *p, SA sa=SA())
Compute the filtered out degree of node p
#define NODE_COOKIE(p)
Return the node cookie
void clear_graph(GT &g) noexcept
Clean a graph: all its nodes and arcs are removed and freed.
DynList< typename GT::Node * > out_nodes(typename GT::Node *p, SA sa=SA())
Return the nodes connected to the filtered outcoming arcs of p.
Container< T > arcs_map(GT &g, std::function< T(typename GT::Arc *)> transformation, SA sa=SA())
Map the filtered arcs of a graph to a transformed type.
size_t in_degree(typename GT::Node *p, SA sa=SA())
Compute the filtered in degree of node p.
GT::Node * mapped_node(typename GT::Node *p) noexcept
Return the mapped node through the cookie of p
std::tuple< typename GT::Arc *, typename GT::Node * > ArcPair
Alias used for encapsulating a pair of arc and node (related between them).
void for_each_node(const GT &g, std::function< void(typename GT::Node *)> operation, SN sn=SN())
Traverse all the nodes of graph filtering some ones according to a condition and executing an operati...
bool forall_arc(const GT &g, std::function< bool(typename GT::Arc *)> cond, SA sa=SA())
Return true if condition cond is met on every filtered arc of the graph.
DynList< typename GT::Arc * > in_arcs(typename GT::Node *p, SA sa=SA())
Return the filtered incoming arcs of p.
#define IS_ARC_VISITED(p, bit)
Determine whether the bit field is or not set to one.
GT::Arc * search_arc(const GT &g, typename GT::Node *src, typename GT::Node *tgt, SA sa=SA()) noexcept
Arc filtered searching given two nodes.
GT::Arc * search_directed_arc(const GT &g, typename GT::Node *src, typename GT::Node *tgt, SA sa=SA()) noexcept
Searching of directed arc linking two nodes.
#define NODE_BITS(p)
Get the control bits of a node.
void for_each_in_arc(typename GT::Node *p, Op op=Op())
Traverse the incoming arcs of a node and executes an operation.
void copy_graph(GT >gt, const GT &gsrc, bool cookie_map=false)
Explicit copy of graph.
void map_nodes(typename GTS::Node *p, typename GTT::Node *q) noexcept
Map two nodes of different types of graphs through their cookies.
DynList< ArcPair< GT > > in_pairs(typename GT::Node *p, SA sa=SA())
Return the filtered incoming pairs of (arc,node) related to node p
Path< GT > find_path_depth_first(const GT &g, typename GT::Node *start_node, typename GT::Node *end_node)
Depth-first search of a path between two nodes.
DynList< typename GT::Arc * > out_arcs(typename GT::Node *p, SA sa=SA())
Return the filtered incoming arcs of p.
Main namespace for Aleph-w library functions.
T foldl_out_arcs(typename GT::Node *p, const T &init, std::function< T(const T &, typename GT::Arc *)> op)
Fold the outcoming arcs of a node.
auto search_in_arc(typename GT::Node *p, Op op=Op())
Search an incoming arc to a node satisfying a condition op.
DynList< typename GT::Arc * > filter_in_arcs(typename GT::Node *p, Op cond)
Filter the incoming arcs meeting an condition.
bool eq(const C1 &c1, const C2 &c2, Eq e=Eq())
Check equality of two containers using a predicate.
auto map_out_arcs(typename GT::Node *p, std::function< T(typename GT::Arc *)> op)
Map the outcoming arcs to a transformation,.
bool all_out_arc(typename GT::Node *p, Op op=Op())
Test if the outcoming arcs meet a condition.
std::decay_t< typename HeadC::Item_Type > T
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
DynList< typename GT::Arc * > filter_out_arcs(typename GT::Node *p, Op cond)
Filter the outcoming arcs meeting an condition.
auto search_out_arc(typename GT::Node *p, Op op=Op())
Search an outcoming arc to a node satisfying a condition op.
T foldl_in_arcs(typename GT::Node *p, const T &init, std::function< T(const T &, typename GT::Arc *)> op)
Fold the incoming arcs of a node.
static bool __find_path_depth_first(const GT &g, typename GT::Node *curr_node, typename GT::Arc *curr_arc, typename GT::Node *end_node, Path< GT > &path)
bool all_in_arc(typename GT::Node *p, Op op=Op())
Test if the incoming arcs meet a condition.
GT::Arc * mapped_arc(typename GT::Arc *a) noexcept
Return the mapped arc through the cookie of p
bool exists_in_arc(typename GT::Node *p, Op op=Op())
Test if it exists an incoming arc satisfying an operation.
bool exists_out_arc(typename GT::Node *p, Op op=Op())
Test if it exists an outcoming arc satisfying an operation.
bool are_equal(const GT &g1, const GT &g2)
Fast graph comparison.
auto map_in_arcs(typename GT::Node *p, std::function< T(typename GT::Arc *)> op)
Map the incoming arcs to a transformation,.
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.
Filtered iterator on all the arcs of a graph.
Arc_Iterator()=default
Type of set all the arcs.
typename Itor::Item_Type Item_Type
typename Itor::Set_Type Set_Type
Type of element: Arc*.
Arc_Iterator(const GT &g, Show_Arc sa=Show_Arc())
Constructor,.
Default copy arc functor.
void operator()(typename GTT::Arc *tgt, typename GTS::Arc *src)
Default copy node functor.
void operator()(typename GTT::Node *tgt, typename GTS::Node *src) noexcept
Default filter for filtered iterators on arcs.
void set_cookie(void *) noexcept
bool operator()(typename GT::Arc *) const noexcept
Default filter for the graph nodes.
bool operator()(typename GT::Node *) const noexcept
Arc of graph implemented with double-linked adjacency lists.
Arc_Node * src_arc_node
The type of data stored in the arc.
Graph_Arc(const Graph_Arc &arc)
Graph_Arc(const Arc_Info &info) noexcept
Copy constructor.
Graph_Arc(Arc_Info &&info=Arc_Info()) noexcept
Move or rvalue constructor.
GTArcCommon< _Arc_Info > Base
Graph_Arc & operator=(const Graph_Arc &arc)
Node belonging to a graph implemented with a double linked adjacency list.
GTNodeCommon< __Node_Info > Base
Graph_Node(const Graph_Node &node) noexcept
Graph_Node(Graph_Node *node)
Copy constructor from a node pointer.
Graph_Node(Node_Info &&info=Node_Info()) noexcept
Move or rvalue constructor.
Graph_Node(const Node_Info &info) noexcept
The type of data stored in the node.
Graph_Node & operator=(const Graph_Node &node)
Iterator on all arcs of a graph.
Arc_Iterator()=default
The type of set.
Node * get_tgt_node() const
Return the target node of current arc.
Arc_Iterator(const List_Graph &g) noexcept
Initialize an iterator for all the arc of g
Arc * get_curr_ne() const noexcept
Arc * get_current_arc_ne() const noexcept
Return the current arc. Throw overflow_error if there is no one.
Node * get_src_node_ne() const
Node * get_src_node() const
Return the source node of the current arc.
Node * get_tgt_node_ne() const
Arc * get_current_arc() const
Node_Iterator(const List_Graph &g)
Construct an iterator on the nodes of g
Filtered iterator of adjacent arcs of a node.
Node_Arc_Iterator(typename GT::Node *p, Show_Arc sa=Show_Arc())
Construct and filtered iterator according to condition sa.
Node_Arc_Iterator()=default
Type of set: p's arcs.
typename Itor::Item_Type Item_Type
typename Itor::Set_Type Set_Type
type of element: Arc*
Filter of painter arcs with that are set the Spanning_Tree control bit.
Painted_Min_Spanning_Tree() noexcept
bool operator()(typename GT::Arc *a) noexcept
Distance::Distance_Type dist
Accumulative distance from the first seen arc until the last seen.
Path_Desc(Node *_node=nullptr, Arc *_arc=nullptr) noexcept
bool operator==(const Path_Desc &r) const noexcept
Treap (a special type of randomized binary search tree) using nodes without virtual destructor.
Common node iterator for graph having its node derived from Dlink class.
Lazy and scalable dynamic array implementation.
Dynamic doubly linked list implementation.
Dynamic key-value map based on balanced binary search trees.
Comprehensive sorting algorithms and search utilities for Aleph-w.
Treap with rank (order statistics).