data-structure-typed 1.35.1 → 1.36.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 (214) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/dist/data-structures/binary-tree/aa-tree.d.ts +2 -0
  3. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +21 -0
  4. package/dist/data-structures/binary-tree/abstract-binary-tree.js +13 -864
  5. package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
  6. package/dist/data-structures/binary-tree/avl-tree.d.ts +94 -0
  7. package/dist/data-structures/binary-tree/avl-tree.js +90 -3
  8. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  9. package/dist/data-structures/binary-tree/b-tree.d.ts +2 -0
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +46 -0
  11. package/dist/data-structures/binary-tree/binary-indexed-tree.js +36 -0
  12. package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  13. package/dist/data-structures/binary-tree/binary-tree.d.ts +536 -0
  14. package/dist/data-structures/binary-tree/binary-tree.js +1194 -2
  15. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  16. package/dist/data-structures/binary-tree/bst.d.ts +133 -0
  17. package/dist/data-structures/binary-tree/bst.js +114 -0
  18. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  19. package/dist/data-structures/binary-tree/index.d.ts +12 -0
  20. package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -0
  21. package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
  22. package/dist/data-structures/binary-tree/segment-tree.d.ts +83 -0
  23. package/dist/data-structures/binary-tree/segment-tree.js +45 -0
  24. package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
  25. package/dist/data-structures/binary-tree/splay-tree.d.ts +2 -0
  26. package/dist/data-structures/binary-tree/tree-multiset.d.ts +209 -0
  27. package/dist/data-structures/binary-tree/tree-multiset.js +178 -0
  28. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  29. package/dist/data-structures/binary-tree/two-three-tree.d.ts +2 -0
  30. package/dist/data-structures/graph/abstract-graph.d.ts +332 -0
  31. package/dist/data-structures/graph/abstract-graph.js +270 -7
  32. package/dist/data-structures/graph/abstract-graph.js.map +1 -1
  33. package/dist/data-structures/graph/directed-graph.d.ts +200 -0
  34. package/dist/data-structures/graph/directed-graph.js +167 -0
  35. package/dist/data-structures/graph/directed-graph.js.map +1 -1
  36. package/dist/data-structures/graph/index.d.ts +4 -0
  37. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  38. package/dist/data-structures/graph/map-graph.js +54 -0
  39. package/dist/data-structures/graph/map-graph.js.map +1 -1
  40. package/dist/data-structures/graph/undirected-graph.d.ts +127 -0
  41. package/dist/data-structures/graph/undirected-graph.js +105 -0
  42. package/dist/data-structures/graph/undirected-graph.js.map +1 -1
  43. package/dist/data-structures/hash/coordinate-map.d.ts +45 -0
  44. package/dist/data-structures/hash/coordinate-map.js +35 -0
  45. package/dist/data-structures/hash/coordinate-map.js.map +1 -1
  46. package/dist/data-structures/hash/coordinate-set.d.ts +37 -0
  47. package/dist/data-structures/hash/coordinate-set.js +28 -0
  48. package/dist/data-structures/hash/coordinate-set.js.map +1 -1
  49. package/dist/data-structures/hash/hash-map.d.ts +56 -0
  50. package/dist/data-structures/hash/hash-map.js +29 -1
  51. package/dist/data-structures/hash/hash-map.js.map +1 -1
  52. package/dist/data-structures/hash/hash-table.d.ts +106 -0
  53. package/dist/data-structures/hash/hash-table.js +88 -6
  54. package/dist/data-structures/hash/hash-table.js.map +1 -1
  55. package/dist/data-structures/hash/index.d.ts +7 -0
  56. package/dist/data-structures/hash/pair.d.ts +2 -0
  57. package/dist/data-structures/hash/tree-map.d.ts +2 -0
  58. package/dist/data-structures/hash/tree-set.d.ts +2 -0
  59. package/dist/data-structures/heap/heap.d.ts +99 -0
  60. package/dist/data-structures/heap/heap.js +200 -78
  61. package/dist/data-structures/heap/heap.js.map +1 -1
  62. package/dist/data-structures/heap/index.d.ts +3 -0
  63. package/dist/data-structures/heap/max-heap.d.ts +12 -0
  64. package/dist/data-structures/heap/max-heap.js +16 -6
  65. package/dist/data-structures/heap/max-heap.js.map +1 -1
  66. package/dist/data-structures/heap/min-heap.d.ts +12 -0
  67. package/dist/data-structures/heap/min-heap.js +16 -6
  68. package/dist/data-structures/heap/min-heap.js.map +1 -1
  69. package/dist/data-structures/index.d.ts +11 -0
  70. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +234 -0
  71. package/dist/data-structures/linked-list/doubly-linked-list.js +202 -0
  72. package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  73. package/dist/data-structures/linked-list/index.d.ts +3 -0
  74. package/dist/data-structures/linked-list/singly-linked-list.d.ts +157 -0
  75. package/dist/data-structures/linked-list/singly-linked-list.js +135 -0
  76. package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
  77. package/dist/data-structures/linked-list/skip-linked-list.d.ts +61 -0
  78. package/dist/data-structures/linked-list/skip-linked-list.js +36 -0
  79. package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
  80. package/dist/data-structures/matrix/index.d.ts +4 -0
  81. package/dist/data-structures/matrix/matrix.d.ts +21 -0
  82. package/dist/data-structures/matrix/matrix.js +15 -0
  83. package/dist/data-structures/matrix/matrix.js.map +1 -1
  84. package/dist/data-structures/matrix/matrix2d.d.ts +108 -0
  85. package/dist/data-structures/matrix/matrix2d.js +91 -2
  86. package/dist/data-structures/matrix/matrix2d.js.map +1 -1
  87. package/dist/data-structures/matrix/navigator.d.ts +52 -0
  88. package/dist/data-structures/matrix/navigator.js +28 -0
  89. package/dist/data-structures/matrix/navigator.js.map +1 -1
  90. package/dist/data-structures/matrix/vector2d.d.ts +201 -0
  91. package/dist/data-structures/matrix/vector2d.js +188 -1
  92. package/dist/data-structures/matrix/vector2d.js.map +1 -1
  93. package/dist/data-structures/priority-queue/index.d.ts +3 -0
  94. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -0
  95. package/dist/data-structures/priority-queue/max-priority-queue.js +16 -17
  96. package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  97. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -0
  98. package/dist/data-structures/priority-queue/min-priority-queue.js +16 -17
  99. package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  100. package/dist/data-structures/priority-queue/priority-queue.d.ts +12 -0
  101. package/dist/data-structures/priority-queue/priority-queue.js +11 -174
  102. package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
  103. package/dist/data-structures/queue/deque.d.ts +165 -0
  104. package/dist/data-structures/queue/deque.js +124 -0
  105. package/dist/data-structures/queue/deque.js.map +1 -1
  106. package/dist/data-structures/queue/index.d.ts +2 -0
  107. package/dist/data-structures/queue/queue.d.ts +107 -0
  108. package/dist/data-structures/queue/queue.js +80 -0
  109. package/dist/data-structures/queue/queue.js.map +1 -1
  110. package/dist/data-structures/stack/index.d.ts +1 -0
  111. package/dist/data-structures/stack/stack.d.ts +63 -0
  112. package/dist/data-structures/stack/stack.js +50 -0
  113. package/dist/data-structures/stack/stack.js.map +1 -1
  114. package/dist/data-structures/tree/index.d.ts +1 -0
  115. package/dist/data-structures/tree/tree.d.ts +14 -0
  116. package/dist/data-structures/tree/tree.js +1 -0
  117. package/dist/data-structures/tree/tree.js.map +1 -1
  118. package/dist/data-structures/trie/index.d.ts +1 -0
  119. package/dist/data-structures/trie/trie.d.ts +61 -0
  120. package/dist/data-structures/trie/trie.js +36 -0
  121. package/dist/data-structures/trie/trie.js.map +1 -1
  122. package/dist/index.d.ts +4 -0
  123. package/dist/interfaces/abstract-binary-tree.d.ts +7 -0
  124. package/dist/interfaces/abstract-graph.d.ts +5 -0
  125. package/dist/interfaces/avl-tree.d.ts +7 -0
  126. package/dist/interfaces/binary-tree.d.ts +6 -0
  127. package/dist/interfaces/bst.d.ts +6 -0
  128. package/dist/interfaces/directed-graph.d.ts +3 -0
  129. package/dist/interfaces/doubly-linked-list.d.ts +1 -0
  130. package/dist/interfaces/heap.d.ts +1 -0
  131. package/dist/interfaces/index.d.ts +15 -0
  132. package/dist/interfaces/navigator.d.ts +1 -0
  133. package/dist/interfaces/priority-queue.d.ts +1 -0
  134. package/dist/interfaces/rb-tree.d.ts +6 -0
  135. package/dist/interfaces/segment-tree.d.ts +1 -0
  136. package/dist/interfaces/singly-linked-list.d.ts +1 -0
  137. package/dist/interfaces/tree-multiset.d.ts +6 -0
  138. package/dist/interfaces/undirected-graph.d.ts +3 -0
  139. package/dist/types/data-structures/abstract-binary-tree.d.ts +32 -0
  140. package/dist/types/data-structures/abstract-binary-tree.js +6 -0
  141. package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
  142. package/dist/types/data-structures/abstract-graph.d.ts +11 -0
  143. package/dist/types/data-structures/avl-tree.d.ts +4 -0
  144. package/dist/types/data-structures/binary-tree.d.ts +6 -0
  145. package/dist/types/data-structures/bst.d.ts +13 -0
  146. package/dist/types/data-structures/directed-graph.d.ts +6 -0
  147. package/dist/types/data-structures/doubly-linked-list.d.ts +1 -0
  148. package/dist/types/data-structures/hash.d.ts +1 -0
  149. package/dist/types/data-structures/heap.d.ts +1 -0
  150. package/dist/types/data-structures/index.d.ts +16 -0
  151. package/dist/types/data-structures/map-graph.d.ts +1 -0
  152. package/dist/types/data-structures/navigator.d.ts +14 -0
  153. package/dist/types/data-structures/priority-queue.d.ts +7 -0
  154. package/dist/types/data-structures/rb-tree.d.ts +8 -0
  155. package/dist/types/data-structures/segment-tree.d.ts +1 -0
  156. package/dist/types/data-structures/singly-linked-list.d.ts +1 -0
  157. package/dist/types/data-structures/tree-multiset.d.ts +4 -0
  158. package/dist/types/helpers.d.ts +1 -0
  159. package/dist/types/index.d.ts +3 -0
  160. package/dist/types/utils/index.d.ts +2 -0
  161. package/dist/types/utils/utils.d.ts +7 -0
  162. package/dist/types/utils/validate-type.d.ts +19 -0
  163. package/dist/utils/index.d.ts +1 -0
  164. package/dist/utils/utils.d.ts +19 -0
  165. package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +3 -509
  166. package/lib/data-structures/binary-tree/abstract-binary-tree.js +1 -1175
  167. package/lib/data-structures/binary-tree/avl-tree.d.ts +1 -1
  168. package/lib/data-structures/binary-tree/binary-tree.d.ts +506 -1
  169. package/lib/data-structures/binary-tree/binary-tree.js +1173 -2
  170. package/lib/data-structures/binary-tree/bst.d.ts +1 -1
  171. package/lib/data-structures/binary-tree/rb-tree.d.ts +1 -1
  172. package/lib/data-structures/binary-tree/tree-multiset.d.ts +1 -1
  173. package/lib/data-structures/graph/abstract-graph.js +3 -5
  174. package/lib/data-structures/heap/heap.d.ts +84 -68
  175. package/lib/data-structures/heap/heap.js +168 -107
  176. package/lib/data-structures/heap/max-heap.d.ts +6 -17
  177. package/lib/data-structures/heap/max-heap.js +11 -17
  178. package/lib/data-structures/heap/min-heap.d.ts +6 -18
  179. package/lib/data-structures/heap/min-heap.js +11 -18
  180. package/lib/data-structures/priority-queue/max-priority-queue.d.ts +4 -7
  181. package/lib/data-structures/priority-queue/max-priority-queue.js +11 -30
  182. package/lib/data-structures/priority-queue/min-priority-queue.d.ts +4 -7
  183. package/lib/data-structures/priority-queue/min-priority-queue.js +11 -31
  184. package/lib/data-structures/priority-queue/priority-queue.d.ts +6 -174
  185. package/lib/data-structures/priority-queue/priority-queue.js +11 -315
  186. package/lib/types/data-structures/abstract-binary-tree.d.ts +1 -3
  187. package/lib/types/data-structures/binary-tree.d.ts +4 -2
  188. package/lib/types/data-structures/heap.d.ts +1 -3
  189. package/package.json +10 -6
  190. package/src/data-structures/binary-tree/abstract-binary-tree.ts +4 -1527
  191. package/src/data-structures/binary-tree/avl-tree.ts +3 -3
  192. package/src/data-structures/binary-tree/binary-tree.ts +1524 -5
  193. package/src/data-structures/binary-tree/bst.ts +3 -3
  194. package/src/data-structures/binary-tree/rb-tree.ts +3 -3
  195. package/src/data-structures/binary-tree/tree-multiset.ts +3 -3
  196. package/src/data-structures/graph/abstract-graph.ts +3 -5
  197. package/src/data-structures/heap/heap.ts +167 -143
  198. package/src/data-structures/heap/max-heap.ts +15 -22
  199. package/src/data-structures/heap/min-heap.ts +15 -23
  200. package/src/data-structures/priority-queue/max-priority-queue.ts +13 -46
  201. package/src/data-structures/priority-queue/min-priority-queue.ts +13 -47
  202. package/src/data-structures/priority-queue/priority-queue.ts +7 -350
  203. package/src/types/data-structures/abstract-binary-tree.ts +1 -1
  204. package/src/types/data-structures/binary-tree.ts +2 -2
  205. package/src/types/data-structures/heap.ts +1 -5
  206. package/test/unit/data-structures/heap/heap.test.ts +26 -18
  207. package/test/unit/data-structures/heap/max-heap.test.ts +50 -42
  208. package/test/unit/data-structures/heap/min-heap.test.ts +38 -68
  209. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +9 -10
  210. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
  211. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +14 -30
  212. package/umd/bundle.min.js +1 -1
  213. package/umd/bundle.min.js.LICENSE.txt +15 -0
  214. package/umd/bundle.min.js.map +1 -1
