fix: remove leftover files
This commit is contained in:
parent
85b584bcf2
commit
4c8ea11893
1 changed files with 0 additions and 65 deletions
65
a.cc
65
a.cc
|
|
@ -1,65 +0,0 @@
|
||||||
#include <deque>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
class ExtremaCircularBuffer {
|
|
||||||
public:
|
|
||||||
explicit ExtremaCircularBuffer(size_t capacity) : capacity(capacity) {}
|
|
||||||
|
|
||||||
void push_back(double value) {
|
|
||||||
if (prices.size() == capacity) {
|
|
||||||
double front_value = prices.front();
|
|
||||||
pop_max(front_value);
|
|
||||||
prices.pop_front();
|
|
||||||
}
|
|
||||||
|
|
||||||
prices.push_back(value);
|
|
||||||
push_max(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pop_front() {
|
|
||||||
if (prices.empty()) {
|
|
||||||
throw std::out_of_range("Cannot pop_front() from empty buffer");
|
|
||||||
}
|
|
||||||
|
|
||||||
double front_value = prices.front();
|
|
||||||
pop_max(front_value);
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
return maxs.front().first;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void push_max(double value) {
|
|
||||||
size_t popped = 0;
|
|
||||||
|
|
||||||
while (!maxs.empty() && maxs.back().first < value) {
|
|
||||||
popped += maxs.back().second + 1;
|
|
||||||
maxs.pop_back();
|
|
||||||
}
|
|
||||||
|
|
||||||
maxs.emplace_back(value, popped);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pop_max(double value) {
|
|
||||||
size_t popped = maxs.front().second;
|
|
||||||
|
|
||||||
if (popped == 0) {
|
|
||||||
maxs.pop_front();
|
|
||||||
} else {
|
|
||||||
--maxs.front().second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::deque<double> prices;
|
|
||||||
std::deque<std::pair<double, size_t>> maxs;
|
|
||||||
size_t capacity;
|
|
||||||
};
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue