135 std::vector<std::vector<Node_> > simple_hosts;
136 std::vector<std::vector<std::pair<Node_, Weight_> > > ranked_hosts;
139 ranked_hosts.resize(num_cells);
140 for (
size_t i = 0; i < num_cells; ++i) {
141 ranked_hosts[i].emplace_back(i, 0);
142 const auto& current = get_neighbors(i);
144 for (
auto x : current) {
145 ranked_hosts[get_index(x)].emplace_back(i, rank);
150 simple_hosts.resize(num_cells);
151 for (
size_t i = 0; i < num_cells; ++i) {
152 simple_hosts[i].emplace_back(i);
153 const auto& current = get_neighbors(i);
154 for (
auto x : current) {
155 simple_hosts[get_index(x)].emplace_back(i);
161 std::vector<std::vector<Node_> > edge_stores(num_cells);
162 std::vector<std::vector<Weight_> > weight_stores(num_cells);
165 std::vector<Weight_> current_score(num_cells);
166 std::vector<Node_> current_added;
167 current_added.reserve(num_cells);
169 for (size_t j = start, end = start + length; j < end; ++j) {
170 const Node_ j_cast = j;
172 const auto& current_neighbors = get_neighbors(j);
173 const size_t nneighbors = current_neighbors.size();
175 for (size_t i = 0; i <= nneighbors; ++i) {
178 const Node_ cur_neighbor = (i == 0 ? j : get_index(current_neighbors[i-1]));
183 if (options.weighting_scheme == SnnWeightScheme::RANKED) {
185 for (const auto& h : ranked_hosts[cur_neighbor]) {
186 auto othernode = h.first;
187 if (othernode < j_cast) {
188 auto& existing_other = current_score[othernode];
191 Weight_ currank = h.second + i_cast;
192 if (existing_other == 0) {
193 existing_other = currank;
194 current_added.push_back(othernode);
195 } else if (existing_other > currank) {
196 existing_other = currank;
202 for (const auto& othernode : simple_hosts[cur_neighbor]) {
203 if (othernode < j_cast) {
204 auto& existing_other = current_score[othernode];
207 if (existing_other == 0) {
208 current_added.push_back(othernode);
217 auto& current_edges = edge_stores[j];
218 current_edges.reserve(current_added.size() * 2);
219 auto& current_weights = weight_stores[j];
220 current_weights.reserve(current_added.size());
222 for (auto othernode : current_added) {
223 Weight_& otherscore = current_score[othernode];
225 if (options.weighting_scheme == SnnWeightScheme::RANKED) {
226 finalscore = static_cast<Weight_>(nneighbors) - 0.5 * static_cast<Weight_>(otherscore);
228 finalscore = otherscore;
229 if (options.weighting_scheme == SnnWeightScheme::JACCARD) {
230 finalscore = finalscore / (2 * (nneighbors + 1) - finalscore);
234 current_edges.push_back(j);
235 current_edges.push_back(othernode);
236 current_weights.push_back(std::max(finalscore, 1e-6));
241 current_added.clear();
247 for (
const auto& w : weight_stores) {
251 output.num_cells = num_cells;
252 output.weights.clear();
253 output.weights.reserve(nedges);
254 for (
const auto& w : weight_stores) {
255 output.weights.insert(output.weights.end(), w.begin(), w.end());
257 weight_stores.clear();
258 weight_stores.shrink_to_fit();
260 output.edges.clear();
261 output.edges.reserve(nedges * 2);
262 for (
const auto& e : edge_stores) {
263 output.edges.insert(output.edges.end(), e.begin(), e.end());