data-structure-typed 1.53.6 → 1.53.8
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/CHANGELOG.md +1 -1
- package/README.md +16 -25
- package/benchmark/report.html +32 -5
- package/benchmark/report.json +326 -23
- package/dist/cjs/common/index.d.ts +12 -0
- package/dist/cjs/common/index.js +29 -0
- package/dist/cjs/common/index.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +9 -12
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +2 -2
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +55 -20
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +102 -68
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +131 -37
- package/dist/cjs/data-structures/binary-tree/bst.js +222 -69
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/index.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/index.js +1 -1
- package/dist/cjs/data-structures/binary-tree/index.js.map +1 -1
- package/dist/{mjs/data-structures/binary-tree/rb-tree.d.ts → cjs/data-structures/binary-tree/red-black-tree.d.ts} +56 -0
- package/dist/cjs/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +60 -4
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +2 -2
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +7 -7
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +30 -0
- package/dist/cjs/data-structures/hash/hash-map.js +30 -0
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +26 -9
- package/dist/cjs/data-structures/heap/heap.js +37 -17
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +54 -9
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +80 -19
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +35 -2
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +55 -11
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +37 -8
- package/dist/cjs/data-structures/queue/deque.js +73 -29
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +41 -1
- package/dist/cjs/data-structures/queue/queue.js +51 -9
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +27 -10
- package/dist/cjs/data-structures/stack/stack.js +39 -20
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +111 -6
- package/dist/cjs/data-structures/trie/trie.js +123 -14
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -2
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/cjs/types/utils/utils.d.ts +10 -6
- package/dist/cjs/utils/utils.js +4 -2
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/common/index.d.ts +12 -0
- package/dist/mjs/common/index.js +29 -0
- package/dist/mjs/common/index.js.map +1 -0
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +10 -12
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +3 -2
- package/dist/mjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +55 -20
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +97 -63
- package/dist/mjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +131 -37
- package/dist/mjs/data-structures/binary-tree/bst.js +224 -69
- package/dist/mjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/index.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/index.js +1 -1
- package/dist/mjs/data-structures/binary-tree/index.js.map +1 -1
- package/dist/{cjs/data-structures/binary-tree/rb-tree.d.ts → mjs/data-structures/binary-tree/red-black-tree.d.ts} +56 -0
- package/dist/mjs/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +60 -4
- package/dist/mjs/data-structures/binary-tree/red-black-tree.js.map +1 -0
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/mjs/data-structures/hash/hash-map.d.ts +30 -0
- package/dist/mjs/data-structures/hash/hash-map.js +30 -0
- package/dist/mjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/mjs/data-structures/heap/heap.d.ts +26 -9
- package/dist/mjs/data-structures/heap/heap.js +37 -17
- package/dist/mjs/data-structures/heap/heap.js.map +1 -1
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +54 -9
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +80 -19
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +35 -2
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +55 -11
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/mjs/data-structures/queue/deque.d.ts +37 -8
- package/dist/mjs/data-structures/queue/deque.js +73 -29
- package/dist/mjs/data-structures/queue/deque.js.map +1 -1
- package/dist/mjs/data-structures/queue/queue.d.ts +41 -1
- package/dist/mjs/data-structures/queue/queue.js +51 -9
- package/dist/mjs/data-structures/queue/queue.js.map +1 -1
- package/dist/mjs/data-structures/stack/stack.d.ts +27 -10
- package/dist/mjs/data-structures/stack/stack.js +39 -20
- package/dist/mjs/data-structures/stack/stack.js.map +1 -1
- package/dist/mjs/data-structures/trie/trie.d.ts +111 -6
- package/dist/mjs/data-structures/trie/trie.js +123 -14
- package/dist/mjs/data-structures/trie/trie.js.map +1 -1
- package/dist/mjs/index.d.ts +1 -1
- package/dist/mjs/index.js +1 -1
- package/dist/mjs/index.js.map +1 -1
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +3 -2
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/mjs/types/utils/utils.d.ts +10 -6
- package/dist/mjs/utils/utils.js +4 -2
- package/dist/mjs/utils/utils.js.map +1 -1
- package/dist/umd/data-structure-typed.js +671 -246
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +7 -7
- package/src/common/index.ts +25 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +9 -11
- package/src/data-structures/binary-tree/avl-tree.ts +3 -2
- package/src/data-structures/binary-tree/binary-tree.ts +110 -66
- package/src/data-structures/binary-tree/bst.ts +232 -72
- package/src/data-structures/binary-tree/index.ts +1 -1
- package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +56 -3
- package/src/data-structures/binary-tree/tree-multi-map.ts +6 -6
- package/src/data-structures/hash/hash-map.ts +30 -0
- package/src/data-structures/heap/heap.ts +72 -49
- package/src/data-structures/linked-list/doubly-linked-list.ts +173 -105
- package/src/data-structures/linked-list/singly-linked-list.ts +61 -11
- package/src/data-structures/queue/deque.ts +72 -28
- package/src/data-structures/queue/queue.ts +50 -7
- package/src/data-structures/stack/stack.ts +39 -20
- package/src/data-structures/trie/trie.ts +123 -13
- package/src/index.ts +1 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/bst.ts +3 -2
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
- package/src/types/utils/utils.ts +16 -10
- package/src/utils/utils.ts +4 -2
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +3 -0
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +4 -1
- package/test/performance/reportor.ts +38 -33
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +47 -47
- package/test/unit/data-structures/binary-tree/bst.test.ts +114 -44
- package/test/unit/data-structures/binary-tree/overall.test.ts +14 -22
- package/test/unit/data-structures/binary-tree/{rb-tree.test.ts → red-black-tree.test.ts} +55 -1
- package/test/unit/data-structures/trie/trie.test.ts +151 -0
- package/test/unit/utils/utils.test.ts +6 -6
- package/dist/cjs/constants/index.d.ts +0 -4
- package/dist/cjs/constants/index.js +0 -9
- package/dist/cjs/constants/index.js.map +0 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +0 -1
- package/dist/mjs/constants/index.d.ts +0 -4
- package/dist/mjs/constants/index.js +0 -6
- package/dist/mjs/constants/index.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/rb-tree.js.map +0 -1
- package/src/constants/index.ts +0 -4
|
@@ -28,10 +28,6 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R, S
|
|
|
28
28
|
* @returns The size of the elements array.
|
|
29
29
|
*/
|
|
30
30
|
get size(): number;
|
|
31
|
-
/**
|
|
32
|
-
* Time Complexity: O(n)
|
|
33
|
-
* Space Complexity: O(n)
|
|
34
|
-
*/
|
|
35
31
|
/**
|
|
36
32
|
* Time Complexity: O(n)
|
|
37
33
|
* Space Complexity: O(n)
|
|
@@ -43,6 +39,9 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R, S
|
|
|
43
39
|
*/
|
|
44
40
|
static fromArray<E>(elements: E[]): Stack<E>;
|
|
45
41
|
/**
|
|
42
|
+
* Time Complexity: O(1)
|
|
43
|
+
* Space Complexity: O(1)
|
|
44
|
+
*
|
|
46
45
|
* The function checks if an array is empty and returns a boolean value.
|
|
47
46
|
* @returns A boolean value indicating whether the `_elements` array is empty or not.
|
|
48
47
|
*/
|
|
@@ -74,15 +73,33 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R, S
|
|
|
74
73
|
*/
|
|
75
74
|
pop(): E | undefined;
|
|
76
75
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
76
|
+
* Time Complexity: O(k)
|
|
77
|
+
* Space Complexity: O(1)
|
|
78
|
+
*
|
|
79
|
+
* The function `pushMany` iterates over elements and pushes them into an array after applying a
|
|
80
|
+
* transformation function if provided.
|
|
81
|
+
* @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `pushMany` function
|
|
82
|
+
* is an iterable containing elements of type `E` or `R`. The function iterates over each element in
|
|
83
|
+
* the iterable and pushes it into the data structure. If a transformation function `toElementFn` is
|
|
84
|
+
* provided, it is used to
|
|
85
|
+
* @returns The `pushMany` function is returning an array of boolean values indicating whether each
|
|
86
|
+
* element was successfully pushed into the data structure.
|
|
87
|
+
*/
|
|
88
|
+
pushMany(elements: Iterable<E> | Iterable<R>): boolean[];
|
|
89
|
+
/**
|
|
90
|
+
* Time Complexity: O(n)
|
|
91
|
+
* Space Complexity: O(1)
|
|
92
|
+
*
|
|
93
|
+
* The toArray function returns a copy of the elements in an array.
|
|
94
|
+
* @returns An array of type E.
|
|
80
95
|
*/
|
|
81
96
|
delete(element: E): boolean;
|
|
82
97
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
98
|
+
* Time Complexity: O(n)
|
|
99
|
+
* Space Complexity: O(1)
|
|
100
|
+
*
|
|
101
|
+
* The toArray function returns a copy of the elements in an array.
|
|
102
|
+
* @returns An array of type E.
|
|
86
103
|
*/
|
|
87
104
|
deleteAt(index: number): boolean;
|
|
88
105
|
/**
|
|
@@ -10,16 +10,7 @@ import { IterableElementBase } from '../base';
|
|
|
10
10
|
export class Stack extends IterableElementBase {
|
|
11
11
|
constructor(elements = [], options) {
|
|
12
12
|
super(options);
|
|
13
|
-
|
|
14
|
-
for (const el of elements) {
|
|
15
|
-
if (this.toElementFn) {
|
|
16
|
-
this.push(this.toElementFn(el));
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
this.push(el);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
13
|
+
this.pushMany(elements);
|
|
23
14
|
}
|
|
24
15
|
_elements = [];
|
|
25
16
|
/**
|
|
@@ -36,10 +27,6 @@ export class Stack extends IterableElementBase {
|
|
|
36
27
|
get size() {
|
|
37
28
|
return this.elements.length;
|
|
38
29
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Time Complexity: O(n)
|
|
41
|
-
* Space Complexity: O(n)
|
|
42
|
-
*/
|
|
43
30
|
/**
|
|
44
31
|
* Time Complexity: O(n)
|
|
45
32
|
* Space Complexity: O(n)
|
|
@@ -53,6 +40,9 @@ export class Stack extends IterableElementBase {
|
|
|
53
40
|
return new Stack(elements);
|
|
54
41
|
}
|
|
55
42
|
/**
|
|
43
|
+
* Time Complexity: O(1)
|
|
44
|
+
* Space Complexity: O(1)
|
|
45
|
+
*
|
|
56
46
|
* The function checks if an array is empty and returns a boolean value.
|
|
57
47
|
* @returns A boolean value indicating whether the `_elements` array is empty or not.
|
|
58
48
|
*/
|
|
@@ -97,18 +87,47 @@ export class Stack extends IterableElementBase {
|
|
|
97
87
|
return this.elements.pop();
|
|
98
88
|
}
|
|
99
89
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
90
|
+
* Time Complexity: O(k)
|
|
91
|
+
* Space Complexity: O(1)
|
|
92
|
+
*
|
|
93
|
+
* The function `pushMany` iterates over elements and pushes them into an array after applying a
|
|
94
|
+
* transformation function if provided.
|
|
95
|
+
* @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `pushMany` function
|
|
96
|
+
* is an iterable containing elements of type `E` or `R`. The function iterates over each element in
|
|
97
|
+
* the iterable and pushes it into the data structure. If a transformation function `toElementFn` is
|
|
98
|
+
* provided, it is used to
|
|
99
|
+
* @returns The `pushMany` function is returning an array of boolean values indicating whether each
|
|
100
|
+
* element was successfully pushed into the data structure.
|
|
101
|
+
*/
|
|
102
|
+
pushMany(elements) {
|
|
103
|
+
const ans = [];
|
|
104
|
+
for (const el of elements) {
|
|
105
|
+
if (this.toElementFn) {
|
|
106
|
+
ans.push(this.push(this.toElementFn(el)));
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
ans.push(this.push(el));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return ans;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Time Complexity: O(n)
|
|
116
|
+
* Space Complexity: O(1)
|
|
117
|
+
*
|
|
118
|
+
* The toArray function returns a copy of the elements in an array.
|
|
119
|
+
* @returns An array of type E.
|
|
103
120
|
*/
|
|
104
121
|
delete(element) {
|
|
105
122
|
const index = this.elements.indexOf(element);
|
|
106
123
|
return this.deleteAt(index);
|
|
107
124
|
}
|
|
108
125
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
126
|
+
* Time Complexity: O(n)
|
|
127
|
+
* Space Complexity: O(1)
|
|
128
|
+
*
|
|
129
|
+
* The toArray function returns a copy of the elements in an array.
|
|
130
|
+
* @returns An array of type E.
|
|
112
131
|
*/
|
|
113
132
|
deleteAt(index) {
|
|
114
133
|
const spliced = this.elements.splice(index, 1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../../src/data-structures/stack/stack.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C;;;;;;;GAOG;AACH,MAAM,OAAO,KAAwB,SAAQ,mBAAsC;IACjF,YAAY,WAAsC,EAAE,EAAE,OAA4B;QAChF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,
|
|
1
|
+
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../../src/data-structures/stack/stack.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C;;;;;;;GAOG;AACH,MAAM,OAAO,KAAwB,SAAQ,mBAAsC;IACjF,YAAY,WAAsC,EAAE,EAAE,OAA4B;QAChF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC1B,CAAC;IAES,SAAS,GAAQ,EAAE,CAAC;IAE9B;;;OAGG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,SAAS,CAAI,QAAa;QAC/B,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC;IACpC,CAAC;IAED;;;;;;OAMG;IACH,IAAI;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QACV,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;;OAMG;IACO,CAAC,YAAY;QACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9C,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -65,13 +65,100 @@ export declare class TrieNode {
|
|
|
65
65
|
* 9. Spell Check: Checking the spelling of words.
|
|
66
66
|
* 10. IP Routing: Used in certain types of IP routing algorithms.
|
|
67
67
|
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
|
|
68
|
+
* @example
|
|
69
|
+
* // Autocomplete: Prefix validation and checking
|
|
70
|
+
* const autocomplete = new Trie<string>(['gmail.com', 'gmail.co.nz', 'gmail.co.jp', 'yahoo.com', 'outlook.com']);
|
|
71
|
+
*
|
|
72
|
+
* // Get all completions for a prefix
|
|
73
|
+
* const gmailCompletions = autocomplete.getWords('gmail');
|
|
74
|
+
* console.log(gmailCompletions); // ['gmail.com', 'gmail.co.nz', 'gmail.co.jp']
|
|
75
|
+
* @example
|
|
76
|
+
* // File System Path Operations
|
|
77
|
+
* const fileSystem = new Trie<string>([
|
|
78
|
+
* '/home/user/documents/file1.txt',
|
|
79
|
+
* '/home/user/documents/file2.txt',
|
|
80
|
+
* '/home/user/pictures/photo.jpg',
|
|
81
|
+
* '/home/user/pictures/vacation/',
|
|
82
|
+
* '/home/user/downloads'
|
|
83
|
+
* ]);
|
|
84
|
+
*
|
|
85
|
+
* // Find common directory prefix
|
|
86
|
+
* console.log(fileSystem.getLongestCommonPrefix()); // '/home/user/'
|
|
87
|
+
*
|
|
88
|
+
* // List all files in a directory
|
|
89
|
+
* const documentsFiles = fileSystem.getWords('/home/user/documents/');
|
|
90
|
+
* console.log(documentsFiles); // ['/home/user/documents/file1.txt', '/home/user/documents/file2.txt']
|
|
91
|
+
* @example
|
|
92
|
+
* // Autocomplete: Basic word suggestions
|
|
93
|
+
* // Create a trie for autocomplete
|
|
94
|
+
* const autocomplete = new Trie<string>([
|
|
95
|
+
* 'function',
|
|
96
|
+
* 'functional',
|
|
97
|
+
* 'functions',
|
|
98
|
+
* 'class',
|
|
99
|
+
* 'classes',
|
|
100
|
+
* 'classical',
|
|
101
|
+
* 'closure',
|
|
102
|
+
* 'const',
|
|
103
|
+
* 'constructor'
|
|
104
|
+
* ]);
|
|
105
|
+
*
|
|
106
|
+
* // Test autocomplete with different prefixes
|
|
107
|
+
* console.log(autocomplete.getWords('fun')); // ['functional', 'functions', 'function']
|
|
108
|
+
* console.log(autocomplete.getWords('cla')); // ['classes', 'classical', 'class']
|
|
109
|
+
* console.log(autocomplete.getWords('con')); // ['constructor', 'const']
|
|
110
|
+
*
|
|
111
|
+
* // Test with non-matching prefix
|
|
112
|
+
* console.log(autocomplete.getWords('xyz')); // []
|
|
113
|
+
* @example
|
|
114
|
+
* // Dictionary: Case-insensitive word lookup
|
|
115
|
+
* // Create a case-insensitive dictionary
|
|
116
|
+
* const dictionary = new Trie<string>([], { caseSensitive: false });
|
|
117
|
+
*
|
|
118
|
+
* // Add words with mixed casing
|
|
119
|
+
* dictionary.add('Hello');
|
|
120
|
+
* dictionary.add('WORLD');
|
|
121
|
+
* dictionary.add('JavaScript');
|
|
122
|
+
*
|
|
123
|
+
* // Test lookups with different casings
|
|
124
|
+
* console.log(dictionary.has('hello')); // true
|
|
125
|
+
* console.log(dictionary.has('HELLO')); // true
|
|
126
|
+
* console.log(dictionary.has('Hello')); // true
|
|
127
|
+
* console.log(dictionary.has('javascript')); // true
|
|
128
|
+
* console.log(dictionary.has('JAVASCRIPT')); // true
|
|
129
|
+
* @example
|
|
130
|
+
* // IP Address Routing Table
|
|
131
|
+
* // Add IP address prefixes and their corresponding routes
|
|
132
|
+
* const routes = {
|
|
133
|
+
* '192.168.1': 'LAN_SUBNET_1',
|
|
134
|
+
* '192.168.2': 'LAN_SUBNET_2',
|
|
135
|
+
* '10.0.0': 'PRIVATE_NETWORK_1',
|
|
136
|
+
* '10.0.1': 'PRIVATE_NETWORK_2'
|
|
137
|
+
* };
|
|
138
|
+
*
|
|
139
|
+
* const ipRoutingTable = new Trie<string>(Object.keys(routes));
|
|
140
|
+
*
|
|
141
|
+
* // Check IP address prefix matching
|
|
142
|
+
* console.log(ipRoutingTable.hasPrefix('192.168.1')); // true
|
|
143
|
+
* console.log(ipRoutingTable.hasPrefix('192.168.2')); // true
|
|
144
|
+
*
|
|
145
|
+
* // Validate IP address belongs to subnet
|
|
146
|
+
* const ip = '192.168.1.100';
|
|
147
|
+
* const subnet = ip.split('.').slice(0, 3).join('.');
|
|
148
|
+
* console.log(ipRoutingTable.hasPrefix(subnet)); // true
|
|
68
149
|
*/
|
|
69
150
|
export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R>> {
|
|
70
151
|
/**
|
|
71
|
-
* The constructor
|
|
72
|
-
*
|
|
73
|
-
* @param
|
|
74
|
-
*
|
|
152
|
+
* The constructor initializes a Trie data structure with optional options and words provided as
|
|
153
|
+
* input.
|
|
154
|
+
* @param {Iterable<string> | Iterable<R>} words - The `words` parameter in the constructor is an
|
|
155
|
+
* iterable containing either strings or elements of type `R`. It is used to initialize the Trie with
|
|
156
|
+
* a list of words or elements. If no `words` are provided, an empty iterable is used as the default
|
|
157
|
+
* value.
|
|
158
|
+
* @param [options] - The `options` parameter in the constructor is an optional object that can
|
|
159
|
+
* contain configuration options for the Trie data structure. One of the options it can have is
|
|
160
|
+
* `caseSensitive`, which is a boolean value indicating whether the Trie should be case-sensitive or
|
|
161
|
+
* not. If `caseSensitive` is set to `
|
|
75
162
|
*/
|
|
76
163
|
constructor(words?: Iterable<string> | Iterable<R>, options?: TrieOptions<R>);
|
|
77
164
|
protected _size: number;
|
|
@@ -101,6 +188,19 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
101
188
|
* @returns {boolean} True if the word was successfully added.
|
|
102
189
|
*/
|
|
103
190
|
add(word: string): boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Time Complexity: O(n * l)
|
|
193
|
+
* Space Complexity: O(1)
|
|
194
|
+
*
|
|
195
|
+
* The `addMany` function in TypeScript takes an iterable of strings or elements of type R, converts
|
|
196
|
+
* them using a provided function if available, and adds them to a data structure while returning an
|
|
197
|
+
* array of boolean values indicating success.
|
|
198
|
+
* @param {Iterable<string> | Iterable<R>} words - The `words` parameter in the `addMany` function is
|
|
199
|
+
* an iterable that contains either strings or elements of type `R`.
|
|
200
|
+
* @returns The `addMany` method returns an array of boolean values indicating whether each word in
|
|
201
|
+
* the input iterable was successfully added to the data structure.
|
|
202
|
+
*/
|
|
203
|
+
addMany(words: Iterable<string> | Iterable<R>): boolean[];
|
|
104
204
|
/**
|
|
105
205
|
* Time Complexity: O(l), where l is the length of the input word.
|
|
106
206
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -135,9 +235,14 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
135
235
|
*/
|
|
136
236
|
delete(word: string): boolean;
|
|
137
237
|
/**
|
|
138
|
-
* Time Complexity: O(n)
|
|
139
|
-
* Space Complexity: O(1)
|
|
238
|
+
* Time Complexity: O(n)
|
|
239
|
+
* Space Complexity: O(1)
|
|
140
240
|
*
|
|
241
|
+
* The function `getHeight` calculates the height of a trie data structure starting from the root
|
|
242
|
+
* node.
|
|
243
|
+
* @returns The `getHeight` method returns the maximum depth or height of the trie tree starting from
|
|
244
|
+
* the root node. It calculates the depth using a breadth-first search (BFS) traversal of the trie
|
|
245
|
+
* tree and returns the maximum depth found.
|
|
141
246
|
*/
|
|
142
247
|
getHeight(): number;
|
|
143
248
|
/**
|
|
@@ -73,13 +73,100 @@ export class TrieNode {
|
|
|
73
73
|
* 9. Spell Check: Checking the spelling of words.
|
|
74
74
|
* 10. IP Routing: Used in certain types of IP routing algorithms.
|
|
75
75
|
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
|
|
76
|
+
* @example
|
|
77
|
+
* // Autocomplete: Prefix validation and checking
|
|
78
|
+
* const autocomplete = new Trie<string>(['gmail.com', 'gmail.co.nz', 'gmail.co.jp', 'yahoo.com', 'outlook.com']);
|
|
79
|
+
*
|
|
80
|
+
* // Get all completions for a prefix
|
|
81
|
+
* const gmailCompletions = autocomplete.getWords('gmail');
|
|
82
|
+
* console.log(gmailCompletions); // ['gmail.com', 'gmail.co.nz', 'gmail.co.jp']
|
|
83
|
+
* @example
|
|
84
|
+
* // File System Path Operations
|
|
85
|
+
* const fileSystem = new Trie<string>([
|
|
86
|
+
* '/home/user/documents/file1.txt',
|
|
87
|
+
* '/home/user/documents/file2.txt',
|
|
88
|
+
* '/home/user/pictures/photo.jpg',
|
|
89
|
+
* '/home/user/pictures/vacation/',
|
|
90
|
+
* '/home/user/downloads'
|
|
91
|
+
* ]);
|
|
92
|
+
*
|
|
93
|
+
* // Find common directory prefix
|
|
94
|
+
* console.log(fileSystem.getLongestCommonPrefix()); // '/home/user/'
|
|
95
|
+
*
|
|
96
|
+
* // List all files in a directory
|
|
97
|
+
* const documentsFiles = fileSystem.getWords('/home/user/documents/');
|
|
98
|
+
* console.log(documentsFiles); // ['/home/user/documents/file1.txt', '/home/user/documents/file2.txt']
|
|
99
|
+
* @example
|
|
100
|
+
* // Autocomplete: Basic word suggestions
|
|
101
|
+
* // Create a trie for autocomplete
|
|
102
|
+
* const autocomplete = new Trie<string>([
|
|
103
|
+
* 'function',
|
|
104
|
+
* 'functional',
|
|
105
|
+
* 'functions',
|
|
106
|
+
* 'class',
|
|
107
|
+
* 'classes',
|
|
108
|
+
* 'classical',
|
|
109
|
+
* 'closure',
|
|
110
|
+
* 'const',
|
|
111
|
+
* 'constructor'
|
|
112
|
+
* ]);
|
|
113
|
+
*
|
|
114
|
+
* // Test autocomplete with different prefixes
|
|
115
|
+
* console.log(autocomplete.getWords('fun')); // ['functional', 'functions', 'function']
|
|
116
|
+
* console.log(autocomplete.getWords('cla')); // ['classes', 'classical', 'class']
|
|
117
|
+
* console.log(autocomplete.getWords('con')); // ['constructor', 'const']
|
|
118
|
+
*
|
|
119
|
+
* // Test with non-matching prefix
|
|
120
|
+
* console.log(autocomplete.getWords('xyz')); // []
|
|
121
|
+
* @example
|
|
122
|
+
* // Dictionary: Case-insensitive word lookup
|
|
123
|
+
* // Create a case-insensitive dictionary
|
|
124
|
+
* const dictionary = new Trie<string>([], { caseSensitive: false });
|
|
125
|
+
*
|
|
126
|
+
* // Add words with mixed casing
|
|
127
|
+
* dictionary.add('Hello');
|
|
128
|
+
* dictionary.add('WORLD');
|
|
129
|
+
* dictionary.add('JavaScript');
|
|
130
|
+
*
|
|
131
|
+
* // Test lookups with different casings
|
|
132
|
+
* console.log(dictionary.has('hello')); // true
|
|
133
|
+
* console.log(dictionary.has('HELLO')); // true
|
|
134
|
+
* console.log(dictionary.has('Hello')); // true
|
|
135
|
+
* console.log(dictionary.has('javascript')); // true
|
|
136
|
+
* console.log(dictionary.has('JAVASCRIPT')); // true
|
|
137
|
+
* @example
|
|
138
|
+
* // IP Address Routing Table
|
|
139
|
+
* // Add IP address prefixes and their corresponding routes
|
|
140
|
+
* const routes = {
|
|
141
|
+
* '192.168.1': 'LAN_SUBNET_1',
|
|
142
|
+
* '192.168.2': 'LAN_SUBNET_2',
|
|
143
|
+
* '10.0.0': 'PRIVATE_NETWORK_1',
|
|
144
|
+
* '10.0.1': 'PRIVATE_NETWORK_2'
|
|
145
|
+
* };
|
|
146
|
+
*
|
|
147
|
+
* const ipRoutingTable = new Trie<string>(Object.keys(routes));
|
|
148
|
+
*
|
|
149
|
+
* // Check IP address prefix matching
|
|
150
|
+
* console.log(ipRoutingTable.hasPrefix('192.168.1')); // true
|
|
151
|
+
* console.log(ipRoutingTable.hasPrefix('192.168.2')); // true
|
|
152
|
+
*
|
|
153
|
+
* // Validate IP address belongs to subnet
|
|
154
|
+
* const ip = '192.168.1.100';
|
|
155
|
+
* const subnet = ip.split('.').slice(0, 3).join('.');
|
|
156
|
+
* console.log(ipRoutingTable.hasPrefix(subnet)); // true
|
|
76
157
|
*/
|
|
77
158
|
export class Trie extends IterableElementBase {
|
|
78
159
|
/**
|
|
79
|
-
* The constructor
|
|
80
|
-
*
|
|
81
|
-
* @param
|
|
82
|
-
*
|
|
160
|
+
* The constructor initializes a Trie data structure with optional options and words provided as
|
|
161
|
+
* input.
|
|
162
|
+
* @param {Iterable<string> | Iterable<R>} words - The `words` parameter in the constructor is an
|
|
163
|
+
* iterable containing either strings or elements of type `R`. It is used to initialize the Trie with
|
|
164
|
+
* a list of words or elements. If no `words` are provided, an empty iterable is used as the default
|
|
165
|
+
* value.
|
|
166
|
+
* @param [options] - The `options` parameter in the constructor is an optional object that can
|
|
167
|
+
* contain configuration options for the Trie data structure. One of the options it can have is
|
|
168
|
+
* `caseSensitive`, which is a boolean value indicating whether the Trie should be case-sensitive or
|
|
169
|
+
* not. If `caseSensitive` is set to `
|
|
83
170
|
*/
|
|
84
171
|
constructor(words = [], options) {
|
|
85
172
|
super(options);
|
|
@@ -89,14 +176,7 @@ export class Trie extends IterableElementBase {
|
|
|
89
176
|
this._caseSensitive = caseSensitive;
|
|
90
177
|
}
|
|
91
178
|
if (words) {
|
|
92
|
-
|
|
93
|
-
if (this.toElementFn) {
|
|
94
|
-
this.add(this.toElementFn(word));
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
this.add(word);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
179
|
+
this.addMany(words);
|
|
100
180
|
}
|
|
101
181
|
}
|
|
102
182
|
_size = 0;
|
|
@@ -150,6 +230,30 @@ export class Trie extends IterableElementBase {
|
|
|
150
230
|
}
|
|
151
231
|
return isNewWord;
|
|
152
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Time Complexity: O(n * l)
|
|
235
|
+
* Space Complexity: O(1)
|
|
236
|
+
*
|
|
237
|
+
* The `addMany` function in TypeScript takes an iterable of strings or elements of type R, converts
|
|
238
|
+
* them using a provided function if available, and adds them to a data structure while returning an
|
|
239
|
+
* array of boolean values indicating success.
|
|
240
|
+
* @param {Iterable<string> | Iterable<R>} words - The `words` parameter in the `addMany` function is
|
|
241
|
+
* an iterable that contains either strings or elements of type `R`.
|
|
242
|
+
* @returns The `addMany` method returns an array of boolean values indicating whether each word in
|
|
243
|
+
* the input iterable was successfully added to the data structure.
|
|
244
|
+
*/
|
|
245
|
+
addMany(words) {
|
|
246
|
+
const ans = [];
|
|
247
|
+
for (const word of words) {
|
|
248
|
+
if (this.toElementFn) {
|
|
249
|
+
ans.push(this.add(this.toElementFn(word)));
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
ans.push(this.add(word));
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return ans;
|
|
256
|
+
}
|
|
153
257
|
/**
|
|
154
258
|
* Time Complexity: O(l), where l is the length of the input word.
|
|
155
259
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -233,9 +337,14 @@ export class Trie extends IterableElementBase {
|
|
|
233
337
|
return isDeleted;
|
|
234
338
|
}
|
|
235
339
|
/**
|
|
236
|
-
* Time Complexity: O(n)
|
|
237
|
-
* Space Complexity: O(1)
|
|
340
|
+
* Time Complexity: O(n)
|
|
341
|
+
* Space Complexity: O(1)
|
|
238
342
|
*
|
|
343
|
+
* The function `getHeight` calculates the height of a trie data structure starting from the root
|
|
344
|
+
* node.
|
|
345
|
+
* @returns The `getHeight` method returns the maximum depth or height of the trie tree starting from
|
|
346
|
+
* the root node. It calculates the depth using a breadth-first search (BFS) traversal of the trie
|
|
347
|
+
* tree and returns the maximum depth found.
|
|
239
348
|
*/
|
|
240
349
|
getHeight() {
|
|
241
350
|
const startNode = this.root;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trie.js","sourceRoot":"","sources":["../../../../src/data-structures/trie/trie.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C;;;GAGG;AACH,MAAM,OAAO,QAAQ;IACnB,YAAY,GAAW;QACrB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC/C,CAAC;IAES,IAAI,CAAS;IAEvB;;;OAGG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,IAAI,GAAG,CAAC,KAAa;QACnB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACpB,CAAC;IAES,SAAS,CAAwB;IAE3C;;;;OAIG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;;;;OAMG;IACH,IAAI,QAAQ,CAAC,KAA4B;QACvC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACzB,CAAC;IAES,MAAM,CAAU;IAE1B;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,IAAI,KAAK,CAAC,KAAc;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;CACF;AAED
|
|
1
|
+
{"version":3,"file":"trie.js","sourceRoot":"","sources":["../../../../src/data-structures/trie/trie.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C;;;GAGG;AACH,MAAM,OAAO,QAAQ;IACnB,YAAY,GAAW;QACrB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC/C,CAAC;IAES,IAAI,CAAS;IAEvB;;;OAGG;IACH,IAAI,GAAG;QACL,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CAAC;YACD,KAAK,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAC9C,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC,CAAC;YACtC,CAAC;QACH,CAAC;QAED,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACO,YAAY,CAAC,GAAW;QAChC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,+CAA+C;QAC1E,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
|
package/dist/mjs/index.d.ts
CHANGED
package/dist/mjs/index.js
CHANGED
package/dist/mjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
|
|
2
2
|
import { IterationType, OptValue } from '../../common';
|
|
3
|
-
import { DFSOperation } from '../../../
|
|
3
|
+
import { DFSOperation } from '../../../common';
|
|
4
4
|
export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
5
|
export type BinaryTreeNested<K, V, R, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
6
|
export type ToEntryFn<K, V, R> = (rawElement: R) => BTNEntry<K, V>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { BST, BSTNode } from '../../../data-structures';
|
|
2
2
|
import type { BinaryTreeOptions } from './binary-tree';
|
|
3
|
-
import {
|
|
3
|
+
import { Comparable } from '../../utils';
|
|
4
4
|
export type BSTNodeNested<K, V> = BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
5
|
export type BSTNested<K, V, R, NODE extends BSTNode<K, V, NODE>> = BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
6
|
export type BSTOptions<K, V, R> = BinaryTreeOptions<K, V, R> & {
|
|
7
|
-
|
|
7
|
+
extractComparable?: (key: K) => Comparable;
|
|
8
|
+
isReverse?: boolean;
|
|
8
9
|
};
|
|
9
10
|
export type BSTNOptKey<K> = K | undefined;
|
|
10
11
|
export type OptNode<NODE> = NODE | undefined;
|
|
@@ -3,4 +3,4 @@ import type { BSTOptions } from "./bst";
|
|
|
3
3
|
export type RBTNColor = 'RED' | 'BLACK';
|
|
4
4
|
export type RedBlackTreeNodeNested<K, V> = RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
5
|
export type RedBlackTreeNested<K, V, R, NODE extends RedBlackTreeNode<K, V, NODE>> = RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
-
export type RBTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
|
|
6
|
+
export type RBTreeOptions<K, V, R> = Omit<BSTOptions<K, V, R>, 'isReverse'> & {};
|
|
@@ -6,13 +6,17 @@ export type TrlFn<A extends any[] = any[], R = any> = (...args: A) => R;
|
|
|
6
6
|
export type TrlAsyncFn = (...args: any[]) => any;
|
|
7
7
|
export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
8
8
|
export type Any = string | number | bigint | boolean | symbol | undefined | object;
|
|
9
|
+
export type Arithmetic = number | bigint;
|
|
9
10
|
export type ComparablePrimitive = number | bigint | string | boolean;
|
|
10
|
-
export
|
|
11
|
-
[key
|
|
12
|
-
}
|
|
13
|
-
|
|
11
|
+
export interface BaseComparableObject {
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface ValueComparableObject extends BaseComparableObject {
|
|
15
|
+
valueOf: () => ComparablePrimitive | ValueComparableObject;
|
|
14
16
|
toString?: () => string;
|
|
15
|
-
}
|
|
17
|
+
}
|
|
18
|
+
export interface StringComparableObject extends BaseComparableObject {
|
|
16
19
|
toString: () => string;
|
|
17
|
-
}
|
|
20
|
+
}
|
|
21
|
+
export type ComparableObject = ValueComparableObject | StringComparableObject;
|
|
18
22
|
export type Comparable = ComparablePrimitive | Date | ComparableObject;
|
package/dist/mjs/utils/utils.js
CHANGED
|
@@ -189,7 +189,8 @@ export const roundFixed = (num, digit = 10) => {
|
|
|
189
189
|
function isPrimitiveComparable(value) {
|
|
190
190
|
const valueType = typeof value;
|
|
191
191
|
if (valueType === 'number')
|
|
192
|
-
return
|
|
192
|
+
return true;
|
|
193
|
+
// if (valueType === 'number') return !Number.isNaN(value);
|
|
193
194
|
return valueType === 'bigint' || valueType === 'string' || valueType === 'boolean';
|
|
194
195
|
}
|
|
195
196
|
/**
|
|
@@ -241,7 +242,8 @@ export function isComparable(value, isForceObjectComparable = false) {
|
|
|
241
242
|
if (typeof value !== 'object')
|
|
242
243
|
return false;
|
|
243
244
|
if (value instanceof Date)
|
|
244
|
-
return
|
|
245
|
+
return true;
|
|
246
|
+
// if (value instanceof Date) return !Number.isNaN(value.getTime());
|
|
245
247
|
if (isForceObjectComparable)
|
|
246
248
|
return true;
|
|
247
249
|
const comparableValue = tryObjectToPrimitive(value);
|