data-structure-typed 1.33.0 → 1.33.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/codeStyles/Project.xml +61 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/CHANGELOG.md +1 -1
- package/README.md +197 -257
- package/coverage/coverage-final.json +63 -63
- package/coverage/coverage-summary.json +16 -16
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +1 -16
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/avl-tree.js +2 -2
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/rb-tree.js +3 -4
- package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/data-structures/hash/hash-table.js +107 -2
- package/dist/data-structures/hash/hash-table.js.map +1 -1
- package/dist/data-structures/heap/max-heap.js.map +1 -1
- package/dist/data-structures/heap/min-heap.js.map +1 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +30 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/data-structures/matrix/matrix2d.js +5 -8
- package/dist/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/data-structures/queue/deque.js.map +1 -1
- package/docs/index.html +197 -256
- package/docs/modules.html +2 -0
- package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +8 -18
- package/lib/data-structures/binary-tree/abstract-binary-tree.js +5 -23
- package/lib/data-structures/binary-tree/avl-tree.d.ts +7 -10
- package/lib/data-structures/binary-tree/avl-tree.js +6 -9
- package/lib/data-structures/binary-tree/binary-tree.d.ts +2 -2
- package/lib/data-structures/binary-tree/bst.d.ts +2 -2
- package/lib/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/lib/data-structures/binary-tree/rb-tree.js +3 -3
- package/lib/data-structures/binary-tree/tree-multiset.d.ts +3 -3
- package/lib/data-structures/binary-tree/tree-multiset.js +1 -1
- package/lib/data-structures/graph/abstract-graph.d.ts +10 -10
- package/lib/data-structures/graph/abstract-graph.js +2 -2
- package/lib/data-structures/graph/directed-graph.d.ts +6 -6
- package/lib/data-structures/graph/directed-graph.js +2 -2
- package/lib/data-structures/graph/map-graph.d.ts +6 -6
- package/lib/data-structures/graph/map-graph.js +2 -2
- package/lib/data-structures/graph/undirected-graph.d.ts +6 -6
- package/lib/data-structures/graph/undirected-graph.js +2 -2
- package/lib/data-structures/hash/hash-table.d.ts +61 -1
- package/lib/data-structures/hash/hash-table.js +136 -0
- package/lib/data-structures/heap/heap.d.ts +31 -31
- package/lib/data-structures/heap/heap.js +11 -11
- package/lib/data-structures/heap/max-heap.d.ts +4 -4
- package/lib/data-structures/heap/max-heap.js +1 -1
- package/lib/data-structures/heap/min-heap.d.ts +4 -4
- package/lib/data-structures/heap/min-heap.js +1 -1
- package/lib/data-structures/linked-list/doubly-linked-list.d.ts +93 -54
- package/lib/data-structures/linked-list/doubly-linked-list.js +79 -22
- package/lib/data-structures/linked-list/singly-linked-list.d.ts +46 -46
- package/lib/data-structures/linked-list/singly-linked-list.js +20 -20
- package/lib/data-structures/matrix/matrix.d.ts +3 -3
- package/lib/data-structures/matrix/matrix2d.d.ts +1 -1
- package/lib/data-structures/matrix/matrix2d.js +3 -2
- package/lib/data-structures/priority-queue/max-priority-queue.d.ts +4 -4
- package/lib/data-structures/priority-queue/min-priority-queue.d.ts +4 -4
- package/lib/data-structures/priority-queue/priority-queue.d.ts +26 -26
- package/lib/data-structures/priority-queue/priority-queue.js +8 -8
- package/lib/data-structures/queue/deque.d.ts +30 -30
- package/lib/data-structures/queue/deque.js +7 -7
- package/lib/data-structures/queue/queue.d.ts +27 -27
- package/lib/data-structures/queue/queue.js +8 -8
- package/lib/data-structures/stack/stack.d.ts +15 -15
- package/lib/data-structures/stack/stack.js +6 -6
- package/lib/data-structures/tree/tree.d.ts +7 -7
- package/lib/interfaces/abstract-binary-tree.d.ts +0 -1
- package/lib/interfaces/avl-tree.d.ts +1 -1
- package/lib/types/data-structures/navigator.d.ts +1 -1
- package/package.json +3 -5
- package/test/integration/index.html +6 -6
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +146 -0
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +44 -0
- package/test/unit/data-structures/hash/coordinate-map.test.ts +54 -0
- package/test/unit/data-structures/hash/coordinate-set.test.ts +41 -0
- package/test/unit/data-structures/hash/hash-table.test.ts +97 -0
- package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -3
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +53 -0
- package/test/unit/data-structures/matrix/matrix.test.ts +54 -0
- package/test/unit/data-structures/matrix/matrix2d.test.ts +138 -0
- package/test/unit/data-structures/matrix/navigator.test.ts +80 -0
- package/test/unit/data-structures/queue/deque.test.ts +131 -0
- package/test/unit/data-structures/queue/queue.test.ts +168 -1
- package/test/unit/data-structures/stack/stack.test.ts +67 -0
- package/test/unit/data-structures/tree/tree.test.ts +39 -0
- package/test/unit/data-structures/trie/trie.test.ts +95 -0
- package/umd/bundle.min.js +1 -1
- package/umd/bundle.min.js.map +1 -1
|
@@ -1,2 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
export class HashNode {
|
|
9
|
+
constructor(key, val) {
|
|
10
|
+
this.key = key;
|
|
11
|
+
this.val = val;
|
|
12
|
+
this.next = null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
1
15
|
export class HashTable {
|
|
16
|
+
get buckets() {
|
|
17
|
+
return this._buckets;
|
|
18
|
+
}
|
|
19
|
+
set buckets(value) {
|
|
20
|
+
this._buckets = value;
|
|
21
|
+
}
|
|
22
|
+
get size() {
|
|
23
|
+
return this._size;
|
|
24
|
+
}
|
|
25
|
+
set size(value) {
|
|
26
|
+
this._size = value;
|
|
27
|
+
}
|
|
28
|
+
get capacity() {
|
|
29
|
+
return this._capacity;
|
|
30
|
+
}
|
|
31
|
+
set capacity(value) {
|
|
32
|
+
this._capacity = value;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The constructor initializes the capacity, size, and buckets of an object.
|
|
36
|
+
* @param [capacity=1000] - The `capacity` parameter represents the maximum number of elements that the data structure
|
|
37
|
+
* can hold. It is an optional parameter with a default value of 1000.
|
|
38
|
+
*/
|
|
39
|
+
constructor(capacity = 1000) {
|
|
40
|
+
this._capacity = capacity;
|
|
41
|
+
this._size = 0;
|
|
42
|
+
this._buckets = new Array(this.capacity).fill(null);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The hash function takes a key, converts it to a string, calculates the sum of the ASCII values of its characters, and
|
|
46
|
+
* returns the remainder when divided by the capacity of the data structure.
|
|
47
|
+
* @param {K} key - The `key` parameter represents the key that needs to be hashed. It is of type `K`, which means it can
|
|
48
|
+
* be any data type that can be converted to a string.
|
|
49
|
+
* @returns The hash value of the key modulo the capacity of the data structure.
|
|
50
|
+
*/
|
|
51
|
+
hash(key) {
|
|
52
|
+
const keyString = String(key);
|
|
53
|
+
let hash = 0;
|
|
54
|
+
for (let i = 0; i < keyString.length; i++) {
|
|
55
|
+
hash += keyString.charCodeAt(i);
|
|
56
|
+
}
|
|
57
|
+
return hash % this.capacity;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The put function adds a key-value pair to a hash table, handling collisions by chaining.
|
|
61
|
+
* @param {K} key - The key parameter represents the key of the key-value pair that you want to insert into the hash
|
|
62
|
+
* table. It is of type K, which can be any data type that can be used as a key, such as a string, number, or object.
|
|
63
|
+
* @param {V} val - The `val` parameter represents the value associated with the key in the hash table.
|
|
64
|
+
* @returns Nothing is being returned. The return type of the function is void, which means it does not return any value.
|
|
65
|
+
*/
|
|
66
|
+
put(key, val) {
|
|
67
|
+
const index = this.hash(key);
|
|
68
|
+
const newNode = new HashNode(key, val);
|
|
69
|
+
if (!this.buckets[index]) {
|
|
70
|
+
this.buckets[index] = newNode;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// Handle collision by chaining
|
|
74
|
+
let currentNode = this.buckets[index];
|
|
75
|
+
while (currentNode.next) {
|
|
76
|
+
if (currentNode.key === key) {
|
|
77
|
+
// Update the val if the key already exists
|
|
78
|
+
currentNode.val = val;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
currentNode = currentNode.next;
|
|
82
|
+
}
|
|
83
|
+
if (currentNode.key === key) {
|
|
84
|
+
// Update the val if the key already exists (last node)
|
|
85
|
+
currentNode.val = val;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// Add the new node to the end of the chain
|
|
89
|
+
currentNode.next = newNode;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
this.size++;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The `get` function retrieves the value associated with a given key from a hash table.
|
|
96
|
+
* @param {K} key - The parameter "key" represents the key of the element that we want to retrieve from the data
|
|
97
|
+
* structure.
|
|
98
|
+
* @returns The method is returning the value associated with the given key if it exists in the hash table. If the key is
|
|
99
|
+
* not found, it returns `undefined`.
|
|
100
|
+
*/
|
|
101
|
+
get(key) {
|
|
102
|
+
const index = this.hash(key);
|
|
103
|
+
let currentNode = this.buckets[index];
|
|
104
|
+
while (currentNode) {
|
|
105
|
+
if (currentNode.key === key) {
|
|
106
|
+
return currentNode.val;
|
|
107
|
+
}
|
|
108
|
+
currentNode = currentNode.next;
|
|
109
|
+
}
|
|
110
|
+
return undefined; // Key not found
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The `remove` function removes a key-value pair from a hash table.
|
|
114
|
+
* @param {K} key - The `key` parameter represents the key of the key-value pair that needs to be removed from the hash
|
|
115
|
+
* table.
|
|
116
|
+
* @returns Nothing is being returned. The `remove` method has a return type of `void`, which means it does not return
|
|
117
|
+
* any value.
|
|
118
|
+
*/
|
|
119
|
+
remove(key) {
|
|
120
|
+
const index = this.hash(key);
|
|
121
|
+
let currentNode = this.buckets[index];
|
|
122
|
+
let prevNode = null;
|
|
123
|
+
while (currentNode) {
|
|
124
|
+
if (currentNode.key === key) {
|
|
125
|
+
if (prevNode) {
|
|
126
|
+
prevNode.next = currentNode.next;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
this.buckets[index] = currentNode.next;
|
|
130
|
+
}
|
|
131
|
+
this.size--;
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
prevNode = currentNode;
|
|
135
|
+
currentNode = currentNode.next;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
2
138
|
}
|
|
@@ -7,33 +7,33 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { PriorityQueue } from '../priority-queue';
|
|
9
9
|
import type { HeapOptions } from '../../types';
|
|
10
|
-
export declare class HeapItem<
|
|
10
|
+
export declare class HeapItem<V = any> {
|
|
11
11
|
/**
|
|
12
12
|
* The constructor function initializes an instance of a class with a priority and a value.
|
|
13
13
|
* @param {number} priority - The `priority` parameter is a number that represents the priority of the value. It is
|
|
14
14
|
* optional and has a default value of `NaN`.
|
|
15
|
-
* @param {
|
|
16
|
-
* `
|
|
15
|
+
* @param {V | null} [val=null] - The `val` parameter is of type `V | null`, which means it can accept a value of type
|
|
16
|
+
* `V` or `null`.
|
|
17
17
|
*/
|
|
18
|
-
constructor(priority?: number, val?:
|
|
18
|
+
constructor(priority?: number, val?: V | null);
|
|
19
19
|
private _priority;
|
|
20
20
|
get priority(): number;
|
|
21
21
|
set priority(value: number);
|
|
22
22
|
private _val;
|
|
23
|
-
get val():
|
|
24
|
-
set val(value:
|
|
23
|
+
get val(): V | null;
|
|
24
|
+
set val(value: V | null);
|
|
25
25
|
}
|
|
26
|
-
export declare abstract class Heap<
|
|
26
|
+
export declare abstract class Heap<V = number> {
|
|
27
27
|
/**
|
|
28
28
|
* The function is a constructor for a class that initializes a priority callback function based on the
|
|
29
29
|
* options provided.
|
|
30
30
|
* @param [options] - An optional object that contains configuration options for the Heap.
|
|
31
31
|
*/
|
|
32
|
-
protected constructor(options?: HeapOptions<
|
|
33
|
-
protected abstract _pq: PriorityQueue<HeapItem<
|
|
34
|
-
get pq(): PriorityQueue<HeapItem<
|
|
35
|
-
protected _priorityExtractor: (val:
|
|
36
|
-
get priorityExtractor(): (val:
|
|
32
|
+
protected constructor(options?: HeapOptions<V>);
|
|
33
|
+
protected abstract _pq: PriorityQueue<HeapItem<V>>;
|
|
34
|
+
get pq(): PriorityQueue<HeapItem<V>>;
|
|
35
|
+
protected _priorityExtractor: (val: V) => number;
|
|
36
|
+
get priorityExtractor(): (val: V) => number;
|
|
37
37
|
/**
|
|
38
38
|
* The function returns the size of a priority queue.
|
|
39
39
|
* @returns The size of the priority queue.
|
|
@@ -44,15 +44,15 @@ export declare abstract class Heap<T = number> {
|
|
|
44
44
|
* @returns {boolean} A boolean value indicating whether the size of the priority queue is less than 1.
|
|
45
45
|
*/
|
|
46
46
|
isEmpty(): boolean;
|
|
47
|
-
peek(isItem?: undefined):
|
|
48
|
-
peek(isItem: false):
|
|
49
|
-
peek(isItem: true): HeapItem<
|
|
50
|
-
peekLast(isItem?: undefined):
|
|
51
|
-
peekLast(isItem: false):
|
|
52
|
-
peekLast(isItem: true): HeapItem<
|
|
47
|
+
peek(isItem?: undefined): V | undefined;
|
|
48
|
+
peek(isItem: false): V | undefined;
|
|
49
|
+
peek(isItem: true): HeapItem<V> | null;
|
|
50
|
+
peekLast(isItem?: undefined): V | undefined;
|
|
51
|
+
peekLast(isItem: false): V | undefined;
|
|
52
|
+
peekLast(isItem: true): HeapItem<V> | null;
|
|
53
53
|
/**
|
|
54
54
|
* The `add` function adds an val to a priority queue with an optional priority value.
|
|
55
|
-
* @param {
|
|
55
|
+
* @param {V} val - The `val` parameter represents the value that you want to add to the heap. It can be of any
|
|
56
56
|
* type.
|
|
57
57
|
* @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
|
|
58
58
|
* val being added to the heap. If the `val` parameter is a number, then the `priority` parameter is set to
|
|
@@ -60,22 +60,22 @@ export declare abstract class Heap<T = number> {
|
|
|
60
60
|
* @returns The `add` method returns the instance of the `Heap` class.
|
|
61
61
|
* @throws {Error} if priority is not a valid number
|
|
62
62
|
*/
|
|
63
|
-
add(priority: number, val?:
|
|
64
|
-
poll(isItem?: undefined):
|
|
65
|
-
poll(isItem: false):
|
|
66
|
-
poll(isItem: true): HeapItem<
|
|
63
|
+
add(priority: number, val?: V): Heap<V>;
|
|
64
|
+
poll(isItem?: undefined): V | undefined;
|
|
65
|
+
poll(isItem: false): V | undefined;
|
|
66
|
+
poll(isItem: true): HeapItem<V> | null;
|
|
67
67
|
/**
|
|
68
68
|
* The function checks if a given node or value exists in the priority queue.
|
|
69
|
-
* @param {
|
|
69
|
+
* @param {V | HeapItem<V>} node - The parameter `node` can be of type `V` or `HeapItem<V>`.
|
|
70
70
|
* @returns a boolean value.
|
|
71
71
|
*/
|
|
72
|
-
has(node:
|
|
73
|
-
toArray(isItem?: undefined): (
|
|
74
|
-
toArray(isItem: false): (
|
|
75
|
-
toArray(isItem: true): (HeapItem<
|
|
76
|
-
sort(isItem?: undefined): (
|
|
77
|
-
sort(isItem: false): (
|
|
78
|
-
sort(isItem: true): (HeapItem<
|
|
72
|
+
has(node: V | HeapItem<V>): boolean;
|
|
73
|
+
toArray(isItem?: undefined): (V | undefined)[];
|
|
74
|
+
toArray(isItem: false): (V | undefined)[];
|
|
75
|
+
toArray(isItem: true): (HeapItem<V> | null)[];
|
|
76
|
+
sort(isItem?: undefined): (V | undefined)[];
|
|
77
|
+
sort(isItem: false): (V | undefined)[];
|
|
78
|
+
sort(isItem: true): (HeapItem<V> | null)[];
|
|
79
79
|
/**
|
|
80
80
|
* The clear function clears the priority queue.
|
|
81
81
|
*/
|
|
@@ -3,8 +3,8 @@ export class HeapItem {
|
|
|
3
3
|
* The constructor function initializes an instance of a class with a priority and a value.
|
|
4
4
|
* @param {number} priority - The `priority` parameter is a number that represents the priority of the value. It is
|
|
5
5
|
* optional and has a default value of `NaN`.
|
|
6
|
-
* @param {
|
|
7
|
-
* `
|
|
6
|
+
* @param {V | null} [val=null] - The `val` parameter is of type `V | null`, which means it can accept a value of type
|
|
7
|
+
* `V` or `null`.
|
|
8
8
|
*/
|
|
9
9
|
constructor(priority = Number.MAX_SAFE_INTEGER, val = null) {
|
|
10
10
|
this._val = val;
|
|
@@ -63,7 +63,7 @@ export class Heap {
|
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* The `peek` function returns the top item in the priority queue without removing it.
|
|
66
|
-
* @returns The `peek()` method is returning either a `HeapItem<
|
|
66
|
+
* @returns The `peek()` method is returning either a `HeapItem<V>` object or `null`.Returns an val with the highest priority in the queue
|
|
67
67
|
*/
|
|
68
68
|
peek(isItem) {
|
|
69
69
|
isItem = isItem !== null && isItem !== void 0 ? isItem : false;
|
|
@@ -72,7 +72,7 @@ export class Heap {
|
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* The `peekLast` function returns the last item in the heap.
|
|
75
|
-
* @returns The method `peekLast()` returns either a `HeapItem<
|
|
75
|
+
* @returns The method `peekLast()` returns either a `HeapItem<V>` object or `null`.Returns an val with the lowest priority in the queue
|
|
76
76
|
*/
|
|
77
77
|
peekLast(isItem) {
|
|
78
78
|
isItem = isItem !== null && isItem !== void 0 ? isItem : false;
|
|
@@ -81,7 +81,7 @@ export class Heap {
|
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* The `add` function adds an val to a priority queue with an optional priority value.
|
|
84
|
-
* @param {
|
|
84
|
+
* @param {V} val - The `val` parameter represents the value that you want to add to the heap. It can be of any
|
|
85
85
|
* type.
|
|
86
86
|
* @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
|
|
87
87
|
* val being added to the heap. If the `val` parameter is a number, then the `priority` parameter is set to
|
|
@@ -96,7 +96,7 @@ export class Heap {
|
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
98
98
|
* The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an val with the highest priority in the queue
|
|
99
|
-
* @returns either a HeapItem<
|
|
99
|
+
* @returns either a HeapItem<V> object or null.
|
|
100
100
|
*/
|
|
101
101
|
poll(isItem) {
|
|
102
102
|
isItem = isItem !== null && isItem !== void 0 ? isItem : false;
|
|
@@ -108,7 +108,7 @@ export class Heap {
|
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
110
|
* The function checks if a given node or value exists in the priority queue.
|
|
111
|
-
* @param {
|
|
111
|
+
* @param {V | HeapItem<V>} node - The parameter `node` can be of type `V` or `HeapItem<V>`.
|
|
112
112
|
* @returns a boolean value.
|
|
113
113
|
*/
|
|
114
114
|
has(node) {
|
|
@@ -122,8 +122,8 @@ export class Heap {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
/**
|
|
125
|
-
* The `toArray` function returns an array of `HeapItem<
|
|
126
|
-
* @returns An array of HeapItem<
|
|
125
|
+
* The `toArray` function returns an array of `HeapItem<V>` objects.
|
|
126
|
+
* @returns An array of HeapItem<V> objects.Returns a sorted list of vals
|
|
127
127
|
*/
|
|
128
128
|
toArray(isItem) {
|
|
129
129
|
isItem = isItem !== null && isItem !== void 0 ? isItem : false;
|
|
@@ -134,9 +134,9 @@ export class Heap {
|
|
|
134
134
|
* The function sorts the elements in the priority queue and returns either the sorted items or their values depending
|
|
135
135
|
* on the value of the isItem parameter.
|
|
136
136
|
* @param {boolean} [isItem] - The `isItem` parameter is a boolean flag that indicates whether the sorted result should
|
|
137
|
-
* be an array of `HeapItem<
|
|
137
|
+
* be an array of `HeapItem<V>` objects or an array of the values (`V`) of those objects. If `isItem` is `true`, the
|
|
138
138
|
* sorted result will be an array of `HeapItem
|
|
139
|
-
* @returns an array of either `HeapItem<
|
|
139
|
+
* @returns an array of either `HeapItem<V>`, `null`, `V`, or `undefined` values.
|
|
140
140
|
*/
|
|
141
141
|
sort(isItem) {
|
|
142
142
|
isItem = isItem !== null && isItem !== void 0 ? isItem : false;
|
|
@@ -12,12 +12,12 @@ import type { HeapOptions } from '../../types';
|
|
|
12
12
|
* @class MaxHeap
|
|
13
13
|
* @extends Heap
|
|
14
14
|
*/
|
|
15
|
-
export declare class MaxHeap<
|
|
16
|
-
protected _pq: PriorityQueue<HeapItem<
|
|
15
|
+
export declare class MaxHeap<V = any> extends Heap<V> {
|
|
16
|
+
protected _pq: PriorityQueue<HeapItem<V>>;
|
|
17
17
|
/**
|
|
18
18
|
* The constructor initializes a PriorityQueue with a custom comparator function.
|
|
19
19
|
* @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
|
|
20
|
-
* type `HeapOptions<
|
|
20
|
+
* type `HeapOptions<V>`, which is a generic type that represents the options for the heap.
|
|
21
21
|
*/
|
|
22
|
-
constructor(options?: HeapOptions<
|
|
22
|
+
constructor(options?: HeapOptions<V>);
|
|
23
23
|
}
|
|
@@ -15,7 +15,7 @@ export class MaxHeap extends Heap {
|
|
|
15
15
|
/**
|
|
16
16
|
* The constructor initializes a PriorityQueue with a custom comparator function.
|
|
17
17
|
* @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
|
|
18
|
-
* type `HeapOptions<
|
|
18
|
+
* type `HeapOptions<V>`, which is a generic type that represents the options for the heap.
|
|
19
19
|
*/
|
|
20
20
|
constructor(options) {
|
|
21
21
|
super(options);
|
|
@@ -12,13 +12,13 @@ import type { HeapOptions } from '../../types';
|
|
|
12
12
|
* @class MinHeap
|
|
13
13
|
* @extends Heap
|
|
14
14
|
*/
|
|
15
|
-
export declare class MinHeap<
|
|
16
|
-
protected _pq: PriorityQueue<HeapItem<
|
|
15
|
+
export declare class MinHeap<V = any> extends Heap<V> {
|
|
16
|
+
protected _pq: PriorityQueue<HeapItem<V>>;
|
|
17
17
|
/**
|
|
18
18
|
* The constructor initializes a PriorityQueue with a comparator function that compares the priority of two HeapItem
|
|
19
19
|
* objects.
|
|
20
20
|
* @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
|
|
21
|
-
* type `HeapOptions<
|
|
21
|
+
* type `HeapOptions<V>`, which is a generic type that represents the options for the heap.
|
|
22
22
|
*/
|
|
23
|
-
constructor(options?: HeapOptions<
|
|
23
|
+
constructor(options?: HeapOptions<V>);
|
|
24
24
|
}
|
|
@@ -16,7 +16,7 @@ export class MinHeap extends Heap {
|
|
|
16
16
|
* The constructor initializes a PriorityQueue with a comparator function that compares the priority of two HeapItem
|
|
17
17
|
* objects.
|
|
18
18
|
* @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
|
|
19
|
-
* type `HeapOptions<
|
|
19
|
+
* type `HeapOptions<V>`, which is a generic type that represents the options for the heap.
|
|
20
20
|
*/
|
|
21
21
|
constructor(options) {
|
|
22
22
|
super(options);
|