mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
use the much faster Stack
This commit is contained in:
parent
77307d70f5
commit
98220dc04f
1 changed files with 23 additions and 22 deletions
45
movext.hh
45
movext.hh
|
|
@ -8,6 +8,7 @@ Copyright 2020 Ahmet Inan <inan@aicodix.de>
|
||||||
|
|
||||||
#include "delay.hh"
|
#include "delay.hh"
|
||||||
#include "deque.hh"
|
#include "deque.hh"
|
||||||
|
#include "stack.hh"
|
||||||
|
|
||||||
namespace DSP {
|
namespace DSP {
|
||||||
|
|
||||||
|
|
@ -46,29 +47,29 @@ template <typename TYPE, int NUM>
|
||||||
class MovMin
|
class MovMin
|
||||||
{
|
{
|
||||||
Delay<TYPE, NUM> window;
|
Delay<TYPE, NUM> window;
|
||||||
Deque<TYPE, NUM> dispenser, refill;
|
Stack<TYPE, NUM> dispenser, refill;
|
||||||
public:
|
public:
|
||||||
MovMin() : window(std::numeric_limits<TYPE>::max())
|
MovMin() : window(std::numeric_limits<TYPE>::max())
|
||||||
{
|
{
|
||||||
dispenser.push_front(std::numeric_limits<TYPE>::max());
|
dispenser.push(std::numeric_limits<TYPE>::max());
|
||||||
}
|
}
|
||||||
TYPE operator () (TYPE input)
|
TYPE operator () (TYPE input)
|
||||||
{
|
{
|
||||||
if (window(input) == dispenser.front())
|
if (window(input) == dispenser.top())
|
||||||
dispenser.pop_front();
|
dispenser.pop();
|
||||||
|
|
||||||
while (!refill.empty() && input < refill.front())
|
while (!refill.empty() && input < refill.top())
|
||||||
refill.pop_front();
|
refill.pop();
|
||||||
refill.push_front(input);
|
refill.push(input);
|
||||||
|
|
||||||
if (dispenser.empty()) {
|
if (dispenser.empty()) {
|
||||||
while (!refill.empty()) {
|
while (!refill.empty()) {
|
||||||
dispenser.push_front(refill.front());
|
dispenser.push(refill.top());
|
||||||
refill.pop_front();
|
refill.pop();
|
||||||
}
|
}
|
||||||
return dispenser.front();
|
return dispenser.top();
|
||||||
}
|
}
|
||||||
return dispenser.front() < refill.back() ? dispenser.front() : refill.back();
|
return dispenser.top() < refill.first() ? dispenser.top() : refill.first();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -76,29 +77,29 @@ template <typename TYPE, int NUM>
|
||||||
class MovMax
|
class MovMax
|
||||||
{
|
{
|
||||||
Delay<TYPE, NUM> window;
|
Delay<TYPE, NUM> window;
|
||||||
Deque<TYPE, NUM> dispenser, refill;
|
Stack<TYPE, NUM> dispenser, refill;
|
||||||
public:
|
public:
|
||||||
MovMax() : window(std::numeric_limits<TYPE>::min())
|
MovMax() : window(std::numeric_limits<TYPE>::min())
|
||||||
{
|
{
|
||||||
dispenser.push_front(std::numeric_limits<TYPE>::min());
|
dispenser.push(std::numeric_limits<TYPE>::min());
|
||||||
}
|
}
|
||||||
TYPE operator () (TYPE input)
|
TYPE operator () (TYPE input)
|
||||||
{
|
{
|
||||||
if (window(input) == dispenser.front())
|
if (window(input) == dispenser.top())
|
||||||
dispenser.pop_front();
|
dispenser.pop();
|
||||||
|
|
||||||
while (!refill.empty() && input > refill.front())
|
while (!refill.empty() && input > refill.top())
|
||||||
refill.pop_front();
|
refill.pop();
|
||||||
refill.push_front(input);
|
refill.push(input);
|
||||||
|
|
||||||
if (dispenser.empty()) {
|
if (dispenser.empty()) {
|
||||||
while (!refill.empty()) {
|
while (!refill.empty()) {
|
||||||
dispenser.push_front(refill.front());
|
dispenser.push(refill.top());
|
||||||
refill.pop_front();
|
refill.pop();
|
||||||
}
|
}
|
||||||
return dispenser.front();
|
return dispenser.top();
|
||||||
}
|
}
|
||||||
return dispenser.front() > refill.back() ? dispenser.front() : refill.back();
|
return dispenser.top() > refill.first() ? dispenser.top() : refill.first();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue