17 #ifndef VCRS_MISC_HEAP_HH
18 #define VCRS_MISC_HEAP_HH
23 namespace awali {
namespace utils {
25 template <
typename T,
typename P>
34 values_.reserve(capacity_min);
35 tickets_.reserve(capacity_min);
39 return values_.size();
43 return values_.empty();
47 size_t pos = values_.size();
49 values_.emplace_back(std::make_tuple(val, p, ticket));
50 tickets_.emplace_back(pos);
55 return std::get<0>(values_.front());
60 swap(0,values_.size()-1);
68 bottom_up(values_.size()-1);
75 for(
size_t i=values_.size()/2-1, l=i+1; i<l; --i)
80 unsigned i = tickets_[t];
82 if(p < std::get<1>(s)) {
93 for(
size_t i=0;i<
size();++i)
94 std::cout << std::get<0>(values_[i])
95 <<
" p: " << std::get<1>(values_[i])
96 <<
" t: " << std::get<2>(values_[i]) << std::endl;
101 void bottom_up(
size_t i) {
105 if(std::get<1>(values_[i])<std::get<1>(values_[j])) {
111 void top_down(
size_t i) {
112 if(2*i+2 > values_.size())
115 if(2*i+2 == values_.size())
118 j=std::get<1>(values_[2*i+1])<std::get<1>(values_[2*i+2])?2*i+1:2*i+2;
119 if(std::get<1>(values_[j])<std::get<1>(values_[i])) {
125 void swap(
size_t i,
size_t j) {
127 values_[i]=values_[j];values_[j]=tmp;
128 tickets_[std::get<2>(values_[i])]=i;
129 tickets_[std::get<2>(values_[j])]=j;
132 std::vector<store_type> values_;
133 std::vector<size_t> tickets_;
Main namespace of Awali.
Definition: ato.hh:22
value_type pop()
Definition: heap.hh:58
void update(claim_ticket_type t, const priority_type &p)
Definition: heap.hh:79
void print()
Definition: heap.hh:92
claim_ticket_type emplace(const value_type &val, const priority_type &p)
Definition: heap.hh:46
value_type front() const
Definition: heap.hh:54
size_t claim_ticket_type
Definition: heap.hh:30
min_heap(size_t capacity_min)
Definition: heap.hh:33
P priority_type
Definition: heap.hh:29
void heapify()
Definition: heap.hh:72
size_t size() const
Definition: heap.hh:38
std::tuple< T, P, size_t > store_type
Definition: heap.hh:31
T value_type
Definition: heap.hh:28
size_t empty() const
Definition: heap.hh:42
claim_ticket_type push(const value_type &val, const priority_type &p)
Definition: heap.hh:66