doubly-linked-list-typed 2.1.1 → 2.1.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 +1299 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.mjs +1294 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/data-structures/base/index.d.ts +2 -1
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
- package/dist/types/data-structures/binary-tree/bst.d.ts +413 -12
- package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -3
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +270 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
- package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
- package/dist/types/data-structures/graph/index.d.ts +2 -1
- package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +503 -5
- package/dist/types/data-structures/heap/index.d.ts +2 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
- package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
- package/dist/types/data-structures/index.d.ts +7 -7
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
- package/dist/types/data-structures/matrix/index.d.ts +1 -1
- package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
- package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
- package/dist/types/data-structures/queue/deque.d.ts +431 -4
- package/dist/types/data-structures/queue/queue.d.ts +308 -4
- package/dist/types/data-structures/stack/stack.d.ts +306 -2
- package/dist/types/data-structures/tree/tree.d.ts +62 -1
- package/dist/types/data-structures/trie/trie.d.ts +350 -4
- package/dist/types/index.d.ts +11 -2
- package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +1 -1
- package/dist/types/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
- package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
- package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
- package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
- package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
- package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
- package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
- package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
- package/dist/types/types/data-structures/hash/index.d.ts +2 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
- package/dist/types/types/data-structures/heap/index.d.ts +1 -0
- package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
- package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
- package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
- package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
- package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
- package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
- package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
- package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
- package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
- package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/utils/index.d.ts +2 -0
- package/dist/types/types/utils/utils.d.ts +22 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/utils.d.ts +209 -22
- package/dist/umd/doubly-linked-list-typed.js +1302 -0
- package/dist/umd/doubly-linked-list-typed.js.map +1 -0
- package/dist/umd/doubly-linked-list-typed.min.js +9 -0
- package/dist/umd/doubly-linked-list-typed.min.js.map +1 -0
- package/package.json +25 -5
- package/src/data-structures/binary-tree/avl-tree-counter.ts +4 -4
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +2 -2
- package/src/data-structures/binary-tree/binary-tree.ts +4 -4
- package/src/data-structures/binary-tree/bst.ts +1 -1
- package/src/data-structures/binary-tree/red-black-tree.ts +2 -2
- package/src/data-structures/binary-tree/tree-counter.ts +4 -4
- package/src/data-structures/binary-tree/tree-multi-map.ts +1 -1
- package/src/data-structures/heap/heap.ts +5 -5
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
- package/src/interfaces/binary-tree.ts +1 -1
- package/tsconfig.base.json +23 -0
- package/tsconfig.json +8 -34
- package/tsconfig.test.json +8 -0
- package/tsconfig.types.json +15 -0
- package/tsup.config.js +28 -0
- package/tsup.node.config.js +37 -0
- package/dist/common/index.js +0 -28
- package/dist/constants/index.js +0 -8
- package/dist/data-structures/base/index.d.ts +0 -2
- package/dist/data-structures/base/index.js +0 -18
- package/dist/data-structures/base/iterable-element-base.js +0 -243
- package/dist/data-structures/base/iterable-entry-base.js +0 -183
- package/dist/data-structures/base/linear-base.js +0 -415
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
- package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
- package/dist/data-structures/binary-tree/avl-tree.js +0 -611
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
- package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
- package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
- package/dist/data-structures/binary-tree/bst.d.ts +0 -413
- package/dist/data-structures/binary-tree/bst.js +0 -903
- package/dist/data-structures/binary-tree/index.js +0 -26
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
- package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
- package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
- package/dist/data-structures/binary-tree/segment-tree.js +0 -297
- package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
- package/dist/data-structures/binary-tree/tree-counter.js +0 -413
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
- package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
- package/dist/data-structures/graph/abstract-graph.js +0 -896
- package/dist/data-structures/graph/directed-graph.d.ts +0 -207
- package/dist/data-structures/graph/directed-graph.js +0 -525
- package/dist/data-structures/graph/index.js +0 -20
- package/dist/data-structures/graph/map-graph.d.ts +0 -78
- package/dist/data-structures/graph/map-graph.js +0 -107
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
- package/dist/data-structures/graph/undirected-graph.js +0 -424
- package/dist/data-structures/hash/hash-map.d.ts +0 -345
- package/dist/data-structures/hash/hash-map.js +0 -692
- package/dist/data-structures/hash/index.d.ts +0 -1
- package/dist/data-structures/hash/index.js +0 -17
- package/dist/data-structures/heap/heap.d.ts +0 -503
- package/dist/data-structures/heap/heap.js +0 -901
- package/dist/data-structures/heap/index.d.ts +0 -3
- package/dist/data-structures/heap/index.js +0 -19
- package/dist/data-structures/heap/max-heap.d.ts +0 -32
- package/dist/data-structures/heap/max-heap.js +0 -40
- package/dist/data-structures/heap/min-heap.d.ts +0 -33
- package/dist/data-structures/heap/min-heap.js +0 -31
- package/dist/data-structures/index.js +0 -28
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
- package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
- package/dist/data-structures/linked-list/index.js +0 -19
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
- package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
- package/dist/data-structures/matrix/index.js +0 -18
- package/dist/data-structures/matrix/matrix.d.ts +0 -168
- package/dist/data-structures/matrix/matrix.js +0 -448
- package/dist/data-structures/matrix/navigator.d.ts +0 -55
- package/dist/data-structures/matrix/navigator.js +0 -111
- package/dist/data-structures/priority-queue/index.js +0 -19
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
- package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
- package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
- package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
- package/dist/data-structures/priority-queue/priority-queue.js +0 -20
- package/dist/data-structures/queue/deque.d.ts +0 -431
- package/dist/data-structures/queue/deque.js +0 -879
- package/dist/data-structures/queue/index.js +0 -18
- package/dist/data-structures/queue/queue.d.ts +0 -308
- package/dist/data-structures/queue/queue.js +0 -473
- package/dist/data-structures/stack/index.js +0 -17
- package/dist/data-structures/stack/stack.d.ts +0 -306
- package/dist/data-structures/stack/stack.js +0 -401
- package/dist/data-structures/tree/index.js +0 -17
- package/dist/data-structures/tree/tree.d.ts +0 -62
- package/dist/data-structures/tree/tree.js +0 -107
- package/dist/data-structures/trie/index.js +0 -17
- package/dist/data-structures/trie/trie.d.ts +0 -350
- package/dist/data-structures/trie/trie.js +0 -610
- package/dist/index.d.ts +0 -12
- package/dist/index.js +0 -28
- package/dist/interfaces/binary-tree.js +0 -2
- package/dist/interfaces/doubly-linked-list.js +0 -2
- package/dist/interfaces/graph.js +0 -2
- package/dist/interfaces/heap.js +0 -2
- package/dist/interfaces/index.js +0 -24
- package/dist/interfaces/navigator.js +0 -2
- package/dist/interfaces/priority-queue.js +0 -2
- package/dist/interfaces/segment-tree.js +0 -2
- package/dist/interfaces/singly-linked-list.js +0 -2
- package/dist/types/common.js +0 -2
- package/dist/types/data-structures/base/base.js +0 -2
- package/dist/types/data-structures/base/index.js +0 -17
- package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/bst.js +0 -2
- package/dist/types/data-structures/binary-tree/index.js +0 -25
- package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
- package/dist/types/data-structures/graph/abstract-graph.js +0 -2
- package/dist/types/data-structures/graph/directed-graph.js +0 -2
- package/dist/types/data-structures/graph/index.js +0 -19
- package/dist/types/data-structures/graph/map-graph.js +0 -2
- package/dist/types/data-structures/graph/undirected-graph.js +0 -2
- package/dist/types/data-structures/hash/hash-map.js +0 -2
- package/dist/types/data-structures/hash/index.js +0 -17
- package/dist/types/data-structures/heap/heap.js +0 -2
- package/dist/types/data-structures/heap/index.js +0 -17
- package/dist/types/data-structures/heap/max-heap.js +0 -2
- package/dist/types/data-structures/heap/min-heap.js +0 -2
- package/dist/types/data-structures/index.js +0 -28
- package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/index.js +0 -19
- package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
- package/dist/types/data-structures/matrix/index.js +0 -18
- package/dist/types/data-structures/matrix/matrix.js +0 -2
- package/dist/types/data-structures/matrix/navigator.js +0 -2
- package/dist/types/data-structures/priority-queue/index.js +0 -19
- package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
- package/dist/types/data-structures/queue/deque.js +0 -2
- package/dist/types/data-structures/queue/index.js +0 -18
- package/dist/types/data-structures/queue/queue.js +0 -2
- package/dist/types/data-structures/stack/index.js +0 -17
- package/dist/types/data-structures/stack/stack.js +0 -2
- package/dist/types/data-structures/tree/index.js +0 -17
- package/dist/types/data-structures/tree/tree.js +0 -2
- package/dist/types/data-structures/trie/index.js +0 -17
- package/dist/types/data-structures/trie/trie.js +0 -2
- package/dist/types/index.js +0 -19
- package/dist/types/utils/index.js +0 -18
- package/dist/types/utils/utils.js +0 -2
- package/dist/types/utils/validate-type.js +0 -2
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -18
- package/dist/utils/number.js +0 -24
- package/dist/utils/utils.d.ts +0 -209
- package/dist/utils/utils.js +0 -353
- package/dist/{common → types/common}/index.d.ts +0 -0
- package/dist/{constants → types/constants}/index.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
- package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
- package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
- package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
- /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
- /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
- /package/dist/{utils → types/utils}/number.d.ts +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
2
|
+
export type Any = string | number | bigint | boolean | symbol | undefined | object;
|
|
3
|
+
export type Arithmetic = number | bigint;
|
|
4
|
+
export type ElemOf<T> = T extends (infer U)[] ? U : never;
|
|
5
|
+
export type ComparablePrimitive = number | bigint | string | boolean;
|
|
6
|
+
export interface BaseComparableObject {
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface ValueComparableObject extends BaseComparableObject {
|
|
10
|
+
valueOf: () => ComparablePrimitive | ValueComparableObject;
|
|
11
|
+
toString?: () => string;
|
|
12
|
+
}
|
|
13
|
+
export interface StringComparableObject extends BaseComparableObject {
|
|
14
|
+
toString: () => string;
|
|
15
|
+
}
|
|
16
|
+
export type ComparableObject = ValueComparableObject | StringComparableObject;
|
|
17
|
+
export type Comparable = ComparablePrimitive | Date | ComparableObject;
|
|
18
|
+
export type TrampolineThunk<T> = {
|
|
19
|
+
readonly isThunk: true;
|
|
20
|
+
readonly fn: () => Trampoline<T>;
|
|
21
|
+
};
|
|
22
|
+
export type Trampoline<T> = T | TrampolineThunk<T>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './utils';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './number';
|
|
@@ -1,22 +1,209 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
import type { Comparable, Trampoline, TrampolineThunk } from '../types';
|
|
9
|
+
/**
|
|
10
|
+
* The function generates a random UUID (Universally Unique Identifier) in TypeScript.
|
|
11
|
+
* @returns A randomly generated UUID (Universally Unique Identifier) in the format
|
|
12
|
+
* 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' where each 'x' is replaced with a random hexadecimal
|
|
13
|
+
* character.
|
|
14
|
+
*/
|
|
15
|
+
export declare const uuidV4: () => string;
|
|
16
|
+
/**
|
|
17
|
+
* The `arrayRemove` function removes elements from an array based on a specified predicate function
|
|
18
|
+
* and returns the removed elements.
|
|
19
|
+
* @param {T[]} array - An array of elements that you want to filter based on the provided predicate
|
|
20
|
+
* function.
|
|
21
|
+
* @param predicate - The `predicate` parameter is a function that takes three arguments:
|
|
22
|
+
* @returns The `arrayRemove` function returns an array containing the elements that satisfy the given
|
|
23
|
+
* `predicate` function.
|
|
24
|
+
*/
|
|
25
|
+
export declare const arrayRemove: <T>(array: T[], predicate: (item: T, index: number, array: T[]) => boolean) => T[];
|
|
26
|
+
/**
|
|
27
|
+
* The function `getMSB` returns the most significant bit of a given number.
|
|
28
|
+
* @param {number} value - The `value` parameter is a number for which we want to find the position of
|
|
29
|
+
* the Most Significant Bit (MSB). The function `getMSB` takes this number as input and calculates the
|
|
30
|
+
* position of the MSB in its binary representation.
|
|
31
|
+
* @returns The function `getMSB` returns the most significant bit (MSB) of the input `value`. If the
|
|
32
|
+
* input value is less than or equal to 0, it returns 0. Otherwise, it calculates the position of the
|
|
33
|
+
* MSB using the `Math.clz32` function and bitwise left shifts 1 to that position.
|
|
34
|
+
*/
|
|
35
|
+
export declare const getMSB: (value: number) => number;
|
|
36
|
+
/**
|
|
37
|
+
* The `rangeCheck` function in TypeScript is used to validate if an index is within a specified range
|
|
38
|
+
* and throws a `RangeError` with a custom message if it is out of bounds.
|
|
39
|
+
* @param {number} index - The `index` parameter represents the value that you want to check if it
|
|
40
|
+
* falls within a specified range.
|
|
41
|
+
* @param {number} min - The `min` parameter represents the minimum value that the `index` should be
|
|
42
|
+
* compared against in the `rangeCheck` function.
|
|
43
|
+
* @param {number} max - The `max` parameter in the `rangeCheck` function represents the maximum value
|
|
44
|
+
* that the `index` parameter is allowed to have. If the `index` is greater than this `max` value, a
|
|
45
|
+
* `RangeError` will be thrown.
|
|
46
|
+
* @param [message=Index out of bounds.] - The `message` parameter is a string that represents the
|
|
47
|
+
* error message to be thrown if the index is out of bounds. By default, if no message is provided when
|
|
48
|
+
* calling the `rangeCheck` function, the message "Index out of bounds." will be used.
|
|
49
|
+
*/
|
|
50
|
+
export declare const rangeCheck: (index: number, min: number, max: number, message?: string) => void;
|
|
51
|
+
/**
|
|
52
|
+
* The function `throwRangeError` throws a RangeError with a custom message if called.
|
|
53
|
+
* @param [message=The value is off-limits.] - The `message` parameter is a string that represents the
|
|
54
|
+
* error message to be displayed when a `RangeError` is thrown. If no message is provided, the default
|
|
55
|
+
* message is 'The value is off-limits.'.
|
|
56
|
+
*/
|
|
57
|
+
export declare const throwRangeError: (message?: string) => void;
|
|
58
|
+
/**
|
|
59
|
+
* The function `isWeakKey` checks if the input is an object or a function in TypeScript.
|
|
60
|
+
* @param {unknown} input - The `input` parameter in the `isWeakKey` function is of type `unknown`,
|
|
61
|
+
* which means it can be any type. The function checks if the `input` is an object (excluding `null`)
|
|
62
|
+
* or a function, and returns a boolean indicating whether the `input` is a weak
|
|
63
|
+
* @returns The function `isWeakKey` returns a boolean value indicating whether the input is an object
|
|
64
|
+
* or a function.
|
|
65
|
+
*/
|
|
66
|
+
export declare const isWeakKey: (input: unknown) => input is object;
|
|
67
|
+
/**
|
|
68
|
+
* The function `calcMinUnitsRequired` calculates the minimum number of units required to accommodate a
|
|
69
|
+
* given total quantity based on a specified unit size.
|
|
70
|
+
* @param {number} totalQuantity - The `totalQuantity` parameter represents the total quantity of items
|
|
71
|
+
* that need to be processed or handled.
|
|
72
|
+
* @param {number} unitSize - The `unitSize` parameter represents the size of each unit or package. It
|
|
73
|
+
* is used in the `calcMinUnitsRequired` function to calculate the minimum number of units required to
|
|
74
|
+
* accommodate a total quantity of items.
|
|
75
|
+
*/
|
|
76
|
+
export declare const calcMinUnitsRequired: (totalQuantity: number, unitSize: number) => number;
|
|
77
|
+
/**
|
|
78
|
+
* The `roundFixed` function in TypeScript rounds a number to a specified number of decimal places.
|
|
79
|
+
* @param {number} num - The `num` parameter is a number that you want to round to a certain number of
|
|
80
|
+
* decimal places.
|
|
81
|
+
* @param {number} [digit=10] - The `digit` parameter in the `roundFixed` function specifies the number
|
|
82
|
+
* of decimal places to round the number to. By default, it is set to 10 if not provided explicitly.
|
|
83
|
+
* @returns The function `roundFixed` returns a number that is rounded to the specified number of
|
|
84
|
+
* decimal places (default is 10 decimal places).
|
|
85
|
+
*/
|
|
86
|
+
export declare const roundFixed: (num: number, digit?: number) => number;
|
|
87
|
+
/**
|
|
88
|
+
* The function `isComparable` in TypeScript checks if a value is comparable, handling primitive values
|
|
89
|
+
* and objects with optional force comparison.
|
|
90
|
+
* @param {unknown} value - The `value` parameter in the `isComparable` function represents the value
|
|
91
|
+
* that you want to check if it is comparable. It can be of any type (`unknown`), and the function will
|
|
92
|
+
* determine if it is comparable based on certain conditions.
|
|
93
|
+
* @param [isForceObjectComparable=false] - The `isForceObjectComparable` parameter in the
|
|
94
|
+
* `isComparable` function is a boolean flag that determines whether to treat non-primitive values as
|
|
95
|
+
* comparable objects. When set to `true`, it forces the function to consider non-primitive values as
|
|
96
|
+
* comparable objects, regardless of their type.
|
|
97
|
+
* @returns The function `isComparable` returns a boolean value indicating whether the `value` is
|
|
98
|
+
* considered comparable or not.
|
|
99
|
+
*/
|
|
100
|
+
export declare function isComparable(value: unknown, isForceObjectComparable?: boolean): value is Comparable;
|
|
101
|
+
/**
|
|
102
|
+
* Creates a trampoline thunk object.
|
|
103
|
+
*
|
|
104
|
+
* A "thunk" is a deferred computation — instead of performing a recursive call immediately,
|
|
105
|
+
* it wraps the next step of the computation in a function. This allows recursive processes
|
|
106
|
+
* to be executed iteratively, preventing stack overflows.
|
|
107
|
+
*
|
|
108
|
+
* @template T - The type of the final computation result.
|
|
109
|
+
* @param computation - A function that, when executed, returns the next trampoline step.
|
|
110
|
+
* @returns A TrampolineThunk object containing the deferred computation.
|
|
111
|
+
*/
|
|
112
|
+
export declare const makeTrampolineThunk: <T>(computation: () => Trampoline<T>) => TrampolineThunk<T>;
|
|
113
|
+
/**
|
|
114
|
+
* Type guard to check whether a given value is a TrampolineThunk.
|
|
115
|
+
*
|
|
116
|
+
* This function is used to distinguish between a final computation result (value)
|
|
117
|
+
* and a deferred computation (thunk).
|
|
118
|
+
*
|
|
119
|
+
* @template T - The type of the value being checked.
|
|
120
|
+
* @param value - The value to test.
|
|
121
|
+
* @returns True if the value is a valid TrampolineThunk, false otherwise.
|
|
122
|
+
*/
|
|
123
|
+
export declare const isTrampolineThunk: <T>(value: Trampoline<T>) => value is TrampolineThunk<T>;
|
|
124
|
+
/**
|
|
125
|
+
* Executes a trampoline computation until a final (non-thunk) result is obtained.
|
|
126
|
+
*
|
|
127
|
+
* The trampoline function repeatedly invokes the deferred computations (thunks)
|
|
128
|
+
* in an iterative loop. This avoids deep recursive calls and prevents stack overflow,
|
|
129
|
+
* which is particularly useful for implementing recursion in a stack-safe manner.
|
|
130
|
+
*
|
|
131
|
+
* @template T - The type of the final result.
|
|
132
|
+
* @param initial - The initial Trampoline value or thunk to start execution from.
|
|
133
|
+
* @returns The final result of the computation (a non-thunk value).
|
|
134
|
+
*/
|
|
135
|
+
export declare function trampoline<T>(initial: Trampoline<T>): T;
|
|
136
|
+
/**
|
|
137
|
+
* Wraps a recursive function inside a trampoline executor.
|
|
138
|
+
*
|
|
139
|
+
* This function transforms a potentially recursive function (that returns a Trampoline<Result>)
|
|
140
|
+
* into a *stack-safe* function that executes iteratively using the `trampoline` runner.
|
|
141
|
+
*
|
|
142
|
+
* In other words, it allows you to write functions that look recursive,
|
|
143
|
+
* but actually run in constant stack space.
|
|
144
|
+
*
|
|
145
|
+
* @template Args - The tuple type representing the argument list of the original function.
|
|
146
|
+
* @template Result - The final return type after all trampoline steps are resolved.
|
|
147
|
+
*
|
|
148
|
+
* @param fn - A function that performs a single step of computation
|
|
149
|
+
* and returns a Trampoline (either a final value or a deferred thunk).
|
|
150
|
+
*
|
|
151
|
+
* @returns A new function with the same arguments, but which automatically
|
|
152
|
+
* runs the trampoline process and returns the *final result* instead
|
|
153
|
+
* of a Trampoline.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* // Example: Computing factorial in a stack-safe way
|
|
157
|
+
* const factorial = makeTrampoline(function fact(n: number, acc: number = 1): Trampoline<number> {
|
|
158
|
+
* return n === 0
|
|
159
|
+
* ? acc
|
|
160
|
+
* : makeTrampolineThunk(() => fact(n - 1, acc * n));
|
|
161
|
+
* });
|
|
162
|
+
*
|
|
163
|
+
* console.log(factorial(100000)); // Works without stack overflow
|
|
164
|
+
*/
|
|
165
|
+
export declare function makeTrampoline<Args extends any[], Result>(fn: (...args: Args) => Trampoline<Result>): (...args: Args) => Result;
|
|
166
|
+
/**
|
|
167
|
+
* Executes an asynchronous trampoline computation until a final (non-thunk) result is obtained.
|
|
168
|
+
*
|
|
169
|
+
* This function repeatedly invokes asynchronous deferred computations (thunks)
|
|
170
|
+
* in an iterative loop. Each thunk may return either a Trampoline<T> or a Promise<Trampoline<T>>.
|
|
171
|
+
*
|
|
172
|
+
* It ensures that asynchronous recursive functions can run without growing the call stack,
|
|
173
|
+
* making it suitable for stack-safe async recursion.
|
|
174
|
+
*
|
|
175
|
+
* @template T - The type of the final result.
|
|
176
|
+
* @param initial - The initial Trampoline or Promise of Trampoline to start execution from.
|
|
177
|
+
* @returns A Promise that resolves to the final result (a non-thunk value).
|
|
178
|
+
*/
|
|
179
|
+
export declare function asyncTrampoline<T>(initial: Trampoline<T> | Promise<Trampoline<T>>): Promise<T>;
|
|
180
|
+
/**
|
|
181
|
+
* Wraps an asynchronous recursive function inside an async trampoline executor.
|
|
182
|
+
*
|
|
183
|
+
* This helper transforms a recursive async function that returns a Trampoline<Result>
|
|
184
|
+
* (or Promise<Trampoline<Result>>) into a *stack-safe* async function that executes
|
|
185
|
+
* iteratively via the `asyncTrampoline` runner.
|
|
186
|
+
*
|
|
187
|
+
* @template Args - The tuple type representing the argument list of the original function.
|
|
188
|
+
* @template Result - The final return type after all async trampoline steps are resolved.
|
|
189
|
+
*
|
|
190
|
+
* @param fn - An async or sync function that performs a single step of computation
|
|
191
|
+
* and returns a Trampoline (either a final value or a deferred thunk).
|
|
192
|
+
*
|
|
193
|
+
* @returns An async function with the same arguments, but which automatically
|
|
194
|
+
* runs the trampoline process and resolves to the *final result*.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* // Example: Async factorial using trampoline
|
|
198
|
+
* const asyncFactorial = makeAsyncTrampoline(async function fact(
|
|
199
|
+
* n: number,
|
|
200
|
+
* acc: number = 1
|
|
201
|
+
* ): Promise<Trampoline<number>> {
|
|
202
|
+
* return n === 0
|
|
203
|
+
* ? acc
|
|
204
|
+
* : makeTrampolineThunk(() => fact(n - 1, acc * n));
|
|
205
|
+
* });
|
|
206
|
+
*
|
|
207
|
+
* asyncFactorial(100000).then(console.log); // Works without stack overflow
|
|
208
|
+
*/
|
|
209
|
+
export declare function makeAsyncTrampoline<Args extends any[], Result>(fn: (...args: Args) => Trampoline<Result> | Promise<Trampoline<Result>>): (...args: Args) => Promise<Result>;
|