45#include <lal/graphs/directed_graph.hpp>
46#include <lal/detail/graphs/traversal.hpp>
47#include <lal/detail/array.hpp>
63 char *
const __restrict__ visited,
64 char *
const __restrict__ in_stack
68 if (visited[u]) {
return false; }
72 for (
const node v : g.get_out_neighbors(u)) {
76 if (visited[v] == 0 and
find_cycle(g,v,visited,in_stack)) {
94 char *
const __restrict__ vis,
95 char *
const __restrict__ in_stack
99 const uint64_t n = g.get_num_nodes();
100 std::fill(&vis[0], &vis[n], 0);
101 std::fill(&in_stack[0], &in_stack[n], 0);
102 bool has_cycle =
false;
103 for (
node u = 0; u < n and not has_cycle; ++u) {
120 const uint64_t n = g.get_num_nodes();
122 char *
const __restrict__ vis = all_mem.
begin();
123 char *
const __restrict__ in_stack = all_mem.
at(n);
136template <
class graph_t>
141 const auto n = g.get_num_nodes();
149 bool cycle_found =
false;
154 bfs.set_process_visited_neighbors(
true);
159 bfs.set_process_neighbour(
160 [&](
const auto& _bfs,
node s,
node t,
bool) ->
void {
167 if (_bfs.node_was_visited(t)) {
173 if (parent[s] != t) {
184 for (
node u = 0; u < n and not cycle_found; ++u) {
185 if (not bfs.node_was_visited(u)) {
201template <
class graph_t>
Abstract graph Breadth-First Search traversal.
Definition traversal.hpp:89
Directed graph class.
Definition directed_graph.hpp:67
bool has_directed_cycles(const graphs::directed_graph &g, char *const __restrict__ vis, char *const __restrict__ in_stack) noexcept
Returns true if, and only if, the graph has DIRECTED cycles.
Definition cycles.hpp:92
bool has_undirected_cycles(const graph_t &g, BFS< graph_t > &bfs) noexcept
Returns true if, and only if, the graph has UNDIRECTED cycles.
Definition cycles.hpp:138
bool find_cycle(const graphs::directed_graph &g, const node u, char *const __restrict__ visited, char *const __restrict__ in_stack) noexcept
Returns true if, and only if, the graph has cycles.
Definition cycles.hpp:60
Main namespace of the library.
Definition basic_types.hpp:48
uint64_t node
Node type. See Node / Vertex page for further details.
Definition basic_types.hpp:51
Wrapper of a C array for automatic deallocation of memory.
Definition array.hpp:59
T * begin() noexcept
Non-constant raw pointer to first element.
Definition array.hpp:300
T * at(const std::size_t i) noexcept
Pointer at a specific location of the array.
Definition array.hpp:281