Commit 038e22a5 authored by Baptiste Esteban's avatar Baptiste Esteban
Browse files

Apply suggestions from MR review

parent 95caa12b
Pipeline #28170 passed with stage
in 12 minutes and 15 seconds
......@@ -41,10 +41,10 @@ namespace mln::morpho::details
private:
static constexpr int m_ndir = decltype(N::after_offsets())::extent;
static constexpr int m_nlevels = 1 << std::numeric_limits<K>::digits;
static constexpr int m_nlevels = 1 << std::numeric_limits<K>::digits;
queue_type m_queues[m_ndir];
int m_current_dir;
int m_current_dir = -1;
int m_current_level;
std::size_t m_size = 0;
};
......@@ -87,7 +87,7 @@ namespace mln::morpho::details
// Update the current level and the current dir if needed
if (m_size > 0 && m_queues[m_current_dir].empty(m_current_level))
{
int lvl = m_queues[0].lower_bound(m_current_level);
int lvl = m_queues[0].lower_bound(m_current_level);
int dir = 0;
for (int i = 1; i < m_ndir; i++)
{
......
......@@ -103,7 +103,7 @@ namespace mln::morpho::details
inline int hvectors_unbounded<void>::lower_bound(int level) const noexcept
{
assert(m_lists != nullptr);
mln_precondition(m_lists != nullptr);
mln_precondition(level < m_nlevels);
while (level < m_nlevels && m_lists[level].size == 0)
......@@ -113,7 +113,7 @@ namespace mln::morpho::details
inline int hvectors_unbounded<void>::upper_bound(int level) const noexcept
{
assert(m_lists != nullptr);
mln_precondition(m_lists != nullptr);
mln_precondition(level < m_nlevels);
while (level >= 0 && m_lists[level].size == 0)
......@@ -123,7 +123,7 @@ namespace mln::morpho::details
inline bool hvectors_unbounded<void>::empty(int level) const noexcept
{
assert(m_lists != nullptr);
mln_precondition(m_lists != nullptr);
return m_lists[level].size == 0;
}
......@@ -156,7 +156,7 @@ namespace mln::morpho::details
template <class P>
inline void hvectors_unbounded<P>::push_front(int level, P p) noexcept
{
assert(m_lists != nullptr);
mln_precondition(m_lists != nullptr);
if (m_lists[level].size == m_lists[level].capacity)
this->resize(level, sizeof(P));
......
......@@ -35,7 +35,7 @@ namespace mln::morpho::details
void hvectors_unbounded<void>::release()
{
assert(m_lists != nullptr);
mln_precondition(m_lists != nullptr);
for (int i = 0; i < m_nlevels; ++i)
{
this->destroy_n(m_lists[i].begin, m_lists[i].size);
......@@ -48,7 +48,7 @@ namespace mln::morpho::details
void hvectors_unbounded<void>::resize(int i, std::size_t size)
{
assert(m_lists != nullptr);
mln_precondition(m_lists != nullptr);
constexpr float kResizingFactor = 2;
int old_capacity = m_lists[i].capacity;
void* old_ptr = m_lists[i].begin;
......
#include <mln/morpho/private/directional_hqueue.hpp>
#include <mln/core/algorithm/iota.hpp>
#include <mln/core/functional_ops.hpp>
#include <mln/core/image/ndimage.hpp>
#include <mln/core/neighborhood/c4.hpp>
......@@ -131,4 +132,39 @@ TEST(Morpho, DirectionalHQueueC6)
n++;
}
ASSERT_EQ(n, 33);
}
TEST(Morpho, DirectionalHQueueResizeHVector)
{
using I = mln::image2d<std::uint16_t>;
using P = mln::image_point_t<I>;
mln::image_build_params params;
params.init_value = std::make_any<std::uint16_t>(0);
I img(100, 100, params);
img({0, 0}) = 20;
auto hqueue = mln::morpho::details::directional_hqueue<P, mln::c4_t, std::uint16_t>();
auto dist = [](const std::uint16_t a, std::uint16_t b) -> std::uint16_t {
return std::abs(static_cast<int>(a) - static_cast<int>(b));
};
mln_foreach (auto p, img.domain())
{
int i = 0;
for (auto q : mln::c4.after(p))
{
if (img.domain().has(q))
hqueue.insert(i, dist(img(p), img(q)), p);
i++;
}
}
std::uint16_t prev = 0;
while (!hqueue.empty())
{
auto [p, q, w] = hqueue.pop();
ASSERT_LE(prev, w);
prev = w;
}
}
\ No newline at end of file
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