FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
mage/cpp/cycles_module/cycles_module.cpp at main · memgraph/mage · GitHub
This repository was archived by the owner on Jan 23, 2026. It is now read-only.
memgraph
/
mage
Public archive
Notifications
You must be signed in to change notification settings
Fork
35
Star
331
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
mage
/
cpp
/
cycles_module
/
cycles_module.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
64 lines (51 loc) · 2.16 KB
Breadcrumbs
mage
/
cpp
/
cycles_module
/
cycles_module.cpp
Copy path
File metadata and controls
64 lines (51 loc) · 2.16 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#
include
<
mg_utils.hpp
>
#
include
"
algorithm/cycles.hpp
"
namespace
{
constexpr
char
const
*
kProcedureGet
=
"
get
"
;
constexpr
char
const
*
kFieldCycleId
=
"
cycle_id
"
;
constexpr
char
const
*
kFieldNode
=
"
node
"
;
void
InsertCycleRecord
(mgp_graph *graph, mgp_result *result, mgp_memory *memory,
const
int
cycle_id,
const
int
node_id) {
auto
*node =
mg_utility::GetNodeForInsertion
(node_id, graph, memory);
if
(!node)
return
;
auto
*record =
mgp::result_new_record
(result);
if
(record ==
nullptr
)
throw
mg_exception::NotEnoughMemoryException
();
mg_utility::InsertIntValueResult
(record,
kFieldCycleId
, cycle_id, memory);
mg_utility::InsertNodeValueResult
(record,
kFieldNode
, node, memory);
}
void
GetCycles
(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_memory *memory) {
try
{
auto
graph =
mg_utility::GetGraphView
(memgraph_graph, result, memory, mg_graph::GraphType::
kUndirectedGraph
);
auto
cycles =
cycles_alg::GetCycles
(*graph);
for
(std::
size_t
cycle_id =
0
; cycle_id < cycles.
size
(); cycle_id++) {
//
Insert each node on the cycle
for
(
const
auto
&node : cycles[cycle_id]) {
InsertCycleRecord
(memgraph_graph, result, memory, cycle_id, graph->
GetMemgraphNodeId
(node.
id
));
}
}
}
catch
(
const
std::exception &e) {
//
We must not let any exceptions out of our module.
mgp::result_set_error_msg
(result, e.
what
());
return
;
}
}
}
//
namespace
//
Each module needs to define mgp_init_module function.
//
Here you can register multiple procedures your module supports.
extern
"
C
"
int
mgp_init_module
(mgp_module *
module
, mgp_memory *memory) {
try
{
auto
*proc =
mgp::module_add_read_procedure
(
module
,
kProcedureGet
, GetCycles);
mgp::proc_add_result
(proc,
kFieldCycleId
,
mgp::type_int
());
mgp::proc_add_result
(proc,
kFieldNode
,
mgp::type_node
());
}
catch
(
const
std::exception &e) {
return
1
;
}
return
0
;
}
//
This is an optional function if you need to release any resources before the
//
module is unloaded. You will probably need this if you acquired some
//
resources in mgp_init_module.
extern
"
C
"
int
mgp_shutdown_module
() {
//
Return 0 to indicate success.
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL