Commit 9fcc818e authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Fix compilation and memory issues.

parent 60bb8cca
Pipeline #15472 passed with stages
in 11 minutes and 28 seconds
......@@ -39,32 +39,38 @@ namespace mln::morpho::experimental
roots.push_back({static_cast<node_id_t>(nodes.size() - 1), level});
}
void on_flood_end(level_t old_level, level_t new_level) noexcept
void on_flood_end([[maybe_unused]] level_t old_level, level_t new_level) noexcept
{
// Attach to parent
assert(!roots.empty());
auto current = roots.back();
roots.pop_back();
assert(old_level == current.level);
assert(old_level > new_level);
// Fixme: optimize this test with a sentinel value
auto par = roots.back();
assert(par.level <= new_level);
root_info par;
if (!roots.empty())
par = roots.back();
if (par.level != new_level)
if (roots.empty() || par.level != new_level)
{
nodes.push_back({-1});
lvlnodes.push_back(new_level);
par = {static_cast<node_id_t>(nodes.size() - 1), new_level};
roots.push_back(par);
}
assert(par.level <= new_level);
nodes[current.node_root_id] = par.node_root_id;
}
void on_flood_end(dontcare_t) noexcept
{
assert(!roots.empty());
// Attach to parent
node_id_t root = roots.back().node_root_id;
roots.pop_back();
......@@ -107,6 +113,7 @@ namespace mln::morpho::experimental
/// Sort the array \c par so that par[i] < i
/// where `par` encodes a DAG relation
/// The parent of the root node is supposed to be -1;
/// permut[-1] is supposed to be a valid memory location
void permute_parent(int* par, int* permut, std::size_t n);
......@@ -115,11 +122,12 @@ namespace mln::morpho::experimental
void
permute_parent_and_node_map(I&& node_map, int* parent, V* levels, std::size_t n)
{
auto permutation_arr = std::make_unique<int[]>(n);
auto permutation_arr = std::make_unique<int[]>(n + 1);
int* perm = permutation_arr.get() + 1;
permute_parent(parent, permutation_arr.get(), n);
permute_array(permutation_arr.get(), levels, n, sizeof(V));
mln::for_each(node_map, [perm = permutation_arr.get()](int& i) { i = perm[i]; });
permute_parent(parent, perm, n);
permute_array(perm, levels, n, sizeof(V));
mln::for_each(node_map, [perm](int& i) { i = perm[i]; });
}
} // namespace details
......
#include <cstddef>
#include <cstring>
#include <cassert>
#include <climits>
#include <memory>
namespace mln::morpho::experimental::details
......@@ -26,30 +27,32 @@ namespace mln::morpho::experimental::details
/// Sort the array \c par so that par[i] < i
/// where `par` encodes a DAG relation
/// The parent of the root node is supposed to be -1;
/// permut[-1] is supposed to be a valid memory location
void permute_parent(int* parent, int* permut, std::size_t n)
{
constexpr int npos = -1;
std::fill(permut, permut + n, npos);
// Negative values in permut will be considered as UNSEEN
std::fill(permut, permut + n, INT_MIN);
permut[-1] = INT_MAX;
std::size_t pos = 0; // Position in the permutation array
for (std::size_t i = 0; i < n; ++i)
{
assert(i <= pos);
if (permut[i] != npos)
if (permut[i] >= 0)
continue;
int branch_length = 0;
for (int k = static_cast<int>(i); permut[k] == npos; k = parent[k])
for (int k = static_cast<int>(i); permut[k] < 0; k = parent[k])
branch_length++;
for (int j = 1, k = static_cast<int>(i); j <= branch_length; ++j, k = parent[k])
permut[k] = pos + branch_length - j;
for (int j = branch_length - 1, k = static_cast<int>(i); j >= 0; --j, k = parent[k])
permut[k] = pos + j;
pos += branch_length;
}
assert(pos == n);
permut[-1] = -1;
int* tmp_par = new int[n];
for (std::size_t i = 0; i < n; ++i)
......
......@@ -5,6 +5,7 @@
#include <mln/core/neighborhood/c4.hpp>
#include <mln/core/image/view/operators.hpp>
#include <mln/core/algorithm/all_of.hpp>
#include <mln/core/algorithm/fill.hpp>
#include <fixtures/ImageCompare/image_compare.hpp>
......@@ -48,6 +49,7 @@ TEST(Morpho, depthfirst_max)
viz.out.resize(input.domain());
viz.cnt.resize(input.domain());
mln::fill(viz.cnt, 0);
mln::morpho::experimental::canvas::depthfirst(input, mln::experimental::c4, viz, {0,0});
// Counting = anti-leveling
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment