-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9694f86
commit 79f49db
Showing
9 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,28 @@ | ||
#include "algo.hpp" | ||
|
||
void Algo::Cover(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_memory *memory) { | ||
mgp::MemoryDispatcherGuard guard{memory}; | ||
const auto arguments = mgp::List(args); | ||
const auto record_factory = mgp::RecordFactory(result); | ||
try { | ||
auto list_nodes = arguments[0].ValueList(); | ||
std::unordered_set<mgp::Node> nodes; | ||
for (const auto elem : list_nodes) { | ||
auto node = elem.ValueNode(); | ||
nodes.insert(node); | ||
} | ||
|
||
for (auto node : nodes) { | ||
for (auto rel : node.OutRelationships()) { | ||
if (nodes.find(rel.To()) != nodes.end()) { | ||
auto record = record_factory.NewRecord(); | ||
record.Insert(std::string(kCoverRet1).c_str(), rel); | ||
} | ||
} | ||
} | ||
|
||
} catch (const std::exception &e) { | ||
record_factory.SetErrorMessage(e.what()); | ||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
#pragma once | ||
|
||
#include <mgp.hpp> | ||
#include <unordered_set> | ||
|
||
namespace Algo {} // namespace Algo | ||
namespace Algo { | ||
|
||
/* cover constants */ | ||
constexpr std::string_view kProcedureCover = "cover"; | ||
constexpr std::string_view kCoverArg1 = "nodes"; | ||
constexpr std::string_view kCoverRet1 = "rel"; | ||
|
||
void Cover(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_memory *memory); | ||
} // namespace Algo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE (d:Dog),(h:Human),(ho:House), (d)-[l:LOVES]->(h),(h)-[:LIVES_IN]->(ho),(d)-[se:SELF_REL]->(d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
query: > | ||
MATCH (n) | ||
WITH collect(n) AS list | ||
CALL algo.cover(list) YIELD rel RETURN rel; | ||
output: | ||
- rel: {'label': 'LIVES_IN','properties': {}} | ||
- rel: {'label': 'LOVES','properties': {}} | ||
- rel: {'label': 'SELF_REL','properties': {}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE (d:Dog),(h:Human),(ho:House), (d)-[l:LOVES]->(h),(h)-[:LIVES_IN]->(ho),(d)-[se:SELF_REL]->(d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
query: > | ||
MATCH (d:Dog) | ||
CALL algo.cover([d]) YIELD rel RETURN rel; | ||
output: | ||
- rel: {'label': 'SELF_REL','properties': {}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
MERGE (d:Dog {name: "Rex" ,id:0}) WITH d UNWIND range(0, 1000) AS id MERGE (h:Human {name: "Humie" + id, id:id}) MERGE (d)-[l:LOVES {id:id, how:"very"}]->(h); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
query: > | ||
MATCH (n) | ||
WITH collect(n) AS list | ||
CALL algo.cover(list) YIELD rel RETURN count(rel) AS count; | ||
output: | ||
- count: 1001 |