diff --git a/procedures/algo_cpp/khop_core.cpp b/procedures/algo_cpp/khop_core.cpp index b44f7f21ca..2b52d6b4b9 100644 --- a/procedures/algo_cpp/khop_core.cpp +++ b/procedures/algo_cpp/khop_core.cpp @@ -1,4 +1,6 @@ /** + * Copyright 2024 Yingqi Zhao + * * @Function: Compute the k-hop algorithm. * @param: * @@ -19,42 +21,37 @@ using namespace lgraph_api; using namespace lgraph_api::olap; -size_t k_hop(OlapBase& graph, size_t root_vid, ParallelVector&result, size_t k) -{ + +size_t k_hop(OlapBase& graph, size_t root_vid, ParallelVector& result, size_t k) { size_t root = root_vid; auto active_in = graph.AllocVertexSubset(); active_in.Add(root); auto active_out = graph.AllocVertexSubset(); - auto parent=graph.AllocVertexArray(); + auto parent = graph.AllocVertexArray(); parent.Fill(0); - parent[root]=root; + parent[root] = root; size_t num_activations = 1; size_t discovered_vertices, j = 0; - for (size_t ii = 0; ii < k ; ii++) - { + for (size_t ii = 0; ii < k; ii++) { active_out.Clear(); num_activations = graph.ProcessVertexActive( [&](size_t vi) { size_t num_activations = 0; - for (auto& edge : graph.OutEdges(vi)) - { + for (auto& edge : graph.OutEdges(vi)) { size_t dst = edge.neighbour; - if (parent[dst] == 0) - { + if (parent[dst] == 0) { auto lock = graph.GuardVertexLock(dst); - if(parent[dst] == 0) - { + if (parent[dst] == 0) { parent[dst] = vi; num_activations += 1; active_out.Add(dst); - result[j++]=dst; + result[j++] = dst; } } } return num_activations; }, - active_in - ); + active_in); printf("activates(%lu) <= %lu \n", ii+1, num_activations); discovered_vertices += num_activations; active_in.Swap(active_out); diff --git a/procedures/algo_cpp/khop_standalone.cpp b/procedures/algo_cpp/khop_standalone.cpp index 887e1ae3ca..91d370c2ec 100644 --- a/procedures/algo_cpp/khop_standalone.cpp +++ b/procedures/algo_cpp/khop_standalone.cpp @@ -1,3 +1,4 @@ +// Copyright 2024 Yingqi Zhao #include "olap/olap_on_disk.h" #include "tools/json.hpp" #include "./algo.h" @@ -5,29 +6,23 @@ using namespace lgraph_api; using namespace lgraph_api::olap; using json = nlohmann::json; -class MyConfig : public ConfigBase -{ +class MyConfig : public ConfigBase { public: std::string root = "0"; std::string name = std::string("khop"); - size_t value_k=3; - void AddParameter(fma_common::Configuration& config) - { + size_t value_k = 3; + void AddParameter(fma_common::Configuration& config) { ConfigBase::AddParameter(config); config.Add(root, "root", true).Comment("Identifier of the root node."); - config.Add(value_k, "value_k", true).Comment( - "Number of search layers(value of k in K-hop algorithm)." - ); + config.Add(value_k, "value_k", true).Comment("Number of search layers(value of k in K-hop algorithm)."); } - void Print() - { + void Print() { ConfigBase::Print(); std::cout << " name: " << name << std::endl; std::cout << " root: " << name << std::endl; std::cout << " value_k: " << value_k << std::endl; } - MyConfig(int& argc, char**& argv) : ConfigBase(argc, argv) - { + MyConfig(int& argc, char**& argv) : ConfigBase(argc, argv) { fma_common::Configuration config; AddParameter(config); config.ExitAfterHelp(true); @@ -36,7 +31,7 @@ class MyConfig : public ConfigBase } }; -extern size_t k_hop(OlapBase& graph, size_t root_vid, ParallelVector&result, size_t k); +extern size_t k_hop(OlapBase& graph, size_t root_vid, ParallelVector& result, size_t k); int main(int argc, char** argv){ double start_time; @@ -78,6 +73,6 @@ int main(int argc, char** argv){ printf("core_cost = %.2lf(s)\n", core_cost); printf("output_cost = %.2lf(s)\n", output_cost); printf("total_cost = %.2lf(s)\n", prepare_cost + core_cost + output_cost); - printf("DONE. \n"); + printf("DONE.\n"); return 0; } \ No newline at end of file