data-structure-typed 1.37.9 → 1.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +9 -9
  2. package/dist/data-structures/binary-tree/avl-tree.js +22 -22
  3. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  4. package/dist/data-structures/binary-tree/binary-tree.d.ts +31 -31
  5. package/dist/data-structures/binary-tree/binary-tree.js +32 -32
  6. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  7. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  8. package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -1
  9. package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
  10. package/dist/data-structures/binary-tree/tree-multiset.d.ts +9 -9
  11. package/dist/data-structures/binary-tree/tree-multiset.js +23 -23
  12. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  13. package/dist/data-structures/hash/hash-map.d.ts +25 -25
  14. package/dist/data-structures/hash/hash-map.js +59 -59
  15. package/dist/data-structures/hash/hash-map.js.map +1 -1
  16. package/dist/data-structures/hash/hash-table.d.ts +34 -34
  17. package/dist/data-structures/hash/hash-table.js +99 -99
  18. package/dist/data-structures/hash/hash-table.js.map +1 -1
  19. package/dist/data-structures/heap/heap.d.ts +67 -68
  20. package/dist/data-structures/heap/heap.js +167 -167
  21. package/dist/data-structures/heap/heap.js.map +1 -1
  22. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
  23. package/dist/data-structures/linked-list/doubly-linked-list.js +3 -3
  24. package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  25. package/dist/data-structures/linked-list/skip-linked-list.d.ts +17 -17
  26. package/dist/data-structures/linked-list/skip-linked-list.js +34 -34
  27. package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
  28. package/dist/data-structures/matrix/matrix2d.d.ts +7 -7
  29. package/dist/data-structures/matrix/matrix2d.js +9 -9
  30. package/dist/data-structures/matrix/matrix2d.js.map +1 -1
  31. package/dist/data-structures/trie/trie.d.ts +2 -2
  32. package/dist/data-structures/trie/trie.js +6 -6
  33. package/dist/data-structures/trie/trie.js.map +1 -1
  34. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -5
  35. package/dist/types/data-structures/binary-tree/bst.js +0 -7
  36. package/dist/types/data-structures/binary-tree/bst.js.map +1 -1
  37. package/dist/types/helpers.d.ts +5 -0
  38. package/dist/types/helpers.js +7 -0
  39. package/dist/types/helpers.js.map +1 -1
  40. package/lib/data-structures/binary-tree/avl-tree.d.ts +9 -9
  41. package/lib/data-structures/binary-tree/avl-tree.js +22 -22
  42. package/lib/data-structures/binary-tree/binary-tree.d.ts +31 -31
  43. package/lib/data-structures/binary-tree/binary-tree.js +32 -32
  44. package/lib/data-structures/binary-tree/rb-tree.d.ts +1 -1
  45. package/lib/data-structures/binary-tree/tree-multiset.d.ts +9 -9
  46. package/lib/data-structures/binary-tree/tree-multiset.js +23 -23
  47. package/lib/data-structures/hash/hash-map.d.ts +25 -25
  48. package/lib/data-structures/hash/hash-map.js +59 -59
  49. package/lib/data-structures/hash/hash-table.d.ts +34 -34
  50. package/lib/data-structures/hash/hash-table.js +99 -99
  51. package/lib/data-structures/heap/heap.d.ts +67 -68
  52. package/lib/data-structures/heap/heap.js +167 -167
  53. package/lib/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
  54. package/lib/data-structures/linked-list/doubly-linked-list.js +3 -3
  55. package/lib/data-structures/linked-list/skip-linked-list.d.ts +17 -17
  56. package/lib/data-structures/linked-list/skip-linked-list.js +34 -34
  57. package/lib/data-structures/matrix/matrix2d.d.ts +7 -7
  58. package/lib/data-structures/matrix/matrix2d.js +9 -9
  59. package/lib/data-structures/trie/trie.d.ts +2 -2
  60. package/lib/data-structures/trie/trie.js +6 -6
  61. package/lib/types/data-structures/binary-tree/bst.d.ts +0 -5
  62. package/lib/types/data-structures/binary-tree/bst.js +1 -6
  63. package/lib/types/helpers.d.ts +5 -0
  64. package/lib/types/helpers.js +6 -1
  65. package/package.json +7 -6
  66. package/src/data-structures/binary-tree/avl-tree.ts +27 -27
  67. package/src/data-structures/binary-tree/binary-tree.ts +55 -55
  68. package/src/data-structures/binary-tree/bst.ts +4 -0
  69. package/src/data-structures/binary-tree/rb-tree.ts +2 -2
  70. package/src/data-structures/binary-tree/tree-multiset.ts +29 -29
  71. package/src/data-structures/hash/hash-map.ts +81 -75
  72. package/src/data-structures/hash/hash-table.ts +112 -109
  73. package/src/data-structures/heap/heap.ts +183 -183
  74. package/src/data-structures/linked-list/doubly-linked-list.ts +4 -4
  75. package/src/data-structures/linked-list/skip-linked-list.ts +45 -38
  76. package/src/data-structures/matrix/matrix2d.ts +10 -10
  77. package/src/data-structures/trie/trie.ts +9 -9
  78. package/src/types/helpers.ts +5 -1
  79. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +1 -1
  80. package/umd/bundle.min.js +1 -1
  81. package/umd/bundle.min.js.map +1 -1
@@ -9,6 +9,32 @@ export class Heap {
9
9
  this.nodes = [];
10
10
  this.comparator = comparator;
11
11
  }
12
+ /**
13
+ * Get the size (number of elements) of the heap.
14
+ */
15
+ get size() {
16
+ return this.nodes.length;
17
+ }
18
+ /**
19
+ * Get the last element in the heap, which is not necessarily a leaf node.
20
+ * @returns The last element or undefined if the heap is empty.
21
+ */
22
+ get leaf() {
23
+ var _a;
24
+ return (_a = this.nodes[this.size - 1]) !== null && _a !== void 0 ? _a : undefined;
25
+ }
26
+ /**
27
+ * Static method that creates a binary heap from an array of nodes and a comparison function.
28
+ * @param nodes
29
+ * @param comparator - Comparison function.
30
+ * @returns A new Heap instance.
31
+ */
32
+ static heapify(nodes, comparator) {
33
+ const binaryHeap = new Heap(comparator);
34
+ binaryHeap.nodes = [...nodes];
35
+ binaryHeap.fix(); // Fix heap properties
36
+ return binaryHeap;
37
+ }
12
38
  /**
13
39
  * Insert an element into the heap and maintain the heap properties.
14
40
  * @param element - The element to be inserted.
@@ -48,54 +74,6 @@ export class Heap {
48
74
  pop() {
49
75
  return this.poll();
50
76
  }
51
- /**
52
- * Float operation to maintain heap properties after adding an element.
53
- * @param index - The index of the newly added element.
54
- */
55
- bubbleUp(index) {
56
- const element = this.nodes[index];
57
- while (index > 0) {
58
- const parentIndex = Math.floor((index - 1) / 2);
59
- const parent = this.nodes[parentIndex];
60
- if (this.comparator(element, parent) < 0) {
61
- this.nodes[index] = parent;
62
- this.nodes[parentIndex] = element;
63
- index = parentIndex;
64
- }
65
- else {
66
- break;
67
- }
68
- }
69
- }
70
- /**
71
- * Sinking operation to maintain heap properties after removing the top element.
72
- * @param index - The index from which to start sinking.
73
- */
74
- sinkDown(index) {
75
- const leftChildIndex = 2 * index + 1;
76
- const rightChildIndex = 2 * index + 2;
77
- const length = this.nodes.length;
78
- let targetIndex = index;
79
- if (leftChildIndex < length && this.comparator(this.nodes[leftChildIndex], this.nodes[targetIndex]) < 0) {
80
- targetIndex = leftChildIndex;
81
- }
82
- if (rightChildIndex < length && this.comparator(this.nodes[rightChildIndex], this.nodes[targetIndex]) < 0) {
83
- targetIndex = rightChildIndex;
84
- }
85
- if (targetIndex !== index) {
86
- const temp = this.nodes[index];
87
- this.nodes[index] = this.nodes[targetIndex];
88
- this.nodes[targetIndex] = temp;
89
- this.sinkDown(targetIndex);
90
- }
91
- }
92
- /**
93
- * Fix the entire heap to maintain heap properties.
94
- */
95
- fix() {
96
- for (let i = Math.floor(this.size / 2); i >= 0; i--)
97
- this.sinkDown(i);
98
- }
99
77
  /**
100
78
  * Peek at the top element of the heap without removing it.
101
79
  * @returns The top element or undefined if the heap is empty.
@@ -106,20 +84,6 @@ export class Heap {
106
84
  }
107
85
  return this.nodes[0];
108
86
  }
109
- /**
110
- * Get the size (number of elements) of the heap.
111
- */
112
- get size() {
113
- return this.nodes.length;
114
- }
115
- /**
116
- * Get the last element in the heap, which is not necessarily a leaf node.
117
- * @returns The last element or undefined if the heap is empty.
118
- */
119
- get leaf() {
120
- var _a;
121
- return (_a = this.nodes[this.size - 1]) !== null && _a !== void 0 ? _a : undefined;
122
- }
123
87
  /**
124
88
  * Check if the heap is empty.
125
89
  * @returns True if the heap is empty, otherwise false.
@@ -213,16 +177,52 @@ export class Heap {
213
177
  return visitedNode;
214
178
  }
215
179
  /**
216
- * Static method that creates a binary heap from an array of nodes and a comparison function.
217
- * @param nodes
218
- * @param comparator - Comparison function.
219
- * @returns A new Heap instance.
180
+ * Float operation to maintain heap properties after adding an element.
181
+ * @param index - The index of the newly added element.
220
182
  */
221
- static heapify(nodes, comparator) {
222
- const binaryHeap = new Heap(comparator);
223
- binaryHeap.nodes = [...nodes];
224
- binaryHeap.fix(); // Fix heap properties
225
- return binaryHeap;
183
+ bubbleUp(index) {
184
+ const element = this.nodes[index];
185
+ while (index > 0) {
186
+ const parentIndex = Math.floor((index - 1) / 2);
187
+ const parent = this.nodes[parentIndex];
188
+ if (this.comparator(element, parent) < 0) {
189
+ this.nodes[index] = parent;
190
+ this.nodes[parentIndex] = element;
191
+ index = parentIndex;
192
+ }
193
+ else {
194
+ break;
195
+ }
196
+ }
197
+ }
198
+ /**
199
+ * Sinking operation to maintain heap properties after removing the top element.
200
+ * @param index - The index from which to start sinking.
201
+ */
202
+ sinkDown(index) {
203
+ const leftChildIndex = 2 * index + 1;
204
+ const rightChildIndex = 2 * index + 2;
205
+ const length = this.nodes.length;
206
+ let targetIndex = index;
207
+ if (leftChildIndex < length && this.comparator(this.nodes[leftChildIndex], this.nodes[targetIndex]) < 0) {
208
+ targetIndex = leftChildIndex;
209
+ }
210
+ if (rightChildIndex < length && this.comparator(this.nodes[rightChildIndex], this.nodes[targetIndex]) < 0) {
211
+ targetIndex = rightChildIndex;
212
+ }
213
+ if (targetIndex !== index) {
214
+ const temp = this.nodes[index];
215
+ this.nodes[index] = this.nodes[targetIndex];
216
+ this.nodes[targetIndex] = temp;
217
+ this.sinkDown(targetIndex);
218
+ }
219
+ }
220
+ /**
221
+ * Fix the entire heap to maintain heap properties.
222
+ */
223
+ fix() {
224
+ for (let i = Math.floor(this.size / 2); i >= 0; i--)
225
+ this.sinkDown(i);
226
226
  }
227
227
  }
228
228
  export class FibonacciHeapNode {
@@ -241,19 +241,6 @@ export class FibonacciHeap {
241
241
  throw new Error('FibonacciHeap constructor: given comparator should be a function.');
242
242
  }
243
243
  }
