data-structure-typed 0.8.18 → 0.9.16

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 (213) hide show
  1. package/.idea/modules.xml +1 -1
  2. package/README.md +197 -2
  3. package/dist/data-structures/binary-tree/aa-tree.js +5 -2
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +1 -5
  5. package/dist/data-structures/binary-tree/avl-tree.js +93 -46
  6. package/dist/data-structures/binary-tree/b-tree.js +5 -2
  7. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -1
  8. package/dist/data-structures/binary-tree/binary-indexed-tree.js +14 -13
  9. package/dist/data-structures/binary-tree/binary-tree.d.ts +20 -32
  10. package/dist/data-structures/binary-tree/binary-tree.js +480 -370
  11. package/dist/data-structures/binary-tree/bst.d.ts +4 -8
  12. package/dist/data-structures/binary-tree/bst.js +152 -107
  13. package/dist/data-structures/binary-tree/rb-tree.js +5 -2
  14. package/dist/data-structures/binary-tree/segment-tree.d.ts +3 -3
  15. package/dist/data-structures/binary-tree/segment-tree.js +91 -61
  16. package/dist/data-structures/binary-tree/splay-tree.js +5 -2
  17. package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -5
  18. package/dist/data-structures/binary-tree/tree-multiset.js +31 -11
  19. package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
  20. package/dist/data-structures/graph/abstract-graph.d.ts +5 -33
  21. package/dist/data-structures/graph/abstract-graph.js +546 -311
  22. package/dist/data-structures/graph/directed-graph.d.ts +5 -13
  23. package/dist/data-structures/graph/directed-graph.js +250 -128
  24. package/dist/data-structures/graph/undirected-graph.d.ts +4 -3
  25. package/dist/data-structures/graph/undirected-graph.js +166 -81
  26. package/dist/data-structures/hash/coordinate-map.d.ts +1 -1
  27. package/dist/data-structures/hash/coordinate-map.js +38 -20
  28. package/dist/data-structures/hash/coordinate-set.js +33 -15
  29. package/dist/data-structures/hash/index.d.ts +5 -0
  30. package/dist/data-structures/hash/index.js +5 -0
  31. package/dist/data-structures/heap/heap.d.ts +2 -8
  32. package/dist/data-structures/heap/heap.js +36 -31
  33. package/dist/data-structures/heap/max-heap.d.ts +3 -2
  34. package/dist/data-structures/heap/max-heap.js +27 -9
  35. package/dist/data-structures/heap/min-heap.d.ts +3 -2
  36. package/dist/data-structures/heap/min-heap.js +27 -9
  37. package/dist/data-structures/index.d.ts +1 -0
  38. package/dist/data-structures/index.js +1 -0
  39. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -1
  40. package/dist/data-structures/linked-list/doubly-linked-list.js +56 -53
  41. package/dist/data-structures/linked-list/singly-linked-list.d.ts +8 -12
  42. package/dist/data-structures/linked-list/singly-linked-list.js +308 -174
  43. package/dist/data-structures/matrix/matrix.js +8 -7
  44. package/dist/data-structures/matrix/matrix2d.d.ts +5 -5
  45. package/dist/data-structures/matrix/matrix2d.js +80 -63
  46. package/dist/data-structures/matrix/navigator.d.ts +2 -16
  47. package/dist/data-structures/matrix/navigator.js +37 -18
  48. package/dist/data-structures/matrix/vector2d.d.ts +18 -18
  49. package/dist/data-structures/matrix/vector2d.js +117 -94
  50. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -2
  51. package/dist/data-structures/priority-queue/max-priority-queue.js +25 -8
  52. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -2
  53. package/dist/data-structures/priority-queue/min-priority-queue.js +25 -8
  54. package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -21
  55. package/dist/data-structures/priority-queue/priority-queue.js +159 -116
  56. package/dist/data-structures/queue/deque.js +82 -56
  57. package/dist/data-structures/queue/queue.d.ts +9 -10
  58. package/dist/data-structures/queue/queue.js +34 -34
  59. package/dist/data-structures/stack/stack.d.ts +9 -10
  60. package/dist/data-structures/stack/stack.js +31 -31
  61. package/dist/data-structures/trampoline.d.ts +14 -23
  62. package/dist/data-structures/trampoline.js +103 -25
  63. package/dist/data-structures/trie/trie.d.ts +13 -3
  64. package/dist/data-structures/trie/trie.js +234 -80
  65. package/dist/data-structures/types/abstract-graph.d.ts +29 -0
  66. package/dist/data-structures/types/abstract-graph.js +2 -0
  67. package/dist/data-structures/types/avl-tree.d.ts +5 -0
  68. package/dist/data-structures/types/avl-tree.js +2 -0
  69. package/dist/data-structures/types/binary-tree.d.ts +16 -0
  70. package/dist/data-structures/types/binary-tree.js +2 -0
  71. package/dist/data-structures/types/bst.d.ts +7 -0
  72. package/dist/data-structures/types/bst.js +2 -0
  73. package/dist/data-structures/types/directed-graph.d.ts +10 -0
  74. package/dist/data-structures/types/directed-graph.js +2 -0
  75. package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
  76. package/dist/data-structures/types/doubly-linked-list.js +2 -0
  77. package/dist/data-structures/types/heap.d.ts +7 -0
  78. package/dist/data-structures/types/heap.js +2 -0
  79. package/dist/data-structures/types/index.d.ts +13 -0
  80. package/dist/data-structures/types/index.js +29 -0
  81. package/dist/data-structures/types/navigator.d.ts +14 -0
  82. package/dist/data-structures/types/navigator.js +2 -0
  83. package/dist/data-structures/types/priority-queue.d.ts +7 -0
  84. package/dist/data-structures/types/priority-queue.js +2 -0
  85. package/dist/data-structures/types/segment-tree.d.ts +1 -0
  86. package/dist/data-structures/types/segment-tree.js +2 -0
  87. package/dist/data-structures/types/singly-linked-list.d.ts +5 -0
  88. package/dist/data-structures/types/singly-linked-list.js +2 -0
  89. package/dist/data-structures/types/tree-multiset.d.ts +5 -0
  90. package/dist/data-structures/types/tree-multiset.js +2 -0
  91. package/dist/{types → data-structures/types}/utils.d.ts +7 -1
  92. package/dist/{types → data-structures/types}/utils.js +20 -19
  93. package/dist/{utils.d.ts → utils/utils.d.ts} +6 -23
  94. package/dist/utils/utils.js +651 -0
  95. package/package.json +20 -42
  96. package/src/data-structures/binary-tree/avl-tree.ts +1 -6
  97. package/src/data-structures/binary-tree/binary-indexed-tree.ts +4 -4
  98. package/src/data-structures/binary-tree/binary-tree.ts +184 -139
  99. package/src/data-structures/binary-tree/bst.ts +15 -24
  100. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  101. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  102. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  103. package/src/data-structures/binary-tree/segment-tree.ts +20 -12
  104. package/src/data-structures/binary-tree/tree-multiset.ts +1 -4
  105. package/src/data-structures/diagrams/README.md +7 -0
  106. package/src/data-structures/graph/abstract-graph.ts +58 -94
  107. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
  108. package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
  109. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
  110. package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
  111. package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
  112. package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
  113. package/src/data-structures/graph/diagrams/edge-list.png +0 -0
  114. package/src/data-structures/graph/diagrams/max-flow.png +0 -0
  115. package/src/data-structures/graph/diagrams/mst.png +0 -0
  116. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  117. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  118. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  119. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  120. package/src/data-structures/graph/directed-graph.ts +12 -28
  121. package/src/data-structures/graph/undirected-graph.ts +11 -10
  122. package/src/data-structures/hash/coordinate-map.ts +1 -1
  123. package/src/data-structures/hash/index.ts +5 -0
  124. package/src/data-structures/heap/heap.ts +2 -11
  125. package/src/data-structures/heap/max-heap.ts +3 -2
  126. package/src/data-structures/heap/min-heap.ts +3 -2
  127. package/src/data-structures/index.ts +1 -0
  128. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -9
  129. package/src/data-structures/linked-list/singly-linked-list.ts +18 -32
  130. package/src/data-structures/matrix/matrix2d.ts +11 -11
  131. package/src/data-structures/matrix/navigator.ts +2 -14
  132. package/src/data-structures/matrix/vector2d.ts +52 -52
  133. package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
  134. package/src/data-structures/priority-queue/min-priority-queue.ts +4 -3
  135. package/src/data-structures/priority-queue/priority-queue.ts +70 -78
  136. package/src/data-structures/queue/deque.ts +2 -2
  137. package/src/data-structures/queue/queue.ts +12 -13
  138. package/src/data-structures/stack/stack.ts +12 -13
  139. package/src/data-structures/trampoline.ts +31 -71
  140. package/src/data-structures/trie/trie.ts +61 -11
  141. package/src/data-structures/types/abstract-graph.ts +51 -0
  142. package/src/data-structures/types/avl-tree.ts +6 -0
  143. package/src/data-structures/types/binary-tree.ts +15 -0
  144. package/src/data-structures/types/bst.ts +5 -0
  145. package/src/data-structures/types/directed-graph.ts +18 -0
  146. package/src/data-structures/types/doubly-linked-list.ts +1 -0
  147. package/src/data-structures/types/heap.ts +8 -0
  148. package/src/data-structures/types/index.ts +13 -0
  149. package/src/data-structures/types/navigator.ts +12 -0
  150. package/src/data-structures/types/priority-queue.ts +9 -0
  151. package/src/data-structures/types/segment-tree.ts +1 -0
  152. package/src/data-structures/types/singly-linked-list.ts +15 -0
  153. package/src/data-structures/types/tree-multiset.ts +3 -0
  154. package/src/{types → data-structures/types}/utils.ts +20 -5
  155. package/src/utils/index.ts +1 -0
  156. package/src/{utils.ts → utils/utils.ts} +32 -132
  157. package/tsconfig.json +9 -6
  158. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  159. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  160. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  161. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  162. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  163. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  164. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  165. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  166. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  167. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  168. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  169. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  170. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  171. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  172. package/dist/types/data-structures/graph/index.d.ts +0 -3
  173. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  174. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  175. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  176. package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
  177. package/dist/types/data-structures/hash/index.d.ts +0 -1
  178. package/dist/types/data-structures/hash/pair.d.ts +0 -1
  179. package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
  180. package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
  181. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  182. package/dist/types/data-structures/heap/index.d.ts +0 -3
  183. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  184. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  185. package/dist/types/data-structures/index.d.ts +0 -9
  186. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  187. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  188. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  189. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
  190. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  191. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  192. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  193. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  194. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  195. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  196. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  197. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  198. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  199. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  200. package/dist/types/data-structures/queue/index.d.ts +0 -1
  201. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  202. package/dist/types/data-structures/stack/index.d.ts +0 -1
  203. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  204. package/dist/types/data-structures/trampoline.d.ts +0 -25
  205. package/dist/types/data-structures/trie/index.d.ts +0 -1
  206. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  207. package/dist/types/types/index.d.ts +0 -1
  208. package/dist/types/types/utils.d.ts +0 -46
  209. package/dist/utils.js +0 -569
  210. package/src/types/index.ts +0 -1
  211. package/src/types/patches/index.d.ts +0 -0
  212. /package/dist/{types → utils}/index.d.ts +0 -0
  213. /package/dist/{types → utils}/index.js +0 -0
@@ -1,5 +1,5 @@
1
- import _ from 'lodash';
2
- import {AnyFunction} from './types';
1
+ import * as _ from 'lodash';
2
+ import {AnyFunction} from '../data-structures/types';
3
3
 
4
4
  export type JSONSerializable = {
5
5
  [key: string]: any
@@ -21,7 +21,7 @@ export function randomText(length: number) {
21
21
  }
22
22
 
23
23
  export const uuidV4 = function () {
24
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
24
+ return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
25
25
  const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
26
26
  return v.toString(16);
27
27
  });
@@ -60,25 +60,15 @@ export function incrementId(prefix?: string) {
60
60
  };
61
61
  }
62
62
 
63
- export const getValue = <T, K extends keyof T>(obj: T, names: K[]): Array<T[K]> => {
64
- return names.map(i => obj[i]);
65
- };
63
+ export const getValue = <T, K extends keyof T>(obj: T, names: K[]): Array<T[K]> => names.map(i => obj[i]);
66
64
 
67
- export const isObject = (object: string | JSONObject | boolean | AnyFunction | number) => {
68
- return object != null && typeof object === 'object';
69
- };
65
+ export const isObject = (object: string | JSONObject | boolean | AnyFunction | number) => object != null && typeof object === 'object';
70
66
 
