MCPcopy Create free account
hub / github.com/Tencent/embedx / DegreeCache

Method DegreeCache

src/graph/cache/cache_node_builder.cc:44–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44bool CacheNodeBuilder::DegreeCache(const vec_int_t& nodes, int thread_id) {
45 DXINFO("Thread: %d is processing...", thread_id);
46 std::vector<std::pair<int_t, int_t>> tmp_out_degrees;
47 int count = nodes.size() * cache_thld_;
48 if (count < 1) {
49 DXERROR("Need cache nodes count >= 1, got %d.", count);
50 return false;
51 }
52 for (auto& node : nodes) {
53 int tmp_out_degree = graph_->GetOutDegree(node);
54 if (tmp_out_degree < 0) {
55 DXERROR("Need node: %" PRIu64 " out degree >= 0, got %d.", node,
56 tmp_out_degree);
57 return false;
58 }
59 tmp_out_degrees.emplace_back(std::make_pair(node, tmp_out_degree));
60 }
61
62 std::stable_sort(
63 tmp_out_degrees.begin(), tmp_out_degrees.end(),
64 [=](const std::pair<int_t, int_t>& a, const std::pair<int_t, int_t>& b) {
65 return a.second > b.second;
66 });
67
68 for (int i = 0; i < count; ++i) {
69 std::lock_guard<std::mutex> guard(mtx_);
70 nodes_.emplace_back(tmp_out_degrees[i].first);
71 }
72 DXINFO("Done.");
73 return true;
74}
75
76bool CacheNodeBuilder::ImportanceCache(const vec_int_t& nodes, int thread_id) {
77 DXINFO("Thread: %d is processing...", thread_id);

Callers

nothing calls this directly

Calls 1

GetOutDegreeMethod · 0.45

Tested by

no test coverage detected