data-structure-typed 1.19.3 → 1.19.4

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 (155) hide show
  1. package/dist/data-structures/binary-tree/aa-tree.js +2 -5
  2. package/dist/data-structures/binary-tree/abstract-binary-tree.js +361 -488
  3. package/dist/data-structures/binary-tree/avl-tree.js +46 -90
  4. package/dist/data-structures/binary-tree/b-tree.js +2 -5
  5. package/dist/data-structures/binary-tree/binary-indexed-tree.js +17 -22
  6. package/dist/data-structures/binary-tree/binary-tree.js +9 -31
  7. package/dist/data-structures/binary-tree/bst.js +96 -139
  8. package/dist/data-structures/binary-tree/rb-tree.js +32 -56
  9. package/dist/data-structures/binary-tree/segment-tree.js +78 -120
  10. package/dist/data-structures/binary-tree/splay-tree.js +2 -5
  11. package/dist/data-structures/binary-tree/tree-multiset.js +176 -253
  12. package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
  13. package/dist/data-structures/graph/abstract-graph.js +340 -574
  14. package/dist/data-structures/graph/directed-graph.js +146 -276
  15. package/dist/data-structures/graph/undirected-graph.js +87 -176
  16. package/dist/data-structures/hash/coordinate-map.js +23 -45
  17. package/dist/data-structures/hash/coordinate-set.js +20 -42
  18. package/dist/data-structures/hash/hash-table.js +2 -5
  19. package/dist/data-structures/hash/pair.js +2 -5
  20. package/dist/data-structures/hash/tree-map.js +2 -5
  21. package/dist/data-structures/hash/tree-set.js +2 -5
  22. package/dist/data-structures/heap/heap.js +53 -77
  23. package/dist/data-structures/heap/max-heap.js +8 -26
  24. package/dist/data-structures/heap/min-heap.js +8 -26
  25. package/dist/data-structures/linked-list/doubly-linked-list.js +132 -197
  26. package/dist/data-structures/linked-list/singly-linked-list.js +112 -173
  27. package/dist/data-structures/linked-list/skip-linked-list.js +2 -5
  28. package/dist/data-structures/matrix/matrix.js +7 -8
  29. package/dist/data-structures/matrix/matrix2d.js +76 -93
  30. package/dist/data-structures/matrix/navigator.js +18 -37
  31. package/dist/data-structures/matrix/vector2d.js +80 -101
  32. package/dist/data-structures/priority-queue/max-priority-queue.js +11 -39
  33. package/dist/data-structures/priority-queue/min-priority-queue.js +11 -39
  34. package/dist/data-structures/priority-queue/priority-queue.js +93 -139
  35. package/dist/data-structures/queue/deque.js +82 -128
  36. package/dist/data-structures/queue/queue.js +24 -25
  37. package/dist/data-structures/stack/stack.js +21 -22
  38. package/dist/data-structures/tree/tree.js +32 -45
  39. package/dist/data-structures/trie/trie.js +93 -200
  40. package/dist/utils/utils.js +22 -107
  41. package/dist/utils/validate-type.js +2 -2
  42. package/package.json +1 -1
  43. package/src/assets/complexities-diff.jpg +0 -0
  44. package/src/assets/data-structure-complexities.jpg +0 -0
  45. package/src/assets/logo.png +0 -0
  46. package/src/assets/overview-diagram-of-data-structures.png +0 -0
  47. package/src/data-structures/binary-tree/aa-tree.ts +3 -0
  48. package/src/data-structures/binary-tree/abstract-binary-tree.ts +1528 -0
  49. package/src/data-structures/binary-tree/avl-tree.ts +297 -0
  50. package/src/data-structures/binary-tree/b-tree.ts +3 -0
  51. package/src/data-structures/binary-tree/binary-indexed-tree.ts +78 -0
  52. package/src/data-structures/binary-tree/binary-tree.ts +40 -0
  53. package/src/data-structures/binary-tree/bst.ts +435 -0
  54. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  55. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  56. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  57. package/src/data-structures/binary-tree/index.ts +12 -0
  58. package/src/data-structures/binary-tree/rb-tree.ts +102 -0
  59. package/src/data-structures/binary-tree/segment-tree.ts +243 -0
  60. package/src/data-structures/binary-tree/splay-tree.ts +3 -0
  61. package/src/data-structures/binary-tree/tree-multiset.ts +694 -0
  62. package/src/data-structures/binary-tree/two-three-tree.ts +3 -0
  63. package/src/data-structures/diagrams/README.md +5 -0
  64. package/src/data-structures/graph/abstract-graph.ts +1032 -0
  65. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  66. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  67. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  68. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  69. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  70. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  71. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  72. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  73. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  74. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  75. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  76. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  77. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  78. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  79. package/src/data-structures/graph/directed-graph.ts +472 -0
  80. package/src/data-structures/graph/index.ts +3 -0
  81. package/src/data-structures/graph/undirected-graph.ts +270 -0
  82. package/src/data-structures/hash/coordinate-map.ts +67 -0
  83. package/src/data-structures/hash/coordinate-set.ts +56 -0
  84. package/src/data-structures/hash/hash-table.ts +3 -0
  85. package/src/data-structures/hash/index.ts +6 -0
  86. package/src/data-structures/hash/pair.ts +3 -0
  87. package/src/data-structures/hash/tree-map.ts +3 -0
  88. package/src/data-structures/hash/tree-set.ts +3 -0
  89. package/src/data-structures/heap/heap.ts +183 -0
  90. package/src/data-structures/heap/index.ts +3 -0
  91. package/src/data-structures/heap/max-heap.ts +31 -0
  92. package/src/data-structures/heap/min-heap.ts +34 -0
  93. package/src/data-structures/index.ts +15 -0
  94. package/src/data-structures/interfaces/abstract-binary-tree.ts +231 -0
  95. package/src/data-structures/interfaces/abstract-graph.ts +40 -0
  96. package/src/data-structures/interfaces/avl-tree.ts +28 -0
  97. package/src/data-structures/interfaces/binary-tree.ts +8 -0
  98. package/src/data-structures/interfaces/bst.ts +32 -0
  99. package/src/data-structures/interfaces/directed-graph.ts +20 -0
  100. package/src/data-structures/interfaces/doubly-linked-list.ts +1 -0
  101. package/src/data-structures/interfaces/heap.ts +1 -0
  102. package/src/data-structures/interfaces/index.ts +15 -0
  103. package/src/data-structures/interfaces/navigator.ts +1 -0
  104. package/src/data-structures/interfaces/priority-queue.ts +1 -0
  105. package/src/data-structures/interfaces/rb-tree.ts +11 -0
  106. package/src/data-structures/interfaces/segment-tree.ts +1 -0
  107. package/src/data-structures/interfaces/singly-linked-list.ts +1 -0
  108. package/src/data-structures/interfaces/tree-multiset.ts +12 -0
  109. package/src/data-structures/interfaces/undirected-graph.ts +6 -0
  110. package/src/data-structures/linked-list/doubly-linked-list.ts +573 -0
  111. package/src/data-structures/linked-list/index.ts +3 -0
  112. package/src/data-structures/linked-list/singly-linked-list.ts +490 -0
  113. package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
  114. package/src/data-structures/matrix/index.ts +4 -0
  115. package/src/data-structures/matrix/matrix.ts +27 -0
  116. package/src/data-structures/matrix/matrix2d.ts +208 -0
  117. package/src/data-structures/matrix/navigator.ts +122 -0
  118. package/src/data-structures/matrix/vector2d.ts +316 -0
  119. package/src/data-structures/priority-queue/index.ts +3 -0
  120. package/src/data-structures/priority-queue/max-priority-queue.ts +49 -0
  121. package/src/data-structures/priority-queue/min-priority-queue.ts +50 -0
  122. package/src/data-structures/priority-queue/priority-queue.ts +354 -0
  123. package/src/data-structures/queue/deque.ts +251 -0
  124. package/src/data-structures/queue/index.ts +2 -0
  125. package/src/data-structures/queue/queue.ts +120 -0
  126. package/src/data-structures/stack/index.ts +1 -0
  127. package/src/data-structures/stack/stack.ts +98 -0
  128. package/src/data-structures/tree/index.ts +1 -0
  129. package/src/data-structures/tree/tree.ts +69 -0
  130. package/src/data-structures/trie/index.ts +1 -0
  131. package/src/data-structures/trie/trie.ts +227 -0
  132. package/src/data-structures/types/abstract-binary-tree.ts +42 -0
  133. package/src/data-structures/types/abstract-graph.ts +5 -0
  134. package/src/data-structures/types/avl-tree.ts +5 -0
  135. package/src/data-structures/types/binary-tree.ts +9 -0
  136. package/src/data-structures/types/bst.ts +12 -0
  137. package/src/data-structures/types/directed-graph.ts +8 -0
  138. package/src/data-structures/types/doubly-linked-list.ts +1 -0
  139. package/src/data-structures/types/heap.ts +5 -0
  140. package/src/data-structures/types/helpers.ts +1 -0
  141. package/src/data-structures/types/index.ts +15 -0
  142. package/src/data-structures/types/navigator.ts +13 -0
  143. package/src/data-structures/types/priority-queue.ts +9 -0
  144. package/src/data-structures/types/rb-tree.ts +8 -0
  145. package/src/data-structures/types/segment-tree.ts +1 -0
  146. package/src/data-structures/types/singly-linked-list.ts +1 -0
  147. package/src/data-structures/types/tree-multiset.ts +8 -0
  148. package/src/index.ts +2 -0
  149. package/src/utils/index.ts +3 -0
  150. package/src/utils/types/index.ts +2 -0
  151. package/src/utils/types/utils.ts +6 -0
  152. package/src/utils/types/validate-type.ts +25 -0
  153. package/src/utils/utils.ts +78 -0
  154. package/src/utils/validate-type.ts +69 -0
  155. package/tsconfig.json +1 -1
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Heap = exports.HeapItem = void 0;
4
- var HeapItem = /** @class */ (function () {
4
+ class HeapItem {
5
5
  /**
6
6
  * The constructor function initializes an instance of a class with a priority and a value.
7
7
  * @param {number} priority - The `priority` parameter is a number that represents the priority of the value. It is
@@ -9,99 +9,76 @@ var HeapItem = /** @class */ (function () {
9
9
  * @param {T | null} [val=null] - The `val` parameter is of type `T | null`, which means it can accept a value of type
10
10
  * `T` or `null`.
11
11
  */
12
- function HeapItem(priority, val) {
13
- if (priority === void 0) { priority = NaN; }
14
- if (val === void 0) { val = null; }
12
+ constructor(priority = NaN, val = null) {
15
13
  this._val = val;
16
14
  this._priority = priority;
17
15
  }
18
- Object.defineProperty(HeapItem.prototype, "priority", {
19
- get: function () {
20
- return this._priority;
21
- },
22
- set: function (value) {
23
- this._priority = value;
24
- },
25
- enumerable: false,
26
- configurable: true
27
- });
28
- Object.defineProperty(HeapItem.prototype, "val", {
29
- get: function () {
30
- return this._val;
31
- },
32
- set: function (value) {
33
- this._val = value;
34
- },
35
- enumerable: false,
36
- configurable: true
37
- });
38
- return HeapItem;
39
- }());
16
+ get priority() {
17
+ return this._priority;
18
+ }
19
+ set priority(value) {
20
+ this._priority = value;
21
+ }
22
+ get val() {
23
+ return this._val;
24
+ }
25
+ set val(value) {
26
+ this._val = value;
27
+ }
28
+ }
40
29
  exports.HeapItem = HeapItem;
41
- var Heap = /** @class */ (function () {
30
+ class Heap {
42
31
  /**
43
32
  * The function is a constructor for a class that initializes a priority callback function based on the
44
33
  * options provided.
45
34
  * @param [options] - An optional object that contains configuration options for the Heap.
46
35
  */
47
- function Heap(options) {
36
+ constructor(options) {
48
37
  if (options) {
49
- var priorityExtractor = options.priorityExtractor;
38
+ const { priorityExtractor } = options;
50
39
  if (priorityExtractor !== undefined && typeof priorityExtractor !== 'function') {
51
40
  throw new Error('.constructor expects a valid priority function');
52
41
  }
53
- this._priorityExtractor = priorityExtractor || (function (el) { return +el; });
42
+ this._priorityExtractor = priorityExtractor || ((el) => +el);
54
43
  }
55
44
  else {
56
- this._priorityExtractor = function (el) { return +el; };
45
+ this._priorityExtractor = (el) => +el;
57
46
  }
58
47
  }
59
- Object.defineProperty(Heap.prototype, "pq", {
60
- get: function () {
61
- return this._pq;
62
- },
63
- enumerable: false,
64
- configurable: true
65
- });
66
- Object.defineProperty(Heap.prototype, "priorityExtractor", {
67
- get: function () {
68
- return this._priorityExtractor;
69
- },
70
- enumerable: false,
71
- configurable: true
72
- });
73
- Object.defineProperty(Heap.prototype, "size", {
74
- /**
75
- * The function returns the size of a priority queue.
76
- * @returns The size of the priority queue.
77
- */
78
- get: function () {
79
- return this._pq.size;
80
- },
81
- enumerable: false,
82
- configurable: true
83
- });
48
+ get pq() {
49
+ return this._pq;
50
+ }
51
+ get priorityExtractor() {
52
+ return this._priorityExtractor;
53
+ }
54
+ /**
55
+ * The function returns the size of a priority queue.
56
+ * @returns The size of the priority queue.
57
+ */
58
+ get size() {
59
+ return this._pq.size;
60
+ }
84
61
  /**
85
62
  * The function checks if a priority queue is empty.
86
63
  * @returns {boolean} A boolean value indicating whether the size of the priority queue is less than 1.
87
64
  */
88
- Heap.prototype.isEmpty = function () {
65
+ isEmpty() {
89
66
  return this._pq.size < 1;
90
- };
67
+ }
91
68
  /**
92
69
  * The `peek` function returns the top item in the priority queue without removing it.
93
70
  * @returns The `peek()` method is returning either a `HeapItem<T>` object or `null`.Returns an val with the highest priority in the queue
94
71
  */
95
- Heap.prototype.peek = function () {
72
+ peek() {
96
73
  return this._pq.peek();
97
- };
74
+ }
98
75
  /**
99
76
  * The `peekLast` function returns the last item in the heap.
100
77
  * @returns The method `peekLast()` returns either a `HeapItem<T>` object or `null`.Returns an val with the lowest priority in the queue
101
78
  */
102
- Heap.prototype.peekLast = function () {
79
+ peekLast() {
103
80
  return this._pq.leaf();
104
- };
81
+ }
105
82
  /**
106
83
  * The `add` function adds an val to a priority queue with an optional priority value.
107
84
  * @param {T} val - The `val` parameter represents the value that you want to add to the heap. It can be of any
@@ -112,7 +89,7 @@ var Heap = /** @class */ (function () {
112
89
  * @returns The `add` method returns the instance of the `Heap` class.
113
90
  * @throws {Error} if priority is not a valid number
114
91
  */
115
- Heap.prototype.add = function (val, priority) {
92
+ add(val, priority) {
116
93
  if (typeof val === 'number') {
117
94
  priority = val;
118
95
  }
@@ -128,49 +105,48 @@ var Heap = /** @class */ (function () {
128
105
  throw new Error('.add expects a numeric priority '
129
106
  + 'or a constructor callback that returns a number');
130
107
  }
131
- var _priority = !Number.isNaN(+priority) ? priority : this._priorityExtractor(val);
108
+ const _priority = !Number.isNaN(+priority) ? priority : this._priorityExtractor(val);
132
109
  this._pq.add(new HeapItem(_priority, val));
133
110
  return this;
134
- };
111
+ }
135
112
  /**
136
113
  * The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an val with the highest priority in the queue
137
114
  * @returns either a HeapItem<T> object or null.
138
115
  */
139
- Heap.prototype.poll = function () {
140
- var top = this._pq.poll();
116
+ poll() {
117
+ const top = this._pq.poll();
141
118
  if (!top) {
142
119
  return null;
143
120
  }
144
121
  return top;
145
- };
122
+ }
146
123
  /**
147
124
  * The function checks if a given node or value exists in the priority queue.
148
125
  * @param {T | HeapItem<T>} node - The parameter `node` can be of type `T` or `HeapItem<T>`.
149
126
  * @returns a boolean value.
150
127
  */
151
- Heap.prototype.has = function (node) {
128
+ has(node) {
152
129
  if (node instanceof HeapItem) {
153
130
  return this.pq.getNodes().includes(node);
154
131
  }
155
132
  else {
156
- return this.pq.getNodes().findIndex(function (item) {
133
+ return this.pq.getNodes().findIndex(item => {
157
134
  return item.val === node;
158
135
  }) !== -1;
159
136
  }
160
- };
137
+ }
161
138
  /**
162
139
  * The `toArray` function returns an array of `HeapItem<T>` objects.
163
140
  * @returns An array of HeapItem<T> objects.Returns a sorted list of vals
164
141
  */
165
- Heap.prototype.toArray = function () {
142
+ toArray() {
166
143
  return this._pq.toArray();
167
- };
144
+ }
168
145
  /**
169
146
  * The clear function clears the priority queue.
170
147
  */
171
- Heap.prototype.clear = function () {
148
+ clear() {
172
149
  this._pq.clear();
173
- };
174
- return Heap;
175
- }());
150
+ }
151
+ }
176
152
  exports.Heap = Heap;
@@ -6,43 +6,25 @@
6
6
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
7
7
  * @license MIT License
8
8
  */
9
- var __extends = (this && this.__extends) || (function () {
10
- var extendStatics = function (d, b) {
11
- extendStatics = Object.setPrototypeOf ||
12
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
13
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
14
- return extendStatics(d, b);
15
- };
16
- return function (d, b) {
17
- if (typeof b !== "function" && b !== null)
18
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
19
- extendStatics(d, b);
20
- function __() { this.constructor = d; }
21
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
22
- };
23
- })();
24
9
  Object.defineProperty(exports, "__esModule", { value: true });
25
10
  exports.MaxHeap = void 0;
26
- var heap_1 = require("./heap");
27
- var priority_queue_1 = require("../priority-queue");
11
+ const heap_1 = require("./heap");
12
+ const priority_queue_1 = require("../priority-queue");
28
13
  /**
29
14
  * @class MaxHeap
30
15
  * @extends Heap
31
16
  */
32
- var MaxHeap = /** @class */ (function (_super) {
33
- __extends(MaxHeap, _super);
17
+ class MaxHeap extends heap_1.Heap {
34
18
  /**
35
19
  * The constructor initializes a PriorityQueue with a custom comparator function.
36
20
  * @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
37
21
  * type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
38
22
  */
39
- function MaxHeap(options) {
40
- var _this = _super.call(this, options) || this;
41
- _this._pq = new priority_queue_1.PriorityQueue({
42
- comparator: function (a, b) { return b.priority - a.priority; }
23
+ constructor(options) {
24
+ super(options);
25
+ this._pq = new priority_queue_1.PriorityQueue({
26
+ comparator: (a, b) => b.priority - a.priority
43
27
  });
44
- return _this;
45
28
  }
46
- return MaxHeap;
47
- }(heap_1.Heap));
29
+ }
48
30
  exports.MaxHeap = MaxHeap;
@@ -6,44 +6,26 @@
6
6
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
7
7
  * @license MIT License
8
8
  */
9
- var __extends = (this && this.__extends) || (function () {
10
- var extendStatics = function (d, b) {
11
- extendStatics = Object.setPrototypeOf ||
12
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
13
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
14
- return extendStatics(d, b);
15
- };
16
- return function (d, b) {
17
- if (typeof b !== "function" && b !== null)
18
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
19
- extendStatics(d, b);
20
- function __() { this.constructor = d; }
21
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
22
- };
23
- })();
24
9
  Object.defineProperty(exports, "__esModule", { value: true });
25
10
  exports.MinHeap = void 0;
26
- var heap_1 = require("./heap");
27
- var priority_queue_1 = require("../priority-queue");
11
+ const heap_1 = require("./heap");
12
+ const priority_queue_1 = require("../priority-queue");
28
13
  /**
29
14
  * @class MinHeap
30
15
  * @extends Heap
31
16
  */
32
- var MinHeap = /** @class */ (function (_super) {
33
- __extends(MinHeap, _super);
17
+ class MinHeap extends heap_1.Heap {
34
18
  /**
35
19
  * The constructor initializes a PriorityQueue with a comparator function that compares the priority of two HeapItem
36
20
  * objects.
37
21
  * @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
38
22
  * type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
39
23
  */
40
- function MinHeap(options) {
41
- var _this = _super.call(this, options) || this;
42
- _this._pq = new priority_queue_1.PriorityQueue({
43
- comparator: function (a, b) { return a.priority - b.priority; }
24
+ constructor(options) {
25
+ super(options);
26
+ this._pq = new priority_queue_1.PriorityQueue({
27
+ comparator: (a, b) => a.priority - b.priority
44
28
  });
45
- return _this;
46
29
  }
47
- return MinHeap;
48
- }(heap_1.Heap));
30
+ }
49
31
  exports.MinHeap = MinHeap;