mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-05-09 07:32:54 +08:00
Update windowed_median.cpp
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
* @author [Yaniv Hollander](https://github.com/YanivHollander)
|
||||
*/
|
||||
#include <cassert> // for assert
|
||||
#include <cstdint> // for std::uint64_t
|
||||
#include <list> // for std::list - used to manage sliding window
|
||||
#include <set> // for std::multiset - used to manage multi-value sorted sliding window values
|
||||
|
||||
@@ -31,13 +30,16 @@
|
||||
* @brief Probability algorithms
|
||||
*/
|
||||
namespace probability {
|
||||
using Window = std::list<int>;
|
||||
using size_type = Window::size_type;
|
||||
|
||||
/**
|
||||
* @class WindowedMedian
|
||||
* @brief A class to calculate the median of a leading sliding window at the back of a stream of integer values.
|
||||
*/
|
||||
class WindowedMedian {
|
||||
const std::uint64_t _windowSize; // Sliding window size
|
||||
std::list<int> _window; // A sliding window of values along the stream
|
||||
const size_type _windowSize; // Sliding window size
|
||||
Window _window; // A sliding window of values along the stream
|
||||
std::multiset<int> _sortedValues; // A DS to represent a balanced multi-value binary search tree (BST)
|
||||
std::multiset<int>::const_iterator _itMedian; // An iterator that points to the root of the multi-value BST
|
||||
|
||||
@@ -96,7 +98,7 @@ public:
|
||||
* @brief Constructs a WindowedMedian object
|
||||
* @param windowSize Sliding window size
|
||||
*/
|
||||
explicit WindowedMedian(std::uint64_t windowSize) : _windowSize(windowSize) {};
|
||||
explicit WindowedMedian(size_type windowSize) : _windowSize(windowSize) {};
|
||||
|
||||
/**
|
||||
* @brief Insert a new value to the stream
|
||||
|
||||
Reference in New Issue
Block a user