data-structure-typed 2.2.0 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -1
- package/README.md +1511 -840
- package/benchmark/report.html +1 -1
- package/benchmark/report.json +145 -169
- package/dist/cjs/index.cjs +20 -20
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +20 -20
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +20 -20
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +20 -20
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -0
- package/dist/types/types/data-structures/base/base.d.ts +1 -1
- package/dist/umd/data-structure-typed.js +20 -20
- package/dist/umd/data-structure-typed.js.map +1 -1
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/base/iterable-entry-base.ts +4 -4
- package/src/data-structures/binary-tree/avl-tree-counter.ts +1 -1
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +4 -2
- package/src/data-structures/binary-tree/binary-tree.ts +3 -2
- package/src/data-structures/binary-tree/bst.ts +2 -1
- package/src/data-structures/binary-tree/red-black-tree.ts +2 -1
- package/src/data-structures/binary-tree/tree-counter.ts +1 -1
- package/src/data-structures/binary-tree/tree-multi-map.ts +2 -1
- package/src/data-structures/graph/abstract-graph.ts +3 -3
- package/src/data-structures/hash/hash-map.ts +4 -4
- package/src/types/data-structures/base/base.ts +1 -1
- package/test/performance/data-structures/binary-tree/red-black-tree.test.ts +39 -36
- package/test/performance/runner-config.json +4 -4
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/bst.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -3
- package/test/unit/data-structures/graph/directed-graph.test.ts +3 -3
- package/test/unit/data-structures/hash/hash-map.test.ts +14 -14
- package/test/performance/reportor.mjs +0 -505
|
@@ -125,7 +125,9 @@ export declare class AVLTreeNode<K = any, V = any> {
|
|
|
125
125
|
* 4. Order Preservation: Maintains the binary search tree property where left child values are less than the parent, and right child values are greater.
|
|
126
126
|
* 5. Efficient Lookups: Offers O(log n) search time, where 'n' is the number of nodes, due to its balanced nature.
|
|
127
127
|
* 6. Complex Insertions and Deletions: Due to rebalancing, these operations are more complex than in a regular BST.
|
|
128
|
-
* 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes
|
|
128
|
+
* 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
129
131
|
* // Find elements in a range
|
|
130
132
|
* // In interval queries, AVL trees, with their strictly balanced structure and lower height, offer better query efficiency, making them ideal for frequent and high-performance interval queries. In contrast, Red-Black trees, with lower update costs, are more suitable for scenarios involving frequent insertions and deletions where the requirements for interval queries are less demanding.
|
|
131
133
|
* type Datum = { timestamp: Date; temperature: number };
|
|
@@ -123,6 +123,7 @@ export declare class BinaryTreeNode<K = any, V = any> {
|
|
|
123
123
|
* 3. Depth and Height: Depth is the number of edges from the root to a node; height is the maximum depth in the tree.
|
|
124
124
|
* 4. Subtrees: Each child of a node forms the root of a subtree.
|
|
125
125
|
* 5. Leaf Nodes: Nodes without children are leaves.
|
|
126
|
+
*
|
|
126
127
|
* @example
|
|
127
128
|
* // determine loan approval using a decision tree
|
|
128
129
|
* // Decision tree structure
|
|
@@ -124,6 +124,7 @@ export declare class BSTNode<K = any, V = any> {
|
|
|
124
124
|
* 5. Logarithmic Operations: Ideal operations like insertion, deletion, and searching are O(log n) time-efficient.
|
|
125
125
|
* 6. Balance Variability: Can become unbalanced; special types maintain balance.
|
|
126
126
|
* 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
|
|
127
|
+
*
|
|
127
128
|
* @example
|
|
128
129
|
* // Merge 3 sorted datasets
|
|
129
130
|
* const dataset1 = new BST<number, string>([
|
|
@@ -110,6 +110,7 @@ export declare class RedBlackTreeNode<K = any, V = any> {
|
|
|
110
110
|
* @template R
|
|
111
111
|
* 1. Efficient self-balancing, but not completely balanced. Compared with AVLTree, the addition and deletion efficiency is high, but the query efficiency is slightly lower.
|
|
112
112
|
* 2. It is BST itself. Compared with Heap which is not completely ordered, RedBlackTree is completely ordered.
|
|
113
|
+
*
|
|
113
114
|
* @example
|
|
114
115
|
* // using Red-Black Tree as a price-based index for stock data
|
|
115
116
|
* // Define the structure of individual stock records
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IterableElementBase, IterableEntryBase } from '../../../data-structures';
|
|
2
2
|
import { LinearBase } from '../../../data-structures/base/linear-base';
|
|
3
|
-
export type EntryCallback<K, V, R> = (
|
|
3
|
+
export type EntryCallback<K, V, R> = (value: V, key: K, index: number, original: IterableEntryBase<K, V>) => R;
|
|
4
4
|
export type ElementCallback<E, R, RT> = (element: E, index: number, original: IterableElementBase<E, R>) => RT;
|
|
5
5
|
export type ReduceEntryCallback<K, V, R> = (accumulator: R, value: V, key: K, index: number, original: IterableEntryBase<K, V>) => R;
|
|
6
6
|
export type ReduceElementCallback<E, R, U = E> = (accumulator: U, value: E, index: number, self: IterableElementBase<E, R>) => U;
|
|
@@ -152,7 +152,7 @@ var dataStructureTyped = (() => {
|
|
|
152
152
|
every(predicate, thisArg) {
|
|
153
153
|
let index = 0;
|
|
154
154
|
for (const item of this) {
|
|
155
|
-
if (!predicate.call(thisArg, item[
|
|
155
|
+
if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
|
|
156
156
|
return false;
|
|
157
157
|
}
|
|
158
158
|
}
|
|
@@ -168,7 +168,7 @@ var dataStructureTyped = (() => {
|
|
|
168
168
|
some(predicate, thisArg) {
|
|
169
169
|
let index = 0;
|
|
170
170
|
for (const item of this) {
|
|
171
|
-
if (predicate.call(thisArg, item[
|
|
171
|
+
if (predicate.call(thisArg, item[1], item[0], index++, this)) {
|
|
172
172
|
return true;
|
|
173
173
|
}
|
|
174
174
|
}
|
|
@@ -184,7 +184,7 @@ var dataStructureTyped = (() => {
|
|
|
184
184
|
let index = 0;
|
|
185
185
|
for (const item of this) {
|
|
186
186
|
const [key, value] = item;
|
|
187
|
-
callbackfn.call(thisArg,
|
|
187
|
+
callbackfn.call(thisArg, value, key, index++, this);
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
/**
|
|
@@ -198,7 +198,7 @@ var dataStructureTyped = (() => {
|
|
|
198
198
|
let index = 0;
|
|
199
199
|
for (const item of this) {
|
|
200
200
|
const [key, value] = item;
|
|
201
|
-
if (callbackfn.call(thisArg,
|
|
201
|
+
if (callbackfn.call(thisArg, value, key, index++, this)) return item;
|
|
202
202
|
}
|
|
203
203
|
return;
|
|
204
204
|
}
|
|
@@ -800,7 +800,7 @@ var dataStructureTyped = (() => {
|
|
|
800
800
|
map(callbackfn, thisArg) {
|
|
801
801
|
const out = this._createLike();
|
|
802
802
|
let index = 0;
|
|
803
|
-
for (const [key, value] of this) out.set(key, callbackfn.call(thisArg,
|
|
803
|
+
for (const [key, value] of this) out.set(key, callbackfn.call(thisArg, value, key, index++, this));
|
|
804
804
|
return out;
|
|
805
805
|
}
|
|
806
806
|
/**
|
|
@@ -813,7 +813,7 @@ var dataStructureTyped = (() => {
|
|
|
813
813
|
filter(predicate, thisArg) {
|
|
814
814
|
const out = this._createLike();
|
|
815
815
|
let index = 0;
|
|
816
|
-
for (const [key, value] of this) if (predicate.call(thisArg,
|
|
816
|
+
for (const [key, value] of this) if (predicate.call(thisArg, value, key, index++, this)) out.set(key, value);
|
|
817
817
|
return out;
|
|
818
818
|
}
|
|
819
819
|
/**
|
|
@@ -1135,7 +1135,7 @@ var dataStructureTyped = (() => {
|
|
|
1135
1135
|
const out = this._createLike();
|
|
1136
1136
|
let index = 0;
|
|
1137
1137
|
for (const [key, value] of this) {
|
|
1138
|
-
if (predicate.call(thisArg,
|
|
1138
|
+
if (predicate.call(thisArg, value, key, index, this)) out.set(key, value);
|
|
1139
1139
|
index++;
|
|
1140
1140
|
}
|
|
1141
1141
|
return out;
|
|
@@ -1153,7 +1153,7 @@ var dataStructureTyped = (() => {
|
|
|
1153
1153
|
const out = this._createLike();
|
|
1154
1154
|
let index = 0;
|
|
1155
1155
|
for (const [key, value] of this) {
|
|
1156
|
-
const [newKey, newValue] = callback.call(thisArg,
|
|
1156
|
+
const [newKey, newValue] = callback.call(thisArg, value, key, index, this);
|
|
1157
1157
|
out.set(newKey, newValue);
|
|
1158
1158
|
index++;
|
|
1159
1159
|
}
|
|
@@ -5719,7 +5719,7 @@ var dataStructureTyped = (() => {
|
|
|
5719
5719
|
const filtered = [];
|
|
5720
5720
|
let index = 0;
|
|
5721
5721
|
for (const [key, value] of this) {
|
|
5722
|
-
if (predicate.call(thisArg,
|
|
5722
|
+
if (predicate.call(thisArg, value, key, index, this)) {
|
|
5723
5723
|
filtered.push([key, value]);
|
|
5724
5724
|
}
|
|
5725
5725
|
index++;
|
|
@@ -5734,7 +5734,7 @@ var dataStructureTyped = (() => {
|
|
|
5734
5734
|
const filtered = [];
|
|
5735
5735
|
let index = 0;
|
|
5736
5736
|
for (const [key, value] of this) {
|
|
5737
|
-
if (predicate.call(thisArg,
|
|
5737
|
+
if (predicate.call(thisArg, value, key, index, this)) {
|
|
5738
5738
|
filtered.push([key, value]);
|
|
5739
5739
|
}
|
|
5740
5740
|
index++;
|
|
@@ -5745,7 +5745,7 @@ var dataStructureTyped = (() => {
|
|
|
5745
5745
|
const mapped = [];
|
|
5746
5746
|
let index = 0;
|
|
5747
5747
|
for (const [key, value] of this) {
|
|
5748
|
-
mapped.push(callback.call(thisArg,
|
|
5748
|
+
mapped.push(callback.call(thisArg, value, key, index, this));
|
|
5749
5749
|
index++;
|
|
5750
5750
|
}
|
|
5751
5751
|
return mapped;
|
|
@@ -7998,7 +7998,7 @@ var dataStructureTyped = (() => {
|
|
|
7998
7998
|
filter(predicate, thisArg) {
|
|
7999
7999
|
const out = this._createInstance();
|
|
8000
8000
|
let i = 0;
|
|
8001
|
-
for (const [k, v] of this) if (predicate.call(thisArg,
|
|
8001
|
+
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.add([k, v]);
|
|
8002
8002
|
return out;
|
|
8003
8003
|
}
|
|
8004
8004
|
/**
|
|
@@ -8016,7 +8016,7 @@ var dataStructureTyped = (() => {
|
|
|
8016
8016
|
map(cb, options, thisArg) {
|
|
8017
8017
|
const out = this._createLike([], options);
|
|
8018
8018
|
let i = 0;
|
|
8019
|
-
for (const [k, v] of this) out.add(cb.call(thisArg,
|
|
8019
|
+
for (const [k, v] of this) out.add(cb.call(thisArg, v, k, i++, this));
|
|
8020
8020
|
return out;
|
|
8021
8021
|
}
|
|
8022
8022
|
/**
|
|
@@ -9112,7 +9112,7 @@ var dataStructureTyped = (() => {
|
|
|
9112
9112
|
const out = this._createLike([], options);
|
|
9113
9113
|
let index = 0;
|
|
9114
9114
|
for (const [key, value] of this) {
|
|
9115
|
-
out.add(callback.call(thisArg,
|
|
9115
|
+
out.add(callback.call(thisArg, value, key, index++, this));
|
|
9116
9116
|
}
|
|
9117
9117
|
return out;
|
|
9118
9118
|
}
|
|
@@ -10075,7 +10075,7 @@ var dataStructureTyped = (() => {
|
|
|
10075
10075
|
const out = this._createLike([], options);
|
|
10076
10076
|
let index = 0;
|
|
10077
10077
|
for (const [key, value] of this) {
|
|
10078
|
-
out.add(callback.call(thisArg,
|
|
10078
|
+
out.add(callback.call(thisArg, value, key, index++, this));
|
|
10079
10079
|
}
|
|
10080
10080
|
return out;
|
|
10081
10081
|
}
|
|
@@ -10637,7 +10637,7 @@ var dataStructureTyped = (() => {
|
|
|
10637
10637
|
const out = this._createLike([], options);
|
|
10638
10638
|
let index = 0;
|
|
10639
10639
|
for (const [key, value] of this) {
|
|
10640
|
-
out.add(callback.call(thisArg,
|
|
10640
|
+
out.add(callback.call(thisArg, value, key, index++, this));
|
|
10641
10641
|
}
|
|
10642
10642
|
return out;
|
|
10643
10643
|
}
|
|
@@ -11146,7 +11146,7 @@ var dataStructureTyped = (() => {
|
|
|
11146
11146
|
map(callback, options, thisArg) {
|
|
11147
11147
|
const out = this._createLike([], options);
|
|
11148
11148
|
let i = 0;
|
|
11149
|
-
for (const [k, v] of this) out.add(callback.call(thisArg,
|
|
11149
|
+
for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
|
|
11150
11150
|
return out;
|
|
11151
11151
|
}
|
|
11152
11152
|
/**
|
|
@@ -11421,7 +11421,7 @@ var dataStructureTyped = (() => {
|
|
|
11421
11421
|
map(callback, options, thisArg) {
|
|
11422
11422
|
const out = this._createLike([], options);
|
|
11423
11423
|
let i = 0;
|
|
11424
|
-
for (const [k, v] of this) out.add(callback.call(thisArg,
|
|
11424
|
+
for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
|
|
11425
11425
|
return out;
|
|
11426
11426
|
}
|
|
11427
11427
|
/**
|
|
@@ -11798,7 +11798,7 @@ var dataStructureTyped = (() => {
|
|
|
11798
11798
|
const out = this._createLike([], options);
|
|
11799
11799
|
let index = 0;
|
|
11800
11800
|
for (const [key, value] of this) {
|
|
11801
|
-
out.add(callback.call(thisArg,
|
|
11801
|
+
out.add(callback.call(thisArg, value, key, index++, this));
|
|
11802
11802
|
}
|
|
11803
11803
|
return out;
|
|
11804
11804
|
}
|
|
@@ -12218,7 +12218,7 @@ var dataStructureTyped = (() => {
|
|
|
12218
12218
|
const out = this._createLike([], options);
|
|
12219
12219
|
let index = 0;
|
|
12220
12220
|
for (const [key, value] of this) {
|
|
12221
|
-
out.add(callback.call(thisArg,
|
|
12221
|
+
out.add(callback.call(thisArg, value, key, index++, this));
|
|
12222
12222
|
}
|
|
12223
12223
|
return out;
|
|
12224
12224
|
}
|