You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
527 B
19 lines
527 B
2 years ago
|
#pragma once
|
||
|
#include "vector_type.hpp"
|
||
|
#include <algorithm>
|
||
|
#include <stdint.h>
|
||
|
template <class Comparator, typename T = uint32_t>
|
||
|
class priority_vector : public vector_type<T> {
|
||
|
const Comparator comp;
|
||
|
public:
|
||
|
priority_vector(Comparator comp = std::less<T>{}) :
|
||
|
comp(comp), vector_type<T>(0) {}
|
||
|
void emplace_back(T val) {
|
||
|
vector_type<T>::emplace_back(val);
|
||
|
std::push_heap(container, container + size, comp);
|
||
|
}
|
||
|
void pop_back() {
|
||
|
std::pop_heap(container, container + size, comp);
|
||
|
--size;
|
||
|
}
|
||
|
};
|