avl-tree-typed 1.49.4 → 1.49.5
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/dist/data-structures/base/iterable-base.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-tree.d.ts +1 -13
- package/dist/data-structures/binary-tree/binary-tree.js +19 -49
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +0 -16
- package/dist/data-structures/binary-tree/tree-multimap.js +1 -43
- package/dist/data-structures/graph/abstract-graph.d.ts +1 -1
- package/dist/data-structures/graph/abstract-graph.js +3 -2
- package/dist/data-structures/hash/hash-map.d.ts +1 -1
- package/dist/data-structures/hash/hash-map.js +2 -2
- package/dist/data-structures/heap/heap.js +2 -3
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/data-structures/matrix/index.d.ts +0 -2
- package/dist/data-structures/matrix/index.js +0 -2
- package/dist/data-structures/matrix/matrix.d.ts +128 -10
- package/dist/data-structures/matrix/matrix.js +400 -15
- package/dist/data-structures/queue/deque.d.ts +2 -2
- package/dist/data-structures/queue/deque.js +5 -7
- package/dist/data-structures/queue/queue.d.ts +1 -1
- package/dist/types/data-structures/base/base.d.ts +1 -1
- package/dist/types/data-structures/heap/heap.d.ts +1 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/utils/utils.d.ts +1 -0
- package/dist/utils/utils.js +6 -1
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +1 -1
- package/src/data-structures/base/iterable-base.ts +7 -10
- package/src/data-structures/binary-tree/avl-tree.ts +15 -8
- package/src/data-structures/binary-tree/binary-tree.ts +57 -74
- package/src/data-structures/binary-tree/bst.ts +16 -13
- package/src/data-structures/binary-tree/rb-tree.ts +16 -10
- package/src/data-structures/binary-tree/tree-multimap.ts +11 -48
- package/src/data-structures/graph/abstract-graph.ts +13 -11
- package/src/data-structures/graph/directed-graph.ts +1 -3
- package/src/data-structures/graph/map-graph.ts +6 -1
- package/src/data-structures/graph/undirected-graph.ts +3 -6
- package/src/data-structures/hash/hash-map.ts +18 -16
- package/src/data-structures/heap/heap.ts +7 -10
- package/src/data-structures/heap/max-heap.ts +2 -1
- package/src/data-structures/heap/min-heap.ts +2 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -3
- package/src/data-structures/matrix/index.ts +0 -2
- package/src/data-structures/matrix/matrix.ts +442 -13
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -10
- package/src/data-structures/queue/deque.ts +18 -39
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/interfaces/binary-tree.ts +7 -2
- package/src/types/common.ts +4 -4
- package/src/types/data-structures/base/base.ts +14 -3
- package/src/types/data-structures/base/index.ts +1 -1
- package/src/types/data-structures/graph/abstract-graph.ts +4 -2
- package/src/types/data-structures/hash/hash-map.ts +3 -3
- package/src/types/data-structures/heap/heap.ts +2 -2
- package/src/types/data-structures/priority-queue/priority-queue.ts +2 -2
- package/src/utils/utils.ts +7 -1
- package/dist/data-structures/matrix/matrix2d.d.ts +0 -107
- package/dist/data-structures/matrix/matrix2d.js +0 -199
- package/dist/data-structures/matrix/vector2d.d.ts +0 -200
- package/dist/data-structures/matrix/vector2d.js +0 -290
- package/src/data-structures/matrix/matrix2d.ts +0 -211
- package/src/data-structures/matrix/vector2d.ts +0 -315
|
@@ -182,7 +182,6 @@ export class DirectedGraph<
|
|
|
182
182
|
* Space Complexity: O(1)
|
|
183
183
|
*/
|
|
184
184
|
|
|
185
|
-
|
|
186
185
|
/**
|
|
187
186
|
* Time Complexity: O(E) where E is the number of edgeMap
|
|
188
187
|
* Space Complexity: O(1)
|
|
@@ -248,7 +247,7 @@ export class DirectedGraph<
|
|
|
248
247
|
vertexKey = vertexOrKey;
|
|
249
248
|
} else {
|
|
250
249
|
vertex = vertexOrKey;
|
|
251
|
-
vertexKey = this._getVertexKey(vertexOrKey)
|
|
250
|
+
vertexKey = this._getVertexKey(vertexOrKey);
|
|
252
251
|
}
|
|
253
252
|
|
|
254
253
|
if (vertex) {
|
|
@@ -600,7 +599,6 @@ export class DirectedGraph<
|
|
|
600
599
|
}
|
|
601
600
|
}
|
|
602
601
|
|
|
603
|
-
|
|
604
602
|
/**
|
|
605
603
|
* Time Complexity: O(1)
|
|
606
604
|
* Space Complexity: O(1)
|
|
@@ -84,7 +84,12 @@ export class MapGraph<
|
|
|
84
84
|
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
85
85
|
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
|
|
86
86
|
*/
|
|
87
|
-
override createVertex(
|
|
87
|
+
override createVertex(
|
|
88
|
+
key: VertexKey,
|
|
89
|
+
value?: V,
|
|
90
|
+
lat: number = this.originCoord[0],
|
|
91
|
+
long: number = this.originCoord[1]
|
|
92
|
+
): VO {
|
|
88
93
|
return new MapVertex(key, value, lat, long) as VO;
|
|
89
94
|
}
|
|
90
95
|
|
|
@@ -162,7 +162,6 @@ export class UndirectedGraph<
|
|
|
162
162
|
* Space Complexity: O(1)
|
|
163
163
|
*/
|
|
164
164
|
|
|
165
|
-
|
|
166
165
|
/**
|
|
167
166
|
* Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
|
|
168
167
|
* Space Complexity: O(1)
|
|
@@ -192,7 +191,6 @@ export class UndirectedGraph<
|
|
|
192
191
|
|
|
193
192
|
if (oneSide && otherSide) {
|
|
194
193
|
return this.deleteEdgeBetween(oneSide, otherSide);
|
|
195
|
-
|
|
196
194
|
} else {
|
|
197
195
|
return;
|
|
198
196
|
}
|
|
@@ -220,10 +218,10 @@ export class UndirectedGraph<
|
|
|
220
218
|
vertexKey = vertexOrKey;
|
|
221
219
|
} else {
|
|
222
220
|
vertex = vertexOrKey;
|
|
223
|
-
vertexKey = this._getVertexKey(vertexOrKey)
|
|
221
|
+
vertexKey = this._getVertexKey(vertexOrKey);
|
|
224
222
|
}
|
|
225
223
|
|
|
226
|
-
const neighbors = this.getNeighbors(vertexOrKey)
|
|
224
|
+
const neighbors = this.getNeighbors(vertexOrKey);
|
|
227
225
|
|
|
228
226
|
if (vertex) {
|
|
229
227
|
neighbors.forEach(neighbor => {
|
|
@@ -234,9 +232,8 @@ export class UndirectedGraph<
|
|
|
234
232
|
});
|
|
235
233
|
this._edgeMap.set(neighbor, restEdges);
|
|
236
234
|
}
|
|
237
|
-
})
|
|
235
|
+
});
|
|
238
236
|
this._edgeMap.delete(vertex);
|
|
239
|
-
|
|
240
237
|
}
|
|
241
238
|
|
|
242
239
|
return this._vertexMap.delete(vertexKey);
|
|
@@ -27,9 +27,12 @@ export class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
|
|
|
27
27
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
28
28
|
* configuration options for the constructor. In this case, it has one property:
|
|
29
29
|
*/
|
|
30
|
-
constructor(
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
constructor(
|
|
31
|
+
elements: Iterable<[K, V]> = [],
|
|
32
|
+
options?: {
|
|
33
|
+
hashFn: (key: K) => string;
|
|
34
|
+
}
|
|
35
|
+
) {
|
|
33
36
|
super();
|
|
34
37
|
if (options) {
|
|
35
38
|
const { hashFn } = options;
|
|
@@ -73,7 +76,6 @@ export class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
|
|
|
73
76
|
this._size++;
|
|
74
77
|
}
|
|
75
78
|
this._objMap.set(key, value);
|
|
76
|
-
|
|
77
79
|
} else {
|
|
78
80
|
const strKey = this._getNoObjKey(key);
|
|
79
81
|
if (this._store[strKey] === undefined) {
|
|
@@ -137,7 +139,7 @@ export class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
|
|
|
137
139
|
delete(key: K): boolean {
|
|
138
140
|
if (this._isObjKey(key)) {
|
|
139
141
|
if (this._objMap.has(key)) {
|
|
140
|
-
this._size
|
|
142
|
+
this._size--;
|
|
141
143
|
}
|
|
142
144
|
|
|
143
145
|
return this._objMap.delete(key);
|
|
@@ -235,19 +237,19 @@ export class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
|
|
|
235
237
|
|
|
236
238
|
protected _hashFn: (key: K) => string = (key: K) => String(key);
|
|
237
239
|
|
|
238
|
-
protected _isObjKey(key: any): key is
|
|
240
|
+
protected _isObjKey(key: any): key is object | ((...args: any[]) => any) {
|
|
239
241
|
const keyType = typeof key;
|
|
240
|
-
return (keyType === 'object' || keyType === 'function') && key !== null
|
|
242
|
+
return (keyType === 'object' || keyType === 'function') && key !== null;
|
|
241
243
|
}
|
|
242
244
|
|
|
243
245
|
protected _getNoObjKey(key: K): string {
|
|
244
246
|
const keyType = typeof key;
|
|
245
247
|
|
|
246
248
|
let strKey: string;
|
|
247
|
-
if (keyType !==
|
|
249
|
+
if (keyType !== 'string' && keyType !== 'number' && keyType !== 'symbol') {
|
|
248
250
|
strKey = this._hashFn(key);
|
|
249
251
|
} else {
|
|
250
|
-
if (keyType ===
|
|
252
|
+
if (keyType === 'number') {
|
|
251
253
|
// TODO numeric key should has its own hash
|
|
252
254
|
strKey = <string>key;
|
|
253
255
|
} else {
|
|
@@ -264,7 +266,6 @@ export class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
|
|
|
264
266
|
* 3. Time Complexity: Similar to HashMap, LinkedHashMap offers constant-time performance for get and put operations in most cases.
|
|
265
267
|
*/
|
|
266
268
|
export class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K, V> {
|
|
267
|
-
|
|
268
269
|
protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>> = {};
|
|
269
270
|
protected _objMap = new WeakMap<object, HashMapLinkedNode<K, V | undefined>>();
|
|
270
271
|
protected _head: HashMapLinkedNode<K, V | undefined>;
|
|
@@ -273,12 +274,13 @@ export class LinkedHashMap<K = any, V = any> extends IterableEntryBase<K, V> {
|
|
|
273
274
|
protected _hashFn: (key: K) => string;
|
|
274
275
|
protected _objHashFn: (key: K) => object;
|
|
275
276
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
277
|
+
constructor(
|
|
278
|
+
elements?: Iterable<[K, V]>,
|
|
279
|
+
options: HashMapOptions<K> = {
|
|
280
|
+
hashFn: (key: K) => String(key),
|
|
281
|
+
objHashFn: (key: K) => <object>key
|
|
282
|
+
}
|
|
283
|
+
) {
|
|
282
284
|
super();
|
|
283
285
|
this._sentinel = <HashMapLinkedNode<K, V>>{};
|
|
284
286
|
this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
|
|
@@ -31,13 +31,13 @@ export class Heap<E = any> extends IterableElementBase<E> {
|
|
|
31
31
|
} else {
|
|
32
32
|
return a - b;
|
|
33
33
|
}
|
|
34
|
-
}
|
|
34
|
+
};
|
|
35
35
|
if (options) {
|
|
36
|
-
this.options = options
|
|
36
|
+
this.options = options;
|
|
37
37
|
} else {
|
|
38
38
|
this.options = {
|
|
39
39
|
comparator: defaultComparator
|
|
40
|
-
}
|
|
40
|
+
};
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
if (elements) {
|
|
@@ -225,7 +225,8 @@ export class Heap<E = any> extends IterableElementBase<E> {
|
|
|
225
225
|
|
|
226
226
|
// Auxiliary recursive function, traverses the binary heap according to the traversal order
|
|
227
227
|
const _dfs = (index: number) => {
|
|
228
|
-
const left = 2 * index + 1,
|
|
228
|
+
const left = 2 * index + 1,
|
|
229
|
+
right = left + 1;
|
|
229
230
|
if (index < this.size) {
|
|
230
231
|
if (order === 'in') {
|
|
231
232
|
_dfs(left);
|
|
@@ -380,7 +381,6 @@ export class Heap<E = any> extends IterableElementBase<E> {
|
|
|
380
381
|
* original Heap.
|
|
381
382
|
*/
|
|
382
383
|
map<T>(callback: ElementCallback<E, T>, comparator: Comparator<T>, thisArg?: any): Heap<T> {
|
|
383
|
-
|
|
384
384
|
const mappedHeap: Heap<T> = new Heap<T>([], { comparator: comparator });
|
|
385
385
|
let index = 0;
|
|
386
386
|
for (const el of this) {
|
|
@@ -432,13 +432,10 @@ export class Heap<E = any> extends IterableElementBase<E> {
|
|
|
432
432
|
protected _sinkDown(index: number, halfLength: number): boolean {
|
|
433
433
|
const element = this.elements[index];
|
|
434
434
|
while (index < halfLength) {
|
|
435
|
-
let left = index << 1 | 1;
|
|
435
|
+
let left = (index << 1) | 1;
|
|
436
436
|
const right = left + 1;
|
|
437
437
|
let minItem = this.elements[left];
|
|
438
|
-
if (
|
|
439
|
-
right < this.elements.length &&
|
|
440
|
-
this.options.comparator(minItem, this.elements[right]) > 0
|
|
441
|
-
) {
|
|
438
|
+
if (right < this.elements.length && this.options.comparator(minItem, this.elements[right]) > 0) {
|
|
442
439
|
left = right;
|
|
443
440
|
minItem = this.elements[right];
|
|
444
441
|
}
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { ElementCallback } from
|
|
9
|
-
import { IterableElementBase } from
|
|
8
|
+
import type { ElementCallback } from '../../types';
|
|
9
|
+
import { IterableElementBase } from '../base';
|
|
10
10
|
|
|
11
11
|
export class SinglyLinkedListNode<E = any> {
|
|
12
12
|
value: E;
|
|
@@ -715,7 +715,6 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
715
715
|
return filteredList;
|
|
716
716
|
}
|
|
717
717
|
|
|
718
|
-
|
|
719
718
|
/**
|
|
720
719
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
721
720
|
* Space Complexity: O(n)
|