#ifndef _STATISTICS_SLIDINGMINMAX_HPP_
#define _STATISTICS_SLIDINGMINMAX_HPP_

#pragma once

#include <cpp/radio/Vector.hpp>
#include <cpp/radio/statistics/SlidingMinMax.hpp>
#include <stddef.h>
#include <blaze/Blaze.h>


namespace Radio
{
namespace Statistics
{

// Sliding Min/Max based on MAXLIST-Algorithm, based on:
// "AN EFFICIENT ALGORITHM FOR RUNNING MAX MIN CALCULATION", 1996, S.C. Douglas, University of Utah
// Dependeding on 'mode' this algorithm calculates either minimum (mode = -1) or maximum (mode = +1)
template <typename T>
class SlidingMinMax
{
public:
    enum Mode
    {
        Min,
        Max
    };

    SlidingMinMax(Mode mode, size_t L, T P);
    ~SlidingMinMax();
    void process(T const &xin);
    T getWinner()
    {
        return m_win_value;
    }
private:
	size_t m_L;
	T m_P;
	size_t m_N;
	Mode m_mode;
	RealScalar m_mode_value;
	T m_win_value;
	size_t m_win_index;

	blaze::DynamicVector<T> m_pU;
	blaze::DynamicVector<T> m_pU_last;
	blaze::DynamicVector<size_t> m_pP;
	blaze::DynamicVector<size_t> m_pP_last;

};

#include "SlidingMinMax.tcc"

} // Statistics
} // Radio

#endif // _STATISTICS_SLIDINGMINMAX_HPP_