71
- export const looseEqual = (a: any, b: any): boolean => {
72
- return a == b;
73
- };
67
+ export const looseEqual = (a: any, b: any): boolean => a == b;
74
68
 
75
- export const strictEqual = (a: any, b: any): boolean => {
76
- return a === b;
77
- };
69
+ export const strictEqual = (a: any, b: any): boolean => a === b;
78
70
 
79
- export const strictObjectIsEqual = (a: any, b: any): boolean => {
80
- return Object.is(a, b);
81
- };
71
+ export const strictObjectIsEqual = (a: any, b: any): boolean => Object.is(a, b);
82
72
 
83
73
  export const deepObjectStrictEqual = (object1: JSONSerializable, object2: JSONSerializable) => {
84
74
  const keys1 = Object.keys(object1);
@@ -100,10 +90,6 @@ export const deepObjectStrictEqual = (object1: JSONSerializable, object2: JSONSe
100
90
  return true;
101
91
  };
102
92
 
103
- export const isTypeEqual = <T>(obj: unknown) => {
104
- const m = obj as unknown as T;
105
- };
106
-
107
93
  export function reverseColor(oldColor: string) {
108
94
  const oldColorTemp = '0x' + oldColor.replace(/#/g, '');
109
95
  const str = '000000' + (0xFFFFFF - Number(oldColorTemp)).toString(16);
@@ -152,48 +138,62 @@ export const addDays = (date: Date, days: number): Date => {
152
138
  };
153
139
 
154
140
  export class WaitManager {
141
+ private _time30 = 20000;
142
+ private readonly _nXSpeed: number = 1;
143
+
144
+ constructor(nXSpeed?: number) {
145
+ if (nXSpeed === undefined) nXSpeed = 1;
146
+ this._nXSpeed = nXSpeed;
147
+ }
148
+
155
149
  private _time1 = 1000;
150
+
156
151
  get time1(): number {
157
152
  return this._time1 / this._nXSpeed;
158
153
  }
159
154
 
160
155
  private _time2 = 2000;
156
+
161
157
  get time2(): number {
162
158
  return this._time2 / this._nXSpeed;
163
159
  }
164
160
 
165
161
  private _time3 = 3000;
162
+
166
163
  get time3(): number {
167
164
  return this._time3 / this._nXSpeed;
168
165
  }
169
166
 
170
167
  private _time4 = 4000;
168
+
171
169
  get time4(): number {
172
170
  return this._time4 / this._nXSpeed;
173
171
  }
174
172
 
175
173
  private _time10 = 10000;
174
+
176
175
  get time10(): number {
177
176
  return this._time10 / this._nXSpeed;
178
177
  }
179
178
 
180
179
  private _time20 = 20000;
180
+
181
181
  get time20(): number {
182
182
  return this._time20 / this._nXSpeed;
183
183
  }
184
184
 
185
- private _time30 = 20000;
186
-
187
185
  get time50(): number {
188
186
  return this._time30 / this._nXSpeed;
189
187
  }
190
188
 
191
189
  private _time60 = 60000;
190
+
192
191
  get time60(): number {
193
192
  return this._time60 / this._nXSpeed;
194
193
  }
195
194
 
196
195
  private _cusTime = 1000;
196
+
197
197
  get cusTime(): number {
198
198
  return this._cusTime / this._nXSpeed;
199
199
  }
@@ -201,13 +201,6 @@ export class WaitManager {
201
201
  set cusTime(v: number) {
202
202
  this._cusTime = v;
203
203
  }
204
-
205
- private readonly _nXSpeed: number = 1;
206
-
207
- constructor(nXSpeed?: number) {
208
- if (nXSpeed === undefined) nXSpeed = 1;
209
- this._nXSpeed = nXSpeed;
210
- }
211
204
  }
212
205
 
213
206
  export const wait = async (ms: number, resolveValue?: any) => {
@@ -219,78 +212,6 @@ export const wait = async (ms: number, resolveValue?: any) => {
219
212
  });
220
213
  };
221
214
 
222
- export class AuthAPIError extends Error {
223
- protected serverErrorStack;
224
- protected serverErrorCode;
225
-
226
- constructor(serverErrorMessage: string, serverErrorCode?: string, serverErrorStack?: string) {
227
- super(serverErrorMessage);
228
- if (serverErrorStack) {
229
- this.serverErrorStack = serverErrorStack;
230
- }
231
- if (serverErrorCode) {
232
- this.serverErrorCode = serverErrorCode;
233
- }
234
- this.name = new.target.name;
235
- if (typeof (Error as any).captureStackTrace === 'function') {
236
- (Error as any).captureStackTrace(this, new.target);
237
- }
238
- if (typeof Object.setPrototypeOf === 'function') {
239
- Object.setPrototypeOf(this, new.target.prototype);
240
- } else {
241
- (this as any).__proto__ = new.target.prototype;
242
- }
243
- }
244
- }
245
-
246
- export class BunnyAPIError extends Error {
247
- protected serverErrorStack;
248
- protected serverErrorCode;
249
-
250
- constructor(serverErrorMessage: string, serverErrorCode?: string, serverErrorStack?: string) {
251
- super(serverErrorMessage);
252
- if (serverErrorStack) {
253
- this.serverErrorStack = serverErrorStack;
254
- }
255
- if (serverErrorCode) {
256
- this.serverErrorCode = serverErrorCode;
257
- }
258
- this.name = new.target.name;
259
- if (typeof (Error as any).captureStackTrace === 'function') {
260
- (Error as any).captureStackTrace(this, new.target);
261
- }
262
- if (typeof Object.setPrototypeOf === 'function') {
263
- Object.setPrototypeOf(this, new.target.prototype);
264
- } else {
265
- (this as any).__proto__ = new.target.prototype;
266
- }
267
- }
268
- }
269
-
270
- export class NomicsAPIError extends Error {
271
- protected serverErrorStack;
272
- protected serverErrorCode;
273
-
274
- constructor(serverErrorMessage: string, serverErrorCode?: string, serverErrorStack?: string) {
275
- super(serverErrorMessage);
276
- if (serverErrorStack) {
277
- this.serverErrorStack = serverErrorStack;
278
- }
279
- if (serverErrorCode) {
280
- this.serverErrorCode = serverErrorCode;
281
- }
282
- this.name = new.target.name;
283
- if (typeof (Error as any).captureStackTrace === 'function') {
284
- (Error as any).captureStackTrace(this, new.target);
285
- }
286
- if (typeof Object.setPrototypeOf === 'function') {
287
- Object.setPrototypeOf(this, new.target.prototype);
288
- } else {
289
- (this as any).__proto__ = new.target.prototype;
290
- }
291
- }
292
- }
293
-
294
215
  export function extractValue<Item>(data: { key: string, value: Item }[]) {
295
216
  let result: Item[] = [];
296
217
  if (data && data.length > 0) {
@@ -328,14 +249,9 @@ export function randomDate(start?: Date, end?: Date, specificProbabilityStart?:
328
249
  return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
329
250
  }
330
251
 
252
+ export const capitalizeWords = (str: string) => str.replace(/(?:^|\s)\S/g, (a: string) => a.toUpperCase());
331
253
 
332
- export const capitalizeWords = (str: string) => {
333
- return str.replace(/(?:^|\s)\S/g, (a: string) => a.toUpperCase());
334
- };
335
-
336
- export const capitalizeFirstLetter = (str: string) => {
337
- return str.charAt(0).toUpperCase() + str.slice(1);
338
- };
254
+ export const capitalizeFirstLetter = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
339
255
 
340
256
  export const comparerArray = <T>(otherArray: T[], limitKeys?: string[]) => {
341
257
  return function (current: T) {
@@ -349,17 +265,11 @@ export const comparerArray = <T>(otherArray: T[], limitKeys?: string[]) => {
349
265
  };
350
266
  };
351
267
 
352
- export const onlyInA = <T>(a: T[], b: T[]) => {
353
- return a.filter(comparerArray(b));
354
- };
268
+ export const onlyInA = <T>(a: T[], b: T[]) => a.filter(comparerArray(b));
355
269
 
356
- export const onlyInB = <T>(a: T[], b: T[]) => {
357
- return b.filter(comparerArray(a));
358
- };
270
+ export const onlyInB = <T>(a: T[], b: T[]) => b.filter(comparerArray(a));
359
271
 
360
- export const diffAB = <T>(a: T[], b: T[]) => {
361
- return onlyInA(a, b).concat(onlyInB(a, b));
362
- };
272
+ export const diffAB = <T>(a: T[], b: T[]) => onlyInA(a, b).concat(onlyInB(a, b));
363
273
 
364
274
  export class StringUtil {
365
275
  // camelCase
@@ -413,8 +323,8 @@ export class StringUtil {
413
323
  }
414
324
  }
415
325
 
416
- type ToCase = 'camel' | 'snake' | 'pascal' | 'constant' | 'kebab' | 'lower' | 'title' | 'sentence' | 'path' | 'dot';
417
- export const deepKeysConvert = (obj: any, toType?: ToCase): any => {
326
+ export type CaseType = 'camel' | 'snake' | 'pascal' | 'constant' | 'kebab' | 'lower' | 'title' | 'sentence' | 'path' | 'dot';
327
+ export const deepKeysConvert = (obj: any, toType?: CaseType): any => {
418
328
  const _toType = toType || 'snake';
419
329
  if (Array.isArray(obj)) {
420
330
  return obj.map(v => deepKeysConvert(v, _toType));
@@ -501,13 +411,6 @@ export const deepReplaceValues = (obj: JSONSerializable, keyReducerMap: { [key i
501
411
  return newObject;
502
412
  };
503
413
 
504
- // function getCallStackSize() {
505
- // let count = 0, fn = arguments.callee;
506
- // while ( (fn = fn.caller) ) {
507
- // count++;
508
- // }
509
- // return count;
510
- // }
511
414
  // TODO determine depth and pass root node as a param through callback
512
415
  export const deepAdd = (obj: JSONSerializable, keyReducerMap: { [key in string]: (item: JSONSerializable) => any }, isItemRootParent?: boolean) => {
513
416
  const newObject = _.clone(obj) as JSONObject | [];
@@ -529,7 +432,6 @@ export const deepAdd = (obj: JSONSerializable, keyReducerMap: { [key in string]:
529
432
 
530
433
  const styleString = (color: string) => `color: ${color}; font-weight: bold`;
531
434
 
532
-
533
435
  const styleHeader = (header: string) => `%c[${header}]`;
534
436
 
535
437
  export const bunnyConsole = {
@@ -544,7 +446,6 @@ export const bunnyConsole = {
544
446
  }
545
447
  };
546
448
 
547
-
548
449
  export const timeStart = () => {
549
450
  return performance ? performance.now() : new Date().getTime();
550
451
  };
@@ -601,5 +502,4 @@ export function zip<T = number, T1 = number>(array1: T[], array2: T1[], options?
601
502
  }
602
503
  }
603
504
  return isToObj ? zippedObjCoords : zipped;
604
- }
605
-
505
+ }
package/tsconfig.json CHANGED
@@ -3,18 +3,17 @@
3
3
  "declaration": true,
4
4
  "outDir": "./dist",
5
5
  "module": "commonjs",
6
- "target": "es6",
6
+ "target": "es5",
7
7
  "lib": [
8
- "es6",
9
- "dom",
10
- "dom.iterable",
8
+ // "es2015",
11
9
  "esnext"
12
10
  ],
13
11
  "strict": true,
14
12
  "esModuleInterop": true,
15
13
  "moduleResolution": "node",
16
14
  "declarationDir": "./dist",
17
- "skipLibCheck": true
15
+ "skipLibCheck": true,
16
+ "downlevelIteration": true,
18
17
 
19
18
  // "allowJs": true,
20
19
  // "allowSyntheticDefaultImports": true,
@@ -23,12 +22,16 @@
23
22
  // "resolveJsonModule": true,
24
23
  // "isolatedModules": true,
25
24
  // "noEmit": true,
25
+ "typeRoots": [
26
+ "node_modules/@types"
27
+ ]
26
28
  },
29
+
27
30
  "include": [
28
31
  "src",
29
- "node_modules/data-structure-typed"
30
32
  ],
31
33
  "exclude": [
34
+ // "node_modules/data-structure-typed",
32
35
  "node_modules",
33
36
  "dist"
34
37
  ]
@@ -1,2 +0,0 @@
1
- export declare class AaTree {
2
- }
@@ -1,21 +0,0 @@
1
- import { BST, BSTNode } from './bst';
2
- import { BinaryTreeNodeId } from './binary-tree';
3
- export interface AVLTreeDeleted<T> {
4
- deleted: AVLTreeNode<T> | null;
5
- needBalanced: AVLTreeNode<T> | null;
6
- }
7
- export declare class AVLTreeNode<T> extends BSTNode<T> {
8
- clone(): AVLTreeNode<T>;
9
- }
10
- export declare class AVLTree<T> extends BST<T> {
11
- createNode(id: BinaryTreeNodeId, val: T, count?: number): AVLTreeNode<T>;
12
- put(id: BinaryTreeNodeId, val: T | null, count?: number): AVLTreeNode<T> | null;
13
- remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): AVLTreeDeleted<T>[];
14
- balanceFactor(node: AVLTreeNode<T>): number;
15
- updateHeight(node: AVLTreeNode<T>): void;
16
- balancePath(node: AVLTreeNode<T>): void;
17
- balanceLL(A: AVLTreeNode<T>): void;
18
- balanceLR(A: AVLTreeNode<T>): void;
19
- balanceRR(A: AVLTreeNode<T>): void;
20
- balanceRL(A: AVLTreeNode<T>): void;
21
- }
@@ -1,2 +0,0 @@
1
- export declare class BTree {
2
- }
@@ -1,8 +0,0 @@
1
- export declare class BinaryIndexedTree {
2
- private readonly _sumTree;
3
- constructor(n: number);
4
- update(i: number, delta: number): void;
5
- getPrefixSum(i: number): number;
6
- getRangeSum(start: number, end: number): number;
7
- static lowBit(x: number): number;
8
- }
@@ -1,140 +0,0 @@
1
- export type BinaryTreeNodePropertyName = 'id' | 'val' | 'count';
2
- export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
3
- export type DFSOrderPattern = 'in' | 'pre' | 'post';
4
- export type BinaryTreeNodeId = number;
5
- export type BinaryTreeDeleted<T> = {
6
- deleted: BinaryTreeNode<T> | null | undefined;
7
- needBalanced: BinaryTreeNode<T> | null;
8
- };
9
- export type ResultByProperty<T> = T | BinaryTreeNode<T> | number | BinaryTreeNodeId;
10
- export type ResultsByProperty<T> = ResultByProperty<T>[];
11
- export interface BinaryTreeNodeObj<T> {
12
- id: BinaryTreeNodeId;
13
- val: T;
14
- count?: number;
15
- }
16
- export declare enum FamilyPosition {
17
- root = 0,
18
- left = 1,
19
- right = 2
20
- }
21
- export declare enum LoopType {
22
- iterative = 1,
23
- recursive = 2
24
- }
25
- export declare class BinaryTreeNode<T> {
26
- protected _id: BinaryTreeNodeId;
27
- get id(): BinaryTreeNodeId;
28
- set id(v: BinaryTreeNodeId);
29
- protected _val: T;
30
- get val(): T;
31
- set val(v: T);
32
- protected _left?: BinaryTreeNode<T> | null;
33
- get left(): BinaryTreeNode<T> | null | undefined;
34
- set left(v: BinaryTreeNode<T> | null | undefined);
35
- protected _right?: BinaryTreeNode<T> | null;
36
- get right(): BinaryTreeNode<T> | null | undefined;
37
- set right(v: BinaryTreeNode<T> | null | undefined);
38
- protected _parent: BinaryTreeNode<T> | null | undefined;
39
- get parent(): BinaryTreeNode<T> | null | undefined;
40
- set parent(v: BinaryTreeNode<T> | null | undefined);
41
- protected _familyPosition: FamilyPosition;
42
- get familyPosition(): FamilyPosition;
43
- set familyPosition(v: FamilyPosition);
44
- protected _count: number;
45
- get count(): number;
46
- set count(v: number);
47
- protected _height: number;
48
- get height(): number;
49
- set height(v: number);
50
- constructor(id: BinaryTreeNodeId, val: T, count?: number);
51
- swapLocation(swapNode: BinaryTreeNode<T>): BinaryTreeNode<T>;
52
- clone(): BinaryTreeNode<T>;
53
- }
54
- export declare class BinaryTree<T> {
55
- protected _root: BinaryTreeNode<T> | null;
56
- get root(): BinaryTreeNode<T> | null;
57
- protected set root(v: BinaryTreeNode<T> | null);
58
- protected _size: number;
59
- get size(): number;
60
- protected set size(v: number);
61
- protected _count: number;
62
- get count(): number;
63
- protected set count(v: number);
64
- private readonly _autoIncrementId;
65
- private _maxId;
66
- private readonly _isDuplicatedVal;
67
- protected _loopType: LoopType;
68
- protected _visitedId: BinaryTreeNodeId[];
69
- protected _visitedVal: Array<T>;
70
- protected _visitedNode: BinaryTreeNode<T>[];
71
- protected _visitedCount: number[];
72
- protected _visitedLeftSum: number[];
73
- protected _resetResults(): void;
74
- constructor(options?: {
75
- loopType?: LoopType;
76
- autoIncrementId?: boolean;
77
- isDuplicatedVal?: boolean;
78
- });
79
- createNode(id: BinaryTreeNodeId, val: T | null, count?: number): BinaryTreeNode<T> | null;
80
- clear(): void;
81
- isEmpty(): boolean;
82
- insertTo({ newNode, parent }: {
83
- newNode: BinaryTreeNode<T> | null;
84
- parent: BinaryTreeNode<T>;
85
- }): BinaryTreeNode<T> | null | undefined;
86
- put(id: BinaryTreeNodeId, val: T, count?: number): BinaryTreeNode<T> | null | undefined;
87
- insertMany(data: T[] | BinaryTreeNode<T>[]): (BinaryTreeNode<T> | null | undefined)[];
88
- fill(data: T[] | BinaryTreeNode<T>[]): boolean;
89
- remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeleted<T>[];
90
- getDepth(node: BinaryTreeNode<T>): number;
91
- getHeight(beginRoot?: BinaryTreeNode<T> | null): number;
92
- getMinHeight(beginRoot?: BinaryTreeNode<T> | null): number;
93
- isBalanced(beginRoot?: BinaryTreeNode<T> | null): boolean;
94
- getNodes(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): (BinaryTreeNode<T> | null | undefined)[];
95
- has(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): boolean;
96
- get(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): BinaryTreeNode<T> | null;
97
- getPathToRoot(node: BinaryTreeNode<T>): BinaryTreeNode<T>[];
98
- protected _pushByPropertyNameStopOrNot(cur: BinaryTreeNode<T>, result: (BinaryTreeNode<T> | null | undefined)[], nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): boolean | undefined;
99
- protected _accumulatedByPropertyName(node: BinaryTreeNode<T>, nodeOrPropertyName?: NodeOrPropertyName): void;
100
- protected _getResultByPropertyName(nodeOrPropertyName?: NodeOrPropertyName): ResultsByProperty<T>;
101
- getLeftMost(): BinaryTreeNode<T> | null;
102
- getLeftMost(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
103
- getRightMost(): BinaryTreeNode<T> | null;
104
- getRightMost(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
105
- isBST(node?: BinaryTreeNode<T> | null): boolean;
106
- getSubTreeSizeAndCount(subTreeRoot: BinaryTreeNode<T> | null | undefined): [number, number];
107
- subTreeSum(subTreeRoot: BinaryTreeNode<T>, propertyName?: BinaryTreeNodePropertyName): number;
108
- subTreeAdd(subTreeRoot: BinaryTreeNode<T>, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
109
- BFS(): BinaryTreeNodeId[];
110
- BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
111
- BFS(nodeOrPropertyName: 'val'): T[];
112
- BFS(nodeOrPropertyName: 'node'): BinaryTreeNode<T>[];
113
- BFS(nodeOrPropertyName: 'count'): number[];
114
- DFS(): BinaryTreeNodeId[];
115
- DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
116
- DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
117
- DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
118
- DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
119
- DFSIterative(): BinaryTreeNodeId[];
120
- DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
121
- DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
122
- DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
123
- DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
124
- levelIterative(node: BinaryTreeNode<T> | null): BinaryTreeNodeId[];
125
- levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
126
- levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'val'): T[];
127
- levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
128
- levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'count'): number[];
129
- listLevels(node: BinaryTreeNode<T> | null): BinaryTreeNodeId[][];
130
- listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
131
- listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'val'): T[][];
132
- listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[][];
133
- listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'count'): number[][];
134
- getPredecessor(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
135
- morris(): BinaryTreeNodeId[];
136
- morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
137
- morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
138
- morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
139
- morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
140
- }
@@ -1,32 +0,0 @@
1
- import { BinaryTree, BinaryTreeNode, BinaryTreeNodeId, BinaryTreeNodePropertyName, LoopType } from './binary-tree';
2
- export type BSTComparator = (a: BinaryTreeNodeId, b: BinaryTreeNodeId) => number;
3
- export type BSTDeletedResult<T> = {
4
- deleted: BSTNode<T> | null;
5
- needBalanced: BSTNode<T> | null;
6
- };
7
- export declare enum CP {
8
- lt = -1,
9
- eq = 0,
10
- gt = 1
11
- }
12
- export declare class BSTNode<T> extends BinaryTreeNode<T> {
13
- clone(): BSTNode<T>;
14
- }
15
- export declare class BST<T> extends BinaryTree<T> {
16
- protected _comparator: BSTComparator;
17
- protected _compare(a: BinaryTreeNodeId, b: BinaryTreeNodeId): CP;
18
- constructor(options?: {
19
- comparator?: BSTComparator;
20
- loopType?: LoopType;
21
- });
22
- createNode(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
23
- put(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
24
- get(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): BSTNode<T> | null;
25
- lastKey(): number;
26
- remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BSTDeletedResult<T>[];
27
- getNodes(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): BSTNode<T>[];
28
- lesserSum(id: BinaryTreeNodeId, propertyName?: BinaryTreeNodePropertyName): number;
29
- allGreaterNodesAdd(node: BSTNode<T>, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
30
- balance(): boolean;
31
- isAVLBalanced(): boolean;
32
- }
@@ -1,4 +0,0 @@
1
- export * from './binary-tree';
2
- export * from './bst';
3
- export * from './binary-indexed-tree';
4
- export * from './segment-tree';
@@ -1,2 +0,0 @@
1
- export declare class RBTree {
2
- }
@@ -1,33 +0,0 @@
1
- export type SegmentTreeNodeVal = number;
2
- export declare class SegmentTreeNode {
3
- protected _start: number;
4
- get start(): number;
5
- set start(v: number);
6
- protected _end: number;
7
- get end(): number;
8
- set end(v: number);
9
- protected _val: SegmentTreeNodeVal | null;
10
- get val(): SegmentTreeNodeVal | null;
11
- set val(v: SegmentTreeNodeVal | null);
12
- protected _sum: number;
13
- get sum(): number;
14
- set sum(v: number);
15
- protected _left: SegmentTreeNode | null;
16
- get left(): SegmentTreeNode | null;
17
- set left(v: SegmentTreeNode | null);
18
- protected _right: SegmentTreeNode | null;
19
- get right(): SegmentTreeNode | null;
20
- set right(v: SegmentTreeNode | null);
21
- constructor(start: number, end: number, sum: number, val?: SegmentTreeNodeVal | null);
22
- }
23
- export declare class SegmentTree {
24
- protected _values: number[];
25
- protected _start: number;
26
- protected _end: number;
27
- protected _root: SegmentTreeNode | null;
28
- get root(): SegmentTreeNode | null;
29
- constructor(values: number[], start?: number, end?: number);
30
- build(start: number, end: number): SegmentTreeNode;
31
- updateNode(index: number, sum: number, val?: SegmentTreeNodeVal): void;
32
- querySumByRange(indexA: number, indexB: number): number;
33
- }
@@ -1,2 +0,0 @@
1
- export declare class SplayTree {
2
- }
@@ -1,11 +0,0 @@
1
- import { BST, BSTNode } from './bst';
2
- import { BinaryTreeNodeId } from './binary-tree';
3
- export type TreeMultiSetDeletedResult<T> = {
4
- deleted: BSTNode<T> | null;
5
- needBalanced: BSTNode<T> | null;
6
- };
7
- export declare class TreeMultiSet<T> extends BST<T> {
8
- createNode(id: BinaryTreeNodeId, val: T, count?: number): BSTNode<T>;
9
- put(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
10
- remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): TreeMultiSetDeletedResult<T>[];
11
- }
@@ -1,2 +0,0 @@
1
- export declare class TwoThreeTree {
2
- }