data-structure-typed 1.49.3 → 1.49.5
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 +70 -69
- package/README_zh-CN.md +44 -49
- package/benchmark/report.html +16 -16
- package/benchmark/report.json +187 -187
- package/dist/cjs/data-structures/base/iterable-base.d.ts +1 -1
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +2 -14
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +19 -49
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +0 -16
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +1 -43
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +2 -11
- package/dist/cjs/data-structures/graph/abstract-graph.js +3 -19
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.js +4 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +1 -1
- package/dist/cjs/data-structures/hash/hash-map.js +2 -2
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.js +2 -3
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/index.d.ts +0 -2
- package/dist/cjs/data-structures/matrix/index.js +0 -2
- package/dist/cjs/data-structures/matrix/index.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.d.ts +128 -10
- package/dist/cjs/data-structures/matrix/matrix.js +400 -15
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +2 -2
- package/dist/cjs/data-structures/queue/deque.js +5 -7
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
- package/dist/cjs/types/data-structures/heap/heap.d.ts +1 -1
- package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/cjs/utils/utils.d.ts +1 -0
- package/dist/cjs/utils/utils.js +6 -1
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/base/iterable-base.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +2 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +2 -14
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +20 -50
- package/dist/mjs/data-structures/binary-tree/bst.js +2 -1
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +2 -1
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +0 -16
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +3 -44
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +2 -11
- package/dist/mjs/data-structures/graph/abstract-graph.js +4 -20
- package/dist/mjs/data-structures/graph/directed-graph.js +4 -0
- package/dist/mjs/data-structures/hash/hash-map.d.ts +1 -1
- package/dist/mjs/data-structures/hash/hash-map.js +2 -2
- package/dist/mjs/data-structures/heap/heap.js +2 -3
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +1 -1
- package/dist/mjs/data-structures/matrix/index.d.ts +0 -2
- package/dist/mjs/data-structures/matrix/index.js +0 -2
- package/dist/mjs/data-structures/matrix/matrix.d.ts +128 -10
- package/dist/mjs/data-structures/matrix/matrix.js +399 -16
- package/dist/mjs/data-structures/queue/deque.d.ts +2 -2
- package/dist/mjs/data-structures/queue/deque.js +7 -9
- package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/mjs/data-structures/queue/queue.js +1 -1
- package/dist/mjs/types/data-structures/base/base.d.ts +1 -1
- package/dist/mjs/types/data-structures/heap/heap.d.ts +1 -1
- package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/mjs/utils/utils.d.ts +1 -0
- package/dist/mjs/utils/utils.js +4 -0
- package/dist/umd/data-structure-typed.js +361 -542
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +4 -3
- package/src/data-structures/base/index.ts +1 -1
- package/src/data-structures/base/iterable-base.ts +7 -10
- package/src/data-structures/binary-tree/avl-tree.ts +15 -8
- package/src/data-structures/binary-tree/binary-tree.ts +57 -74
- package/src/data-structures/binary-tree/bst.ts +16 -13
- package/src/data-structures/binary-tree/rb-tree.ts +16 -10
- package/src/data-structures/binary-tree/tree-multimap.ts +11 -48
- package/src/data-structures/graph/abstract-graph.ts +14 -24
- package/src/data-structures/graph/directed-graph.ts +8 -6
- package/src/data-structures/graph/map-graph.ts +6 -1
- package/src/data-structures/graph/undirected-graph.ts +4 -7
- package/src/data-structures/hash/hash-map.ts +18 -16
- package/src/data-structures/heap/heap.ts +7 -10
- package/src/data-structures/heap/max-heap.ts +2 -1
- package/src/data-structures/heap/min-heap.ts +2 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +3 -5
- package/src/data-structures/matrix/index.ts +0 -2
- package/src/data-structures/matrix/matrix.ts +442 -13
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -10
- package/src/data-structures/queue/deque.ts +18 -39
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/interfaces/binary-tree.ts +7 -2
- package/src/types/common.ts +4 -4
- package/src/types/data-structures/base/base.ts +14 -3
- package/src/types/data-structures/base/index.ts +1 -1
- package/src/types/data-structures/graph/abstract-graph.ts +4 -2
- package/src/types/data-structures/hash/hash-map.ts +3 -3
- package/src/types/data-structures/heap/heap.ts +2 -2
- package/src/types/data-structures/priority-queue/priority-queue.ts +2 -2
- package/src/utils/utils.ts +7 -1
- package/test/integration/avl-tree.test.ts +18 -1
- package/test/integration/bst.test.ts +2 -2
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +1 -1
- package/test/performance/data-structures/comparison/comparison.test.ts +18 -23
- package/test/performance/data-structures/hash/hash-map.test.ts +3 -4
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +16 -28
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +4 -12
- package/test/performance/data-structures/queue/deque.test.ts +11 -12
- package/test/performance/data-structures/queue/queue.test.ts +15 -14
- package/test/performance/data-structures/stack/stack.test.ts +11 -11
- package/test/performance/reportor.ts +14 -15
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +14 -3
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +65 -15
- package/test/unit/data-structures/binary-tree/bst.test.ts +52 -26
- package/test/unit/data-structures/binary-tree/overall.test.ts +16 -18
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +17 -6
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -21
- package/test/unit/data-structures/graph/abstract-graph.test.ts +11 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +112 -40
- package/test/unit/data-structures/graph/undirected-graph.test.ts +63 -33
- package/test/unit/data-structures/hash/hash-map.test.ts +64 -23
- package/test/unit/data-structures/hash/hash-table.test.ts +0 -4
- package/test/unit/data-structures/heap/heap.test.ts +0 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +6 -5
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -4
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -4
- package/test/unit/data-structures/matrix/matrix.test.ts +345 -52
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +0 -1
- package/test/unit/data-structures/queue/deque.test.ts +0 -6
- package/test/unit/data-structures/queue/queue.test.ts +1 -1
- package/test/unit/data-structures/stack/stack.test.ts +3 -4
- package/test/unit/unrestricted-interconversion.test.ts +50 -44
- package/test/utils/big-o.ts +14 -14
- package/test/utils/performanc.ts +1 -1
- package/typedoc.json +30 -0
- package/dist/cjs/data-structures/matrix/matrix2d.d.ts +0 -107
- package/dist/cjs/data-structures/matrix/matrix2d.js +0 -200
- package/dist/cjs/data-structures/matrix/matrix2d.js.map +0 -1
- package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -200
- package/dist/cjs/data-structures/matrix/vector2d.js +0 -291
- package/dist/cjs/data-structures/matrix/vector2d.js.map +0 -1
- package/dist/mjs/data-structures/matrix/matrix2d.d.ts +0 -107
- package/dist/mjs/data-structures/matrix/matrix2d.js +0 -196
- package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -200
- package/dist/mjs/data-structures/matrix/vector2d.js +0 -289
- package/src/data-structures/matrix/matrix2d.ts +0 -211
- package/src/data-structures/matrix/vector2d.ts +0 -315
- package/test/unit/data-structures/matrix/matrix2d.test.ts +0 -345
- package/test/unit/data-structures/matrix/vector2d.test.ts +0 -171
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IterableElementBase } from
|
|
2
|
-
import { calcMinUnitsRequired, rangeCheck } from
|
|
1
|
+
import { IterableElementBase } from '../base';
|
|
2
|
+
import { calcMinUnitsRequired, rangeCheck } from '../../utils';
|
|
3
3
|
/**
|
|
4
4
|
* 1. Operations at Both Ends: Supports adding and removing elements at both the front and back of the queue. This allows it to be used as a stack (last in, first out) and a queue (first in, first out).
|
|
5
5
|
* 2. Efficient Random Access: Being based on an array, it offers fast random access capability, allowing constant time access to any element.
|
|
@@ -23,7 +23,7 @@ export class Deque extends IterableElementBase {
|
|
|
23
23
|
* @param bucketSize - The `bucketSize` parameter is the maximum number of elements that can be
|
|
24
24
|
* stored in each bucket. It determines the size of each bucket in the data structure.
|
|
25
25
|
*/
|
|
26
|
-
constructor(elements = [], bucketSize =
|
|
26
|
+
constructor(elements = [], bucketSize = 1 << 12) {
|
|
27
27
|
super();
|
|
28
28
|
let _size;
|
|
29
29
|
if ('length' in elements) {
|
|
@@ -45,7 +45,7 @@ export class Deque extends IterableElementBase {
|
|
|
45
45
|
}
|
|
46
46
|
const needBucketNum = calcMinUnitsRequired(_size, this._bucketSize);
|
|
47
47
|
this._bucketFirst = this._bucketLast = (this._bucketCount >> 1) - (needBucketNum >> 1);
|
|
48
|
-
this._firstInBucket = this._lastInBucket = (this._bucketSize - _size % this._bucketSize) >> 1;
|
|
48
|
+
this._firstInBucket = this._lastInBucket = (this._bucketSize - (_size % this._bucketSize)) >> 1;
|
|
49
49
|
for (const element of elements) {
|
|
50
50
|
this.push(element);
|
|
51
51
|
}
|
|
@@ -99,8 +99,7 @@ export class Deque extends IterableElementBase {
|
|
|
99
99
|
this._bucketLast = 0;
|
|
100
100
|
this._lastInBucket = 0;
|
|
101
101
|
}
|
|
102
|
-
if (this._bucketLast === this._bucketFirst &&
|
|
103
|
-
this._lastInBucket === this._firstInBucket)
|
|
102
|
+
if (this._bucketLast === this._bucketFirst && this._lastInBucket === this._firstInBucket)
|
|
104
103
|
this._reallocate();
|
|
105
104
|
}
|
|
106
105
|
this._size += 1;
|
|
@@ -166,8 +165,7 @@ export class Deque extends IterableElementBase {
|
|
|
166
165
|
this._bucketFirst = this._bucketCount - 1;
|
|
167
166
|
this._firstInBucket = this._bucketSize - 1;
|
|
168
167
|
}
|
|
169
|
-
if (this._bucketFirst === this._bucketLast &&
|
|
170
|
-
this._firstInBucket === this._lastInBucket)
|
|
168
|
+
if (this._bucketFirst === this._bucketLast && this._firstInBucket === this._lastInBucket)
|
|
171
169
|
this._reallocate();
|
|
172
170
|
}
|
|
173
171
|
this._size += 1;
|
|
@@ -766,7 +764,7 @@ export class Deque extends IterableElementBase {
|
|
|
766
764
|
if (bucketIndex >= this._bucketCount) {
|
|
767
765
|
bucketIndex -= this._bucketCount;
|
|
768
766
|
}
|
|
769
|
-
indexInBucket = (overallIndex + 1) % this._bucketSize - 1;
|
|
767
|
+
indexInBucket = ((overallIndex + 1) % this._bucketSize) - 1;
|
|
770
768
|
if (indexInBucket < 0) {
|
|
771
769
|
indexInBucket = this._bucketSize - 1;
|
|
772
770
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @class
|
|
5
5
|
*/
|
|
6
6
|
import type { ElementCallback } from '../../types';
|
|
7
|
-
import { IterableElementBase } from
|
|
7
|
+
import { IterableElementBase } from '../base';
|
|
8
8
|
import { SinglyLinkedList } from '../linked-list';
|
|
9
9
|
/**
|
|
10
10
|
* 1. First In, First Out (FIFO): The core feature of a queue is its first in, first out nature. The element added to the queue first will be the one to be removed first.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IterableElementBase } from
|
|
1
|
+
import { IterableElementBase } from '../base';
|
|
2
2
|
import { SinglyLinkedList } from '../linked-list';
|
|
3
3
|
/**
|
|
4
4
|
* 1. First In, First Out (FIFO): The core feature of a queue is its first in, first out nature. The element added to the queue first will be the one to be removed first.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IterableElementBase, IterableEntryBase } from
|
|
1
|
+
import { IterableElementBase, IterableEntryBase } from '../../../data-structures';
|
|
2
2
|
export type EntryCallback<K, V, R> = (value: V, key: K, index: number, container: IterableEntryBase<K, V>) => R;
|
|
3
3
|
export type ElementCallback<V, R> = (element: V, index: number, container: IterableElementBase<V>) => R;
|
|
4
4
|
export type ReduceEntryCallback<K, V, R> = (accumulator: R, value: V, key: K, index: number, container: IterableEntryBase<K, V>) => R;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { HeapOptions } from
|
|
1
|
+
import { HeapOptions } from '../heap';
|
|
2
2
|
export type PriorityQueueOptions<T> = HeapOptions<T> & {};
|
|
@@ -22,3 +22,4 @@ export declare const rangeCheck: (index: number, min: number, max: number, messa
|
|
|
22
22
|
export declare const throwRangeError: (message?: string) => void;
|
|
23
23
|
export declare const isWeakKey: (input: unknown) => input is object;
|
|
24
24
|
export declare const calcMinUnitsRequired: (totalQuantity: number, unitSize: number) => number;
|
|
25
|
+
export declare const roundFixed: (num: number, digit?: number) => number;
|
package/dist/mjs/utils/utils.js
CHANGED
|
@@ -64,3 +64,7 @@ export const isWeakKey = (input) => {
|
|
|
64
64
|
return (inputType === 'object' && input !== null) || inputType === 'function';
|
|
65
65
|
};
|
|
66
66
|
export const calcMinUnitsRequired = (totalQuantity, unitSize) => Math.floor((totalQuantity + unitSize - 1) / unitSize);
|
|
67
|
+
export const roundFixed = (num, digit = 10) => {
|
|
68
|
+
const multiplier = Math.pow(10, digit);
|
|
69
|
+
return Math.round(num * multiplier) / multiplier;
|
|
70
|
+
};
|