Skip to content

Commit

Permalink
Merge branch 'main' of github.com:memgraph/mage into T518-allSimplePaths
Browse files Browse the repository at this point in the history
  • Loading branch information
imilinovic committed Oct 26, 2023
2 parents a02bc86 + b67f6aa commit 3e6066d
Show file tree
Hide file tree
Showing 79 changed files with 1,128 additions and 793 deletions.
2 changes: 1 addition & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ add_subdirectory(path_module)
add_subdirectory(node_module)
add_subdirectory(neighbors_module)
add_subdirectory(refactor_module)
add_subdirectory(schema_module)
add_subdirectory(algo_module)


add_cugraph_subdirectory(cugraph_module)
2 changes: 0 additions & 2 deletions cpp/algo_module/algorithm/algo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ constexpr const std::string_view kAllSimplePathsArg4 = "max_length";
constexpr const std::string_view kResultAllSimplePaths = "path";

/* cover constants */
constexpr std::string_view kProcedureCover = "cover";
constexpr std::string_view kCoverArg1 = "nodes";
constexpr std::string_view kCoverRet1 = "rel";

void AllSimplePaths(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_memory *memory);
Expand Down
3 changes: 1 addition & 2 deletions cpp/map_module/algorithm/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,8 @@ void Map::Merge(mgp_list *args, mgp_func_context *ctx, mgp_func_result *res, mgp
const auto map2 = arguments[1].ValueMap();

mgp::Map merged_map = mgp::Map(std::move(map2));

for (const auto element : map1) {
if (merged_map.At(element.key).IsNull()) {
if (!merged_map.KeyExists(element.key)) {
merged_map.Insert(element.key, element.value);
}
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/memgraph
Submodule memgraph updated 406 files
52 changes: 52 additions & 0 deletions cpp/node_module/algorithm/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,55 @@ void Node::RelationshipTypes(mgp_list *args, mgp_graph *memgraph_graph, mgp_resu
return;
}
}

void Node::DegreeIn(mgp_list *args, mgp_func_context *ctx, mgp_func_result *res, mgp_memory *memory) {
mgp::MemoryDispatcherGuard guard{memory};
const auto arguments = mgp::List(args);
auto result = mgp::Result(res);
try {
const auto node = arguments[0].ValueNode();
const auto type = arguments[1].ValueString();
if (type.size() == 0) {
result.SetValue((int64_t)node.InDegree());
return;
}
int64_t degree = 0;
for (const auto rel : node.InRelationships()) {
if (rel.Type() == type) {
degree += 1;
}
}
result.SetValue(degree);


} catch (const std::exception &e) {
result.SetErrorMessage(e.what());
return;
}
}

void Node::DegreeOut(mgp_list *args, mgp_func_context *ctx, mgp_func_result *res, mgp_memory *memory) {
mgp::MemoryDispatcherGuard guard{memory};
const auto arguments = mgp::List(args);
auto result = mgp::Result(res);
try {
const auto node = arguments[0].ValueNode();
const auto type = arguments[1].ValueString();
if (type.size() == 0) {
result.SetValue((int64_t)node.OutDegree());
return;
}
int64_t degree = 0;
for (const auto rel : node.OutRelationships()) {
if (rel.Type() == type) {
degree += 1;
}
}
result.SetValue(degree);


} catch (const std::exception &e) {
result.SetErrorMessage(e.what());
return;
}
}
14 changes: 14 additions & 0 deletions cpp/node_module/algorithm/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ constexpr std::string_view kRelationshipTypesArg1 = "node";
constexpr std::string_view kRelationshipTypesArg2 = "types";
constexpr std::string_view kResultRelationshipTypes = "relationship_types";

/* degree_in constants */
constexpr std::string_view kFunctionDegreeIn = "degree_in";
constexpr std::string_view kDegreeInArg1 = "node";
constexpr std::string_view kDegreeInArg2 = "type";

/* degree_out constants */
constexpr std::string_view kFunctionDegreeOut = "degree_out";
constexpr std::string_view kDegreeOutArg1 = "node";
constexpr std::string_view kDegreeOutArg2 = "type";

void RelationshipsExist(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_memory *memory);

bool RelationshipExist(const mgp::Node &node, std::string &rel_type);
Expand All @@ -35,4 +45,8 @@ void RelationshipExists(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *r

void RelationshipTypes(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_memory *memory);

void DegreeIn(mgp_list *args, mgp_func_context *ctx, mgp_func_result *res, mgp_memory *memory);

void DegreeOut(mgp_list *args, mgp_func_context *ctx, mgp_func_result *res, mgp_memory *memory);

} // namespace Node
14 changes: 13 additions & 1 deletion cpp/node_module/node_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

extern "C" int mgp_init_module(struct mgp_module *module, struct mgp_memory *memory) {
try {
mgp::MemoryDispatcherGuard guard{memory};;

mgp::MemoryDispatcherGuard guard{memory};

AddProcedure(Node::RelationshipsExist, std::string(Node::kProcedureRelationshipsExist).c_str(),
mgp::ProcedureType::Read,
{mgp::Parameter(std::string(Node::kArgumentNodesRelationshipsExist).c_str(), mgp::Type::Node),
Expand All @@ -25,6 +27,16 @@ extern "C" int mgp_init_module(struct mgp_module *module, struct mgp_memory *mem
mgp::Parameter(Node::kRelationshipTypesArg2, {mgp::Type::List, mgp::Type::String}, mgp::Value(mgp::List{}))},
{mgp::Return(Node::kResultRelationshipTypes, {mgp::Type::List, mgp::Type::String})}, module, memory);

mgp::AddFunction(Node::DegreeIn, Node::kFunctionDegreeIn,
{mgp::Parameter(Node::kDegreeInArg1, mgp::Type::Node),
mgp::Parameter(Node::kDegreeInArg2, mgp::Type::String, "")},
module, memory);

mgp::AddFunction(Node::DegreeOut, Node::kFunctionDegreeOut,
{mgp::Parameter(Node::kDegreeOutArg1, mgp::Type::Node),
mgp::Parameter(Node::kDegreeOutArg2, mgp::Type::String, "")},
module, memory);

} catch (const std::exception &e) {
return 1;
}
Expand Down
Loading

0 comments on commit 3e6066d

Please sign in to comment.