| 96 | } |
| 97 | |
| 98 | bool CacheNodeBuilder::Build(const InMemoryGraph* graph, int cache_type, |
| 99 | double cache_thld, int thread_num) { |
| 100 | nodes_.clear(); |
| 101 | if (cache_thld == 0) { |
| 102 | DXINFO("Cache_thld == 0, cache was not enabled."); |
| 103 | return true; |
| 104 | } else if (cache_thld < 0) { |
| 105 | DXERROR("Need cache_thld > 0, got cache_thld: %f.", cache_thld); |
| 106 | return false; |
| 107 | } |
| 108 | cache_thld_ = cache_thld; |
| 109 | graph_ = graph; |
| 110 | |
| 111 | auto& nodes = graph->node_keys(); |
| 112 | DXINFO("Cache_type = %d,cache_thld = %f.", cache_type, cache_thld); |
| 113 | |
| 114 | if (cache_type == 0) { |
| 115 | return io_util::ParallelProcess<int_t>( |
| 116 | nodes, |
| 117 | [this](const vec_int_t& nodes, int thread_id) { |
| 118 | return RandomCache(nodes, thread_id); |
| 119 | }, |
| 120 | thread_num); |
| 121 | } else if (cache_type == 1) { |
| 122 | return io_util::ParallelProcess<int_t>( |
| 123 | nodes, |
| 124 | [this](const vec_int_t& nodes, int thread_id) { |
| 125 | return DegreeCache(nodes, thread_id); |
| 126 | }, |
| 127 | thread_num); |
| 128 | } else if (cache_type == 2) { |
| 129 | return io_util::ParallelProcess<int_t>( |
| 130 | nodes, |
| 131 | [this](const vec_int_t& nodes, int thread_id) { |
| 132 | return ImportanceCache(nodes, thread_id); |
| 133 | }, |
| 134 | thread_num); |
| 135 | } else { |
| 136 | DXERROR("Need type: random(0) || degree(1) || importance(2), got type: %d.", |
| 137 | (int)cache_type); |
| 138 | return false; |
| 139 | } |
| 140 | return true; |
| 141 | } |
| 142 | |
| 143 | std::unique_ptr<CacheNodeBuilder> CacheNodeBuilder::Create( |
| 144 | const InMemoryGraph* graph, int cache_type, double cache_thld, |