chenyc
2025-12-09 65e034683b28d799e73c7d7e5e4769fab5b9bc9c
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
var __extends = this && this.t || function() {
    var extendStatics = function(i, r) {
        extendStatics = Object.setPrototypeOf || {
            __proto__: []
        } instanceof Array && function(i, r) {
            i.__proto__ = r;
        } || function(i, r) {
            for (var t in r) if (Object.prototype.hasOwnProperty.call(r, t)) i[t] = r[t];
        };
        return extendStatics(i, r);
    };
    return function(i, r) {
        if (typeof r !== "function" && r !== null) throw new TypeError("Class extends value " + String(r) + " is not a constructor or null");
        extendStatics(i, r);
        function __() {
            this.constructor = i;
        }
        i.prototype = r === null ? Object.create(r) : (__.prototype = r.prototype, new __);
    };
}();
 
var __read = this && this.q || function(i, r) {
    var t = typeof Symbol === "function" && i[Symbol.iterator];
    if (!t) return i;
    var e = t.call(i), n, u = [], s;
    try {
        while ((r === void 0 || r-- > 0) && !(n = e.next()).done) u.push(n.value);
    } catch (i) {
        s = {
            error: i
        };
    } finally {
        try {
            if (n && !n.done && (t = e["return"])) t.call(e);
        } finally {
            if (s) throw s.error;
        }
    }
    return u;
};
 
var __spreadArray = this && this.D || function(i, r, t) {
    if (t || arguments.length === 2) for (var e = 0, n = r.length, u; e < n; e++) {
        if (u || !(e in r)) {
            if (!u) u = Array.prototype.slice.call(r, 0, e);
            u[e] = r[e];
        }
    }
    return i.concat(u || Array.prototype.slice.call(r));
};
 
import { Base } from "../ContainerBase";
 
var PriorityQueue = function(i) {
    __extends(PriorityQueue, i);
    function PriorityQueue(r, t, e) {
        if (r === void 0) {
            r = [];
        }
        if (t === void 0) {
            t = function(i, r) {
                if (i > r) return -1;
                if (i < r) return 1;
                return 0;
            };
        }
        if (e === void 0) {
            e = true;
        }
        var n = i.call(this) || this;
        n.$ = t;
        if (Array.isArray(r)) {
            n.ii = e ? __spreadArray([], __read(r), false) : r;
        } else {
            n.ii = [];
            var u = n;
            r.forEach((function(i) {
                u.ii.push(i);
            }));
        }
        n.M = n.ii.length;
        var s = n.M >> 1;
        for (var o = n.M - 1 >> 1; o >= 0; --o) {
            n.ri(o, s);
        }
        return n;
    }
    PriorityQueue.prototype.ti = function(i) {
        var r = this.ii[i];
        while (i > 0) {
            var t = i - 1 >> 1;
            var e = this.ii[t];
            if (this.$(e, r) <= 0) break;
            this.ii[i] = e;
            i = t;
        }
        this.ii[i] = r;
    };
    PriorityQueue.prototype.ri = function(i, r) {
        var t = this.ii[i];
        while (i < r) {
            var e = i << 1 | 1;
            var n = e + 1;
            var u = this.ii[e];
            if (n < this.M && this.$(u, this.ii[n]) > 0) {
                e = n;
                u = this.ii[n];
            }
            if (this.$(u, t) >= 0) break;
            this.ii[i] = u;
            i = e;
        }
        this.ii[i] = t;
    };
    PriorityQueue.prototype.clear = function() {
        this.M = 0;
        this.ii.length = 0;
    };
    PriorityQueue.prototype.push = function(i) {
        this.ii.push(i);
        this.ti(this.M);
        this.M += 1;
    };
    PriorityQueue.prototype.pop = function() {
        if (this.M === 0) return;
        var i = this.ii[0];
        var r = this.ii.pop();
        this.M -= 1;
        if (this.M) {
            this.ii[0] = r;
            this.ri(0, this.M >> 1);
        }
        return i;
    };
    PriorityQueue.prototype.top = function() {
        return this.ii[0];
    };
    PriorityQueue.prototype.find = function(i) {
        return this.ii.indexOf(i) >= 0;
    };
    PriorityQueue.prototype.remove = function(i) {
        var r = this.ii.indexOf(i);
        if (r < 0) return false;
        if (r === 0) {
            this.pop();
        } else if (r === this.M - 1) {
            this.ii.pop();
            this.M -= 1;
        } else {
            this.ii.splice(r, 1, this.ii.pop());
            this.M -= 1;
            this.ti(r);
            this.ri(r, this.M >> 1);
        }
        return true;
    };
    PriorityQueue.prototype.updateItem = function(i) {
        var r = this.ii.indexOf(i);
        if (r < 0) return false;
        this.ti(r);
        this.ri(r, this.M >> 1);
        return true;
    };
    PriorityQueue.prototype.toArray = function() {
        return __spreadArray([], __read(this.ii), false);
    };
    return PriorityQueue;
}(Base);
 
export default PriorityQueue;
//# sourceMappingURL=PriorityQueue.js.map