Skip to content

Commit

Permalink
Fixed code format.
Browse files Browse the repository at this point in the history
  • Loading branch information
AidenPearce-ZYQ committed Nov 23, 2024
1 parent 4ec3703 commit 2ac9f66
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
27 changes: 12 additions & 15 deletions procedures/algo_cpp/khop_core.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/**
* Copyright 2024 Yingqi Zhao
*
* @Function: Compute the k-hop algorithm.
* @param:
*
Expand All @@ -19,42 +21,37 @@

using namespace lgraph_api;
using namespace lgraph_api::olap;
size_t k_hop(OlapBase<Empty>& graph, size_t root_vid, ParallelVector<size_t>&result, size_t k)
{

size_t k_hop(OlapBase<Empty>& graph, size_t root_vid, ParallelVector<size_t>& 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<size_t>();
auto parent = graph.AllocVertexArray<size_t>();
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>(
[&](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);
Expand Down
23 changes: 9 additions & 14 deletions procedures/algo_cpp/khop_standalone.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
// Copyright 2024 Yingqi Zhao
#include "olap/olap_on_disk.h"
#include "tools/json.hpp"
#include "./algo.h"
using namespace lgraph_api;
using namespace lgraph_api::olap;
using json = nlohmann::json;

class MyConfig : public ConfigBase<Empty>
{
class MyConfig : public ConfigBase<Empty> {
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<Empty>::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<Empty>::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<Empty>(argc, argv)
{
MyConfig(int& argc, char**& argv) : ConfigBase<Empty>(argc, argv) {
fma_common::Configuration config;
AddParameter(config);
config.ExitAfterHelp(true);
Expand All @@ -36,7 +31,7 @@ class MyConfig : public ConfigBase<Empty>
}
};

extern size_t k_hop(OlapBase<Empty>& graph, size_t root_vid, ParallelVector<size_t>&result, size_t k);
extern size_t k_hop(OlapBase<Empty>& graph, size_t root_vid, ParallelVector<size_t>& result, size_t k);

int main(int argc, char** argv){
double start_time;
Expand Down Expand Up @@ -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;
}

0 comments on commit 2ac9f66

Please sign in to comment.