Last change
on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 | /**
|
---|
3 | * @license
|
---|
4 | * Copyright Google LLC All Rights Reserved.
|
---|
5 | *
|
---|
6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
7 | * found in the LICENSE file at https://angular.io/license
|
---|
8 | */
|
---|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
10 | exports.PriorityQueue = void 0;
|
---|
11 | /** Naive priority queue; not intended for large datasets */
|
---|
12 | class PriorityQueue {
|
---|
13 | constructor(_comparator) {
|
---|
14 | this._comparator = _comparator;
|
---|
15 | this._items = new Array();
|
---|
16 | }
|
---|
17 | clear() {
|
---|
18 | this._items = new Array();
|
---|
19 | }
|
---|
20 | push(item) {
|
---|
21 | const index = this._items.findIndex((existing) => this._comparator(item, existing) <= 0);
|
---|
22 | if (index === -1) {
|
---|
23 | this._items.push(item);
|
---|
24 | }
|
---|
25 | else {
|
---|
26 | this._items.splice(index, 0, item);
|
---|
27 | }
|
---|
28 | }
|
---|
29 | pop() {
|
---|
30 | if (this._items.length === 0) {
|
---|
31 | return undefined;
|
---|
32 | }
|
---|
33 | return this._items.splice(0, 1)[0];
|
---|
34 | }
|
---|
35 | peek() {
|
---|
36 | if (this._items.length === 0) {
|
---|
37 | return undefined;
|
---|
38 | }
|
---|
39 | return this._items[0];
|
---|
40 | }
|
---|
41 | get size() {
|
---|
42 | return this._items.length;
|
---|
43 | }
|
---|
44 | toArray() {
|
---|
45 | return this._items.slice();
|
---|
46 | }
|
---|
47 | }
|
---|
48 | exports.PriorityQueue = PriorityQueue;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.