9#include <NDEVR/QueueBuffer.h>
26 template <
class t_a,
class t_b,
class t_index = u
int04>
33 using UIndex = std::make_unsigned_t<Index>;
49 : m_on_match(
std::move(on_match))
50 , m_on_near_match(
std::move(on_near_match))
59 m_on_match = std::move(on_match);
68 m_on_near_match = std::move(on_near_match);
91 if (m_a.size() > 0 && m_a.last().index == idx)
96 m_a.push(
NodeA{ idx, std::move(a) });
113 if (m_b.size() > 0 && m_b.last().index == idx)
115 m_b.last().value = b;
118 m_b.push(
NodeB{ idx, std::move(b) });
177 const UIndex d1 = ub - ua;
178 const UIndex d2 = ua - ub;
179 return (d1 < d2) ? d1 : d2;
191 static_assert(std::is_integral_v<Index>,
"Index must be integral");
193 while (!m_a.empty() && !m_b.empty())
195 const Index ia = m_a.front().index;
196 const Index ib = m_b.front().index;
201 m_on_match(m_a.front().value, m_b.front().value);
210 while (m_a.size() > 0 &&
seqLess(m_a.front().index, ib))
217 if (dist <= distance_tolerance)
220 m_on_near_match(m_a.front().value, m_b.front().value);
225 while (m_b.size() > 0 && !
seqLess(ia, m_b.front().index))
236 uint04 distance_tolerance = 50U;
void clear()
Clears both internal queues, discarding all pending elements.
std::function< void(const A &, const B &)> OnMatchFn
Callback type invoked when indices match exactly.
void pushA(Index idx, A a)
Pushes an element into the A stream with the given index.
std::make_unsigned_t< Index > UIndex
Unsigned version of the index type for circular arithmetic.
std::function< void(const A &, const B &)> OnNearMatchFn
Callback type invoked when indices are within the distance tolerance.
static constexpr UIndex circularDistance(Index a, Index b) noexcept
Computes the minimum circular distance between two indices.
void pushB(Index idx, B b)
Pushes an element into the B stream with the given index.
void setOnNearMatch(OnNearMatchFn on_near_match)
Sets the callback for near index matches.
void drain()
Processes the front of both queues, invoking callbacks for matched or near-matched pairs.
t_b B
Alias for the second element type.
t_index Index
Alias for the index type.
static constexpr UIndex HalfRange() noexcept
Computes half the total range of the unsigned index type.
t_a A
Alias for the first element type.
IndexMatchQueue()=default
Default constructor.
static constexpr bool seqLess(Index a, Index b) noexcept
Determines whether index a precedes index b in circular sequence order.
IndexMatchQueue(OnMatchFn on_match, OnNearMatchFn on_near_match={})
Constructs the queue with match callbacks.
void setOnMatch(OnMatchFn on_match)
Sets the callback for exact index matches.
Stores objects in a first-in, first out queue based Buffer with push and pop functions.
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Internal node storing an A-stream element and its associated index.
A value
The stored element value.
Index index
The sequence index for this element.
Internal node storing a B-stream element and its associated index.
Index index
The sequence index for this element.
B value
The stored element value.