@@ -0,0 +1,12 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Kirk Qi
5
+ * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import { Heap } from '../heap';
9
+ import { CompareFunction } from '../../types';
10
+ export declare class PriorityQueue<E> extends Heap<E> {
11
+ constructor(comparator: CompareFunction<E>);
12
+ }
@@ -1,180 +1,17 @@
1
1
  "use strict";
2
+ /**
3
+ * data-structure-typed
4
+ *
5
+ * @author Kirk Qi
6
+ * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
7
+ * @license MIT License
8
+ */
2
9
  Object.defineProperty(exports, "__esModule", { value: true });
3
10
  exports.PriorityQueue = void 0;
4
- class PriorityQueue {
5
- constructor(options) {
6
- this._nodes = [];
7
- this._comparator = (a, b) => {
8
- const aKey = a, bKey = b;
9
- return aKey - bKey;
10
- };
11
- const { nodes, comparator, isFix = true } = options;
12
- this._comparator = comparator;
13
- if (nodes && Array.isArray(nodes) && nodes.length > 0) {
14
- this._nodes = [...nodes];
15
- isFix && this._fix();
16
- }
17
- }
18
- get nodes() {
19
- return this._nodes;
20
- }
21
- get size() {
22
- return this.nodes.length;
23
- }
24
- static heapify(options) {
25
- const heap = new PriorityQueue(options);
26
- heap._fix();
27
- return heap;
28
- }
29
- static isPriorityQueueified(options) {
30
- return new PriorityQueue(Object.assign(Object.assign({}, options), { isFix: false })).isValid();
31
- }
32
- getNodes() {
33
- return this._nodes;
34
- }
35
- add(node) {
36
- this.nodes.push(node);
37
- this._heapifyUp(this.size - 1);
38
- }
39
- has(node) {
40
- return this.nodes.includes(node);
41
- }
42
- peek() {
43
- return this.size ? this.nodes[0] : null;
44
- }
45
- poll() {
46
- var _a, _b;
47
- let res = null;
48
- if (this.size > 1) {
49
- this._swap(0, this.nodes.length - 1);
50
- res = (_a = this.nodes.pop()) !== null && _a !== void 0 ? _a : null;
51
- this._heapifyDown(0);
52
- }
53
- else if (this.size === 1) {
54
- res = (_b = this.nodes.pop()) !== null && _b !== void 0 ? _b : null;
55
- }
56
- return res;
57
- }
58
- leaf() {
59
- var _a;
60
- return (_a = this.nodes[this.size - 1]) !== null && _a !== void 0 ? _a : null;
61
- }
62
- isEmpty() {
63
- return this.size === 0;
64
- }
65
- clear() {
66
- this._setNodes([]);
67
- }
68
- toArray() {
69
- return [...this.nodes];
70
- }
71
- clone() {
72
- return new PriorityQueue({
73
- nodes: this.nodes,
74
- comparator: this._comparator
75
- });
76
- }
77
- isValid() {
78
- for (let i = 0; i < this.nodes.length; i++) {
79
- const leftChildIndex = this._getLeft(i);
80
- const rightChildIndex = this._getRight(i);
81
- if (this._isValidIndex(leftChildIndex) && !this._compare(leftChildIndex, i)) {
82
- return false;
83
- }
84
- if (this._isValidIndex(rightChildIndex) && !this._compare(rightChildIndex, i)) {
85
- return false;
86
- }
87
- }
88
- return true;
89
- }
90
- sort() {
91
- const visitedNode = [];
92
- while (this.size !== 0) {
93
- const top = this.poll();
94
- if (top)
95
- visitedNode.push(top);
96
- }
97
- return visitedNode;
98
- }
99
- dfs(dfsMode) {
100
- const visitedNode = [];
101
- const traverse = (cur) => {
102
- var _a, _b, _c;
103
- const leftChildIndex = this._getLeft(cur);
104
- const rightChildIndex = this._getRight(cur);
105
- switch (dfsMode) {
106
- case 'in':
107
- this._isValidIndex(leftChildIndex) && traverse(leftChildIndex);
108
- visitedNode.push((_a = this.nodes[cur]) !== null && _a !== void 0 ? _a : null);
109
- this._isValidIndex(rightChildIndex) && traverse(rightChildIndex);
110
- break;
111
- case 'pre':
112
- visitedNode.push((_b = this.nodes[cur]) !== null && _b !== void 0 ? _b : null);
113
- this._isValidIndex(leftChildIndex) && traverse(leftChildIndex);
114
- this._isValidIndex(rightChildIndex) && traverse(rightChildIndex);
115
- break;
116
- case 'post':
117
- this._isValidIndex(leftChildIndex) && traverse(leftChildIndex);
118
- this._isValidIndex(rightChildIndex) && traverse(rightChildIndex);
119
- visitedNode.push((_c = this.nodes[cur]) !== null && _c !== void 0 ? _c : null);
120
- break;
121
- }
122
- };
123
- this._isValidIndex(0) && traverse(0);
124
- return visitedNode;
125
- }
126
- _setNodes(value) {
127
- this._nodes = value;
128
- }
129
- _compare(a, b) {
130
- return this._comparator(this.nodes[a], this.nodes[b]) > 0;
131
- }
132
- _swap(a, b) {
133
- const temp = this.nodes[a];
134
- this.nodes[a] = this.nodes[b];
135
- this.nodes[b] = temp;
136
- }
137
- _isValidIndex(index) {
138
- return index > -1 && index < this.nodes.length;
139
- }
140
- _getParent(child) {
141
- return Math.floor((child - 1) / 2);
142
- }
143
- _getLeft(parent) {
144
- return 2 * parent + 1;
145
- }
146
- _getRight(parent) {
147
- return 2 * parent + 2;
148
- }
149
- _getComparedChild(parent) {
150
- let min = parent;
151
- const left = this._getLeft(parent), right = this._getRight(parent);
152
- if (left < this.size && this._compare(min, left)) {
153
- min = left;
154
- }
155
- if (right < this.size && this._compare(min, right)) {
156
- min = right;
157
- }
158
- return min;
159
- }
160
- _heapifyUp(start) {
161
- while (start > 0 && this._compare(this._getParent(start), start)) {
162
- const parent = this._getParent(start);
163
- this._swap(start, parent);
164
- start = parent;
165
- }
166
- }
167
- _heapifyDown(start) {
168
- let min = this._getComparedChild(start);
169
- while (this._compare(start, min)) {
170
- this._swap(min, start);
171
- start = min;
172
- min = this._getComparedChild(start);
173
- }
174
- }
175
- _fix() {
176
- for (let i = Math.floor(this.size / 2); i > -1; i--)
177
- this._heapifyDown(i);
11
+ const heap_1 = require("../heap");
12
+ class PriorityQueue extends heap_1.Heap {
13
+ constructor(comparator) {
14
+ super(comparator);
178
15
  }
179
16
  }
180
17
  exports.PriorityQueue = PriorityQueue;
@@ -1 +1 @@
1
- {"version":3,"file":"priority-queue.js","sourceRoot":"","sources":["../../../src/data-structures/priority-queue/priority-queue.ts"],"names":[],"mappings":";;;AASA,MAAa,aAAa;IAMxB,YAAY,OAAgC;QAWlC,WAAM,GAAQ,EAAE,CAAC;QAkNR,gBAAW,GAA+B,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE;YAC1E,MAAM,IAAI,GAAG,CAAsB,EACjC,IAAI,GAAG,CAAsB,CAAC;YAChC,OAAO,IAAI,GAAG,IAAI,CAAC;QACrB,CAAC,CAAC;QAhOA,MAAM,EAAC,KAAK,EAAE,UAAU,EAAE,KAAK,GAAG,IAAI,EAAC,GAAG,OAAO,CAAC;QAClD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAE9B,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;YAErD,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;YACzB,KAAK,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;SACtB;IACH,CAAC;IAID,IAAI,KAAK;Q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AG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE;YAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC5E,CAAC;CAGF;AA7VD,sCA6VC"}
1
+ {"version":3,"file":"priority-queue.js","sourceRoot":"","sources":["../../../src/data-structures/priority-queue/priority-queue.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,kCAA6B;AAG7B,MAAa,aAAiB,SAAQ,WAAO;IAC3C,YAAY,UAA8B;QACxC,KAAK,CAAC,UAAU,CAAC,CAAC;IACpB,CAAC;CACF;AAJD,sCAIC"}
@@ -0,0 +1,165 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import { DoublyLinkedList } from '../linked-list';
9
+ export declare class Deque<E = any> extends DoublyLinkedList<E> {
10
+ }
11
+ export declare class ObjectDeque<E = number> {
12
+ constructor(capacity?: number);
13
+ private _nodes;
14
+ get nodes(): {
15
+ [p: number]: E;
16
+ };
17
+ private _capacity;
18
+ get capacity(): number;
19
+ set capacity(value: number);
20
+ private _first;
21
+ get first(): number;
22
+ set first(value: number);
23
+ private _last;
24
+ get last(): number;
25
+ set last(value: number);
26
+ private _size;
27
+ get size(): number;
28
+ /**
29
+ * The "addFirst" function adds a value to the beginning of an array-like data structure.
30
+ * @param {E} value - The `value` parameter represents the value that you want to add to the beginning of the data
31
+ * structure.
32
+ */
33
+ addFirst(value: E): void;
34
+ /**
35
+ * The addLast function adds a value to the end of an array-like data structure.
36
+ * @param {E} value - The `value` parameter represents the value that you want to add to the end of the data structure.
37
+ */
38
+ addLast(value: E): void;
39
+ /**
40
+ * The function `pollFirst()` removes and returns the first element in a data structure.
41
+ * @returns The value of the first element in the data structure.
42
+ */
43
+ pollFirst(): E | undefined;
44
+ /**
45
+ * The `peekFirst` function returns the first element in an array-like data structure if it exists.
46
+ * @returns The element at the first position of the `_nodes` array.
47
+ */
48
+ peekFirst(): E | undefined;
49
+ /**
50
+ * The `pollLast()` function removes and returns the last element in a data structure.
51
+ * @returns The value that was removed from the data structure.
52
+ */
53
+ pollLast(): E | undefined;
54
+ /**
55
+ * The `peekLast()` function returns the last element in an array-like data structure.
56
+ * @returns The last element in the array "_nodes" is being returned.
57
+ */
58
+ peekLast(): E | undefined;
59
+ /**
60
+ * The get function returns the element at the specified index in an array-like data structure.
61
+ * @param {number} index - The index parameter is a number that represents the position of the element you want to
62
+ * retrieve from the array.
63
+ * @returns The element at the specified index in the `_nodes` array is being returned. If there is no element at that
64
+ * index, `null` is returned.
65
+ */
66
+ get(index: number): NonNullable<E> | null;
67
+ /**
68
+ * The function checks if the size of a data structure is less than or equal to zero.
69
+ * @returns The method is returning a boolean value indicating whether the size of the object is less than or equal to 0.
70
+ */
71
+ isEmpty(): boolean;
72
+ protected _seNodes(value: {
73
+ [p: number]: E;
74
+ }): void;
75
+ protected _setSize(value: number): void;
76
+ }
77
+ export declare class ArrayDeque<E> {
78
+ protected _nodes: E[];
79
+ get size(): number;
80
+ /**
81
+ * O(n) time complexity of adding at the beginning and the end
82
+ */
83
+ /**
84
+ * The function "addLast" adds a value to the end of an array.
85
+ * @param {E} value - The value parameter represents the value that you want to add to the end of the array.
86
+ * @returns The return value is the new length of the array after the value has been added.
87
+ */
88
+ addLast(value: E): number;
89
+ /**
90
+ * The function "pollLast" returns and removes the last element from an array, or returns null if the array is empty.
91
+ * @returns The method `pollLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
92
+ */
93
+ pollLast(): E | null;
94
+ /**
95
+ * The `pollFirst` function removes and returns the first element from an array, or returns null if the array is empty.
96
+ * @returns The `pollFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
97
+ * empty.
98
+ */
99
+ pollFirst(): E | null;
100
+ /**
101
+ * O(n) time complexity of adding at the beginning and the end
102
+ */
103
+ /**
104
+ * The function "addFirst" adds a value to the beginning of an array.
105
+ * @param {E} value - The value parameter represents the value that you want to add to the beginning of the array.
106
+ * @returns The return value of the `addFirst` function is the new length of the array `_nodes` after adding the
107
+ * `value` at the beginning.
108
+ */
109
+ addFirst(value: E): number;
110
+ /**
111
+ * The `peekFirst` function returns the first element of an array or null if the array is empty.
112
+ * @returns The function `peekFirst()` is returning the first element (`E`) of the `_nodes` array. If the array is
113
+ * empty, it will return `null`.
114
+ */
115
+ peekFirst(): E | null;
116
+ /**
117
+ * The `peekLast` function returns the last element of an array or null if the array is empty.
118
+ * @returns The method `peekLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
119
+ */
120
+ peekLast(): E | null;
121
+ /**
122
+ * O(1) time complexity of obtaining the value
123
+ */
124
+ /**
125
+ * The get function returns the element at the specified index in an array, or null if the index is out of bounds.
126
+ * @param {number} index - The index parameter is a number that represents the position of the element you want to
127
+ * retrieve from the array.
128
+ * @returns The method is returning the element at the specified index in the `_nodes` array. If the element exists, it
129
+ * will be returned. If the element does not exist (i.e., the index is out of bounds), `null` will be returned.
130
+ */
131
+ get(index: number): E | null;
132
+ /**
133
+ * The set function assigns a value to a specific index in an array.
134
+ * @param {number} index - The index parameter is a number that represents the position of the element in the array
135
+ * that you want to set a new value for.
136
+ * @param {E} value - The value parameter represents the new value that you want to set at the specified index in the
137
+ * _nodes array.
138
+ * @returns The value that is being set at the specified index in the `_nodes` array.
139
+ */
140
+ set(index: number, value: E): E;
141
+ /**
142
+ * The insert function adds a value at a specified index in an array.
143
+ * @param {number} index - The index parameter specifies the position at which the value should be inserted in the
144
+ * array. It is a number that represents the index of the array where the value should be inserted. The index starts
145
+ * from 0, so the first element of the array has an index of 0, the second element has
146
+ * @param {E} value - The value parameter represents the value that you want to insert into the array at the specified
147
+ * index.
148
+ * @returns The splice method returns an array containing the removed elements, if any. In this case, since no elements
149
+ * are being removed, an empty array will be returned.
150
+ */
151
+ insert(index: number, value: E): E[];
152
+ /**
153
+ * The remove function removes an element from an array at a specified index.
154
+ * @param {number} index - The index parameter specifies the position of the element to be removed from the array. It
155
+ * is a number that represents the index of the element to be removed.
156
+ * @returns The method is returning an array containing the removed element.
157
+ */
158
+ remove(index: number): E[];
159
+ /**
160
+ * The function checks if an array called "_nodes" is empty.
161
+ * @returns The method `isEmpty()` is returning a boolean value. It returns `true` if the length of the `_nodes` array
162
+ * is 0, indicating that the array is empty. Otherwise, it returns `false`.
163
+ */
164
+ isEmpty(): boolean;
165
+ }
@@ -1,10 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ArrayDeque = exports.ObjectDeque = exports.Deque = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
4
11
  const linked_list_1 = require("../linked-list");
12
+ // O(n) time complexity of obtaining the value
13
+ // O(1) time complexity of adding at the beginning and the end
5
14
  class Deque extends linked_list_1.DoublyLinkedList {
6
15
  }
7
16
  exports.Deque = Deque;
17
+ // O(1) time complexity of obtaining the value
18
+ // O(n) time complexity of adding at the beginning and the end
19
+ // todo tested slowest one
8
20
  class ObjectDeque {
9
21
  constructor(capacity) {
10
22
  this._nodes = {};
@@ -39,6 +51,11 @@ class ObjectDeque {
39
51
  get size() {
40
52
  return this._size;
41
53
  }
54
+ /**
55
+ * The "addFirst" function adds a value to the beginning of an array-like data structure.
56
+ * @param {E} value - The `value` parameter represents the value that you want to add to the beginning of the data
57
+ * structure.
58
+ */
42
59
  addFirst(value) {
43
60
  if (this._size === 0) {
44
61
  const mid = Math.floor(this._capacity / 2);
@@ -51,6 +68,10 @@ class ObjectDeque {
51
68
  this._nodes[this._first] = value;
52
69
  this._size++;
53
70
  }
71
+ /**
72
+ * The addLast function adds a value to the end of an array-like data structure.
73
+ * @param {E} value - The `value` parameter represents the value that you want to add to the end of the data structure.
74
+ */
54
75
  addLast(value) {
55
76
  if (this._size === 0) {
56
77
  const mid = Math.floor(this._capacity / 2);
@@ -63,6 +84,10 @@ class ObjectDeque {
63
84
  this._nodes[this._last] = value;
64
85
  this._size++;
65
86
  }
87
+ /**
88
+ * The function `pollFirst()` removes and returns the first element in a data structure.
89
+ * @returns The value of the first element in the data structure.
90
+ */
66
91
  pollFirst() {
67
92
  if (!this._size)
68
93
  return;
@@ -72,10 +97,18 @@ class ObjectDeque {
72
97
  this._size--;
73
98
  return value;
74
99
  }
100
+ /**
101
+ * The `peekFirst` function returns the first element in an array-like data structure if it exists.
102
+ * @returns The element at the first position of the `_nodes` array.
103
+ */
75
104
  peekFirst() {
76
105
  if (this._size)
77
106
  return this._nodes[this._first];
78
107
  }
108
+ /**
109
+ * The `pollLast()` function removes and returns the last element in a data structure.
110
+ * @returns The value that was removed from the data structure.
111
+ */
79
112
  pollLast() {
80
113
  if (!this._size)
81
114
  return;
@@ -85,13 +118,28 @@ class ObjectDeque {
85
118
  this._size--;
86
119
  return value;
87
120
  }
121
+ /**
122
+ * The `peekLast()` function returns the last element in an array-like data structure.
123
+ * @returns The last element in the array "_nodes" is being returned.
124
+ */
88
125
  peekLast() {
89
126
  if (this._size)
90
127
  return this._nodes[this._last];
91
128
  }
129
+ /**
130
+ * The get function returns the element at the specified index in an array-like data structure.
131
+ * @param {number} index - The index parameter is a number that represents the position of the element you want to
132
+ * retrieve from the array.
133
+ * @returns The element at the specified index in the `_nodes` array is being returned. If there is no element at that
134
+ * index, `null` is returned.
135
+ */
92
136
  get(index) {
93
137
  return this._nodes[this._first + index] || null;
94
138
  }
139
+ /**
140
+ * The function checks if the size of a data structure is less than or equal to zero.
141
+ * @returns The method is returning a boolean value indicating whether the size of the object is less than or equal to 0.
142
+ */
95
143
  isEmpty() {
96
144
  return this._size <= 0;
97
145
  }
@@ -103,6 +151,8 @@ class ObjectDeque {
103
151
  }
104
152
  }
105
153
  exports.ObjectDeque = ObjectDeque;
154
+ // O(1) time complexity of obtaining the value
155
+ // O(n) time complexity of adding at the beginning and the end
106
156
  class ArrayDeque {
107
157
  constructor() {
108
158
  this._nodes = [];
@@ -110,41 +160,115 @@ class ArrayDeque {
110
160
  get size() {
111
161
  return this._nodes.length;
112
162
  }
163
+ /**
164
+ * O(n) time complexity of adding at the beginning and the end
165
+ */
166
+ /**
167
+ * The function "addLast" adds a value to the end of an array.
168
+ * @param {E} value - The value parameter represents the value that you want to add to the end of the array.
169
+ * @returns The return value is the new length of the array after the value has been added.
170
+ */
113
171
  addLast(value) {
114
172
  return this._nodes.push(value);
115
173
  }
174
+ /**
175
+ * The function "pollLast" returns and removes the last element from an array, or returns null if the array is empty.
176
+ * @returns The method `pollLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
177
+ */
116
178
  pollLast() {
117
179
  var _a;
118
180
  return (_a = this._nodes.pop()) !== null && _a !== void 0 ? _a : null;
119
181
  }
182
+ /**
183
+ * The `pollFirst` function removes and returns the first element from an array, or returns null if the array is empty.
184
+ * @returns The `pollFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
185
+ * empty.
186
+ */
120
187
  pollFirst() {
121
188
  var _a;
122
189
  return (_a = this._nodes.shift()) !== null && _a !== void 0 ? _a : null;
123
190
  }
191
+ /**
192
+ * O(n) time complexity of adding at the beginning and the end
193
+ */
194
+ /**
195
+ * The function "addFirst" adds a value to the beginning of an array.
196
+ * @param {E} value - The value parameter represents the value that you want to add to the beginning of the array.
197
+ * @returns The return value of the `addFirst` function is the new length of the array `_nodes` after adding the
198
+ * `value` at the beginning.
199
+ */
124
200
  addFirst(value) {
125
201
  return this._nodes.unshift(value);
126
202
  }
203
+ /**
204
+ * The `peekFirst` function returns the first element of an array or null if the array is empty.
205
+ * @returns The function `peekFirst()` is returning the first element (`E`) of the `_nodes` array. If the array is
206
+ * empty, it will return `null`.
207
+ */
127
208
  peekFirst() {
128
209
  var _a;
129
210
  return (_a = this._nodes[0]) !== null && _a !== void 0 ? _a : null;
130
211
  }
212
+ /**
213
+ * The `peekLast` function returns the last element of an array or null if the array is empty.
214
+ * @returns The method `peekLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
215
+ */
131
216
  peekLast() {
132
217
  var _a;
133
218
  return (_a = this._nodes[this._nodes.length - 1]) !== null && _a !== void 0 ? _a : null;
134
219
  }
220
+ /**
221
+ * O(1) time complexity of obtaining the value
222
+ */
223
+ /**
224
+ * The get function returns the element at the specified index in an array, or null if the index is out of bounds.
225
+ * @param {number} index - The index parameter is a number that represents the position of the element you want to
226
+ * retrieve from the array.
227
+ * @returns The method is returning the element at the specified index in the `_nodes` array. If the element exists, it
228
+ * will be returned. If the element does not exist (i.e., the index is out of bounds), `null` will be returned.
229
+ */
135
230
  get(index) {
136
231
  var _a;
137
232
  return (_a = this._nodes[index]) !== null && _a !== void 0 ? _a : null;
138
233
  }
234
+ /**
235
+ * The set function assigns a value to a specific index in an array.
236
+ * @param {number} index - The index parameter is a number that represents the position of the element in the array
237
+ * that you want to set a new value for.
238
+ * @param {E} value - The value parameter represents the new value that you want to set at the specified index in the
239
+ * _nodes array.
240
+ * @returns The value that is being set at the specified index in the `_nodes` array.
241
+ */
139
242
  set(index, value) {
140
243
  return (this._nodes[index] = value);
141
244
  }
245
+ /**
246
+ * The insert function adds a value at a specified index in an array.
247
+ * @param {number} index - The index parameter specifies the position at which the value should be inserted in the
248
+ * array. It is a number that represents the index of the array where the value should be inserted. The index starts
249
+ * from 0, so the first element of the array has an index of 0, the second element has
250
+ * @param {E} value - The value parameter represents the value that you want to insert into the array at the specified
251
+ * index.
252
+ * @returns The splice method returns an array containing the removed elements, if any. In this case, since no elements
253
+ * are being removed, an empty array will be returned.
254
+ */
142
255
  insert(index, value) {
143
256
  return this._nodes.splice(index, 0, value);
144
257
  }
258
+ /**
259
+ * The remove function removes an element from an array at a specified index.
260
+ * @param {number} index - The index parameter specifies the position of the element to be removed from the array. It
261
+ * is a number that represents the index of the element to be removed.
262
+ * @returns The method is returning an array containing the removed element.
263
+ */
145
264
  remove(index) {
146
265
  return this._nodes.splice(index, 1);
147
266
  }
267
+ /**
268
+ * The function checks if an array called "_nodes" is empty.
269
+ * @returns The method `isEmpty()` is returning a boolean value. It returns `true` if the length of the `_nodes` array
270
+ * is 0, indicating that the array is empty. Otherwise, it returns `false`.
271
+ */
148
272
  isEmpty() {
149
273
  return this._nodes.length === 0;
150
274
  }
@@ -1 +1 @@
1
- {"version":3,"file":"deque.js","sourceRoot":"","sources":["../../../src/data-structures/queue/deque.ts"],"names":[],"mappings":";;;AAOA,gDAAgD;AAIhD,MAAa,KAAe,SAAQ,8BAAmB;CAAG;AAA1D,sBAA0D;AAK1D,MAAa,WAAW;IACtB,YAAY,QAAiB;QAIrB,WAAM,GAAuB,EAAE,CAAC;QAMhC,cAAS,GAAG,MAAM,CAAC,gBAAgB,CAAC;QAUpC,WAAM,GAAG,CAAC,CAAC,CAAC;QAUZ,UAAK,GAAG,CAAC,CAAC,CAAC;QAUX,UAAK,GAAG,CAAC,CAAC;QAvChB,IAAI,QAAQ,KAAK,SAAS;YAAE,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IACxD,CAAC;IAID,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAID,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,IAAI,QAAQ,CAAC,KAAa;QACxB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACzB,CAAC;IAID,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAI,KAAK,CAAC,KAAa;QACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAID,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,IAAI,IAAI,CAAC,KAAa;QACpB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;I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