fix(algos): refactor extrema circular buffer
This commit is contained in:
parent
5fd49dfb1e
commit
3c949f3da3
4 changed files with 2 additions and 18 deletions
|
|
@ -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<double> prices;
|
||||
std::map<double, size_t> sorted_prices;
|
||||
size_t capacity;
|
||||
/* methods & fields omitted for brevity */
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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<double> prices;
|
||||
std::deque<std::pair<double, size_t>> maxs;
|
||||
size_t capacity;
|
||||
/* methods & fields omitted for brevity */
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue