data-structure-typed 2.5.3 → 2.6.1
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/.github/workflows/ci.yml +7 -2
- package/.github/workflows/release-package.yml +9 -2
- package/.husky/pre-commit +3 -0
- package/CHANGELOG.md +1 -1
- package/MIGRATION.md +48 -0
- package/README.md +20 -2
- package/README_CN.md +20 -2
- package/SPECIFICATION.md +24 -0
- package/SPECIFICATION.zh-CN.md +24 -0
- package/dist/cjs/binary-tree.cjs +1897 -19
- package/dist/cjs/graph.cjs +174 -0
- package/dist/cjs/hash.cjs +33 -0
- package/dist/cjs/heap.cjs +71 -0
- package/dist/cjs/index.cjs +2383 -3
- package/dist/cjs/linked-list.cjs +224 -2
- package/dist/cjs/matrix.cjs +24 -0
- package/dist/cjs/priority-queue.cjs +71 -0
- package/dist/cjs/queue.cjs +221 -1
- package/dist/cjs/stack.cjs +59 -0
- package/dist/cjs/trie.cjs +62 -0
- package/dist/cjs-legacy/binary-tree.cjs +1897 -19
- package/dist/cjs-legacy/graph.cjs +174 -0
- package/dist/cjs-legacy/hash.cjs +33 -0
- package/dist/cjs-legacy/heap.cjs +71 -0
- package/dist/cjs-legacy/index.cjs +2383 -3
- package/dist/cjs-legacy/linked-list.cjs +224 -2
- package/dist/cjs-legacy/matrix.cjs +24 -0
- package/dist/cjs-legacy/priority-queue.cjs +71 -0
- package/dist/cjs-legacy/queue.cjs +221 -1
- package/dist/cjs-legacy/stack.cjs +59 -0
- package/dist/cjs-legacy/trie.cjs +62 -0
- package/dist/esm/binary-tree.mjs +1897 -19
- package/dist/esm/graph.mjs +174 -0
- package/dist/esm/hash.mjs +33 -0
- package/dist/esm/heap.mjs +71 -0
- package/dist/esm/index.mjs +2383 -3
- package/dist/esm/linked-list.mjs +224 -2
- package/dist/esm/matrix.mjs +24 -0
- package/dist/esm/priority-queue.mjs +71 -0
- package/dist/esm/queue.mjs +221 -1
- package/dist/esm/stack.mjs +59 -0
- package/dist/esm/trie.mjs +62 -0
- package/dist/esm-legacy/binary-tree.mjs +1897 -19
- package/dist/esm-legacy/graph.mjs +174 -0
- package/dist/esm-legacy/hash.mjs +33 -0
- package/dist/esm-legacy/heap.mjs +71 -0
- package/dist/esm-legacy/index.mjs +2383 -3
- package/dist/esm-legacy/linked-list.mjs +224 -2
- package/dist/esm-legacy/matrix.mjs +24 -0
- package/dist/esm-legacy/priority-queue.mjs +71 -0
- package/dist/esm-legacy/queue.mjs +221 -1
- package/dist/esm-legacy/stack.mjs +59 -0
- package/dist/esm-legacy/trie.mjs +62 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
- package/dist/types/data-structures/base/linear-base.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +36 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +75 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +72 -0
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +375 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +389 -0
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +330 -0
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +438 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
- package/dist/types/data-structures/heap/heap.d.ts +42 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
- package/dist/types/data-structures/queue/deque.d.ts +90 -1
- package/dist/types/data-structures/queue/queue.d.ts +36 -0
- package/dist/types/data-structures/stack/stack.d.ts +30 -0
- package/dist/types/data-structures/trie/trie.d.ts +36 -0
- package/dist/umd/data-structure-typed.js +2383 -3
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +108 -108
- package/docs-site-docusaurus/docs/api/classes/BST.md +101 -101
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +66 -66
- package/docs-site-docusaurus/docs/api/classes/Deque.md +235 -51
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +21 -21
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +231 -67
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +14 -14
- package/docs-site-docusaurus/docs/api/classes/Heap.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +83 -13
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +124 -20
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +140 -32
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +30 -26
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +159 -51
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +20 -20
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/Queue.md +142 -34
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +117 -117
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +158 -50
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +21 -21
- package/docs-site-docusaurus/docs/api/classes/Stack.md +108 -26
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +33 -33
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +75 -39
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +301 -39
- package/docs-site-docusaurus/docs/api/classes/Trie.md +110 -28
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +20 -20
- package/jest.integration.config.js +1 -2
- package/package.json +51 -50
- package/src/common/error.ts +15 -32
- package/src/common/index.ts +0 -3
- package/src/data-structures/base/iterable-element-base.ts +32 -3
- package/src/data-structures/base/linear-base.ts +13 -36
- package/src/data-structures/binary-tree/avl-tree.ts +31 -493
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +47 -530
- package/src/data-structures/binary-tree/binary-tree.ts +326 -1236
- package/src/data-structures/binary-tree/bst.ts +158 -1010
- package/src/data-structures/binary-tree/red-black-tree.ts +451 -1233
- package/src/data-structures/binary-tree/segment-tree.ts +73 -333
- package/src/data-structures/binary-tree/tree-map.ts +462 -4749
- package/src/data-structures/binary-tree/tree-multi-map.ts +310 -4530
- package/src/data-structures/binary-tree/tree-multi-set.ts +300 -3652
- package/src/data-structures/binary-tree/tree-set.ts +437 -4443
- package/src/data-structures/graph/abstract-graph.ts +98 -167
- package/src/data-structures/graph/directed-graph.ts +137 -532
- package/src/data-structures/graph/map-graph.ts +0 -3
- package/src/data-structures/graph/undirected-graph.ts +132 -484
- package/src/data-structures/hash/hash-map.ts +154 -549
- package/src/data-structures/heap/heap.ts +200 -753
- package/src/data-structures/linked-list/doubly-linked-list.ts +153 -809
- package/src/data-structures/linked-list/singly-linked-list.ts +122 -749
- package/src/data-structures/linked-list/skip-linked-list.ts +211 -864
- package/src/data-structures/matrix/matrix.ts +179 -494
- package/src/data-structures/matrix/navigator.ts +0 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -6
- package/src/data-structures/priority-queue/min-priority-queue.ts +6 -11
- package/src/data-structures/priority-queue/priority-queue.ts +1 -2
- package/src/data-structures/queue/deque.ts +241 -807
- package/src/data-structures/queue/queue.ts +102 -589
- package/src/data-structures/stack/stack.ts +76 -475
- package/src/data-structures/trie/trie.ts +98 -592
- package/src/types/common.ts +0 -10
- package/src/types/data-structures/binary-tree/bst.ts +0 -7
- package/src/types/data-structures/binary-tree/red-black-tree.ts +0 -1
- package/src/types/data-structures/graph/abstract-graph.ts +0 -2
- package/src/types/data-structures/hash/hash-map.ts +0 -3
- package/src/types/data-structures/hash/index.ts +0 -1
- package/src/types/data-structures/matrix/navigator.ts +0 -2
- package/src/types/utils/utils.ts +0 -7
- package/src/types/utils/validate-type.ts +0 -7
- package/src/utils/number.ts +0 -2
- package/src/utils/utils.ts +0 -5
package/src/types/common.ts
CHANGED
|
@@ -1,25 +1,15 @@
|
|
|
1
1
|
export type CP = 1 | -1 | 0;
|
|
2
|
-
|
|
3
2
|
export type IterationType = 'ITERATIVE' | 'RECURSIVE';
|
|
4
|
-
|
|
5
3
|
export type FamilyPosition = 'ROOT' | 'LEFT' | 'RIGHT' | 'ROOT_LEFT' | 'ROOT_RIGHT' | 'ISOLATED' | 'MAL_NODE';
|
|
6
|
-
|
|
7
4
|
export type Comparator<K> = (a: K, b: K) => number;
|
|
8
|
-
|
|
9
5
|
export type DFSOrderPattern = 'PRE' | 'IN' | 'POST';
|
|
10
|
-
|
|
11
6
|
export type NodeDisplayLayout = [string[], number, number, number];
|
|
12
|
-
|
|
13
7
|
export interface IterableWithSize<T> extends Iterable<T> {
|
|
14
8
|
size: number | ((...args: unknown[]) => number);
|
|
15
9
|
}
|
|
16
|
-
|
|
17
10
|
export interface IterableWithLength<T> extends Iterable<T> {
|
|
18
11
|
length: number | ((...args: unknown[]) => number);
|
|
19
12
|
}
|
|
20
|
-
|
|
21
13
|
export type OptValue<V> = V | undefined;
|
|
22
|
-
|
|
23
14
|
export type IterableWithSizeOrLength<T> = IterableWithSize<T> | IterableWithLength<T>;
|
|
24
|
-
|
|
25
15
|
export type CRUD = 'CREATED' | 'READ' | 'UPDATED' | 'DELETED';
|
|
@@ -2,19 +2,12 @@ import type { BinaryTreeOptions } from './binary-tree';
|
|
|
2
2
|
import type { Comparator, OptValue } from '../../common';
|
|
3
3
|
|
|
4
4
|
type BSTBaseOptions<K, V, R> = Omit<BinaryTreeOptions<K, V, R>, 'isDuplicate'>;
|
|
5
|
-
|
|
6
5
|
export type BSTOptions<K, V, R> = BSTBaseOptions<K, V, R> & {
|
|
7
6
|
comparator?: Comparator<K>;
|
|
8
7
|
enableOrderStatistic?: boolean;
|
|
9
8
|
}
|
|
10
|
-
|
|
11
9
|
export type BSTNOptKey<K> = K | undefined;
|
|
12
|
-
|
|
13
10
|
export type OptNode<NODE> = NODE | undefined;
|
|
14
|
-
|
|
15
11
|
export type BSTNEntry<K, V> = [BSTNOptKey<K>, OptValue<V>];
|
|
16
|
-
|
|
17
12
|
export type BSTNOptKeyOrNode<K, NODE> = BSTNOptKey<K> | NODE;
|
|
18
|
-
|
|
19
13
|
export type BSTNRep<K, V, NODE> = BSTNEntry<K, V> | BSTNOptKeyOrNode<K, NODE>;
|
|
20
|
-
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export type VertexKey = string | number;
|
|
2
|
-
|
|
3
2
|
export type DijkstraResult<V> =
|
|
4
3
|
| {
|
|
5
4
|
distMap: Map<V, number>;
|
|
@@ -11,7 +10,6 @@ export type DijkstraResult<V> =
|
|
|
11
10
|
minPath: V[];
|
|
12
11
|
}
|
|
13
12
|
| undefined;
|
|
14
|
-
|
|
15
13
|
export type GraphOptions<V = any> = {
|
|
16
14
|
vertexValueInitializer?: (key: VertexKey) => V;
|
|
17
15
|
defaultEdgeWeight?: number;
|
|
@@ -4,16 +4,13 @@ export type HashMapLinkedNode<K, V> = {
|
|
|
4
4
|
next: HashMapLinkedNode<K, V>;
|
|
5
5
|
prev: HashMapLinkedNode<K, V>;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
7
|
export type LinkedHashMapOptions<K, V, R> = {
|
|
9
8
|
hashFn?: (key: K) => string;
|
|
10
9
|
objHashFn?: (key: K) => object;
|
|
11
10
|
toEntryFn?: (rawElement: R) => [K, V];
|
|
12
11
|
};
|
|
13
|
-
|
|
14
12
|
export type HashMapOptions<K, V, R> = {
|
|
15
13
|
hashFn?: (key: K) => string;
|
|
16
14
|
toEntryFn?: (rawElement: R) => [K, V];
|
|
17
15
|
};
|
|
18
|
-
|
|
19
16
|
export type HashMapStoreItem<K, V> = { key: K; value: V };
|
package/src/types/utils/utils.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
2
|
-
|
|
3
2
|
export type Any = string | number | bigint | boolean | symbol | undefined | object;
|
|
4
|
-
|
|
5
3
|
export type Arithmetic = number | bigint;
|
|
6
|
-
|
|
7
4
|
export type ElemOf<T> = T extends (infer U)[] ? U : never;
|
|
8
|
-
|
|
9
5
|
export type ComparablePrimitive = number | bigint | string | boolean;
|
|
10
6
|
|
|
11
7
|
export interface BaseComparableObject {
|
|
@@ -22,12 +18,9 @@ export interface StringComparableObject extends BaseComparableObject {
|
|
|
22
18
|
}
|
|
23
19
|
|
|
24
20
|
export type ComparableObject = ValueComparableObject | StringComparableObject;
|
|
25
|
-
|
|
26
21
|
export type Comparable = ComparablePrimitive | Date | ComparableObject;
|
|
27
|
-
|
|
28
22
|
export type TrampolineThunk<T> = {
|
|
29
23
|
readonly isThunk: true;
|
|
30
24
|
readonly fn: () => Trampoline<T>;
|
|
31
25
|
};
|
|
32
|
-
|
|
33
26
|
export type Trampoline<T> = T | TrampolineThunk<T>;
|
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
export type KeyValueObject = { [key: string]: unknown };
|
|
2
|
-
|
|
3
2
|
export type KeyValueObjectWithKey = { [key: string]: unknown; key: string | number | symbol };
|
|
4
|
-
|
|
5
3
|
export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
|
|
6
|
-
|
|
7
4
|
export type ObjectWithoutKey = Omit<KeyValueObject, 'key'>;
|
|
8
|
-
|
|
9
5
|
export type ObjectWithNonNumberKey = {
|
|
10
6
|
[key: string]: unknown;
|
|
11
7
|
key: string | boolean | symbol | null | object | undefined;
|
|
12
8
|
};
|
|
13
|
-
|
|
14
9
|
export type ObjectWithNumberKey = {
|
|
15
10
|
[key: string]: unknown;
|
|
16
11
|
key: number;
|
|
17
12
|
};
|
|
18
|
-
|
|
19
13
|
export type RestrictValByKey =
|
|
20
14
|
| NonNumberNonObjectButDefined
|
|
21
15
|
| ObjectWithoutKey
|
|
22
16
|
| ObjectWithNonNumberKey
|
|
23
17
|
| ObjectWithNumberKey;
|
|
24
|
-
|
|
25
18
|
export type DummyAny =
|
|
26
19
|
| string
|
|
27
20
|
| number
|
package/src/utils/number.ts
CHANGED
|
@@ -14,9 +14,7 @@
|
|
|
14
14
|
export function toBinaryString(num: number, digit = 32) {
|
|
15
15
|
// Convert number to binary string
|
|
16
16
|
let binaryString = (num >>> 0).toString(2); // Use the unsigned right shift operator to ensure you get a binary representation of a 32-bit unsigned integer
|
|
17
|
-
|
|
18
17
|
// Use pad Start to ensure the string length is 32 bits
|
|
19
18
|
binaryString = binaryString.padStart(digit, '0');
|
|
20
|
-
|
|
21
19
|
return binaryString;
|
|
22
20
|
}
|
package/src/utils/utils.ts
CHANGED
|
@@ -34,7 +34,6 @@ export const arrayRemove = function <T>(array: T[], predicate: (item: T, index:
|
|
|
34
34
|
let i = -1,
|
|
35
35
|
len = array ? array.length : 0;
|
|
36
36
|
const result = [];
|
|
37
|
-
|
|
38
37
|
while (++i < len) {
|
|
39
38
|
const value = array[i];
|
|
40
39
|
if (predicate(value, i, array)) {
|
|
@@ -43,7 +42,6 @@ export const arrayRemove = function <T>(array: T[], predicate: (item: T, index:
|
|
|
43
42
|
len--;
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
|
-
|
|
47
45
|
return result;
|
|
48
46
|
};
|
|
49
47
|
|
|
@@ -190,7 +188,6 @@ function tryObjectToPrimitive(obj: object): ComparablePrimitive | null {
|
|
|
190
188
|
export function isComparable(value: unknown, isForceObjectComparable = false): value is Comparable {
|
|
191
189
|
if (value === null || value === undefined) return false;
|
|
192
190
|
if (isPrimitiveComparable(value)) return true;
|
|
193
|
-
|
|
194
191
|
if (typeof value !== 'object') return false;
|
|
195
192
|
if (value instanceof Date) return true;
|
|
196
193
|
// if (value instanceof Date) return !Number.isNaN(value.getTime());
|
|
@@ -303,12 +300,10 @@ export function makeTrampoline<Args extends any[], Result>(
|
|
|
303
300
|
*/
|
|
304
301
|
export async function asyncTrampoline<T>(initial: Trampoline<T> | Promise<Trampoline<T>>): Promise<T> {
|
|
305
302
|
let current = await initial; // Wait for the initial step to resolve if it's a Promise
|
|
306
|
-
|
|
307
303
|
// Keep executing thunks until we reach a non-thunk (final) value
|
|
308
304
|
while (isTrampolineThunk(current)) {
|
|
309
305
|
current = await current.fn(); // Execute the thunk function (may be async)
|
|
310
306
|
}
|
|
311
|
-
|
|
312
307
|
// Once the final value is reached, return it
|
|
313
308
|
return current;
|
|
314
309
|
}
|