aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/queue.h
blob: ade2c0754411992295e5c611f3c62dba84ed793d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once

#include "fwd.h"
#include "deque.h"
#include "vector.h"
#include "utility.h"

#include <util/str_stl.h>

#include <queue>

template <class T, class S>
class TQueue: public std::queue<T, S> {
    using TBase = std::queue<T, S>;

public:
    using TBase::TBase;

    inline explicit operator bool() const noexcept {
        return !this->empty();
    }

    inline void clear() {
        this->c.clear();
    }

    inline S& Container() Y_LIFETIME_BOUND {
        return this->c;
    }

    inline const S& Container() const Y_LIFETIME_BOUND {
        return this->c;
    }
};

template <class T, class S, class C>
class TPriorityQueue: public std::priority_queue<T, S, C> {
    using TBase = std::priority_queue<T, S, C>;

public:
    using TBase::TBase;

    inline explicit operator bool() const noexcept {
        return !this->empty();
    }

    inline void clear() {
        this->c.clear();
    }

    inline T PopValue() {
        Y_ASSERT(!this->empty());
        std::pop_heap(Container().begin(), Container().end(), this->comp);
        T value = std::move(Container().back());
        this->c.pop_back();
        return value;
    }

    inline S& Container() Y_LIFETIME_BOUND {
        return this->c;
    }

    inline const S& Container() const Y_LIFETIME_BOUND {
        return this->c;
    }
};