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
import { Base, initContainer } from "../ContainerBase";
declare class PriorityQueue<T> extends Base {
    /**
     * @description PriorityQueue's constructor.
     * @param container - Initialize container, must have a forEach function.
     * @param cmp - Compare function.
     * @param copy - When the container is an array, you can choose to directly operate on the original object of
     *               the array or perform a shallow copy. The default is shallow copy.
     * @example
     * new PriorityQueue();
     * new PriorityQueue([1, 2, 3]);
     * new PriorityQueue([1, 2, 3], (x, y) => x - y);
     * new PriorityQueue([1, 2, 3], (x, y) => x - y, false);
     */
    constructor(container?: initContainer<T>, cmp?: (x: T, y: T) => number, copy?: boolean);
    clear(): void;
    /**
     * @description Push element into a container in order.
     * @param item - The element you want to push.
     * @returns The size of heap after pushing.
     * @example
     * queue.push(1);
     */
    push(item: T): void;
    /**
     * @description Removes the top element.
     * @returns The element you popped.
     * @example
     * queue.pop();
     */
    pop(): T | undefined;
    /**
     * @description Accesses the top element.
     * @example
     * const top = queue.top();
     */
    top(): T | undefined;
    /**
     * @description Check if element is in heap.
     * @param item - The item want to find.
     * @returns Whether element is in heap.
     * @example
     * const que = new PriorityQueue([], (x, y) => x.id - y.id);
     * const obj = { id: 1 };
     * que.push(obj);
     * console.log(que.find(obj));  // true
     */
    find(item: T): boolean;
    /**
     * @description Remove specified item from heap.
     * @param item - The item want to remove.
     * @returns Whether remove success.
     * @example
     * const que = new PriorityQueue([], (x, y) => x.id - y.id);
     * const obj = { id: 1 };
     * que.push(obj);
     * que.remove(obj);
     */
    remove(item: T): boolean;
    /**
     * @description Update item and it's pos in the heap.
     * @param item - The item want to update.
     * @returns Whether update success.
     * @example
     * const que = new PriorityQueue([], (x, y) => x.id - y.id);
     * const obj = { id: 1 };
     * que.push(obj);
     * obj.id = 2;
     * que.updateItem(obj);
     */
    updateItem(item: T): boolean;
    /**
     * @returns Return a copy array of heap.
     * @example
     * const arr = queue.toArray();
     */
    toArray(): T[];
}
export default PriorityQueue;