data-structure-typed 1.12.10 → 1.12.21

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.
Files changed (158) hide show
  1. package/README.md +7 -0
  2. package/dist/data-structures/binary-tree/avl-tree.d.ts +14 -5
  3. package/dist/data-structures/binary-tree/avl-tree.js +15 -6
  4. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +11 -2
  5. package/dist/data-structures/binary-tree/binary-indexed-tree.js +11 -2
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +26 -17
  7. package/dist/data-structures/binary-tree/binary-tree.js +72 -62
  8. package/dist/data-structures/binary-tree/bst.d.ts +92 -5
  9. package/dist/data-structures/binary-tree/bst.js +89 -5
  10. package/dist/data-structures/binary-tree/segment-tree.d.ts +41 -2
  11. package/dist/data-structures/binary-tree/segment-tree.js +41 -2
  12. package/dist/data-structures/binary-tree/tree-multiset.d.ts +34 -3
  13. package/dist/data-structures/binary-tree/tree-multiset.js +35 -4
  14. package/dist/data-structures/graph/abstract-graph.d.ts +5 -0
  15. package/dist/data-structures/graph/abstract-graph.js +12 -4
  16. package/dist/data-structures/graph/directed-graph.d.ts +18 -4
  17. package/dist/data-structures/graph/directed-graph.js +24 -37
  18. package/dist/data-structures/graph/undirected-graph.d.ts +13 -0
  19. package/dist/data-structures/graph/undirected-graph.js +18 -2
  20. package/dist/data-structures/hash/coordinate-map.d.ts +5 -2
  21. package/dist/data-structures/hash/coordinate-map.js +5 -2
  22. package/dist/data-structures/hash/coordinate-set.d.ts +5 -2
  23. package/dist/data-structures/hash/coordinate-set.js +5 -2
  24. package/dist/data-structures/heap/heap.d.ts +9 -6
  25. package/dist/data-structures/heap/heap.js +8 -8
  26. package/dist/data-structures/heap/max-heap.d.ts +5 -2
  27. package/dist/data-structures/heap/max-heap.js +5 -2
  28. package/dist/data-structures/heap/min-heap.d.ts +5 -2
  29. package/dist/data-structures/heap/min-heap.js +5 -2
  30. package/dist/data-structures/index.d.ts +1 -0
  31. package/dist/data-structures/index.js +1 -0
  32. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  33. package/dist/data-structures/linked-list/doubly-linked-list.js +4 -4
  34. package/dist/data-structures/linked-list/singly-linked-list.d.ts +5 -2
  35. package/dist/data-structures/linked-list/singly-linked-list.js +5 -2
  36. package/dist/data-structures/matrix/matrix.d.ts +5 -2
  37. package/dist/data-structures/matrix/matrix.js +5 -2
  38. package/dist/data-structures/matrix/matrix2d.d.ts +5 -2
  39. package/dist/data-structures/matrix/matrix2d.js +5 -2
  40. package/dist/data-structures/matrix/navigator.d.ts +5 -2
  41. package/dist/data-structures/matrix/vector2d.d.ts +5 -2
  42. package/dist/data-structures/matrix/vector2d.js +5 -2
  43. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +5 -2
  44. package/dist/data-structures/priority-queue/max-priority-queue.js +5 -2
  45. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +5 -2
  46. package/dist/data-structures/priority-queue/min-priority-queue.js +5 -2
  47. package/dist/data-structures/priority-queue/priority-queue.d.ts +7 -4
  48. package/dist/data-structures/priority-queue/priority-queue.js +2 -2
  49. package/dist/data-structures/queue/deque.d.ts +12 -9
  50. package/dist/data-structures/queue/deque.js +12 -9
  51. package/dist/data-structures/queue/queue.d.ts +4 -4
  52. package/dist/data-structures/queue/queue.js +4 -4
  53. package/dist/data-structures/stack/stack.d.ts +1 -1
  54. package/dist/data-structures/stack/stack.js +1 -1
  55. package/dist/data-structures/trie/trie.d.ts +6 -3
  56. package/dist/data-structures/trie/trie.js +7 -4
  57. package/dist/utils/index.d.ts +1 -0
  58. package/dist/utils/index.js +1 -0
  59. package/dist/utils/types/utils.d.ts +8 -10
  60. package/dist/utils/types/utils.js +0 -1
  61. package/dist/utils/utils.d.ts +18 -8
  62. package/dist/utils/utils.js +93 -47
  63. package/package.json +3 -3
  64. package/src/assets/logo.png +0 -0
  65. package/src/data-structures/binary-tree/avl-tree.ts +15 -6
  66. package/src/data-structures/binary-tree/binary-indexed-tree.ts +11 -2
  67. package/src/data-structures/binary-tree/binary-tree.ts +70 -58
  68. package/src/data-structures/binary-tree/bst.ts +94 -7
  69. package/src/data-structures/binary-tree/segment-tree.ts +41 -2
  70. package/src/data-structures/binary-tree/tree-multiset.ts +35 -4
  71. package/src/data-structures/graph/abstract-graph.ts +12 -4
  72. package/src/data-structures/graph/directed-graph.ts +26 -39
  73. package/src/data-structures/graph/undirected-graph.ts +18 -2
  74. package/src/data-structures/hash/coordinate-map.ts +5 -2
  75. package/src/data-structures/hash/coordinate-set.ts +5 -2
  76. package/src/data-structures/heap/heap.ts +13 -10
  77. package/src/data-structures/heap/max-heap.ts +5 -2
  78. package/src/data-structures/heap/min-heap.ts +5 -2
  79. package/src/data-structures/index.ts +2 -0
  80. package/src/data-structures/linked-list/doubly-linked-list.ts +9 -6
  81. package/src/data-structures/linked-list/singly-linked-list.ts +5 -2
  82. package/src/data-structures/matrix/matrix.ts +5 -2
  83. package/src/data-structures/matrix/matrix2d.ts +5 -2
  84. package/src/data-structures/matrix/navigator.ts +5 -2
  85. package/src/data-structures/matrix/vector2d.ts +5 -2
  86. package/src/data-structures/priority-queue/max-priority-queue.ts +5 -2
  87. package/src/data-structures/priority-queue/min-priority-queue.ts +5 -2
  88. package/src/data-structures/priority-queue/priority-queue.ts +7 -4
  89. package/src/data-structures/queue/deque.ts +12 -9
  90. package/src/data-structures/queue/queue.ts +4 -4
  91. package/src/data-structures/stack/stack.ts +1 -1
  92. package/src/data-structures/trie/trie.ts +7 -4
  93. package/src/utils/index.ts +2 -1
  94. package/src/utils/types/utils.ts +10 -12
  95. package/src/utils/utils.ts +57 -11
  96. package/tests/unit/data-structures/binary-tree/bst.test.ts +1 -1
  97. package/tests/unit/data-structures/graph/directed-graph.test.ts +1 -0
  98. package/dist/utils/trampoline.d.ts +0 -14
  99. package/dist/utils/trampoline.js +0 -130
  100. package/docs/.nojekyll +0 -1
  101. package/docs/assets/highlight.css +0 -85
  102. package/docs/assets/main.js +0 -58
  103. package/docs/assets/search.js +0 -1
  104. package/docs/assets/style.css +0 -1367
  105. package/docs/classes/AVLTree.html +0 -2046
  106. package/docs/classes/AVLTreeNode.html +0 -423
  107. package/docs/classes/AaTree.html +0 -117
  108. package/docs/classes/AbstractEdge.html +0 -198
  109. package/docs/classes/AbstractGraph.html +0 -891
  110. package/docs/classes/AbstractVertex.html +0 -164
  111. package/docs/classes/ArrayDeque.html +0 -384
  112. package/docs/classes/BST.html +0 -1893
  113. package/docs/classes/BSTNode.html +0 -425
  114. package/docs/classes/BTree.html +0 -117
  115. package/docs/classes/BinaryIndexedTree.html +0 -244
  116. package/docs/classes/BinaryTree.html +0 -1754
  117. package/docs/classes/BinaryTreeNode.html +0 -396
  118. package/docs/classes/Character.html +0 -165
  119. package/docs/classes/CoordinateMap.html +0 -394
  120. package/docs/classes/CoordinateSet.html +0 -355
  121. package/docs/classes/Deque.html +0 -617
  122. package/docs/classes/DirectedEdge.html +0 -247
  123. package/docs/classes/DirectedGraph.html +0 -1207
  124. package/docs/classes/DirectedVertex.html +0 -154
  125. package/docs/classes/DoublyLinkedList.html +0 -619
  126. package/docs/classes/DoublyLinkedListNode.html +0 -160
  127. package/docs/classes/Heap.html +0 -315
  128. package/docs/classes/Matrix2D.html +0 -447
  129. package/docs/classes/MatrixNTI2D.html +0 -181
  130. package/docs/classes/MaxHeap.html +0 -325
  131. package/docs/classes/MaxPriorityQueue.html +0 -668
  132. package/docs/classes/MinHeap.html +0 -326
  133. package/docs/classes/MinPriorityQueue.html +0 -668
  134. package/docs/classes/Navigator.html +0 -285
  135. package/docs/classes/ObjectDeque.html +0 -289
  136. package/docs/classes/PriorityQueue.html +0 -643
  137. package/docs/classes/Queue.html +0 -337
  138. package/docs/classes/RBTree.html +0 -117
  139. package/docs/classes/SegmentTree.html +0 -234
  140. package/docs/classes/SegmentTreeNode.html +0 -302
  141. package/docs/classes/SinglyLinkedList.html +0 -1035
  142. package/docs/classes/SinglyLinkedListNode.html +0 -304
  143. package/docs/classes/SplayTree.html +0 -117
  144. package/docs/classes/Stack.html +0 -313
  145. package/docs/classes/TreeMultiSet.html +0 -1897
  146. package/docs/classes/Trie.html +0 -317
  147. package/docs/classes/TrieNode.html +0 -221
  148. package/docs/classes/TwoThreeTree.html +0 -117
  149. package/docs/classes/UndirectedEdge.html +0 -220
  150. package/docs/classes/UndirectedGraph.html +0 -1006
  151. package/docs/classes/UndirectedVertex.html +0 -154
  152. package/docs/classes/Vector2D.html +0 -746
  153. package/docs/enums/CP.html +0 -126
  154. package/docs/enums/FamilyPosition.html +0 -126
  155. package/docs/enums/LoopType.html +0 -119
  156. package/docs/index.html +0 -288
  157. package/docs/modules.html +0 -146
  158. package/src/utils/trampoline.ts +0 -51
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Queue = void 0;
4
4
  /**
5
5
  * @license MIT
6
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
6
+ * @copyright Tyler Zeng <zrwusa@gmail.com>
7
7
  * @class
8
8
  */
9
9
  var Queue = /** @class */ (function () {
@@ -29,11 +29,11 @@ var Queue = /** @class */ (function () {
29
29
  return new Queue(elements);
30
30
  };
31
31
  /**
32
- * The offer function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
32
+ * The add function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
33
33
  * @param {T} element - The `element` parameter represents the element that you want to add to the queue.
34
- * @returns The `offer` method is returning a `Queue<T>` object.
34
+ * @returns The `add` method is returning a `Queue<T>` object.
35
35
  */
36
- Queue.prototype.offer = function (element) {
36
+ Queue.prototype.add = function (element) {
37
37
  this._nodes.push(element);
38
38
  return this;
39
39
  };
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license MIT
3
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @copyright Tyler Zeng <zrwusa@gmail.com>
4
4
  * @class
5
5
  */
6
6
  export declare class Stack<T> {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Stack = void 0;
4
4
  /**
5
5
  * @license MIT
6
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
6
+ * @copyright Tyler Zeng <zrwusa@gmail.com>
7
7
  * @class
8
8
  */
9
9
  var Stack = /** @class */ (function () {
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  export declare class TrieNode {
6
9
  protected _value: string;
@@ -19,7 +22,7 @@ export declare class Trie {
19
22
  protected _root: TrieNode;
20
23
  get root(): TrieNode;
21
24
  set root(v: TrieNode);
22
- put(word: string): boolean;
25
+ add(word: string): boolean;
23
26
  has(input: string): boolean;
24
27
  remove(word: string): boolean;
25
28
  /**
@@ -13,8 +13,11 @@ var __values = (this && this.__values) || function(o) {
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.Trie = exports.TrieNode = void 0;
15
15
  /**
16
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
17
- * @license MIT
16
+ * data-structure-typed
17
+ *
18
+ * @author Tyler Zeng
19
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
20
+ * @license MIT License
18
21
  */
19
22
  var TrieNode = /** @class */ (function () {
20
23
  function TrieNode(v) {
@@ -63,7 +66,7 @@ var Trie = /** @class */ (function () {
63
66
  try {
64
67
  for (var words_1 = __values(words), words_1_1 = words_1.next(); !words_1_1.done; words_1_1 = words_1.next()) {
65
68
  var i = words_1_1.value;
66
- this.put(i);
69
+ this.add(i);
67
70
  }
68
71
  }
69
72
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -85,7 +88,7 @@ var Trie = /** @class */ (function () {
85
88
  enumerable: false,
86
89
  configurable: true
87
90
  });
88
- Trie.prototype.put = function (word) {
91
+ Trie.prototype.add = function (word) {
89
92
  var e_2, _a;
90
93
  var cur = this._root;
91
94
  try {
@@ -1 +1,2 @@
1
1
  export * from './utils';
2
+ export * from './types';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./utils"), exports);
18
+ __exportStar(require("./types"), exports);
@@ -1,3 +1,10 @@
1
+ export type JSONSerializable = {
2
+ [key: string]: any;
3
+ };
4
+ export type JSONValue = string | number | boolean | undefined | JSONObject;
5
+ export interface JSONObject {
6
+ [key: string]: JSONValue;
7
+ }
1
8
  export type AnyFunction<A extends any[] = any[], R = any> = (...args: A) => R;
2
9
  export type Primitive = number | string | boolean | symbol | undefined | null | void | AnyFunction | Date;
3
10
  export type Cast<T, TComplex> = {
@@ -6,13 +13,6 @@ export type Cast<T, TComplex> = {
6
13
  export type DeepLeavesWrap<T, TComplex> = T extends string ? Cast<string, TComplex> : T extends number ? Cast<number, TComplex> : T extends boolean ? Cast<boolean, TComplex> : T extends undefined ? Cast<undefined, TComplex> : T extends null ? Cast<null, TComplex> : T extends void ? Cast<void, TComplex> : T extends symbol ? Cast<symbol, TComplex> : T extends AnyFunction ? Cast<AnyFunction, TComplex> : T extends Date ? Cast<Date, TComplex> : {
7
14
  [K in keyof T]: T[K] extends (infer U)[] ? DeepLeavesWrap<U, TComplex>[] : DeepLeavesWrap<T[K], TComplex>;
8
15
  };
9
- export type JSONSerializable = {
10
- [key: string]: any;
11
- };
12
- export type JSONValue = string | number | boolean | undefined | JSONObject;
13
- export interface JSONObject {
14
- [key: string]: JSONValue;
15
- }
16
16
  export type TypeName<T> = T extends string ? 'string' : T extends number ? 'number' : T extends boolean ? 'boolean' : T extends undefined ? 'undefined' : T extends AnyFunction ? 'function' : 'object';
17
17
  export type JsonKeys<T> = keyof {
18
18
  [P in keyof T]: number;
@@ -51,10 +51,8 @@ export type DeepProxyOnChange = (target: any, property: string | symbol, value:
51
51
  export type DeepProxyOnGet = (target: any, property: string | symbol, value: any, receiver: any, descriptor: any, result: any) => void;
52
52
  export type CurryFunc<T> = T extends (...args: infer Args) => infer R ? Args extends [infer Arg, ...infer RestArgs] ? (arg: Arg) => CurryFunc<(...args: RestArgs) => R> : R : T;
53
53
  export type ToThunkFn = () => ReturnType<TrlFn>;
54
- declare const THUNK_SYMBOL: unique symbol;
55
54
  export type Thunk = () => ReturnType<ToThunkFn> & {
56
- __THUNK__: typeof THUNK_SYMBOL;
55
+ __THUNK__: Symbol;
57
56
  };
58
57
  export type TrlFn = (...args: any[]) => any;
59
58
  export type TrlAsyncFn = (...args: any[]) => any;
60
- export {};
@@ -52,4 +52,3 @@ var TreeNode = /** @class */ (function () {
52
52
  return TreeNode;
53
53
  }());
54
54
  exports.TreeNode = TreeNode;
55
- var THUNK_SYMBOL = Symbol('thunk');
@@ -1,11 +1,4 @@
1
- import { AnyFunction } from './types';
2
- export type JSONSerializable = {
3
- [key: string]: any;
4
- };
5
- export type JSONValue = string | number | boolean | undefined | JSONObject;
6
- export interface JSONObject {
7
- [key: string]: JSONValue;
8
- }
1
+ import type { AnyFunction, JSONObject, JSONSerializable } from './types';
9
2
  export declare function randomText(length: number): string;
10
3
  export declare const uuidV4: () => string;
11
4
  export declare class IncrementId {
@@ -103,3 +96,20 @@ export declare function zip<T = number, T1 = number>(array1: T[], array2: T1[],
103
96
  x: T;
104
97
  y: T1;
105
98
  }[];
99
+ /**
100
+ * data-structure-typed
101
+ *
102
+ * @author Tyler Zeng
103
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
104
+ * @license MIT License
105
+ */
106
+ import { Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from './types';
107
+ export declare const THUNK_SYMBOL: unique symbol;
108
+ export declare const isThunk: (fnOrValue: any) => boolean;
109
+ export declare const toThunk: (fn: ToThunkFn) => Thunk;
110
+ export declare const trampoline: (fn: TrlFn) => ((...args: [...Parameters<TrlFn>]) => any) & {
111
+ cont: (...args: [...Parameters<TrlFn>]) => Thunk;
112
+ };
113
+ export declare const trampolineAsync: (fn: TrlAsyncFn) => ((...args: [...Parameters<TrlAsyncFn>]) => Promise<any>) & {
114
+ cont: (...args: [...Parameters<TrlAsyncFn>]) => Thunk;
115
+ };
@@ -10,29 +10,6 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- var desc = Object.getOwnPropertyDescriptor(m, k);
16
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
- desc = { enumerable: true, get: function() { return m[k]; } };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26
- }) : function(o, v) {
27
- o["default"] = v;
28
- });
29
- var __importStar = (this && this.__importStar) || function (mod) {
30
- if (mod && mod.__esModule) return mod;
31
- var result = {};
32
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
- __setModuleDefault(result, mod);
34
- return result;
35
- };
36
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -105,9 +82,12 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
105
82
  }
106
83
  return to.concat(ar || Array.prototype.slice.call(from));
107
84
  };
85
+ var __importDefault = (this && this.__importDefault) || function (mod) {
86
+ return (mod && mod.__esModule) ? mod : { "default": mod };
87
+ };
108
88
  Object.defineProperty(exports, "__esModule", { value: true });
109
- exports.zip = exports.memo = exports.arrayRemove = exports.timeEnd = exports.timeStart = exports.bunnyConsole = exports.deepAdd = exports.deepReplaceValues = exports.deepRenameKeys = exports.deepRemoveByKey = exports.deepKeysConvert = exports.StringUtil = exports.diffAB = exports.onlyInB = exports.onlyInA = exports.comparerArray = exports.capitalizeFirstLetter = exports.capitalizeWords = exports.randomDate = exports.minuted = exports.keyValueToArray = exports.extractValue = exports.wait = exports.WaitManager = exports.addDays = exports.isLeafParent = exports.isSameStructure = exports.reverseColor = exports.deepObjectStrictEqual = exports.strictObjectIsEqual = exports.strictEqual = exports.looseEqual = exports.isObject = exports.getValue = exports.incrementId = exports.IncrementId = exports.uuidV4 = exports.randomText = void 0;
110
- var _ = __importStar(require("lodash"));
89
+ exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = exports.zip = exports.memo = exports.arrayRemove = exports.timeEnd = exports.timeStart = exports.bunnyConsole = exports.deepAdd = exports.deepReplaceValues = exports.deepRenameKeys = exports.deepRemoveByKey = exports.deepKeysConvert = exports.StringUtil = exports.diffAB = exports.onlyInB = exports.onlyInA = exports.comparerArray = exports.capitalizeFirstLetter = exports.capitalizeWords = exports.randomDate = exports.minuted = exports.keyValueToArray = exports.extractValue = exports.wait = exports.WaitManager = exports.addDays = exports.isLeafParent = exports.isSameStructure = exports.reverseColor = exports.deepObjectStrictEqual = exports.strictObjectIsEqual = exports.strictEqual = exports.looseEqual = exports.isObject = exports.getValue = exports.incrementId = exports.IncrementId = exports.uuidV4 = exports.randomText = void 0;
90
+ var lodash_1 = __importDefault(require("lodash"));
111
91
  function randomText(length) {
112
92
  var result = '';
113
93
  var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
@@ -396,7 +376,7 @@ var comparerArray = function (otherArray, limitKeys) {
396
376
  return function (current) {
397
377
  return otherArray.filter(function (other) {
398
378
  if (!limitKeys) {
399
- return _.isEqual(current, other);
379
+ return lodash_1.default.isEqual(current, other);
400
380
  }
401
381
  else {
402
382
  // TODO
@@ -416,43 +396,43 @@ var StringUtil = /** @class */ (function () {
416
396
  }
417
397
  // camelCase
418
398
  StringUtil.toCamelCase = function (str) {
419
- return _.camelCase(str);
399
+ return lodash_1.default.camelCase(str);
420
400
  };
421
401
  // snake_case
422
402
  StringUtil.toSnakeCase = function (str) {
423
- return _.snakeCase(str);
403
+ return lodash_1.default.snakeCase(str);
424
404
  };
425
405
  // PascalCase
426
406
  StringUtil.toPascalCase = function (str) {
427
- return _.startCase(_.camelCase(str)).replace(/ /g, '');
407
+ return lodash_1.default.startCase(lodash_1.default.camelCase(str)).replace(/ /g, '');
428
408
  };
429
409
  // CONSTANT_CASE
430
410
  StringUtil.toConstantCase = function (str) {
431
- return _.upperCase(str).replace(/ /g, '_');
411
+ return lodash_1.default.upperCase(str).replace(/ /g, '_');
432
412
  };
433
413
  // kebab-case
434
414
  StringUtil.toKebabCase = function (str) {
435
- return _.kebabCase(str);
415
+ return lodash_1.default.kebabCase(str);
436
416
  };
437
417
  // lowercase
438
418
  StringUtil.toLowerCase = function (str) {
439
- return _.lowerCase(str).replace(/ /g, '');
419
+ return lodash_1.default.lowerCase(str).replace(/ /g, '');
440
420
  };
441
421
  // Title Case
442
422
  StringUtil.toTitleCase = function (str) {
443
- return _.startCase(_.camelCase(str));
423
+ return lodash_1.default.startCase(lodash_1.default.camelCase(str));
444
424
  };
445
425
  // Sentence case
446
426
  StringUtil.toSentenceCase = function (str) {
447
- return _.upperFirst(_.lowerCase(str));
427
+ return lodash_1.default.upperFirst(lodash_1.default.lowerCase(str));
448
428
  };
449
429
  // path/case
450
430
  StringUtil.toPathCase = function (str) {
451
- return _.lowerCase(str).replace(/ /g, '/');
431
+ return lodash_1.default.lowerCase(str).replace(/ /g, '/');
452
432
  };
453
433
  // dot.case
454
434
  StringUtil.toDotCase = function (str) {
455
- return _.lowerCase(str).replace(/ /g, '.');
435
+ return lodash_1.default.lowerCase(str).replace(/ /g, '.');
456
436
  };
457
437
  return StringUtil;
458
438
  }());
@@ -508,27 +488,27 @@ var deepKeysConvert = function (obj, toType) {
508
488
  };
509
489
  exports.deepKeysConvert = deepKeysConvert;
510
490
  var deepRemoveByKey = function (obj, keysToBeRemoved) {
511
- var result = _.transform(obj, function (result, value, key) {
512
- if (_.isObject(value)) {
491
+ var result = lodash_1.default.transform(obj, function (result, value, key) {
492
+ if (lodash_1.default.isObject(value)) {
513
493
  value = (0, exports.deepRemoveByKey)(value, keysToBeRemoved);
514
494
  }
515
495
  if (!keysToBeRemoved.includes(key)) {
516
- _.isArray(obj) ? result.push(value) : result[key] = value;
496
+ lodash_1.default.isArray(obj) ? result.push(value) : result[key] = value;
517
497
  }
518
498
  });
519
499
  return result;
520
500
  };
521
501
  exports.deepRemoveByKey = deepRemoveByKey;
522
502
  var deepRenameKeys = function (obj, keysMap) {
523
- return _.transform(obj, function (result, value, key) {
503
+ return lodash_1.default.transform(obj, function (result, value, key) {
524
504
  var currentKey = keysMap[key] || key;
525
- result[currentKey] = _.isObject(value) ? (0, exports.deepRenameKeys)(value, keysMap) : value;
505
+ result[currentKey] = lodash_1.default.isObject(value) ? (0, exports.deepRenameKeys)(value, keysMap) : value;
526
506
  });
527
507
  };
528
508
  exports.deepRenameKeys = deepRenameKeys;
529
509
  var deepReplaceValues = function (obj, keyReducerMap) {
530
- var newObject = _.clone(obj);
531
- _.each(obj, function (val, key) {
510
+ var newObject = lodash_1.default.clone(obj);
511
+ lodash_1.default.each(obj, function (val, key) {
532
512
  for (var item in keyReducerMap) {
533
513
  if (key === item) {
534
514
  newObject[key] = keyReducerMap[item](newObject);
@@ -543,14 +523,14 @@ var deepReplaceValues = function (obj, keyReducerMap) {
543
523
  exports.deepReplaceValues = deepReplaceValues;
544
524
  // TODO determine depth and pass root node as a param through callback
545
525
  var deepAdd = function (obj, keyReducerMap, isItemRootParent) {
546
- var newObject = _.clone(obj);
547
- if (_.isObject(newObject) && !_.isArray(newObject)) {
526
+ var newObject = lodash_1.default.clone(obj);
527
+ if (lodash_1.default.isObject(newObject) && !lodash_1.default.isArray(newObject)) {
548
528
  for (var item in keyReducerMap) {
549
529
  newObject[item] = keyReducerMap[item](newObject);
550
530
  }
551
531
  }
552
- _.each(obj, function (val, key) {
553
- if (_.isObject(val)) {
532
+ lodash_1.default.each(obj, function (val, key) {
533
+ if (lodash_1.default.isObject(val)) {
554
534
  for (var item in keyReducerMap) {
555
535
  // @ts-ignore
556
536
  newObject[key] = (0, exports.deepAdd)(val, keyReducerMap, isItemRootParent);
@@ -649,3 +629,69 @@ function zip(array1, array2, options) {
649
629
  return isToObj ? zippedObjCoords : zipped;
650
630
  }
651
631
  exports.zip = zip;
632
+ exports.THUNK_SYMBOL = Symbol('thunk');
633
+ var isThunk = function (fnOrValue) {
634
+ return typeof fnOrValue === 'function' && fnOrValue.__THUNK__ === exports.THUNK_SYMBOL;
635
+ };
636
+ exports.isThunk = isThunk;
637
+ var toThunk = function (fn) {
638
+ var thunk = function () { return fn(); };
639
+ thunk.__THUNK__ = exports.THUNK_SYMBOL;
640
+ return thunk;
641
+ };
642
+ exports.toThunk = toThunk;
643
+ var trampoline = function (fn) {
644
+ var cont = function () {
645
+ var args = [];
646
+ for (var _i = 0; _i < arguments.length; _i++) {
647
+ args[_i] = arguments[_i];
648
+ }
649
+ return (0, exports.toThunk)(function () { return fn.apply(void 0, __spreadArray([], __read(args), false)); });
650
+ };
651
+ return Object.assign(function () {
652
+ var args = [];
653
+ for (var _i = 0; _i < arguments.length; _i++) {
654
+ args[_i] = arguments[_i];
655
+ }
656
+ var result = fn.apply(void 0, __spreadArray([], __read(args), false));
657
+ while ((0, exports.isThunk)(result) && typeof result === 'function') {
658
+ result = result();
659
+ }
660
+ return result;
661
+ }, { cont: cont });
662
+ };
663
+ exports.trampoline = trampoline;
664
+ var trampolineAsync = function (fn) {
665
+ var cont = function () {
666
+ var args = [];
667
+ for (var _i = 0; _i < arguments.length; _i++) {
668
+ args[_i] = arguments[_i];
669
+ }
670
+ return (0, exports.toThunk)(function () { return fn.apply(void 0, __spreadArray([], __read(args), false)); });
671
+ };
672
+ return Object.assign(function () {
673
+ var args = [];
674
+ for (var _i = 0; _i < arguments.length; _i++) {
675
+ args[_i] = arguments[_i];
676
+ }
677
+ return __awaiter(void 0, void 0, void 0, function () {
678
+ var result;
679
+ return __generator(this, function (_a) {
680
+ switch (_a.label) {
681
+ case 0: return [4 /*yield*/, fn.apply(void 0, __spreadArray([], __read(args), false))];
682
+ case 1:
683
+ result = _a.sent();
684
+ _a.label = 2;
685
+ case 2:
686
+ if (!((0, exports.isThunk)(result) && typeof result === 'function')) return [3 /*break*/, 4];
687
+ return [4 /*yield*/, result()];
688
+ case 3:
689
+ result = _a.sent();
690
+ return [3 /*break*/, 2];
691
+ case 4: return [2 /*return*/, result];
692
+ }
693
+ });
694
+ });
695
+ }, { cont: cont });
696
+ };
697
+ exports.trampolineAsync = trampolineAsync;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "1.12.10",
3
+ "version": "1.12.21",
4
4
  "description": "Explore our comprehensive Javascript Data Structure / TypeScript Data Structure Library, meticulously crafted to empower developers with a versatile set of essential data structures. Our library includes a wide range of data structures, such as Binary Tree, AVL Tree, Binary Search Tree (BST), Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed Graph, Undirected Graph, Singly Linked List, Hash, CoordinateSet, CoordinateMap, Heap, Doubly Linked List, Priority Queue, Max Priority Queue, Min Priority Queue, Queue, ObjectDeque, ArrayDeque, Stack, and Trie. Each data structure is thoughtfully designed and implemented using TypeScript to provide efficient, reliable, and easy-to-use solutions for your programming needs. Whether you're optimizing algorithms, managing data, or enhancing performance, our TypeScript Data Structure Library is your go-to resource. Elevate your coding experience with these fundamental building blocks for software development.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -39,8 +39,8 @@
39
39
  "Min Priority Queue",
40
40
  "Trie"
41
41
  ],
42
- "author": "Tyler Zeng",
43
- "license": "ISC",
42
+ "author": "Tyler Zeng zrwusa@gmail.com",
43
+ "license": "MIT",
44
44
  "bugs": {
45
45
  "url": "https://github.com/zrwusa/data-structure-typed/issues"
46
46
  },
Binary file
@@ -1,11 +1,20 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  import {BST, BSTNode} from './bst';
6
9
  import type {AVLTreeDeleted, BinaryTreeNodeId} from '../types';
7
10
 
8
11
  export class AVLTreeNode<T> extends BSTNode<T> {
12
+ /**
13
+ * The function overrides the clone method of the AVLTreeNode class to create a new AVLTreeNode object with the same
14
+ * id, value, and count.
15
+ * @returns The method is returning a new instance of the AVLTreeNode class with the same id, val, and count values as
16
+ * the current instance.
17
+ */
9
18
  override clone(): AVLTreeNode<T> {
10
19
  return new AVLTreeNode<T>(this.id, this.val, this.count);
11
20
  }
@@ -18,9 +27,9 @@ export class AVLTree<T> extends BST<T> {
18
27
  }
19
28
 
20
29
  /**
21
- * The function overrides the put method of a Binary Search Tree to insert a node with a given id and value, and then
30
+ * The function overrides the add method of a Binary Search Tree to insert a node with a given id and value, and then
22
31
  * balances the tree.
23
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to put or
32
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add or
24
33
  * update in the AVL tree.
25
34
  * @param {T | null} val - The `val` parameter represents the value that you want to assign to the node with the given
26
35
  * `id`. It can be of type `T` (the generic type) or `null`.
@@ -29,8 +38,8 @@ export class AVLTree<T> extends BST<T> {
29
38
  * to `1`, indicating that the value should be inserted once.
30
39
  * @returns The method is returning either an AVLTreeNode<T> object or null.
31
40
  */
32
- override put(id: BinaryTreeNodeId, val: T | null, count?: number): AVLTreeNode<T> | null {
33
- const inserted = super.put(id, val, count);
41
+ override add(id: BinaryTreeNodeId, val: T | null, count?: number): AVLTreeNode<T> | null {
42
+ const inserted = super.add(id, val, count);
34
43
  if (inserted) this.balancePath(inserted);
35
44
  return inserted;
36
45
  }
@@ -1,10 +1,19 @@
1
1
  /**
2
- * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
- * @license MIT
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
4
7
  */
5
8
  export class BinaryIndexedTree {
6
9
  private readonly _sumTree: number[];
7
10
 
11
+ /**
12
+ * The constructor initializes an array with a specified length and fills it with zeros.
13
+ * @param {number} n - The parameter `n` represents the size of the array that will be used to store the sum tree. The
14
+ * sum tree is a binary tree data structure used to efficiently calculate the sum of a range of elements in an array.
15
+ * The size of the sum tree array is `n + 1` because
16
+ */
8
17
  constructor(n: number) {
9
18
  this._sumTree = new Array<number>(n + 1).fill(0);
10
19
  }