45#include <lal/graphs/directed_graph.hpp>
46#include <lal/detail/graphs/traversal.hpp>
47#include <lal/detail/data_array.hpp>
62 char *
const __restrict__ visited,
63 char *
const __restrict__ in_stack
67 if (visited[u]) {
return false; }
71 for (
node v : g.get_out_neighbours(u)) {
75 if (visited[v] == 0 and
find_cycle(g,v,visited,in_stack)) {
93 char *
const __restrict__ vis,
94 char *
const __restrict__ in_stack
98 const uint64_t n = g.get_num_nodes();
99 std::fill(&vis[0], &vis[n], 0);
100 std::fill(&in_stack[0], &in_stack[n], 0);
101 bool has_cycle =
false;
102 for (
node u = 0; u < n and not has_cycle; ++u) {
117 const uint64_t n = g.get_num_nodes();
119 char *
const __restrict__ vis = all_mem.
begin();
120 char *
const __restrict__ in_stack = all_mem.
at(n);
134template <
class graph_t>
136 const auto n = g.get_num_nodes();
144 bool cycle_found =
false;
149 bfs.set_process_visited_neighbours(
true);
154 bfs.set_process_neighbour(
155 [&](
const auto& _bfs,
node s,
node t,
bool) ->
void {
162 if (_bfs.node_was_visited(t)) {
168 if (parent[s] != t) {
179 for (
node u = 0; u < n and not cycle_found; ++u) {
180 if (not bfs.node_was_visited(u)) {
196template <
class graph_t>
Abstract graph Breadth-First Search traversal.
Definition: traversal.hpp:89
Directed graph class.
Definition: directed_graph.hpp:68
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:91
bool find_cycle(const graphs::directed_graph &g, 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
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:135
Main namespace of the library.
Definition: basic_types.hpp:50
uint64_t node
Node type. See Node / Vertex page for further details.
Definition: basic_types.hpp:53
Wrapper of a C array for autmatic deallocation of memory.
Definition: data_array.hpp:59
T * at(std::size_t i) noexcept
Pointer at a specific location of the array.
Definition: data_array.hpp:272
T * begin() noexcept
Non-constant raw pointer to first element.
Definition: data_array.hpp:291