Skip to content

Commit

Permalink
#37 Changed the internal queue of labels to check in merge_labels fro…
Browse files Browse the repository at this point in the history
…m being a vector to a stack
  • Loading branch information
carljohnsen committed Aug 8, 2024
1 parent 1abcff7 commit dd935fa
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/lib/cpp/cpu/connected_components.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <fstream>
#include <iostream>
#include <omp.h>
#include <stack>
#include <unordered_set>

// Debug functions
Expand Down Expand Up @@ -963,29 +964,29 @@ std::tuple<std::vector<int64_t>,std::vector<int64_t>,int64_t> merge_labels(mappi
};

int64_t next_free = 1;
std::vector<std::tuple<int64_t, int64_t>> to_check;
for (int64_t i = 1; i < renames[0].size(); i++) {
std::stack<std::tuple<int64_t, int64_t>> to_check;
for (int64_t i = 1; i < (int64_t)renames[0].size(); i++) {
if (renames[0][i] != 0) continue;

renames[0][i] = next_free;
for (int64_t entry : mappings[0][i]) {
to_check.push_back({1, entry});
to_check.push({1, entry});
}
while (!to_check.empty()) {
auto [current, entry] = to_check.back();
to_check.pop_back();
auto [current, entry] = to_check.top();
to_check.pop();
renames[current][entry] = next_free;
for (int64_t entry2 : mappings[current][entry]) {
if (renames[!current][entry2] == 0)
to_check.push_back({!current, entry2});
to_check.push({!current, entry2});
}
}

next_free++;
}

// Renames the rest which haven't been touched
for (int64_t i = 1; i < renames[1].size(); i++) {
for (int64_t i = 1; i < (int64_t)renames[1].size(); i++) {
if (renames[1][i] == 0) renames[1][i] = next_free++;
}

Expand Down

0 comments on commit dd935fa

Please sign in to comment.