diff --git a/posts/trading/extrema-circular-buffer.html b/posts/trading/extrema-circular-buffer.html index 1250223..00c63c0 100644 --- a/posts/trading/extrema-circular-buffer.html +++ b/posts/trading/extrema-circular-buffer.html @@ -201,11 +201,6 @@

further improvements

    -
  1. - While the final approach is theoretically faster than the - second, with small data sets the overhead of the latter is - likely to upset any performance gains. -
  2. The class could leverage templates to take in a comparator std::less<double> diff --git a/public/code/trading/extrema-circular-buffer/map.cpp b/public/code/trading/extrema-circular-buffer/map.cpp index 9adb021..cb589aa 100644 --- a/public/code/trading/extrema-circular-buffer/map.cpp +++ b/public/code/trading/extrema-circular-buffer/map.cpp @@ -4,8 +4,6 @@ class ExtremaCircularBuffer { public: - ExtremaCircularBuffer(size_t capacity) : capacity(capacity) {} - void push_back(double value) { if (prices.size() == capacity) { double front = prices.front(); @@ -49,8 +47,5 @@ public: return sorted_prices.begin()->first; } -private: - std::deque prices; - std::map sorted_prices; - size_t capacity; + /* methods & fields omitted for brevity */ }; diff --git a/public/code/trading/extrema-circular-buffer/monotonic.cpp b/public/code/trading/extrema-circular-buffer/monotonic.cpp index 68e1f75..3581581 100644 --- a/public/code/trading/extrema-circular-buffer/monotonic.cpp +++ b/public/code/trading/extrema-circular-buffer/monotonic.cpp @@ -4,8 +4,6 @@ class ExtremaCircularBuffer { public: - explicit ExtremaCircularBuffer(size_t capacity) : capacity(capacity) {} - void push_back(double value) { if (prices.size() == capacity) { double front_value = prices.front(); @@ -27,8 +25,6 @@ public: prices.pop_front(); } - size_t size() const { return prices.size(); } - double get_max() const { if (prices.empty()) { throw std::out_of_range("Cannot find max() of empty buffer"); @@ -59,7 +55,5 @@ private: } } - std::deque prices; - std::deque> maxs; - size_t capacity; + /* methods & fields omitted for brevity */ }; diff --git a/public/code/trading/extrema-circular-buffer/ringbuffer.cpp b/public/code/trading/extrema-circular-buffer/ringbuffer.cpp new file mode 100644 index 0000000..e69de29