some thoughts about scheduling
This commit is contained in:
parent
26114aad5f
commit
544db92b6e
11 changed files with 123 additions and 23 deletions
|
@ -4,7 +4,6 @@
|
|||
#include "helpers.h"
|
||||
|
||||
#include "iostream"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
#include "config.h"
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
#define UNUSED(variable) (void)variable
|
||||
|
||||
|
@ -18,7 +19,51 @@ std::string extract(std::string& string, std::string::size_type begin, std::stri
|
|||
|
||||
template <class T>
|
||||
struct FirstGreater {
|
||||
bool operator () (T left, T right) {
|
||||
bool operator () (const T& left, const T& right) {
|
||||
return std::get<0>(left) > std::get<0>(right);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type, class Container, class Compare = std::less<Type>>
|
||||
class PriorityQueue {
|
||||
public:
|
||||
explicit PriorityQueue(const Compare& compare = Compare()):
|
||||
container(),
|
||||
compare(compare)
|
||||
{}
|
||||
|
||||
const Type& top () const {
|
||||
return container.front();
|
||||
}
|
||||
|
||||
bool empty () const {
|
||||
return container.empty();
|
||||
}
|
||||
|
||||
template<class... Args>
|
||||
void emplace (Args&&... args) {
|
||||
container.emplace_back(std::forward<Args>(args)...);
|
||||
std::push_heap(container.begin(), container.end(), compare);
|
||||
}
|
||||
|
||||
void push (const Type& element) {
|
||||
container.push_back(element);
|
||||
std::push_heap(container.begin(), container.end(), compare);
|
||||
}
|
||||
|
||||
void push (Type&& element) {
|
||||
container.push_back(std::move(element));
|
||||
std::push_heap(container.begin(), container.end(), compare);
|
||||
}
|
||||
|
||||
Type pop () {
|
||||
std::pop_heap(container.begin(), container.end(), compare);
|
||||
Type result = std::move(container.back());
|
||||
container.pop_back();
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
Container container;
|
||||
Compare compare;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue