min-heap-typed 1.39.6 → 1.40.0
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/binary-tree/avl-tree.js +0 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -3
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +2 -11
- package/dist/data-structures/binary-tree/binary-tree.d.ts +5 -20
- package/dist/data-structures/binary-tree/binary-tree.js +8 -29
- package/dist/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/data-structures/binary-tree/bst.js +3 -3
- package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -3
- package/dist/data-structures/binary-tree/rb-tree.js +1 -7
- package/dist/data-structures/binary-tree/segment-tree.d.ts +10 -26
- package/dist/data-structures/binary-tree/segment-tree.js +10 -58
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -1
- package/dist/data-structures/binary-tree/tree-multiset.js +6 -6
- package/dist/data-structures/graph/abstract-graph.d.ts +5 -24
- package/dist/data-structures/graph/abstract-graph.js +4 -43
- package/dist/data-structures/graph/directed-graph.d.ts +4 -10
- package/dist/data-structures/graph/directed-graph.js +2 -20
- package/dist/data-structures/graph/map-graph.d.ts +4 -10
- package/dist/data-structures/graph/map-graph.js +2 -20
- package/dist/data-structures/graph/undirected-graph.d.ts +1 -8
- package/dist/data-structures/graph/undirected-graph.js +1 -14
- package/dist/data-structures/hash/coordinate-map.d.ts +0 -1
- package/dist/data-structures/hash/coordinate-map.js +0 -3
- package/dist/data-structures/hash/coordinate-set.d.ts +0 -1
- package/dist/data-structures/hash/coordinate-set.js +0 -3
- package/dist/data-structures/hash/hash-map.d.ts +8 -14
- package/dist/data-structures/hash/hash-map.js +4 -22
- package/dist/data-structures/hash/hash-table.d.ts +6 -9
- package/dist/data-structures/hash/hash-table.js +0 -9
- package/dist/data-structures/heap/heap.d.ts +12 -6
- package/dist/data-structures/heap/heap.js +40 -22
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +6 -14
- package/dist/data-structures/linked-list/doubly-linked-list.js +18 -42
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +5 -11
- package/dist/data-structures/linked-list/singly-linked-list.js +17 -35
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +29 -10
- package/dist/data-structures/linked-list/skip-linked-list.js +62 -17
- package/dist/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/data-structures/matrix/matrix2d.d.ts +1 -1
- package/dist/data-structures/matrix/navigator.d.ts +4 -4
- package/dist/data-structures/queue/deque.d.ts +8 -12
- package/dist/data-structures/queue/deque.js +31 -43
- package/dist/data-structures/queue/queue.d.ts +20 -5
- package/dist/data-structures/queue/queue.js +35 -18
- package/dist/data-structures/stack/stack.d.ts +2 -1
- package/dist/data-structures/stack/stack.js +10 -7
- package/dist/data-structures/tree/tree.d.ts +3 -9
- package/dist/data-structures/tree/tree.js +3 -21
- package/dist/data-structures/trie/trie.d.ts +6 -12
- package/dist/data-structures/trie/trie.js +6 -24
- package/dist/interfaces/binary-tree.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +2 -4
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -15
- package/src/data-structures/binary-tree/binary-tree.ts +17 -42
- package/src/data-structures/binary-tree/bst.ts +5 -6
- package/src/data-structures/binary-tree/rb-tree.ts +13 -21
- package/src/data-structures/binary-tree/segment-tree.ts +16 -83
- package/src/data-structures/binary-tree/tree-multiset.ts +8 -9
- package/src/data-structures/graph/abstract-graph.ts +21 -67
- package/src/data-structures/graph/directed-graph.ts +13 -39
- package/src/data-structures/graph/map-graph.ts +7 -32
- package/src/data-structures/graph/undirected-graph.ts +9 -26
- package/src/data-structures/hash/coordinate-map.ts +0 -4
- package/src/data-structures/hash/coordinate-set.ts +0 -4
- package/src/data-structures/hash/hash-map.ts +13 -37
- package/src/data-structures/hash/hash-table.ts +6 -18
- package/src/data-structures/hash/tree-map.ts +2 -1
- package/src/data-structures/hash/tree-set.ts +2 -1
- package/src/data-structures/heap/heap.ts +58 -30
- package/src/data-structures/heap/max-heap.ts +1 -1
- package/src/data-structures/heap/min-heap.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +26 -60
- package/src/data-structures/linked-list/singly-linked-list.ts +24 -49
- package/src/data-structures/linked-list/skip-linked-list.ts +73 -25
- package/src/data-structures/matrix/matrix.ts +2 -2
- package/src/data-structures/matrix/matrix2d.ts +1 -1
- package/src/data-structures/matrix/navigator.ts +4 -4
- package/src/data-structures/matrix/vector2d.ts +2 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/data-structures/queue/deque.ts +38 -53
- package/src/data-structures/queue/queue.ts +38 -20
- package/src/data-structures/stack/stack.ts +13 -9
- package/src/data-structures/tree/tree.ts +7 -33
- package/src/data-structures/trie/trie.ts +14 -40
- package/src/interfaces/binary-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/bst.ts +1 -1
- package/src/types/data-structures/matrix/navigator.ts +1 -1
- package/src/types/utils/utils.ts +1 -1
- package/src/types/utils/validate-type.ts +2 -2
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
* @class
|
|
5
5
|
*/
|
|
6
6
|
export class Stack<E = any> {
|
|
7
|
-
protected _elements: E[];
|
|
8
|
-
|
|
9
7
|
/**
|
|
10
8
|
* The constructor initializes an array of elements, which can be provided as an optional parameter.
|
|
11
9
|
* @param {E[]} [elements] - The `elements` parameter is an optional parameter of type `E[]`, which represents an array
|
|
@@ -16,6 +14,12 @@ export class Stack<E = any> {
|
|
|
16
14
|
this._elements = Array.isArray(elements) ? elements : [];
|
|
17
15
|
}
|
|
18
16
|
|
|
17
|
+
protected _elements: E[];
|
|
18
|
+
|
|
19
|
+
get elements(): E[] {
|
|
20
|
+
return this._elements;
|
|
21
|
+
}
|
|
22
|
+
|
|
19
23
|
/**
|
|
20
24
|
* The function "fromArray" creates a new Stack object from an array of elements.
|
|
21
25
|
* @param {E[]} elements - The `elements` parameter is an array of elements of type `E`.
|
|
@@ -31,7 +35,7 @@ export class Stack<E = any> {
|
|
|
31
35
|
* @returns A boolean value indicating whether the `_elements` array is empty or not.
|
|
32
36
|
*/
|
|
33
37
|
isEmpty(): boolean {
|
|
34
|
-
return this.
|
|
38
|
+
return this.elements.length === 0;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
/**
|
|
@@ -39,7 +43,7 @@ export class Stack<E = any> {
|
|
|
39
43
|
* @returns The size of the elements array.
|
|
40
44
|
*/
|
|
41
45
|
size(): number {
|
|
42
|
-
return this.
|
|
46
|
+
return this.elements.length;
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
/**
|
|
@@ -49,7 +53,7 @@ export class Stack<E = any> {
|
|
|
49
53
|
peek(): E | null {
|
|
50
54
|
if (this.isEmpty()) return null;
|
|
51
55
|
|
|
52
|
-
return this.
|
|
56
|
+
return this.elements[this.elements.length - 1];
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
/**
|
|
@@ -58,7 +62,7 @@ export class Stack<E = any> {
|
|
|
58
62
|
* @returns The `push` method is returning the updated `Stack<E>` object.
|
|
59
63
|
*/
|
|
60
64
|
push(element: E): Stack<E> {
|
|
61
|
-
this.
|
|
65
|
+
this.elements.push(element);
|
|
62
66
|
return this;
|
|
63
67
|
}
|
|
64
68
|
|
|
@@ -70,7 +74,7 @@ export class Stack<E = any> {
|
|
|
70
74
|
pop(): E | null {
|
|
71
75
|
if (this.isEmpty()) return null;
|
|
72
76
|
|
|
73
|
-
return this.
|
|
77
|
+
return this.elements.pop() || null;
|
|
74
78
|
}
|
|
75
79
|
|
|
76
80
|
/**
|
|
@@ -78,7 +82,7 @@ export class Stack<E = any> {
|
|
|
78
82
|
* @returns An array of type E.
|
|
79
83
|
*/
|
|
80
84
|
toArray(): E[] {
|
|
81
|
-
return this.
|
|
85
|
+
return this.elements.slice();
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
/**
|
|
@@ -93,6 +97,6 @@ export class Stack<E = any> {
|
|
|
93
97
|
* @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
|
|
94
98
|
*/
|
|
95
99
|
clone(): Stack<E> {
|
|
96
|
-
return new Stack(this.
|
|
100
|
+
return new Stack(this.elements.slice());
|
|
97
101
|
}
|
|
98
102
|
}
|
|
@@ -1,38 +1,12 @@
|
|
|
1
1
|
export class TreeNode<V = any> {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
this._children = children || [];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
private _key: string;
|
|
9
|
-
|
|
10
|
-
get key(): string {
|
|
11
|
-
return this._key;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
set key(value: string) {
|
|
15
|
-
this._key = value;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
private _value?: V | undefined;
|
|
2
|
+
key: string;
|
|
3
|
+
value?: V | undefined;
|
|
4
|
+
children?: TreeNode<V>[] | undefined;
|
|
19
5
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
set value(value: V | undefined) {
|
|
25
|
-
this._value = value;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
private _children?: TreeNode<V>[] | undefined;
|
|
29
|
-
|
|
30
|
-
get children(): TreeNode<V>[] | undefined {
|
|
31
|
-
return this._children;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
set children(value: TreeNode<V>[] | undefined) {
|
|
35
|
-
this._children = value;
|
|
6
|
+
constructor(key: string, value?: V, children?: TreeNode<V>[]) {
|
|
7
|
+
this.key = key;
|
|
8
|
+
this.value = value || undefined;
|
|
9
|
+
this.children = children || [];
|
|
36
10
|
}
|
|
37
11
|
|
|
38
12
|
addChildren(children: TreeNode<V> | TreeNode<V>[]) {
|
|
@@ -11,40 +11,14 @@
|
|
|
11
11
|
* and a flag indicating whether it's the end of a word.
|
|
12
12
|
*/
|
|
13
13
|
export class TrieNode {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this._children = new Map<string, TrieNode>();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
private _key;
|
|
21
|
-
|
|
22
|
-
get key(): string {
|
|
23
|
-
return this._key;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
set key(v: string) {
|
|
27
|
-
this._key = v;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
protected _children: Map<string, TrieNode>;
|
|
31
|
-
|
|
32
|
-
get children(): Map<string, TrieNode> {
|
|
33
|
-
return this._children;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
set children(v: Map<string, TrieNode>) {
|
|
37
|
-
this._children = v;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
protected _isEnd: boolean;
|
|
41
|
-
|
|
42
|
-
get isEnd(): boolean {
|
|
43
|
-
return this._isEnd;
|
|
44
|
-
}
|
|
14
|
+
key: string;
|
|
15
|
+
children: Map<string, TrieNode>;
|
|
16
|
+
isEnd: boolean;
|
|
45
17
|
|
|
46
|
-
|
|
47
|
-
this.
|
|
18
|
+
constructor(key: string) {
|
|
19
|
+
this.key = key;
|
|
20
|
+
this.isEnd = false;
|
|
21
|
+
this.children = new Map<string, TrieNode>();
|
|
48
22
|
}
|
|
49
23
|
}
|
|
50
24
|
|
|
@@ -52,8 +26,6 @@ export class TrieNode {
|
|
|
52
26
|
* Trie represents a Trie data structure. It provides basic Trie operations and additional methods.
|
|
53
27
|
*/
|
|
54
28
|
export class Trie {
|
|
55
|
-
private readonly _caseSensitive: boolean;
|
|
56
|
-
|
|
57
29
|
constructor(words?: string[], caseSensitive = true) {
|
|
58
30
|
this._root = new TrieNode('');
|
|
59
31
|
this._caseSensitive = caseSensitive;
|
|
@@ -64,16 +36,18 @@ export class Trie {
|
|
|
64
36
|
}
|
|
65
37
|
}
|
|
66
38
|
|
|
39
|
+
protected _caseSensitive: boolean;
|
|
40
|
+
|
|
41
|
+
get caseSensitive(): boolean {
|
|
42
|
+
return this._caseSensitive;
|
|
43
|
+
}
|
|
44
|
+
|
|
67
45
|
protected _root: TrieNode;
|
|
68
46
|
|
|
69
47
|
get root() {
|
|
70
48
|
return this._root;
|
|
71
49
|
}
|
|
72
50
|
|
|
73
|
-
set root(v: TrieNode) {
|
|
74
|
-
this._root = v;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
51
|
/**
|
|
78
52
|
* Add a word to the Trie structure.
|
|
79
53
|
* @param {string} word - The word to add.
|
|
@@ -277,7 +251,7 @@ export class Trie {
|
|
|
277
251
|
return words;
|
|
278
252
|
}
|
|
279
253
|
|
|
280
|
-
|
|
254
|
+
protected _caseProcess(str: string) {
|
|
281
255
|
if (!this._caseSensitive) {
|
|
282
256
|
str = str.toLowerCase(); // Convert str to lowercase if case-insensitive
|
|
283
257
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {BinaryTreeNode} from '../data-structures';
|
|
2
|
-
import {BinaryTreeDeletedResult,
|
|
2
|
+
import {BinaryTreeDeletedResult, BinaryTreeNodeNested, BTNCallback, BTNKey} from '../types';
|
|
3
3
|
|
|
4
4
|
export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>> {
|
|
5
5
|
createNode(key: BTNKey, value?: N['value']): N;
|
package/src/types/utils/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type ToThunkFn = () => ReturnType<TrlFn>;
|
|
2
|
-
export type Thunk = () => ReturnType<ToThunkFn> & {__THUNK__: symbol};
|
|
2
|
+
export type Thunk = () => ReturnType<ToThunkFn> & { __THUNK__: symbol };
|
|
3
3
|
export type TrlFn = (...args: any[]) => any;
|
|
4
4
|
export type TrlAsyncFn = (...args: any[]) => any;
|
|
5
5
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export type KeyValueObject = {[key: string]: any};
|
|
1
|
+
export type KeyValueObject = { [key: string]: any };
|
|
2
2
|
|
|
3
|
-
export type KeyValueObjectWithKey = {[key: string]: any; key: string | number | symbol};
|
|
3
|
+
export type KeyValueObjectWithKey = { [key: string]: any; key: string | number | symbol };
|
|
4
4
|
|
|
5
5
|
export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
|
|
6
6
|
|