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
|
/**
|
|
@@ -14,16 +14,7 @@ class Stack extends base_1.IterableElementBase {
|
|
|
14
14
|
constructor(elements = [], options) {
|
|
15
15
|
super(options);
|
|
16
16
|
this._elements = [];
|
|
17
|
-
|
|
18
|
-
for (const el of elements) {
|
|
19
|
-
if (this.toElementFn) {
|
|
20
|
-
this.push(this.toElementFn(el));
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
this.push(el);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
17
|
+
this.pushMany(elements);
|
|
27
18
|
}
|
|
28
19
|
/**
|
|
29
20
|
* The elements function returns the elements of this set.
|
|
@@ -39,10 +30,6 @@ class Stack extends base_1.IterableElementBase {
|
|
|
39
30
|
get size() {
|
|
40
31
|
return this.elements.length;
|
|
41
32
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Time Complexity: O(n)
|
|
44
|
-
* Space Complexity: O(n)
|
|
45
|
-
*/
|
|
46
33
|
/**
|
|
47
34
|
* Time Complexity: O(n)
|
|
48
35
|
* Space Complexity: O(n)
|
|
@@ -56,6 +43,9 @@ class Stack extends base_1.IterableElementBase {
|
|
|
56
43
|
return new Stack(elements);
|
|
57
44
|
}
|
|
58
45
|
/**
|
|
46
|
+
* Time Complexity: O(1)
|
|
47
|
+
* Space Complexity: O(1)
|
|
48
|
+
*
|
|
59
49
|
* The function checks if an array is empty and returns a boolean value.
|
|
60
50
|
* @returns A boolean value indicating whether the `_elements` array is empty or not.
|
|
61
51
|
*/
|
|
@@ -100,18 +90,47 @@ class Stack extends base_1.IterableElementBase {
|
|
|
100
90
|
return this.elements.pop();
|
|
101
91
|
}
|
|
102
92
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
93
|
+
* Time Complexity: O(k)
|
|
94
|
+
* Space Complexity: O(1)
|
|
95
|
+
*
|
|
96
|
+
* The function `pushMany` iterates over elements and pushes them into an array after applying a
|
|
97
|
+
* transformation function if provided.
|
|
98
|
+
* @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `pushMany` function
|
|
99
|
+
* is an iterable containing elements of type `E` or `R`. The function iterates over each element in
|
|
100
|
+
* the iterable and pushes it into the data structure. If a transformation function `toElementFn` is
|
|
101
|
+
* provided, it is used to
|
|
102
|
+
* @returns The `pushMany` function is returning an array of boolean values indicating whether each
|
|
103
|
+
* element was successfully pushed into the data structure.
|
|
104
|
+
*/
|
|
105
|
+
pushMany(elements) {
|
|
106
|
+
const ans = [];
|
|
107
|
+
for (const el of elements) {
|
|
108
|
+
if (this.toElementFn) {
|
|
109
|
+
ans.push(this.push(this.toElementFn(el)));
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
ans.push(this.push(el));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return ans;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Time Complexity: O(n)
|
|
119
|
+
* Space Complexity: O(1)
|
|
120
|
+
*
|
|
121
|
+
* The toArray function returns a copy of the elements in an array.
|
|
122
|
+
* @returns An array of type E.
|
|
106
123
|
*/
|
|
107
124
|
delete(element) {
|
|
108
125
|
const index = this.elements.indexOf(element);
|
|
109
126
|
return this.deleteAt(index);
|
|
110
127
|
}
|
|
111
128
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
129
|
+
* Time Complexity: O(n)
|
|
130
|
+
* Space Complexity: O(1)
|
|
131
|
+
*
|
|
132
|
+
* The toArray function returns a copy of the elements in an array.
|
|
133
|
+
* @returns An array of type E.
|
|
115
134
|
*/
|
|
116
135
|
deleteAt(index) {
|
|
117
136
|
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,kCAA8C;AAE9C;;;;;;;GAOG;AACH,MAAa,KAAwB,SAAQ,0BAAsC;IACjF,YAAY,WAAsC,EAAE,EAAE,OAA4B;QAChF,KAAK,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../../src/data-structures/stack/stack.ts"],"names":[],"mappings":";;;AAQA,kCAA8C;AAE9C;;;;;;;GAOG;AACH,MAAa,KAAwB,SAAQ,0BAAsC;IACjF,YAAY,WAAsC,EAAE,EAAE,OAA4B;QAChF,KAAK,CAAC,OAAO,CAAC,CAAC;QAIP,cAAS,GAAQ,EAAE,CAAC;QAH5B,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC1B,CAAC;IAID;;;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;QACF,IAAI,IAAI,CAAC,OAAO,EAAE;YAAE,OAAO,SAAS,CAAC;QAErC,OAAO,IAA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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;AAhPD,sBAgPC"}
|
|
@@ -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
|
/**
|
|
@@ -74,13 +74,100 @@ exports.TrieNode = TrieNode;
|
|
|
74
74
|
* 9. Spell Check: Checking the spelling of words.
|
|
75
75
|
* 10. IP Routing: Used in certain types of IP routing algorithms.
|
|
76
76
|
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
|
|
77
|
+
* @example
|
|
78
|
+
* // Autocomplete: Prefix validation and checking
|
|
79
|
+
* const autocomplete = new Trie<string>(['gmail.com', 'gmail.co.nz', 'gmail.co.jp', 'yahoo.com', 'outlook.com']);
|
|
80
|
+
*
|
|
81
|
+
* // Get all completions for a prefix
|
|
82
|
+
* const gmailCompletions = autocomplete.getWords('gmail');
|
|
83
|
+
* console.log(gmailCompletions); // ['gmail.com', 'gmail.co.nz', 'gmail.co.jp']
|
|
84
|
+
* @example
|
|
85
|
+
* // File System Path Operations
|
|
86
|
+
* const fileSystem = new Trie<string>([
|
|
87
|
+
* '/home/user/documents/file1.txt',
|
|
88
|
+
* '/home/user/documents/file2.txt',
|
|
89
|
+
* '/home/user/pictures/photo.jpg',
|
|
90
|
+
* '/home/user/pictures/vacation/',
|
|
91
|
+
* '/home/user/downloads'
|
|
92
|
+
* ]);
|
|
93
|
+
*
|
|
94
|
+
* // Find common directory prefix
|
|
95
|
+
* console.log(fileSystem.getLongestCommonPrefix()); // '/home/user/'
|
|
96
|
+
*
|
|
97
|
+
* // List all files in a directory
|
|
98
|
+
* const documentsFiles = fileSystem.getWords('/home/user/documents/');
|
|
99
|
+
* console.log(documentsFiles); // ['/home/user/documents/file1.txt', '/home/user/documents/file2.txt']
|
|
100
|
+
* @example
|
|
101
|
+
* // Autocomplete: Basic word suggestions
|
|
102
|
+
* // Create a trie for autocomplete
|
|
103
|
+
* const autocomplete = new Trie<string>([
|
|
104
|
+
* 'function',
|
|
105
|
+
* 'functional',
|
|
106
|
+
* 'functions',
|
|
107
|
+
* 'class',
|
|
108
|
+
* 'classes',
|
|
109
|
+
* 'classical',
|
|
110
|
+
* 'closure',
|
|
111
|
+
* 'const',
|
|
112
|
+
* 'constructor'
|
|
113
|
+
* ]);
|
|
114
|
+
*
|
|
115
|
+
* // Test autocomplete with different prefixes
|
|
116
|
+
* console.log(autocomplete.getWords('fun')); // ['functional', 'functions', 'function']
|
|
117
|
+
* console.log(autocomplete.getWords('cla')); // ['classes', 'classical', 'class']
|
|
118
|
+
* console.log(autocomplete.getWords('con')); // ['constructor', 'const']
|
|
119
|
+
*
|
|
120
|
+
* // Test with non-matching prefix
|
|
121
|
+
* console.log(autocomplete.getWords('xyz')); // []
|
|
122
|
+
* @example
|
|
123
|
+
* // Dictionary: Case-insensitive word lookup
|
|
124
|
+
* // Create a case-insensitive dictionary
|
|
125
|
+
* const dictionary = new Trie<string>([], { caseSensitive: false });
|
|
126
|
+
*
|
|
127
|
+
* // Add words with mixed casing
|
|
128
|
+
* dictionary.add('Hello');
|
|
129
|
+
* dictionary.add('WORLD');
|
|
130
|
+
* dictionary.add('JavaScript');
|
|
131
|
+
*
|
|
132
|
+
* // Test lookups with different casings
|
|
133
|
+
* console.log(dictionary.has('hello')); // true
|
|
134
|
+
* console.log(dictionary.has('HELLO')); // true
|
|
135
|
+
* console.log(dictionary.has('Hello')); // true
|
|
136
|
+
* console.log(dictionary.has('javascript')); // true
|
|
137
|
+
* console.log(dictionary.has('JAVASCRIPT')); // true
|
|
138
|
+
* @example
|
|
139
|
+
* // IP Address Routing Table
|
|
140
|
+
* // Add IP address prefixes and their corresponding routes
|
|
141
|
+
* const routes = {
|
|
142
|
+
* '192.168.1': 'LAN_SUBNET_1',
|
|
143
|
+
* '192.168.2': 'LAN_SUBNET_2',
|
|
144
|
+
* '10.0.0': 'PRIVATE_NETWORK_1',
|
|
145
|
+
* '10.0.1': 'PRIVATE_NETWORK_2'
|
|
146
|
+
* };
|
|
147
|
+
*
|
|
148
|
+
* const ipRoutingTable = new Trie<string>(Object.keys(routes));
|
|
149
|
+
*
|
|
150
|
+
* // Check IP address prefix matching
|
|
151
|
+
* console.log(ipRoutingTable.hasPrefix('192.168.1')); // true
|
|
152
|
+
* console.log(ipRoutingTable.hasPrefix('192.168.2')); // true
|
|
153
|
+
*
|
|
154
|
+
* // Validate IP address belongs to subnet
|
|
155
|
+
* const ip = '192.168.1.100';
|
|
156
|
+
* const subnet = ip.split('.').slice(0, 3).join('.');
|
|
157
|
+
* console.log(ipRoutingTable.hasPrefix(subnet)); // true
|
|
77
158
|
*/
|
|
78
159
|
class Trie extends base_1.IterableElementBase {
|
|
79
160
|
/**
|
|
80
|
-
* The constructor
|
|
81
|
-
*
|
|
82
|
-
* @param
|
|
83
|
-
*
|
|
161
|
+
* The constructor initializes a Trie data structure with optional options and words provided as
|
|
162
|
+
* input.
|
|
163
|
+
* @param {Iterable<string> | Iterable<R>} words - The `words` parameter in the constructor is an
|
|
164
|
+
* iterable containing either strings or elements of type `R`. It is used to initialize the Trie with
|
|
165
|
+
* a list of words or elements. If no `words` are provided, an empty iterable is used as the default
|
|
166
|
+
* value.
|
|
167
|
+
* @param [options] - The `options` parameter in the constructor is an optional object that can
|
|
168
|
+
* contain configuration options for the Trie data structure. One of the options it can have is
|
|
169
|
+
* `caseSensitive`, which is a boolean value indicating whether the Trie should be case-sensitive or
|
|
170
|
+
* not. If `caseSensitive` is set to `
|
|
84
171
|
*/
|
|
85
172
|
constructor(words = [], options) {
|
|
86
173
|
super(options);
|
|
@@ -93,14 +180,7 @@ class Trie extends base_1.IterableElementBase {
|
|
|
93
180
|
this._caseSensitive = caseSensitive;
|
|
94
181
|
}
|
|
95
182
|
if (words) {
|
|
96
|
-
|
|
97
|
-
if (this.toElementFn) {
|
|
98
|
-
this.add(this.toElementFn(word));
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
this.add(word);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
183
|
+
this.addMany(words);
|
|
104
184
|
}
|
|
105
185
|
}
|
|
106
186
|
/**
|
|
@@ -151,6 +231,30 @@ class Trie extends base_1.IterableElementBase {
|
|
|
151
231
|
}
|
|
152
232
|
return isNewWord;
|
|
153
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Time Complexity: O(n * l)
|
|
236
|
+
* Space Complexity: O(1)
|
|
237
|
+
*
|
|
238
|
+
* The `addMany` function in TypeScript takes an iterable of strings or elements of type R, converts
|
|
239
|
+
* them using a provided function if available, and adds them to a data structure while returning an
|
|
240
|
+
* array of boolean values indicating success.
|
|
241
|
+
* @param {Iterable<string> | Iterable<R>} words - The `words` parameter in the `addMany` function is
|
|
242
|
+
* an iterable that contains either strings or elements of type `R`.
|
|
243
|
+
* @returns The `addMany` method returns an array of boolean values indicating whether each word in
|
|
244
|
+
* the input iterable was successfully added to the data structure.
|
|
245
|
+
*/
|
|
246
|
+
addMany(words) {
|
|
247
|
+
const ans = [];
|
|
248
|
+
for (const word of words) {
|
|
249
|
+
if (this.toElementFn) {
|
|
250
|
+
ans.push(this.add(this.toElementFn(word)));
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
ans.push(this.add(word));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return ans;
|
|
257
|
+
}
|
|
154
258
|
/**
|
|
155
259
|
* Time Complexity: O(l), where l is the length of the input word.
|
|
156
260
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -234,9 +338,14 @@ class Trie extends base_1.IterableElementBase {
|
|
|
234
338
|
return isDeleted;
|
|
235
339
|
}
|
|
236
340
|
/**
|
|
237
|
-
* Time Complexity: O(n)
|
|
238
|
-
* Space Complexity: O(1)
|
|
341
|
+
* Time Complexity: O(n)
|
|
342
|
+
* Space Complexity: O(1)
|
|
239
343
|
*
|
|
344
|
+
* The function `getHeight` calculates the height of a trie data structure starting from the root
|
|
345
|
+
* node.
|
|
346
|
+
* @returns The `getHeight` method returns the maximum depth or height of the trie tree starting from
|
|
347
|
+
* the root node. It calculates the depth using a breadth-first search (BFS) traversal of the trie
|
|
348
|
+
* tree and returns the maximum depth found.
|
|
240
349
|
*/
|
|
241
350
|
getHeight() {
|
|
242
351
|
const startNode = this.root;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trie.js","sourceRoot":"","sources":["../../../../src/data-structures/trie/trie.ts"],"names":[],"mappings":";;;AAQA,kCAA8C;AAE9C;;;GAGG;AACH,MAAa,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;IAID;;;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;IAID;;;;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;IAID;;;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;AAlED,4BAkEC;AAED
|
|
1
|
+
{"version":3,"file":"trie.js","sourceRoot":"","sources":["../../../../src/data-structures/trie/trie.ts"],"names":[],"mappings":";;;AAQA,kCAA8C;AAE9C;;;GAGG;AACH,MAAa,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;IAID;;;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;IAID;;;;OAIG;IACH,IAAI,QAAQ;QACV,OAAO,I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AAC,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;AApcD,oBAocC"}
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -18,5 +18,5 @@ __exportStar(require("./data-structures"), exports);
|
|
|
18
18
|
__exportStar(require("./utils"), exports);
|
|
19
19
|
__exportStar(require("./interfaces"), exports);
|
|
20
20
|
__exportStar(require("./types"), exports);
|
|
21
|
-
__exportStar(require("./
|
|
21
|
+
__exportStar(require("./common"), exports);
|
|
22
22
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,0CAAwB;AACxB,+CAA6B;AAC7B,0CAAwB;AACxB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,0CAAwB;AACxB,+CAA6B;AAC7B,0CAAwB;AACxB,2CAAyB"}
|
|
@@ -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/cjs/utils/utils.js
CHANGED
|
@@ -214,7 +214,8 @@ exports.roundFixed = roundFixed;
|
|
|
214
214
|
function isPrimitiveComparable(value) {
|
|
215
215
|
const valueType = typeof value;
|
|
216
216
|
if (valueType === 'number')
|
|
217
|
-
return
|
|
217
|
+
return true;
|
|
218
|
+
// if (valueType === 'number') return !Number.isNaN(value);
|
|
218
219
|
return valueType === 'bigint' || valueType === 'string' || valueType === 'boolean';
|
|
219
220
|
}
|
|
220
221
|
/**
|
|
@@ -266,7 +267,8 @@ function isComparable(value, isForceObjectComparable = false) {
|
|
|
266
267
|
if (typeof value !== 'object')
|
|
267
268
|
return false;
|
|
268
269
|
if (value instanceof Date)
|
|
269
|
-
return
|
|
270
|
+
return true;
|
|
271
|
+
// if (value instanceof Date) return !Number.isNaN(value.getTime());
|
|
270
272
|
if (isForceObjectComparable)
|
|
271
273
|
return true;
|
|
272
274
|
const comparableValue = tryObjectToPrimitive(value);
|