244
- /**
245
- * Default comparator function used by the heap.
246
- * @param {E} a
247
- * @param {E} b
248
- * @protected
249
- */
250
- defaultComparator(a, b) {
251
- if (a < b)
252
- return -1;
253
- if (a > b)
254
- return 1;
255
- return 0;
256
- }
257
244
  /**
258
245
  * Get the size (number of elements) of the heap.
259
246
  * @returns {number} The size of the heap. Returns 0 if the heap is empty. Returns -1 if the heap is invalid.
@@ -263,29 +250,6 @@ export class FibonacciHeap {
263
250
  this.min = undefined;
264
251
  this.size = 0;
265
252
  }
266
- /**
267
- * Create a new node.
268
- * @param element
269
- * @protected
270
- */
271
- createNode(element) {
272
- return new FibonacciHeapNode(element);
273
- }
274
- /**
275
- * Merge the given node with the root list.
276
- * @param node - The node to be merged.
277
- */
278
- mergeWithRoot(node) {
279
- if (!this.root) {
280
- this.root = node;
281
- }
282
- else {
283
- node.right = this.root.right;
284
- node.left = this.root;
285
- this.root.right.left = node;
286
- this.root.right = node;
287
- }
288
- }
289
253
  /**
290
254
  * O(1) time operation.
291
255
  * Insert an element into the heap and maintain the heap properties.
@@ -346,20 +310,6 @@ export class FibonacciHeap {
346
310
  }
347
311
  return nodes;
348
312
  }
349
- /**
350
- * O(log n) time operation.
351
- * Remove and return the top element (smallest or largest element) from the heap.
352
- * @param node - The node to be removed.
353
- * @protected
354
- */
355
- removeFromRoot(node) {
356
- if (this.root === node)
357
- this.root = node.right;
358
- if (node.left)
359
- node.left.right = node.right;
360
- if (node.right)
361
- node.right.left = node.left;
362
- }
363
313
  /**
364
314
  * O(log n) time operation.
365
315
  * Remove and return the top element (smallest or largest element) from the heap.
@@ -377,52 +327,6 @@ export class FibonacciHeap {
377
327
  parent.child.right = node;
378
328
  }
379
329
  }
380
- /**
381
- * O(log n) time operation.
382
- * Remove and return the top element (smallest or largest element) from the heap.
383
- * @param y
384
- * @param x
385
- * @protected
386
- */
387
- link(y, x) {
388
- this.removeFromRoot(y);
389
- y.left = y;
390
- y.right = y;
391
- this.mergeWithChild(x, y);
392
- x.degree++;
393
- y.parent = x;
394
- }
395
- /**
396
- * O(log n) time operation.
397
- * Remove and return the top element (smallest or largest element) from the heap.
398
- * @protected
399
- */
400
- consolidate() {
401
- const A = new Array(this.size);
402
- const nodes = this.consumeLinkedList(this.root);
403
- let x, y, d, t;
404
- for (const node of nodes) {
405
- x = node;
406
- d = x.degree;
407
- while (A[d]) {
408
- y = A[d];
409
- if (this.comparator(x.element, y.element) > 0) {
410
- t = x;
411
- x = y;
412
- y = t;
413
- }
414
- this.link(y, x);
415
- A[d] = undefined;
416
- d++;
417
- }
418
- A[d] = x;
419
- }
420
- for (let i = 0; i < this.size; i++) {
421
- if (A[i] && this.comparator(A[i].element, this.min.element) <= 0) {
422
- this.min = A[i];
423
- }
424
- }
425
- }
426
330
  /**
427
331
  * O(log n) time operation.
428
332
  * Remove and return the top element (smallest or largest element) from the heap.
@@ -488,4 +392,100 @@ export class FibonacciHeap {
488
392
  // Clear the heap that was merged
489
393
  heapToMerge.clear();
490
394
  }
395
+ /**
396
+ * Default comparator function used by the heap.
397
+ * @param {E} a
398
+ * @param {E} b
399
+ * @protected
400
+ */
401
+ defaultComparator(a, b) {
402
+ if (a < b)
403
+ return -1;
404
+ if (a > b)
405
+ return 1;
406
+ return 0;
407
+ }
408
+ /**
409
+ * Create a new node.
410
+ * @param element
411
+ * @protected
412
+ */
413
+ createNode(element) {
414
+ return new FibonacciHeapNode(element);
415
+ }
416
+ /**
417
+ * Merge the given node with the root list.
418
+ * @param node - The node to be merged.
419
+ */
420
+ mergeWithRoot(node) {
421
+ if (!this.root) {
422
+ this.root = node;
423
+ }
424
+ else {
425
+ node.right = this.root.right;
426
+ node.left = this.root;
427
+ this.root.right.left = node;
428
+ this.root.right = node;
429
+ }
430
+ }
431
+ /**
432
+ * O(log n) time operation.
433
+ * Remove and return the top element (smallest or largest element) from the heap.
434
+ * @param node - The node to be removed.
435
+ * @protected
436
+ */
437
+ removeFromRoot(node) {
438
+ if (this.root === node)
439
+ this.root = node.right;
440
+ if (node.left)
441
+ node.left.right = node.right;
442
+ if (node.right)
443
+ node.right.left = node.left;
444
+ }
445
+ /**
446
+ * O(log n) time operation.
447
+ * Remove and return the top element (smallest or largest element) from the heap.
448
+ * @param y
449
+ * @param x
450
+ * @protected
451
+ */
452
+ link(y, x) {
453
+ this.removeFromRoot(y);
454
+ y.left = y;
455
+ y.right = y;
456
+ this.mergeWithChild(x, y);
457
+ x.degree++;
458
+ y.parent = x;
459
+ }
460
+ /**
461
+ * O(log n) time operation.
462
+ * Remove and return the top element (smallest or largest element) from the heap.
463
+ * @protected
464
+ */
465
+ consolidate() {
466
+ const A = new Array(this.size);
467
+ const nodes = this.consumeLinkedList(this.root);
468
+ let x, y, d, t;
469
+ for (const node of nodes) {
470
+ x = node;
471
+ d = x.degree;
472
+ while (A[d]) {
473
+ y = A[d];
474
+ if (this.comparator(x.element, y.element) > 0) {
475
+ t = x;
476
+ x = y;
477
+ y = t;
478
+ }
479
+ this.link(y, x);
480
+ A[d] = undefined;
481
+ d++;
482
+ }
483
+ A[d] = x;
484
+ }
485
+ for (let i = 0; i < this.size; i++) {
486
+ if (A[i] && this.comparator(A[i].element, this.min.element) <= 0) {
487
+ this.min = A[i];
488
+ }
489
+ }
490
+ }
491
491
  }
@@ -35,6 +35,7 @@ export declare class DoublyLinkedList<E = any> {
35
35
  set tail(value: DoublyLinkedListNode<E> | null);
36
36
  private _length;
37
37
  get length(): number;
38
+ get size(): number;
38
39
  /**
39
40
  * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
40
41
  * given array.
@@ -98,7 +99,6 @@ export declare class DoublyLinkedList<E = any> {
98
99
  * @returns The method `peekLast()` returns the last node of the doubly linked list, or `null` if the list is empty.
99
100
  */
100
101
  peekLast(): E | undefined;
101
- get size(): number;
102
102
  /**
103
103
  * The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
104
104
  * @param {number} index - The index parameter is a number that represents the position of the element we want to
@@ -59,6 +59,9 @@ export class DoublyLinkedList {
59
59
  get length() {
60
60
  return this._length;
61
61
  }
62
+ get size() {
63
+ return this.length;
64
+ }
62
65
  /**
63
66
  * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
64
67
  * given array.
@@ -194,9 +197,6 @@ export class DoublyLinkedList {
194
197
  var _a;
195
198
  return (_a = this.tail) === null || _a === void 0 ? void 0 : _a.val;
196
199
  }
197
- get size() {
198
- return this.length;
199
- }
200
200
  /**
201
201
  * The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
202
202
  * @param {number} index - The index parameter is a number that represents the position of the element we want to
@@ -12,18 +12,6 @@ export declare class SkipListNode<K, V> {
12
12
  constructor(key: K, value: V, level: number);
13
13
  }
14
14
  export declare class SkipList<K, V> {
15
- get probability(): number;
16
- set probability(value: number);
17
- get maxLevel(): number;
18
- set maxLevel(value: number);
19
- get level(): number;
20
- set level(value: number);
21
- get head(): SkipListNode<K, V>;
22
- set head(value: SkipListNode<K, V>);
23
- private _head;
24
- private _level;
25
- private _maxLevel;
26
- private _probability;
27
15
  /**
28
16
  * The constructor initializes a SkipList with a specified maximum level and probability.
29
17
  * @param [maxLevel=16] - The `maxLevel` parameter represents the maximum level that a skip list can have. It determines
@@ -32,11 +20,18 @@ export declare class SkipList<K, V> {
32
20
  * level in the skip list. It is used to determine the height of each node in the skip list.
33
21
  */
34
22
  constructor(maxLevel?: number, probability?: number);
35
- /**
36
- * The function "randomLevel" generates a random level based on a given probability and maximum level.
37
- * @returns the level, which is a number.
38
- */
39
- private randomLevel;
23
+ private _head;
24
+ get head(): SkipListNode<K, V>;
25
+ set head(value: SkipListNode<K, V>);
26
+ private _level;
27
+ get level(): number;
28
+ set level(value: number);
29
+ private _maxLevel;
30
+ get maxLevel(): number;
31
+ set maxLevel(value: number);
32
+ private _probability;
33
+ get probability(): number;
34
+ set probability(value: number);
40
35
  /**
41
36
  * The add function adds a new node with a given key and value to a Skip List data structure.
42
37
  * @param {K} key - The key parameter represents the key of the node that needs to be added to the skip list.
@@ -58,4 +53,9 @@ export declare class SkipList<K, V> {
58
53
  * skip list, and `false` if the key was not found in the skip list.
59
54
  */
60
55
  delete(key: K): boolean;
56
+ /**
57
+ * The function "randomLevel" generates a random level based on a given probability and maximum level.
58
+ * @returns the level, which is a number.
59
+ */
60
+ private randomLevel;
61
61
  }
