red-black-tree-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/dist/cjs/index.cjs +8 -8
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +8 -8
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +8 -8
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +8 -8
- 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/red-black-tree-typed.js +8 -8
- package/dist/umd/red-black-tree-typed.js.map +1 -1
- package/dist/umd/red-black-tree-typed.min.js +2 -2
- package/dist/umd/red-black-tree-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
|
@@ -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;
|
|
@@ -911,7 +911,7 @@ var redBlackTreeTyped = (() => {
|
|
|
911
911
|
every(predicate, thisArg) {
|
|
912
912
|
let index = 0;
|
|
913
913
|
for (const item of this) {
|
|
914
|
-
if (!predicate.call(thisArg, item[
|
|
914
|
+
if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
|
|
915
915
|
return false;
|
|
916
916
|
}
|
|
917
917
|
}
|
|
@@ -927,7 +927,7 @@ var redBlackTreeTyped = (() => {
|
|
|
927
927
|
some(predicate, thisArg) {
|
|
928
928
|
let index = 0;
|
|
929
929
|
for (const item of this) {
|
|
930
|
-
if (predicate.call(thisArg, item[
|
|
930
|
+
if (predicate.call(thisArg, item[1], item[0], index++, this)) {
|
|
931
931
|
return true;
|
|
932
932
|
}
|
|
933
933
|
}
|
|
@@ -943,7 +943,7 @@ var redBlackTreeTyped = (() => {
|
|
|
943
943
|
let index = 0;
|
|
944
944
|
for (const item of this) {
|
|
945
945
|
const [key, value] = item;
|
|
946
|
-
callbackfn.call(thisArg,
|
|
946
|
+
callbackfn.call(thisArg, value, key, index++, this);
|
|
947
947
|
}
|
|
948
948
|
}
|
|
949
949
|
/**
|
|
@@ -957,7 +957,7 @@ var redBlackTreeTyped = (() => {
|
|
|
957
957
|
let index = 0;
|
|
958
958
|
for (const item of this) {
|
|
959
959
|
const [key, value] = item;
|
|
960
|
-
if (callbackfn.call(thisArg,
|
|
960
|
+
if (callbackfn.call(thisArg, value, key, index++, this)) return item;
|
|
961
961
|
}
|
|
962
962
|
return;
|
|
963
963
|
}
|
|
@@ -2208,7 +2208,7 @@ var redBlackTreeTyped = (() => {
|
|
|
2208
2208
|
filter(predicate, thisArg) {
|
|
2209
2209
|
const out = this._createInstance();
|
|
2210
2210
|
let i = 0;
|
|
2211
|
-
for (const [k, v] of this) if (predicate.call(thisArg,
|
|
2211
|
+
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.add([k, v]);
|
|
2212
2212
|
return out;
|
|
2213
2213
|
}
|
|
2214
2214
|
/**
|
|
@@ -2226,7 +2226,7 @@ var redBlackTreeTyped = (() => {
|
|
|
2226
2226
|
map(cb, options, thisArg) {
|
|
2227
2227
|
const out = this._createLike([], options);
|
|
2228
2228
|
let i = 0;
|
|
2229
|
-
for (const [k, v] of this) out.add(cb.call(thisArg,
|
|
2229
|
+
for (const [k, v] of this) out.add(cb.call(thisArg, v, k, i++, this));
|
|
2230
2230
|
return out;
|
|
2231
2231
|
}
|
|
2232
2232
|
/**
|
|
@@ -3322,7 +3322,7 @@ var redBlackTreeTyped = (() => {
|
|
|
3322
3322
|
const out = this._createLike([], options);
|
|
3323
3323
|
let index = 0;
|
|
3324
3324
|
for (const [key, value] of this) {
|
|
3325
|
-
out.add(callback.call(thisArg,
|
|
3325
|
+
out.add(callback.call(thisArg, value, key, index++, this));
|
|
3326
3326
|
}
|
|
3327
3327
|
return out;
|
|
3328
3328
|
}
|
|
@@ -3760,7 +3760,7 @@ var redBlackTreeTyped = (() => {
|
|
|
3760
3760
|
const out = this._createLike([], options);
|
|
3761
3761
|
let index = 0;
|
|
3762
3762
|
for (const [key, value] of this) {
|
|
3763
|
-
out.add(callback.call(thisArg,
|
|
3763
|
+
out.add(callback.call(thisArg, value, key, index++, this));
|
|
3764
3764
|
}
|
|
3765
3765
|
return out;
|
|
3766
3766
|
}
|