diff --git a/movext.hh b/movext.hh index 8c29d10..ab9bf08 100644 --- a/movext.hh +++ b/movext.hh @@ -7,7 +7,6 @@ Copyright 2020 Ahmet Inan #pragma once #include "delay.hh" -#include "deque.hh" #include "stack.hh" namespace DSP { @@ -15,19 +14,19 @@ namespace DSP { template class MovExt { - Deque window; + Delay window; Stack dispenser, refill; EQUAL equal; COMP comp; public: + MovExt(TYPE init) : window(init) + { + dispenser.push(init); + } TYPE operator () (TYPE input) { - if (window.full()) { - if (equal(window.front(), dispenser.top())) - dispenser.pop(); - window.pop_front(); - } - window.push_back(input); + if (window(input) == dispenser.top()) + dispenser.pop(); while (!refill.empty() && comp(input, refill.top())) refill.pop(); @@ -47,60 +46,28 @@ public: template class MovMin { - Delay window; - Stack dispenser, refill; + MovExt, std::less, NUM> movmin; public: - MovMin() : window(std::numeric_limits::max()) + MovMin() : movmin(std::numeric_limits::max()) { - dispenser.push(std::numeric_limits::max()); } TYPE operator () (TYPE input) { - if (window(input) == dispenser.top()) - dispenser.pop(); - - while (!refill.empty() && input < refill.top()) - refill.pop(); - refill.push(input); - - if (dispenser.empty()) { - while (!refill.empty()) { - dispenser.push(refill.top()); - refill.pop(); - } - return dispenser.top(); - } - return dispenser.top() < refill.first() ? dispenser.top() : refill.first(); + return movmin(input); } }; template class MovMax { - Delay window; - Stack dispenser, refill; + MovExt, std::greater, NUM> movmax; public: - MovMax() : window(std::numeric_limits::min()) + MovMax() : movmax(std::numeric_limits::min()) { - dispenser.push(std::numeric_limits::min()); } TYPE operator () (TYPE input) { - if (window(input) == dispenser.top()) - dispenser.pop(); - - while (!refill.empty() && input > refill.top()) - refill.pop(); - refill.push(input); - - if (dispenser.empty()) { - while (!refill.empty()) { - dispenser.push(refill.top()); - refill.pop(); - } - return dispenser.top(); - } - return dispenser.top() > refill.first() ? dispenser.top() : refill.first(); + return movmax(input); } };