@@ -13,30 +13,6 @@ export class SkipListNode {
13
13
  }
14
14
  }
15
15
  export class SkipList {
16
- get probability() {
17
- return this._probability;
18
- }
19
- set probability(value) {
20
- this._probability = value;
21
- }
22
- get maxLevel() {
23
- return this._maxLevel;
24
- }
25
- set maxLevel(value) {
26
- this._maxLevel = value;
27
- }
28
- get level() {
29
- return this._level;
30
- }
31
- set level(value) {
32
- this._level = value;
33
- }
34
- get head() {
35
- return this._head;
36
- }
37
- set head(value) {
38
- this._head = value;
39
- }
40
16
  /**
41
17
  * The constructor initializes a SkipList with a specified maximum level and probability.
42
18
  * @param [maxLevel=16] - The `maxLevel` parameter represents the maximum level that a skip list can have. It determines
@@ -50,16 +26,29 @@ export class SkipList {
50
26
  this._maxLevel = maxLevel;
51
27
  this._probability = probability;
52
28
  }
53
- /**
54
- * The function "randomLevel" generates a random level based on a given probability and maximum level.
55
- * @returns the level, which is a number.
56
- */
57
- randomLevel() {
58
- let level = 1;
59
- while (Math.random() < this.probability && level < this.maxLevel) {
60
- level++;
61
- }
62
- return level;
29
+ get head() {
30
+ return this._head;
31
+ }
32
+ set head(value) {
33
+ this._head = value;
34
+ }
35
+ get level() {
36
+ return this._level;
37
+ }
38
+ set level(value) {
39
+ this._level = value;
40
+ }
41
+ get maxLevel() {
42
+ return this._maxLevel;
43
+ }
44
+ set maxLevel(value) {
45
+ this._maxLevel = value;
46
+ }
47
+ get probability() {
48
+ return this._probability;
49
+ }
50
+ set probability(value) {
51
+ this._probability = value;
63
52
  }
64
53
  /**
65
54
  * The add function adds a new node with a given key and value to a Skip List data structure.
@@ -134,4 +123,15 @@ export class SkipList {
134
123
  }
135
124
  return false;
136
125
  }
126
+ /**
127
+ * The function "randomLevel" generates a random level based on a given probability and maximum level.
128
+ * @returns the level, which is a number.
129
+ */
130
+ randomLevel() {
131
+ let level = 1;
132
+ while (Math.random() < this.probability && level < this.maxLevel) {
133
+ level++;
134
+ }
135
+ return level;
136
+ }
137
137
  }
@@ -31,13 +31,6 @@ export declare class Matrix2D {
31
31
  * array of numbers.
32
32
  */
33
33
  get m(): number[][];
34
- /**
35
- * The function "toVector" returns a new Vector2D object with the values from the first and second elements of the
36
- * _matrix array.
37
- * @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
38
- * the first column of the matrix.
39
- */
40
- toVector(): Vector2D;
41
34
  /**
42
35
  * The function takes two 2D matrices as input and returns their sum as a new 2D matrix.
43
36
  * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to be added.
@@ -104,5 +97,12 @@ export declare class Matrix2D {
104
97
  * @returns The method is returning a new instance of the Matrix2D class.
105
98
  */
106
99
  static translate(vector: Vector2D): Matrix2D;
100
+ /**
101
+ * The function "toVector" returns a new Vector2D object with the values from the first and second elements of the
102
+ * _matrix array.
103
+ * @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
104
+ * the first column of the matrix.
105
+ */
106
+ toVector(): Vector2D;
107
107
  }
108
108
  export default Matrix2D;
@@ -53,15 +53,6 @@ export class Matrix2D {
53
53
  get m() {
54
54
  return this._matrix;
55
55
  }
56
- /**
57
- * The function "toVector" returns a new Vector2D object with the values from the first and second elements of the
58
- * _matrix array.
59
- * @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
60
- * the first column of the matrix.
61
- */
62
- toVector() {
63
- return new Vector2D(this._matrix[0][0], this._matrix[1][0]);
64
- }
65
56
  /**
66
57
  * The function takes two 2D matrices as input and returns their sum as a new 2D matrix.
67
58
  * @param {Matrix2D} matrix1 - Matrix2D - The first matrix to be added.
@@ -192,5 +183,14 @@ export class Matrix2D {
192
183
  [0, 0, vector.w]
193
184
  ]);
194
185
  }
186
+ /**
187
+ * The function "toVector" returns a new Vector2D object with the values from the first and second elements of the
188
+ * _matrix array.
189
+ * @returns A new instance of the Vector2D class is being returned. The values of the returned vector are taken from
190
+ * the first column of the matrix.
191
+ */
192
+ toVector() {
193
+ return new Vector2D(this._matrix[0][0], this._matrix[1][0]);
194
+ }
195
195
  }
196
196
  export default Matrix2D;
@@ -25,11 +25,11 @@ export declare class TrieNode {
25
25
  * Trie represents a Trie data structure. It provides basic Trie operations and additional methods.
26
26
  */
27
27
  export declare class Trie {
28
+ private readonly _caseSensitive;
28
29
  constructor(words?: string[], caseSensitive?: boolean);
29
30
  protected _root: TrieNode;
30
31
  get root(): TrieNode;
31
32
  set root(v: TrieNode);
32
- private readonly _caseSensitive;
33
33
  /**
34
34
  * Add a word to the Trie structure.
35
35
  * @param {string} word - The word to add.
@@ -42,7 +42,6 @@ export declare class Trie {
42
42
  * @returns {boolean} True if the word is present in the Trie.
43
43
  */
44
44
  has(word: string): boolean;
45
- private _caseProcess;
46
45
  /**
47
46
  * Remove a word from the Trie structure.
48
47
  * @param{string} word - The word to delete.
@@ -81,4 +80,5 @@ export declare class Trie {
81
80
  * @returns {string[]} an array of strings.
82
81
  */
83
82
  getWords(prefix?: string, max?: number): string[];
83
+ private _caseProcess;
84
84
  }
@@ -88,12 +88,6 @@ export class Trie {
88
88
  }
89
89
  return cur.isEnd;
90
90
  }
91
- _caseProcess(str) {
92
- if (!this._caseSensitive) {
93
- str = str.toLowerCase(); // Convert str to lowercase if case-insensitive
94
- }
95
- return str;
96
- }
97
91
  /**
98
92
  * Remove a word from the Trie structure.
99
93
  * @param{string} word - The word to delete.
@@ -260,4 +254,10 @@ export class Trie {
260
254
  dfs(startNode, prefix);
261
255
  return words;
262
256
  }
257
+ _caseProcess(str) {
258
+ if (!this._caseSensitive) {
259
+ str = str.toLowerCase(); // Convert str to lowercase if case-insensitive
260
+ }
261
+ return str;
262
+ }
263
263
  }
@@ -5,8 +5,3 @@ export type BSTNodeNested<T> = BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNo
5
5
  export type BSTOptions = BinaryTreeOptions & {
6
6
  comparator?: BSTComparator;
7
7
  };
8
- export declare enum CP {
9
- lt = "lt",
10
- eq = "eq",
11
- gt = "gt"
12
- }
@@ -1,6 +1 @@
1
- export var CP;
2
- (function (CP) {
3
- CP["lt"] = "lt";
4
- CP["eq"] = "eq";
5
- CP["gt"] = "gt";
6
- })(CP || (CP = {}));
1
+ export {};