72 template <
typename Node_Info>
75 template <
typename Arc_Info>
83 template <
typename __Graph_Node,
typename __Graph_Arc>
92 template <
typename MT,
typename Entry_Info,
typename Copy>
122 template <
typename __Node_Info = Empty_Class>
143 noexcept(std::is_nothrow_copy_constructible_v<Node_Info>)
158 noexcept(
std::is_nothrow_move_constructible_v<
Node_Info>)
165 noexcept(std::is_nothrow_copy_constructible_v<Node_Info>)
227 template <
typename _Arc_Info = Empty_Class>
251 noexcept(std::is_nothrow_copy_constructible_v<Arc_Info>)
267 noexcept(
std::is_nothrow_move_constructible_v<
Arc_Info>)
434 template <
typename _Graph_Node = Graph_Node<
unsigned long>,
435 typename _Graph_Arc = Graph_Arc<
unsigned long>>
437 :
public GraphCommon<List_Graph<_Graph_Node, _Graph_Arc>,
438 _Graph_Node, _Graph_Arc>
453 _Graph_Node, _Graph_Arc>;
456 _Graph_Node, _Graph_Arc>;
467 return static_cast<Node *
>(p);
472 return static_cast<Arc *
>(p);
482 return static_cast<Arc *
>(arc_node->arc);
559 assert(node !=
nullptr);
561 while (not node->arc_list.is_empty())
614 return reinterpret_cast<Arc *
>(arc);
620 assert(src_node !=
nullptr and tgt_node !=
nullptr and a !=
nullptr);
621 Arc *arc =
static_cast<Arc *
>(a);
622 arc->src_node = src_node;
623 arc->tgt_node = tgt_node;
627 auto src_guard = std::make_unique<Arc_Node>(arc);
637 if (src_node == tgt_node)
639 src_arc_node = src_guard.release();
640 arc->tgt_arc_node = src_arc_node;
645 src_arc_node = src_guard.release();
648 arc->tgt_arc_node = tgt_arc_node;
649 tgt_node->arc_list.
append(tgt_arc_node);
650 ++tgt_node->num_arcs;
654 src_arc_node = src_guard.release();
657 arc->src_arc_node = src_arc_node;
658 src_node->arc_list.
append(src_arc_node);
659 ++src_node->num_arcs;
675 assert(arc !=
nullptr);
678 Arc_Node *src_arc_node = arc->src_arc_node;
681 --src_node->num_arcs;
687 if (src_node != tgt_node)
689 Arc_Node *tgt_arc_node = arc->tgt_arc_node;
691 --tgt_node->num_arcs;
725 assert(arc !=
nullptr);
727 Arc_Node *src_arc_node = arc->src_arc_node;
729 --src_node->num_arcs;
734 if (src_node != tgt_node)
736 Arc_Node *tgt_arc_node = arc->tgt_arc_node;
738 --tgt_node->num_arcs;
759 assert(arc !=
nullptr);
762 Arc_Node *src_arc_node = arc->src_arc_node;
763 Arc_Node *tgt_arc_node = arc->tgt_arc_node;
767 if (src_node != tgt_node)
769 tgt_node->arc_list.
append(tgt_arc_node);
770 ++tgt_node->num_arcs;
774 src_node->arc_list.append(src_arc_node);
775 ++src_node->num_arcs;
1042 template <
class GT,
class SA>
1044 std::is_nothrow_copy_constructible_v<SA>
and std::is_nothrow_move_constructible_v<SA>
1150 template <
class GT,
class Show_Arc = Dft_Show_Arc<GT>>
1153 typename GT::Node_Arc_Iterator,
1157 typename GT::Node_Arc_Iterator,
1161 typename GT::Node_Arc_Iterator,
1197 template <
class GT,
class Show_Arc = Dft_Show_Arc<GT>>
1263 noexcept(std::is_nothrow_copy_constructible_v<F>)
1268 noexcept(std::is_nothrow_move_constructible_v<F>)
1277 operator F & ()
const noexcept {
return *
filter; }
1284 template <
class GT,
class Show_Node = Dft_Show_Node<GT>>
1318 template <AlephGraph GT, NodeFilter<GT> SN = Dft_Show_Node<GT>,
class Op>
1319 requires std::is_invocable_r_v<void, Op &, typename GT::Node *>
1337 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>,
class Op>
1338 requires std::is_invocable_r_v<void, Op &, typename GT::Arc *>
1357 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>,
class Op>
1358 requires std::is_invocable_r_v<void, Op &, typename GT::Arc *>
1379 template <AlephGraph GT, NodeFilter<GT> SN = Dft_Show_Node<GT>,
class Op>
1380 requires std::is_invocable_r_v<bool, Op &, typename GT::Node *>
1401 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>,
class Op>
1402 requires std::is_invocable_r_v<bool, Op &, typename GT::Arc *>
1423 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>,
class Op>
1424 requires std::is_invocable_r_v<bool, Op &, typename GT::Arc *>
1449 template <AlephGraph
GT,
typename T,
1452 requires std::is_invocable_r_v<T, Op &, typename GT::Node *>
1458 for_each_node<GT, SN>(g, [&ret_val, &transformation](
typename GT::Node *p)
1475 template <AlephGraph
GT,
typename T,
1479 std::function<
T (
typename GT::Node *)> transformation,
1486 return nodes_map<GT, T, Container, SN>(
1487 g, [&transformation](
typename GT::Node * p) {
return transformation(p); }, sn);
1503 template <AlephGraph
GT,
typename T,
1506 requires std::is_invocable_r_v<T, Op &, typename GT::Arc *>
1512 for_each_arc<GT, SA>(g, [&ret_val, &transformation](
typename GT::Arc *p)
1527 template <AlephGraph
GT,
typename T,
1531 std::function<
T (
typename GT::Arc *)> transformation,
1536 return arcs_map<GT, T, Container, SA>(
1537 g, [&transformation](
typename GT::Arc * a) {
return transformation(a); }, sa);
1560 template <AlephGraph
GT,
typename T,
1563 requires std::is_invocable_r_v<T, Op &, typename GT::Arc *>
1570 for_each_arc<GT, SA>(g, p, [&ret_val, &transformation](
typename GT::Arc *p)
1585 template <AlephGraph
GT,
typename T,
1590 std::function<
T (
typename GT::Arc *)> transformation,
1595 return arcs_map<GT, T, Container, SA>(
1596 g, p, [&transformation](
typename GT::Arc * a) {
return transformation(a); }, sa);
1609 template <AlephGraph GT,
typename T, NodeFilter<GT> SN = Dft_Show_Node<GT>,
class Op>
1610 requires std::is_invocable_r_v<T, Op &, const T &, typename GT::Node *>
1616 for_each_node<GT, SN>(g, [&ret_val, &operation](
typename GT::Node *p)
1632 template <AlephGraph GT,
typename T, ArcFilter<GT> SA = Dft_Show_Arc<GT>,
class Op>
1633 requires std::is_invocable_r_v<T, Op &, const T &, typename GT::Arc *>
1639 for_each_arc<GT, SA>(g, [&ret_val, &operation](
typename GT::Arc *a)
1656 template <AlephGraph GT,
typename T, ArcFilter<GT> SA = Dft_Show_Arc<GT>,
class Op>
1657 requires std::is_invocable_r_v<T, Op &, const T &, typename GT::Arc *>
1664 for_each_arc<GT, SA>(g, p, [&ret_val, &operation](
typename GT::Arc *a)
1691 template <
typename __Graph_Node = Graph_Node<
int>,
1692 typename __Graph_Arc = Graph_Arc<
int>>
1702 using ArcPair = std::tuple<typename GT::Arc *, typename GT::Node *>;
1724 return a->src_node ==
src;
1730 return static_cast<typename
GT::Node *
>(a->tgt_node);
1754 return a->tgt_node ==
tgt;
1760 return static_cast<typename
GT::Node *
>(a->src_node);
1768 template <
class GT,
class Filter>
1772 typename GT::Node_Arc_Iterator, Filter>;
1794 static constexpr bool shows_ne =
noexcept(std::declval<Itor &>().next_ne());
1824 return it.has_curr();
1831 return it.get_curr();
1838 return it.get_curr_ne();
1852 return filt.get_node(a);
1940 template <
class GT,
class Show_Arc = Dft_Show_Arc<GT>>
2043 template <
class GT,
class SA = Dft_Show_Arc<GT>>
2067 <<
"In_Iterator(g, p): the graph says that it is directed, but its type does not, "
2068 <<
"so that its arcs into p are not in the list of p: use in_arcs(g, p), or "
2169 template <
class GT,
class SA>
2170 requires DigraphType<GT>
2222 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2243 while ((
size_t(1) << b) < 2 * n)
2250 const auto key = std::uint64_t(
reinterpret_cast<std::uintptr_t
>(p));
2251 return size_t((key * 0x9E3779B97F4A7C15ULL) >> (64 -
bits));
2254 [[nodiscard]]
size_t mask() const noexcept {
return (
size_t(1) <<
bits) - 1; }
2269 <<
"In_Arcs_Index: the node is not of the indexed graph";
2374 [[nodiscard]]
size_t size() const noexcept {
return size_t(
num); }
2388 first(g.get_num_nodes() + 1, 0),
2392 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.
next_ne(), ++n)
2394 Node *p = it.get_curr_ne();
2396 while (
keys(i) !=
nullptr)
2397 i = (i + 1) &
mask();
2408 for (
typename GT::Arc_Iterator it(g); it.has_curr(); it.
next_ne())
2409 if (
Arc *a = it.get_curr_ne(); sa(a))
2411 const size_t t =
number_of(
static_cast<Node *
>(a->tgt_node));
2420 for (
size_t i = 1; i <
first.
size(); ++i)
2423 for (
size_t j =
k; j-- > 0; )
2479 std::swap(
bits, other.bits);
2514 namespace in_arcs_detail
2526 template <AlephGraph GT,
class SA,
class Op>
2530 for (
typename GT::Arc_Iterator it(g); it.has_curr(); it.
next_ne())
2531 if (
typename GT::Arc *a = it.get_curr_ne(); a->tgt_node == p
and sa(a)
and not op(a))
2540 template <AlephGraph GT,
class SA>
2544 for (
typename GT::Arc_Iterator it(g); it.has_curr(); it.
next_ne())
2545 if (
typename GT::Arc *a = it.get_curr_ne(); a->tgt_node == p
and sa(a))
2558 template <AlephGraph GT,
class SA,
class Op>
2565 if (not op(it.get_curr_ne()))
2582 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2587 ret.
append(it.get_node_ne());
2605 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2609 "in_nodes(p) does not see the arcs into p on a digraph, whose list of p "
2610 "holds only the arcs that leave p: use in_nodes(g, p)");
2613 ret.
append(it.get_node_ne());
2632 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2651 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2656 ret.
append(it.get_curr());
2670 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2674 "in_arcs(p) does not see the arcs into p on a digraph, whose list of p "
2675 "holds only the arcs that leave p: use in_arcs(g, p)");
2678 ret.
append(it.get_curr());
2694 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2712 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2717 ret.
append(it.get_curr());
2730 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2734 "in_pairs(p) does not see the arcs into p on a digraph, whose list of p "
2735 "holds only the arcs that leave p: use in_pairs(g, p)");
2739 typename GT::Arc *a = it.get_curr();
2758 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2777 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2783 typename GT::Arc *a = it.get_curr();
2805 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2809 "in_degree(p) does not see the arcs into p on a digraph, whose list of p "
2810 "holds only the arcs that leave p: use in_degree(g, p), or In_Arcs_Index "
2833 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2858 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2889 template <AlephGraph GT,
class Itor,
class Operation>
2893 for (Itor it(p); it.has_curr(); it.
next_ne())
2894 if (not op(it.get_curr()))
2916 template <AlephGraph GT,
class Itor,
class Operation>
2920 for (Itor it(p); it.has_curr(); it.
next_ne())
2945 template <AlephGraph GT,
class Op>
2950 "traverse_in_arcs(p, op) does not see the arcs into p on a digraph, whose list "
2951 "of p holds only the arcs that leave p: use traverse_in_arcs(g, p, op)");
2952 return traverse_arcs<GT, _In_Iterator<GT>, Op>(p, op);
2968 template <AlephGraph GT,
class Op>
2987 template <AlephGraph GT,
class Op>
2992 "for_each_in_arc(p, op) does not see the arcs into p on a digraph, whose list "
2993 "of p holds only the arcs that leave p: use for_each_in_arc(g, p, op)");
2994 for_each_arc<GT, _In_Iterator<GT>, Op>(p, op);
3006 template <AlephGraph GT,
class Op>
3030 template <AlephGraph GT,
class Op>
3035 "all_in_arc(p, op) does not see the arcs into p on a digraph, whose list of p "
3036 "holds only the arcs that leave p: use all_in_arc(g, p, op)");
3037 return traverse_in_arcs<GT>(p, [&op](
auto a)
3051 template <AlephGraph GT,
class Op>
3073 template <AlephGraph GT,
class Op>
3078 "exists_in_arc(p, op) does not see the arcs into p on a digraph, whose list of "
3079 "p holds only the arcs that leave p: use exists_in_arc(g, p, op)");
3080 return not traverse_in_arcs<GT>(p, [&op](
auto a)
3094 template <AlephGraph GT,
class Op>
3117 template <AlephGraph GT,
class Op>
3122 "search_in_arc(p, op) does not see the arcs into p on a digraph, whose list of "
3123 "p holds only the arcs that leave p: use search_in_arc(g, p, op)");
3124 typename GT::Arc *ret =
nullptr;
3125 traverse_in_arcs<GT>(p, [&op, &ret](
auto a)
3145 template <AlephGraph GT,
class Op>
3149 typename GT::Arc *ret =
nullptr;
3179 template <AlephGraph GT,
typename T,
class Op>
3180 requires (std::is_invocable_r_v<T, Op &, typename GT::Arc *>
3181 and not std::is_same_v<Op, std::function<
T (
typename GT::Arc *)>>)
3186 "map_in_arcs(p, op) does not see the arcs into p on a digraph, whose list of p "
3187 "holds only the arcs that leave p: use map_in_arcs(g, p, op)");
3189 for_each_in_arc<GT>(p, [&ret, &op](
auto a)
3207 template <AlephGraph
GT,
typename T,
3208 class Op = std::function<
T (
typename GT::Arc *)>>
3209 requires std::is_same_v<Op, std::function<
T (
typename GT::Arc *)>>
3215 return map_in_arcs<GT, T>(p, [&op](
typename GT::Arc * a) {
return op(a); });
3226 template <AlephGraph GT,
typename T,
class Op>
3227 requires std::is_invocable_r_v<T, Op &, typename GT::Arc *>
3235 ret.
append(Call::call(op, a));
3247 template <AlephGraph GT,
typename T>
3251 return map_in_arcs<GT, T>(g, p, [&op](
typename GT::Arc * a) {
return op(a); });
3272 template <AlephGraph GT,
typename T,
class Op>
3273 requires std::is_invocable_r_v<T, Op &, const T &, typename GT::Arc *>
3279 "foldl_in_arcs(p, init, op) does not see the arcs into p on a digraph, whose "
3280 "list of p holds only the arcs that leave p: use foldl_in_arcs(g, p, init, op)");
3282 for_each_in_arc<GT>(p, [&ret, &op](
auto a)
3299 template <AlephGraph GT,
typename T,
class Op>
3300 requires std::is_invocable_r_v<T, Op &, const T &, typename GT::Arc *>
3308 ret = Call::call(op, ret, a);
3322 template <AlephGraph GT,
class Op>
3327 "filter_in_arcs(p, cond) does not see the arcs into p on a digraph, whose list "
3328 "of p holds only the arcs that leave p: use filter_in_arcs(g, p, cond)");
3330 for_each_in_arc<GT>(p, [&ret, &cond](
auto a)
3346 template <AlephGraph GT,
class Op>
3371 template <AlephGraph GT,
class Op>
3375 return traverse_arcs<GT, _Out_Iterator<GT>, Op>(p, op);
3384 template <AlephGraph GT,
class Op>
3388 for_each_arc<GT, _Out_Iterator<GT>, Op>(p, op);
3401 template <AlephGraph GT,
class Op>
3405 return traverse_out_arcs<GT>(p, [&op](
auto a)
3421 template <AlephGraph GT,
class Op>
3425 return not traverse_out_arcs<GT>(p, [&op](
auto a)
3442 template <AlephGraph GT,
class Op>
3446 typename GT::Arc *ret =
nullptr;
3447 traverse_out_arcs<GT>(p, [&op, &ret](
auto a)
3474 template <AlephGraph GT,
typename T,
class Op>
3475 requires (std::is_invocable_r_v<T, Op &, typename GT::Arc *>
3476 and not std::is_same_v<Op, std::function<
T (
typename GT::Arc *)>>)
3481 for_each_out_arc<GT>(p, [&ret, &op](
auto a)
3498 template <AlephGraph
GT,
typename T,
3499 class Op = std::function<
T (
typename GT::Arc *)>>
3500 requires std::is_same_v<Op, std::function<
T (
typename GT::Arc *)>>
3506 return map_out_arcs<GT, T>(p, [&op](
typename GT::Arc * a) {
return op(a); });
3525 template <AlephGraph GT,
typename T,
class Op>
3526 requires std::is_invocable_r_v<T, Op &, const T &, typename GT::Arc *>
3532 for_each_out_arc<GT>(p, [&ret, &op](
auto a)
3545 template <AlephGraph GT,
class Op>
3550 for_each_out_arc<GT>(p, [&ret, &cond](
auto a)
3572 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
3578 assert(src !=
nullptr and tgt !=
nullptr);
3581 std::swap(tgt, src);
3584 if (itor.get_tgt_node_ne() == tgt)
3585 return itor.get_current_arc_ne();
3601 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
3608 assert(src !=
nullptr and tgt !=
nullptr);
3611 if (
typename GT::Arc *a = it.get_curr(); a->src_node == src
and a->tgt_node == tgt)
3621 template <AlephGraph GT>
3628 template <AlephGraph GT>
3635 template <AlephGraph GTSRC, AlephGraph GTTGT>
3638 return static_cast<typename GTTGT::Node *
>(
NODE_COOKIE(p));
3642 template <AlephGraph GTSRC, AlephGraph GTTGT>
3643 typename GTTGT::Arc *
mapped_arc(
typename GTSRC::Arc *a)
noexcept
3645 return static_cast<typename GTTGT::Arc *
>(
ARC_COOKIE(a));
3667 template <AlephGraph GT>
3669 void copy_graph(
GT & gtgt,
const GT & gsrc,
bool cookie_map =
false);
3683 template <AlephGraph GT>
3696 template <AlephGraph GT,
class Operation, NodeFilter<GT> SN = Dft_Show_Node<GT>>
3716 op(g, it.get_curr());
3727 op(g, it.get_curr());
3741 template <AlephGraph GT,
class Operation, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
3761 op(g, it.get_curr());
3767 op(g, it.get_curr());
3777 Operation op = Operation())
const
3780 op(g, it.get_current_arc_ne());
3784 Operation op = Operation())
const
3787 op(g, it.get_current_arc_ne());
3857 if (not (
node->get_info() ==
r.node->get_info()))
3861 return r.arc ==
nullptr;
3863 if (
r.arc ==
nullptr)
3866 return arc->get_info() ==
r.arc->get_info();
3886 if (prev !=
nullptr)
3888 if (prev->
arc ==
nullptr)
3899 return prev ==
nullptr or prev->
arc ==
nullptr;
3910 if (prev !=
nullptr and
3917 return prev ==
nullptr or prev->
arc ==
nullptr;
3949 assert(start_node !=
nullptr);
3981 if (start_node ==
nullptr)
3987 [[nodiscard]]
size_t size() const noexcept
3995 return list.is_empty();
4002 while (not
list.is_empty())
4003 list.remove_first();
4034 std::swap(
g, path.g);
4035 list.swap(path.list);
4054 assert(arc !=
nullptr);
4059 auto & last_path_desc =
list.get_last();
4062 <<
"arc has not link to last node of path";
4064 last_path_desc.arc = arc;
4089 if (
list.is_empty())
4099 <<
"There is no an arc connecting to the node";
4126 assert(p !=
nullptr);
4128 if (
list.is_empty())
4134 auto & last_path_desc =
list.get_last();
4140 assert(arc->src_node == last_path_desc.node);
4142 last_path_desc.arc = arc;
4166 assert(arc !=
nullptr);
4171 auto & last_path_desc =
list.get_last();
4174 <<
"The arc does not connect the last node";
4176 last_path_desc.arc = arc;
4197 assert(arc !=
nullptr);
4202 auto & first_path_desc =
list.get_first();
4203 auto first_node = first_path_desc.node;
4205 <<
"arc has not link to first node of path";
4232 if (
list.is_empty())
4268 assert(p !=
nullptr);
4271 if (
list.is_empty())
4301 assert(arc !=
nullptr);
4306 auto & first_path_desc =
list.get_first();
4307 Node *first_node = first_path_desc.node;
4309 <<
"The arc does not connect the first node";
4318 return list.get_first().node;
4325 auto & last_path_desc =
list.get_last();
4326 assert(last_path_desc.arc ==
nullptr);
4327 return last_path_desc.node;
4334 return list.get_first().arc;
4342 <<
"Path with only a node (without any arc)";
4365 auto d =
list.remove_last();
4366 if (not
list.is_empty())
4367 list.get_last().arc =
nullptr;
4378 auto d =
list.remove_first();
4385 std::swap(
g, path.g);
4386 list.swap(path.list);
4528 template <
class Operation>
4532 op(it.get_current_node_ne());
4539 template <
class Operation>
4543 op(it.get_current_arc_ne());
4550 if (it.get_current_node_ne() == node)
4559 if (it.get_current_arc_ne() == arc)
4598 return eq(this->list, p.list);
4604 return not
eq(this->list, p.list);
4608 template <AlephGraph GT>
4623 if (curr_node == end_node)
4642 if (
auto tgt = here.template next_target<Find_Path>(end_node))
4644 path.
append(here.it.get_current_arc_ne());
4645 if (tgt == end_node)
4649 frames.
push(std::move(here));
4660 Frame & f = frames.
top();
4662 if (
auto tgt = f.template next_target<Find_Path>(end_node))
4664 path.
append(f.it.get_current_arc_ne());
4665 if (tgt == end_node)
4693 template <AlephGraph GT>
4706 auto arc = it.get_current_arc_ne();
4708 auto next_node = it.get_tgt_node();
4712 if (__find_path_depth_first<GT>(g, next_node, arc, end_node, path))
4730 template <AlephGraph GTS, AlephGraph GTT>
4731 void map_nodes(
typename GTS::Node *p,
typename GTT::Node *q)
noexcept
4733 assert(p !=
nullptr and q !=
nullptr);
4758 template <AlephGraph GTS, AlephGraph GTT>
4759 void map_arcs(
typename GTS::Arc *p,
typename GTT::Arc *q)
noexcept
4761 assert(p !=
nullptr and q !=
nullptr);
4775 template <AlephGraph GT>
4778 for (
typename GT::Arc_Iterator it(g); it.has_curr();)
4780 typename GT::Arc *arc = it.get_curr_ne();
4785 for (
typename GT::Node_Iterator it(g); it.has_curr();)
4787 typename GT::Node *p = it.get_curr_ne();
4793 template <AlephGraph GT>
4802 for (
typename GT::Node_Iterator it(gsrc); it.has_curr(); it.
next_ne())
4804 typename GT::Node *src_node = it.get_current_node_ne();
4805 std::unique_ptr<typename GT::Node>
4807 map.
insert(src_node, tgt_node.get());
4809 typename GT::Node *tgt = tgt_node.release();
4821 for (
typename GT::Arc_Iterator it(gsrc); it.has_curr(); it.
next_ne())
4823 typename GT::Arc *src_arc = it.get_current_arc_ne();
4830 *tgt_arc = *src_arc;
4840 std::remove_cvref_t<
decltype(gtgt)> empty;
4851 template <
class GTT,
class GTS>
4854 void operator()(
typename GTT::Node *tgt,
typename GTS::Node *src)
noexcept
4864 template <
class GTT,
class GTS>
4869 tgt->get_info() = src->get_info();
4881 template <AlephGraph GTT, AlephGraph GTS,
4885 const bool cookie_map =
false)
4892 for (
typename GTS::Node_Iterator it(gsrc); it.has_curr(); it.
next_ne())
4894 typename GTS::Node *src_node = it.get_current_node_ne();
4895 std::unique_ptr<typename GTT::Node> tgt_node(
new typename GTT::Node);
4896 Copy_Node()(tgt_node.get(), src_node);
4897 map.
insert(src_node, tgt_node.get());
4899 typename GTT::Node *tgt = tgt_node.release();
4900 gtgt.insert_node(tgt);
4903 map_nodes<GTS, GTT>(src_node, tgt);
4906 assert(gtgt.get_num_nodes() == gsrc.get_num_nodes());
4910 for (
typename GTS::Arc_Iterator it(gsrc); it.has_curr(); it.
next_ne())
4912 typename GTS::Arc *src_arc = it.get_current_arc_ne();
4915 typename GTT::Node *src_node = map[gsrc.get_src_node(src_arc)];
4916 typename GTT::Node *tgt_node = map[gsrc.get_tgt_node(src_arc)];
4917 typename GTT::Arc *tgt_arc = gtgt.insert_arc(src_node, tgt_node);
4918 Copy_Arc()(tgt_arc, src_arc);
4920 map_arcs<GTS, GTT>(src_arc, tgt_arc);
4923 assert(gtgt.get_num_arcs() == gsrc.get_num_arcs());
4928 std::remove_cvref_t<
decltype(gtgt)> empty;
4929 empty.get_cookie() = gtgt.get_cookie();
4949 template <AlephGraph GT, NodeFilter<GT> SN = Dft_Show_Node<GT>, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
4967 void copy(
GT & gtgt,
const GT & gsrc,
const bool cookie_map)
4977 typename GT::Node *src_node = it.get_curr();
4978 std::unique_ptr<typename GT::Node>
4979 tgt_node(
new typename GT::Node(src_node));
4980 map.
insert(src_node, tgt_node.get());
4982 typename GT::Node *tgt = tgt_node.release();
4993 typename GT::Arc *src_arc = it.get_curr();
4998 if (src_image ==
nullptr or tgt_image ==
nullptr)
5002 gtgt.
insert_arc(src_image->second, tgt_image->second,
5028 copy(gtgt, gsrc, cookie_map);
5045 template <AlephGraph GT,
class Distance>
5056 noexcept(
std::is_nothrow_default_constructible_v<
Distance>)
5106 template <AlephGraph GT>
5144 template <
class,
class>
class Tree =
Treap>
5161 for (
typename GT::Node_Iterator it(src); it.has_curr(); it.
next_ne())
5163 Node *src_node = it.get_curr();
5169 for (
typename GT::Arc_Iterator it(src); it.has_curr(); it.
next_ne())
5171 Arc *src_arc = it.get_curr();
5272 <<
"Node not found in mapping (not from original graph?)";
5290 return ptr ? ptr->second :
nullptr;
5303 return node_map.search(orig) !=
nullptr;
5334 template <
typename Op>
5390 Node *original_node =
nullptr;
5393 if (
pair.second == node)
5395 original_node = pair.first;
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error()
Throws std::domain_error unconditionally.
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
#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.
C++20 concepts for the protocol shared by graph algorithms.
STL-compatible iterator adapters for Aleph containers.
Simplified graph interface for common use cases.
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
Space-efficient bit array implementation.
Arc_Node(void *__arc) noexcept
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
T & base()
Return a reference to the first element of array.
void swap(Array &s) noexcept
Swap this with s
static Array create(const size_t n)
Create an array with n logical elements.
void putn(const size_t n)
Reserve n additional logical slots in the array without value-initializing them.
Read-only view of an Aleph iterator: the iterator of a constant container.
auto is_in_last() const noexcept(noexcept(std::declval< I & >().is_in_last())) -> decltype(std::declval< I & >().is_in_last())
true if the current item is the last one.
auto reset_last() noexcept(noexcept(std::declval< I & >().reset_last())) -> decltype(std::declval< I & >().reset_last())
Position the view on the last item.
auto prev() noexcept(noexcept(std::declval< I & >().prev())) -> decltype(std::declval< I & >().prev())
Move to the previous item; what the underlying iterator throws.
auto has_curr() const noexcept(noexcept(std::declval< I & >().has_curr())) -> decltype(std::declval< I & >().has_curr())
true if there is a current item.
auto get_curr_ne() const noexcept(noexcept(std::declval< I & >().get_curr_ne())) -> const_iterator_detail::const_item_t< decltype(std::declval< I & >().get_curr_ne())>
get_curr() without the checks of the underlying iterator.
auto get_curr() const noexcept(noexcept(std::declval< I & >().get_curr())) -> const_iterator_detail::const_item_t< decltype(std::declval< I & >().get_curr())>
The current item, read-only.
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.
Stack of the frames of a depth-first search that does not recurse.
T & push(Args &&...args)
Builds a frame on top of the stack.
bool is_empty() const noexcept
Whether the stack has no frames.
T & top() noexcept
The top frame; the stack must not be empty.
void pop() noexcept
Destroys the top frame; the stack must not be empty.
Filtered iterator on directed graphs.
GT::Arc * get_curr_ne() const noexcept
Return the current arc.
GT::Node * get_node_ne() const noexcept
Return the connected node to current arc.
static constexpr bool goes_to_last
Whether the iterator goes to its last arc, which reset_last() and end() need.
GT::Node * get_node() const
Return the connected node to current arc.
void next_ne() noexcept(shows_ne)
next() without its check: the current arc must exist.
GT::Arc * get_curr() const
Return the current arc.
void reset_first() noexcept(shows_ne)
Reset the iterator to the first arc.
void end() noexcept(shows_ne)
Put the iterator in end state.
static constexpr bool shows_ne
Whether what the filter says of an arc cannot throw, nor its conversion to bool: the moves without ch...
Digraph_Iterator(typename GT::Node *p)
Initialize an iterator on adjacent arcs (incoming or outcoming) of p
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...
auto get_tgt_node() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static constexpr bool goes_back
Iterator type.
void prev()
Move the iterator one position backward.
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.
typename Itor::Item_Type Item_Type
void next()
Move the iterator one position forward.
void reset_last() noexcept(shows_ne)
Reset the iterator to the last arc.
Generic directed graph (digraph) wrapper template.
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.
void swap(Dlink *link) noexcept
Swap this with list whose header is link.
Dlink * del() noexcept
Remove this from the list. this must not be a header node.
void insert(Dlink *node) noexcept
Insert node after this.
Dynamic doubly linked list with O(1) size and bidirectional access.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
Dynamic map implemented with an AVL tree.
Generic key-value map implemented on top of a binary search tree.
Pair * search(const Key &key) noexcept(nothrow_search)
Collect all keys.
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
Generic filter iterator wrapper.
void reset_last()
Resets the iterator to the last filtered element.
void next()
Advances the iterator to the next filtered element.
static constexpr bool goes_to_last
Whether the base iterator goes to its last item and moves back, as reset_last() needs.
void prev()
Moves the iterator backward to the previous filtered element.
static constexpr bool goes_back
Whether the base iterator moves back, as prev() and prev_ne() need.
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
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.
Iterator on the arcs into a node, in the order of the arc iterator of the graph when the index was bu...
Arc * get_current_arc_ne() const noexcept
See get_curr_ne().
Arc * get_curr_ne() const noexcept
Return the current arc, which must exist.
void prev()
Move to the previous arc.
void next()
Move to the next arc.
void next_ne() noexcept
Move to the next arc; the iterator must be on an arc.
size_t size() const noexcept
Return the number of arcs of the iterator.
Node * get_node_ne() const noexcept
Return the source of the current arc, which must exist.
bool has_curr() const noexcept
Return true if the iterator is on an arc.
void reset_first() noexcept
Put the iterator on the first arc.
void end() noexcept
Put the iterator past the last arc.
void prev_ne() noexcept
Move to the previous arc; the iterator must be on an arc.
Arc * get_current_arc() const
See get_curr().
Iterator() noexcept=default
An iterator without arcs.
Node * get_node() const
Return the source of the current arc. Throws as get_curr().
Arc * Item_Type
The type of the items: arcs.
Iterator(const In_Arcs_Index &index, const Node *p)
An iterator on the arcs into p of index.
Arc * get_curr() const
Return the current arc.
void reset_last() noexcept
Put the iterator on the last arc.
Index of the arcs that go into each node of a graph.
size_t in_degree(const Node *p) const
Return the number of arcs into p that the filter showed.
In_Arcs_Index(In_Arcs_Index &&other)
Take the arcs of another index, which is left as the index of a graph without nodes.
static unsigned table_bits(const size_t n) noexcept
size_t place_of(const Node *p) const noexcept
In_Arcs_Index(const GT &g, SA sa=SA())
Index the arcs of g into each node that sa shows.
In_Arcs_Index & operator=(const In_Arcs_Index &other)=default
Copy another index.
In_Arcs_Index(const In_Arcs_Index &other)=default
Copy another index.
size_t checked_number_of(const Node *p) const
Iterator get_it(const Node *p) const
Return an iterator on the arcs into p that the filter showed.
void swap(In_Arcs_Index &other) noexcept
Exchange in this index and another.
size_t mask() const noexcept
size_t size() const noexcept
Return the number of arcs of the index: those that the filter showed.
size_t number_of(const Node *p) const noexcept
Filtered iterator for incoming arcs of a node.
typename GT::Arc * Item_Type
static GT::Node * of_lists(const GT &g, typename GT::Node *p)
void next_ne() noexcept(NothrowPredicateWith< SA &, typename GT::Arc * >)
next() without the check of the current arc; noexcept when the filter is, else what the filter throws...
In_Iterator(typename GT::Node *p, SA sa=SA())
Iterator on the arcs of the list of p whose target is p and that sa shows.
Digraph_Iterator< GT, __In_Filt< GT > > Base
In_Iterator(const GT &g, typename GT::Node *p, SA sa=SA())
Iterator on the arcs of g into p that sa shows; on a graph of an undirected type, those of the list o...
static void refuse_a_digraph()
void prev()
Move to the previous arc that the filter shows.
A filter that an algorithm object keeps: one given as an lvalue is used where it is,...
Kept_Filter(const Kept_Filter &k) noexcept(std::is_nothrow_copy_constructible_v< F >)
Copy a moved filter, or use the same lvalue.
Kept_Filter & operator=(const Kept_Filter &)=delete
Kept_Filter(F &f) noexcept
Use f where it is.
F & get() const noexcept
The filter.
Kept_Filter(F &&f) noexcept(std::is_nothrow_move_constructible_v< F >)
Keep f, moved.
Kept_Filter(Kept_Filter &&k) noexcept(std::is_nothrow_move_constructible_v< F >)
Move a moved filter, or use the same lvalue.
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
Arc * get_curr() const
See get_current_arc().
Node * get_tgt_node_ne() const noexcept
Arc_Node * get_current_arc_node() const
Arc * get_curr_ne() const noexcept
Return the current arc, which must exist.
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
Arc * get_current_arc() const
Return the current arc.
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
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.
virtual void remove_node(Node *node)
Remove a node from the graph and free its memory.
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.
void prev()
Move to the previous arc that the filter shows.
Out_Iterator(typename GT::Node *p, Show_Arc sa=Show_Arc())
void next_ne() noexcept(NothrowPredicateWith< Show_Arc &, typename GT::Arc * >)
next() without the check of the current arc; noexcept when the filter is, else what the filter throws...
typename GT::Arc * Item_Type
Digraph_Iterator< GT, __Out_Filt< GT > > Base
Iterator on nodes and arcs of a path.
Node * get_current_node_ne() const noexcept
Node * get_current_node() const
Return the current node of a path.
const Path_Desc & get_curr_path_desc_ne() const noexcept
std::tuple< Node *, Arc * > get_tuple() const
Return a tuple with the current node and arc.
std::tuple< Node *, Arc * > get_tuple_ne() const noexcept
Node * get_curr_ne() const noexcept
Return the current node, which must exist.
Arc * get_current_arc_ne() const noexcept
const Path_Desc & get_curr_path_desc() const
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
bool has_current_node() const noexcept
Return true if the iterator has a current node.
Aleph::const_iterator_t< DynDlist< Path_Desc > > Base
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: each arc goes from its node to the next one,...
bool contains_node(Node *node) const noexcept
Return true if node belongs to the path.
void insert_directed(Node *p)
Insert a node at the beginning of 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: each arc joins its node with the next one, either way,...
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.
void clear()
Empties the container.
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
The iterator on the arcs into a node of a digraph type, which In_Iterator is on a type built with the...
Common methods for the arc of a graph.
ArcInfo & get_info() noexcept
Return a modifiable reference to the arc data.
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.
constexpr size_t get_num_nodes() const noexcept
Return the total of 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.
void *& get_cookie() noexcept
Return a modifiable reference to graph's cookie.
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
Return the number of arcs of the graph.
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
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.
QuadTree - Hierarchical spatial index for 2D points.
A graph usable by the graph algorithms.
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.
Generic filter iterator wrapper for Aleph containers.
Graph base classes and common utilities via CRTP.
DynArray< Graph::Arc * > arcs
DynList< typename GT::Node * > in_nodes(typename GT::Node *p, SA sa=SA())
Return the nodes connected to the filtered incoming arcs to p.
GT::Arc * search_arc(const GT &g, typename GT::Node *src, typename GT::Node *tgt, SA sa=SA()) noexcept(nothrow_arc_filter_v< GT, SA >)
Arc filtered searching given two nodes.
void for_each_out_arc(typename GT::Node *p, Op op=Op())
Traverse the outcoming arcs of a node and executes an operation.
constexpr bool nothrow_arc_filter_v
Whether a filter of type SA of the arcs of GT is copied, moved and called without exceptions: then an...
GT::Node * mapped_node(typename GT::Node *p) noexcept
Return the mapped node through the cookie of p
void for_each_node(const GT &g, Op operation, SN sn=SN())
Traverse all the nodes of graph filtering some ones according to a condition and executing an operati...
#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.
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
Container< T > arcs_map(GT &g, Op transformation, SA sa=SA())
Map the filtered arcs of a graph to a transformed type.
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.
void inter_copy_graph(GTT >gt, const GTS &gsrc, const bool cookie_map=false)
Copy between different types of graphs.
GT::Arc * search_directed_arc(const GT &g, typename GT::Node *src, typename GT::Node *tgt, SA sa=SA()) noexcept(nothrow_arc_filter_v< GT, SA >)
Searching of directed arc linking two nodes.
bool forall_node(const GT &g, Op cond, SN sn=SN())
Return true if condition cond is met on every filtered node of the graph.
Container< T > nodes_map(GT &g, Op transformation, SN sn=SN())
Map the filtered nodes of a graph to a transformed type.
#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
DynList< typename GT::Node * > out_nodes(typename GT::Node *p, SA sa=SA())
Return the nodes connected to the filtered outcoming arcs of p.
size_t in_degree(typename GT::Node *p, SA sa=SA())
Compute the filtered in degree of node p.
std::tuple< typename GT::Arc *, typename GT::Node * > ArcPair
Alias used for encapsulating a pair of arc and node (related between them).
T foldl_nodes(GT &g, const T &init, Op operation, SN sn=SN())
Fold the filtered nodes of a graph.
void for_each_arc(const GT &g, Op operation, SA sa=SA())
Traverse all the arcs of graph filtering some ones according to a condition and executing an operatio...
void clear_graph(GT &g)
Clean a graph: all its nodes and arcs are removed and freed.
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.
T foldl_arcs(GT &g, const T &init, Op operation, SA sa=SA())
Fold the filtered arcs of a graph.
#define NODE_BITS(p)
Get the control bits of a node.
bool forall_arc(const GT &g, Op cond, SA sa=SA())
Return true if condition cond is met on every filtered arc of the graph.
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.
bool traverse_arcs_into(const GT &g, typename GT::Node *p, SA &sa, Op op)
Calls op(a) on each arc a of g into p that sa shows, while it returns true, and tells whether it went...
size_t digraph_in_degree(const GT &g, typename GT::Node *p, SA &sa)
The number of arcs of the digraph g into p that sa shows, among the arcs of the graph,...
bool traverse_digraph_arcs_into(const GT &g, typename GT::Node *p, SA &sa, Op op)
Calls op(a) on each arc a of the digraph g into p that sa shows, while it returns true,...
Main namespace for Aleph-w library functions.
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.
@ Call
dst <- callee(args...)
bool all_out_arc(typename GT::Node *p, Op op=Op())
Test if the outcoming arcs meet a condition.
bool all(Container &container, Operation &operation)
Return true if all elements satisfy a predicate.
auto map_out_arcs(typename GT::Node *p, Op op)
Map the outcoming arcs to a transformation,.
std::decay_t< typename HeadC::Item_Type > T
and
Check uniqueness with explicit hash + equality functors.
auto map_in_arcs(typename GT::Node *p, Op op)
Map the incoming arcs to a transformation,.
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
T foldl_in_arcs(typename GT::Node *p, const T &init, Op op)
Fold the incoming arcs of a node.
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.
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)
T foldl_out_arcs(typename GT::Node *p, const T &init, Op op)
Fold the outcoming arcs of a node.
bool all_in_arc(typename GT::Node *p, Op op=Op())
Test if the incoming arcs meet a condition.
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.
GT::Arc * mapped_arc(typename GT::Arc *a) noexcept
Return the mapped arc through the cookie of p
bool are_equal(const GT &g1, const GT &g2)
Fast graph comparison.
static std::atomic< bool > init
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Filtered iterator 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,.
The next arc of a node to look at, for a depth-first search that keeps only that in a frame.
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(Arc_Info &&info=Arc_Info()) noexcept(std::is_nothrow_move_constructible_v< Arc_Info >)
Move or rvalue constructor.
Graph_Arc(const Arc_Info &info) noexcept(std::is_nothrow_copy_constructible_v< Arc_Info >)
Copy constructor.
Graph_Arc & operator=(const Graph_Arc &arc)
Node belonging to a graph implemented with a double linked adjacency list.
Graph_Node(const Node_Info &info) noexcept(std::is_nothrow_copy_constructible_v< Node_Info >)
The type of data stored in the node.
Graph_Node(const Graph_Node &node) noexcept(std::is_nothrow_copy_constructible_v< Node_Info >)
Graph_Node(Node_Info &&info=Node_Info()) noexcept(std::is_nothrow_move_constructible_v< Node_Info >)
Move or rvalue constructor.
Graph_Node(Graph_Node *node)
Copy constructor from a node pointer.
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(std::is_nothrow_default_constructible_v< Distance >)
Build the filter with a distance accessor built by Distance().
Painted_Min_Spanning_Tree(Distance __distance)
Build the filter with a distance accessor.
Distance distance
Distance accessor for the arc weights.
Distance::Distance_Type dist
Accumulative distance from the first seen arc until the last seen.
bool operator()(typename GT::Arc *a)
Show the arc if it is painted, and then add its weight to dist.
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.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
Stack of the frames of a depth-first search that does not recurse.
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).
Treap< int >::Node * last_node