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,22 +1,40 @@
1
1
  "use strict";
2
2
  /**
3
- * @copyright 2020 Pablo Rios <zrwusa@gmail.com>
3
+ * @copyright 2020 Tyler Zeng <zrwusa@gmail.com>
4
4
  * @license MIT
5
5
  */
6
+ var __extends = (this && this.__extends) || (function () {
7
+ var extendStatics = function (d, b) {
8
+ extendStatics = Object.setPrototypeOf ||
9
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
10
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
11
+ return extendStatics(d, b);
12
+ };
13
+ return function (d, b) {
14
+ if (typeof b !== "function" && b !== null)
15
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
16
+ extendStatics(d, b);
17
+ function __() { this.constructor = d; }
18
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
19
+ };
20
+ })();
6
21
  Object.defineProperty(exports, "__esModule", { value: true });
7
22
  exports.MaxHeap = void 0;
8
- const heap_1 = require("./heap");
9
- const priority_queue_1 = require("../priority-queue");
23
+ var heap_1 = require("./heap");
24
+ var priority_queue_1 = require("../priority-queue");
10
25
  /**
11
26
  * @class MaxHeap
12
27
  * @extends Heap
13
28
  */
14
- class MaxHeap extends heap_1.Heap {
15
- constructor(options) {
16
- super(options);
17
- this._pq = new priority_queue_1.PriorityQueue({
18
- comparator: (a, b) => b.priority - a.priority
29
+ var MaxHeap = /** @class */ (function (_super) {
30
+ __extends(MaxHeap, _super);
31
+ function MaxHeap(options) {
32
+ var _this = _super.call(this, options) || this;
33
+ _this._pq = new priority_queue_1.PriorityQueue({
34
+ comparator: function (a, b) { return b.priority - a.priority; }
19
35
  });
36
+ return _this;
20
37
  }
21
- }
38
+ return MaxHeap;
39
+ }(heap_1.Heap));
22
40
  exports.MaxHeap = MaxHeap;
@@ -1,9 +1,10 @@
1
1
  /**
2
- * @copyright 2020 Pablo Rios <zrwusa@gmail.com>
2
+ * @copyright 2020 Tyler Zeng <zrwusa@gmail.com>
3
3
  * @license MIT
4
4
  */
5
- import { Heap, HeapItem, HeapOptions } from './heap';
5
+ import { Heap } from './heap';
6
6
  import { PriorityQueue } from '../priority-queue';
7
+ import type { HeapItem, HeapOptions } from '../types';
7
8
  /**
8
9
  * @class MinHeap
9
10
  * @extends Heap
@@ -1,22 +1,40 @@
1
1
  "use strict";
2
2
  /**
3
- * @copyright 2020 Pablo Rios <zrwusa@gmail.com>
3
+ * @copyright 2020 Tyler Zeng <zrwusa@gmail.com>
4
4
  * @license MIT
5
5
  */
6
+ var __extends = (this && this.__extends) || (function () {
7
+ var extendStatics = function (d, b) {
8
+ extendStatics = Object.setPrototypeOf ||
9
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
10
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
11
+ return extendStatics(d, b);
12
+ };
13
+ return function (d, b) {
14
+ if (typeof b !== "function" && b !== null)
15
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
16
+ extendStatics(d, b);
17
+ function __() { this.constructor = d; }
18
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
19
+ };
20
+ })();
6
21
  Object.defineProperty(exports, "__esModule", { value: true });
7
22
  exports.MinHeap = void 0;
8
- const heap_1 = require("./heap");
9
- const priority_queue_1 = require("../priority-queue");
23
+ var heap_1 = require("./heap");
24
+ var priority_queue_1 = require("../priority-queue");
10
25
  /**
11
26
  * @class MinHeap
12
27
  * @extends Heap
13
28
  */
14
- class MinHeap extends heap_1.Heap {
15
- constructor(options) {
16
- super(options);
17
- this._pq = new priority_queue_1.PriorityQueue({
18
- comparator: (a, b) => a.priority - b.priority
29
+ var MinHeap = /** @class */ (function (_super) {
30
+ __extends(MinHeap, _super);
31
+ function MinHeap(options) {
32
+ var _this = _super.call(this, options) || this;
33
+ _this._pq = new priority_queue_1.PriorityQueue({
34
+ comparator: function (a, b) { return a.priority - b.priority; }
19
35
  });
36
+ return _this;
20
37
  }
21
- }
38
+ return MinHeap;
39
+ }(heap_1.Heap));
22
40
  exports.MinHeap = MinHeap;
@@ -8,3 +8,4 @@ export * from './heap';
8
8
  export * from './priority-queue';
9
9
  export * from './matrix';
10
10
  export * from './trie';
11
+ export * from './types';
@@ -24,3 +24,4 @@ __exportStar(require("./heap"), exports);
24
24
  __exportStar(require("./priority-queue"), exports);
25
25
  __exportStar(require("./matrix"), exports);
26
26
  __exportStar(require("./trie"), exports);
27
+ __exportStar(require("./types"), exports);
@@ -4,7 +4,6 @@ export declare class DoublyLinkedListNode<T> {
4
4
  prev: DoublyLinkedListNode<T> | null;
5
5
  constructor(nodeValue: T);
6
6
  }
7
- export type DoublyLinkedListGetBy = 'node' | 'val';
8
7
  export declare class DoublyLinkedList<T> {
9
8
  private _first;
10
9
  private _last;
@@ -1,40 +1,38 @@
1
1
  "use strict";
2
- // 操作 常见名称 Ada Java JavaScript C++ Python Perl PHP Ruby
3
- // 尾部插入 inject, snoc Append offerLast push push_back append push array_push push
4
- // 头部插入 push, cons Prepend offerFirst unshift push_front appendleft unshift array_unshift unshift
5
- // 尾部删除 eject Delete_Last pollLast pop pop_back pop pop array_pop pop
6
- // 头部删除 pop Delete_First pollFirst shift pop_front popleft shift array_shift shift
7
- // 查看尾部 Last_Element peekLast [length - 1] back [-1] $array[-1] end last
8
- // 查看头部 First_Element peekFirst [0] front [0] $array[0] reset first
9
2
  Object.defineProperty(exports, "__esModule", { value: true });
10
3
  exports.DoublyLinkedList = exports.DoublyLinkedListNode = void 0;
11
- class DoublyLinkedListNode {
12
- constructor(nodeValue) {
4
+ var DoublyLinkedListNode = /** @class */ (function () {
5
+ function DoublyLinkedListNode(nodeValue) {
13
6
  this.val = nodeValue;
14
7
  this.next = null;
15
8
  this.prev = null;
16
9
  }
17
- }
10
+ return DoublyLinkedListNode;
11
+ }());
18
12
  exports.DoublyLinkedListNode = DoublyLinkedListNode;
19
- class DoublyLinkedList {
20
- constructor() {
13
+ var DoublyLinkedList = /** @class */ (function () {
14
+ function DoublyLinkedList() {
21
15
  this._first = null;
22
16
  this._last = null;
23
17
  this._size = 0;
24
18
  // --- end extra methods ---
25
19
  }
26
- get size() {
27
- return this._size;
28
- }
29
- set size(v) {
30
- this._size = v;
31
- }
20
+ Object.defineProperty(DoublyLinkedList.prototype, "size", {
21
+ get: function () {
22
+ return this._size;
23
+ },
24
+ set: function (v) {
25
+ this._size = v;
26
+ },
27
+ enumerable: false,
28
+ configurable: true
29
+ });
32
30
  /**
33
31
  * Adds a node at the beginning of the linked list
34
32
  * @param val Value to be stored at the beginning of the linked list
35
33
  */
36
- offerFirst(val) {
37
- const newNode = new DoublyLinkedListNode(val);
34
+ DoublyLinkedList.prototype.offerFirst = function (val) {
35
+ var newNode = new DoublyLinkedListNode(val);
38
36
  if (this._size === 0) {
39
37
  this._first = newNode;
40
38
  this._last = newNode;
@@ -47,13 +45,13 @@ class DoublyLinkedList {
47
45
  }
48
46
  this._size++;
49
47
  return true;
50
- }
48
+ };
51
49
  /**
52
50
  * Adds a node to the end of the linked list
53
51
  * @param val Value to be stored in the Doubly linked list node
54
52
  */
55
- offerLast(val) {
56
- const newNode = new DoublyLinkedListNode(val);
53
+ DoublyLinkedList.prototype.offerLast = function (val) {
54
+ var newNode = new DoublyLinkedListNode(val);
57
55
  if (this._size === 0) {
58
56
  this._first = newNode;
59
57
  this._last = newNode;
@@ -66,8 +64,8 @@ class DoublyLinkedList {
66
64
  }
67
65
  this._size++;
68
66
  return true;
69
- }
70
- peekFirst(by) {
67
+ };
68
+ DoublyLinkedList.prototype.peekFirst = function (by) {
71
69
  var _a, _b, _c, _d, _e;
72
70
  switch (by) {
73
71
  case 'node':
@@ -77,9 +75,10 @@ class DoublyLinkedList {
77
75
  default:
78
76
  return (_e = (_d = this._first) === null || _d === void 0 ? void 0 : _d.val) !== null && _e !== void 0 ? _e : null;
79
77
  }
80
- }
81
- peekLast(by = 'val') {
78
+ };
79
+ DoublyLinkedList.prototype.peekLast = function (by) {
82
80
  var _a, _b, _c, _d, _e;
81
+ if (by === void 0) { by = 'val'; }
83
82
  switch (by) {
84
83
  case 'node':
85
84
  return (_a = this._last) !== null && _a !== void 0 ? _a : null;
@@ -88,15 +87,16 @@ class DoublyLinkedList {
88
87
  default:
89
88
  return (_e = (_d = this._last) === null || _d === void 0 ? void 0 : _d.val) !== null && _e !== void 0 ? _e : null;
90
89
  }
91
- }
90
+ };
92
91
  /**
93
92
  * Removes a node form the beginning of the linked list and will return the node val
94
93
  */
95
- pollFirst(by = 'val') {
94
+ DoublyLinkedList.prototype.pollFirst = function (by) {
96
95
  var _a, _b, _c;
96
+ if (by === void 0) { by = 'val'; }
97
97
  if (this._size === 0)
98
98
  return null;
99
- const oldHead = this._first;
99
+ var oldHead = this._first;
100
100
  if (this._size === 1) {
101
101
  this._first = null;
102
102
  this._last = null;
@@ -117,15 +117,16 @@ class DoublyLinkedList {
117
117
  default:
118
118
  return (_c = oldHead === null || oldHead === void 0 ? void 0 : oldHead.val) !== null && _c !== void 0 ? _c : null;
119
119
  }
120
- }
120
+ };
121
121
  /**
122
122
  * Removes a node at the end of the linked list and will return the node value
123
123
  */
124
- pollLast(by = 'val') {
124
+ DoublyLinkedList.prototype.pollLast = function (by) {
125
125
  var _a, _b, _c;
126
+ if (by === void 0) { by = 'val'; }
126
127
  if (this._size === 0)
127
128
  return null;
128
- const polled = this._last;
129
+ var polled = this._last;
129
130
  if (this._size === 1) {
130
131
  this._first = null;
131
132
  this._last = null;
@@ -146,7 +147,7 @@ class DoublyLinkedList {
146
147
  default:
147
148
  return (_c = polled === null || polled === void 0 ? void 0 : polled.val) !== null && _c !== void 0 ? _c : null;
148
149
  }
149
- }
150
+ };
150
151
  /**
151
152
  * Returns the node at the specified index of the linked list.
152
153
  * If index = 0; first element in the list is returned.
@@ -154,11 +155,12 @@ class DoublyLinkedList {
154
155
  * @param index Index of the node to be retrieved
155
156
  * @param by Return value type
156
157
  */
157
- get(index, by = 'val') {
158
+ DoublyLinkedList.prototype.get = function (index, by) {
158
159
  var _a, _b;
160
+ if (by === void 0) { by = 'val'; }
159
161
  if (index < 0 || index >= this._size)
160
162
  return null;
161
- let count, current;
163
+ var count, current;
162
164
  if (index <= this._size / 2) {
163
165
  count = 0;
164
166
  current = this._first;
@@ -183,7 +185,7 @@ class DoublyLinkedList {
183
185
  default:
184
186
  return (_b = current === null || current === void 0 ? void 0 : current.val) !== null && _b !== void 0 ? _b : null;
185
187
  }
186
- }
188
+ };
187
189
  /**
188
190
  * Updates the value of the node at the specified index.
189
191
  * If index = 0; Value of the first element in the list is updated.
@@ -191,33 +193,33 @@ class DoublyLinkedList {
191
193
  * @param index Index of the node to be updated
192
194
  * @param val New value of the node
193
195
  */
194
- set(index, val) {
195
- const foundNode = this.get(index, 'node');
196
+ DoublyLinkedList.prototype.set = function (index, val) {
197
+ var foundNode = this.get(index, 'node');
196
198
  if (foundNode !== null) {
197
199
  foundNode.val = val;
198
200
  return true;
199
201
  }
200
202
  return false;
201
- }
202
- isEmpty() {
203
+ };
204
+ DoublyLinkedList.prototype.isEmpty = function () {
203
205
  return this._size === 0;
204
- }
206
+ };
205
207
  // --- start extra methods ---
206
208
  /**
207
209
  * Inserts a new node at the specified index.
208
210
  * @param index Index at which the new node has to be inserted
209
211
  * @param val Value of the new node to be inserted
210
212
  */
211
- insert(index, val) {
213
+ DoublyLinkedList.prototype.insert = function (index, val) {
212
214
  if (index < 0 || index > this._size)
213
215
  return false;
214
216
  if (index === 0)
215
217
  return !!this.offerFirst(val);
216
218
  if (index === this._size)
217
219
  return !!this.offerLast(val);
218
- const newNode = new DoublyLinkedListNode(val);
219
- const prevNode = this.get(index - 1, 'node');
220
- const nextNode = prevNode === null || prevNode === void 0 ? void 0 : prevNode.next;
220
+ var newNode = new DoublyLinkedListNode(val);
221
+ var prevNode = this.get(index - 1, 'node');
222
+ var nextNode = prevNode === null || prevNode === void 0 ? void 0 : prevNode.next;
221
223
  if (prevNode)
222
224
  prevNode.next = newNode;
223
225
  newNode.prev = prevNode;
@@ -226,12 +228,12 @@ class DoublyLinkedList {
226
228
  nextNode.prev = newNode;
227
229
  this._size++;
228
230
  return true;
229
- }
231
+ };
230
232
  /**
231
233
  * Removes a node at the specified index and returns its value.
232
234
  * @param index Index at which the node has to be removed.
233
235
  */
234
- remove(index) {
236
+ DoublyLinkedList.prototype.remove = function (index) {
235
237
  var _a, _b, _c;
236
238
  if (index < 0 || index > this._size - 1)
237
239
  return null;
@@ -240,9 +242,9 @@ class DoublyLinkedList {
240
242
  else if (index === this._size - 1)
241
243
  return (_b = (_a = this.pollLast('node')) === null || _a === void 0 ? void 0 : _a.val) !== null && _b !== void 0 ? _b : null;
242
244
  else {
243
- const prevNode = this.get(index - 1, 'node');
244
- const removeNode = prevNode === null || prevNode === void 0 ? void 0 : prevNode.next;
245
- const nextNode = removeNode === null || removeNode === void 0 ? void 0 : removeNode.next;
245
+ var prevNode = this.get(index - 1, 'node');
246
+ var removeNode = prevNode === null || prevNode === void 0 ? void 0 : prevNode.next;
247
+ var nextNode = removeNode === null || removeNode === void 0 ? void 0 : removeNode.next;
246
248
  if (prevNode)
247
249
  prevNode.next = nextNode !== null && nextNode !== void 0 ? nextNode : null;
248
250
  if (nextNode)
@@ -254,6 +256,7 @@ class DoublyLinkedList {
254
256
  this._size--;
255
257
  return (_c = removeNode === null || removeNode === void 0 ? void 0 : removeNode.val) !== null && _c !== void 0 ? _c : null;
256
258
  }
257
- }
258
- }
259
+ };
260
+ return DoublyLinkedList;
261
+ }());
259
262
  exports.DoublyLinkedList = DoublyLinkedList;
@@ -1,7 +1,4 @@
1
- /** Type used for filter and find methods, returning a boolean */
2
- type TTestFunction<NodeData> = (data: NodeData, index: number, list: SinglyLinkedList<NodeData>) => boolean;
3
- /** Type used for map and forEach methods, returning anything */
4
- type TMapFunction<NodeData> = (data: any, index: number, list: SinglyLinkedList<NodeData>) => any;
1
+ import type { TMapFunction, TTestFunction } from '../types';
5
2
  /**
6
3
  * The class which represents one link or node in a linked list
7
4
  * ```ts
@@ -72,6 +69,13 @@ export declare class SinglyLinkedListNode<NodeData = any> {
72
69
  * ```
73
70
  */
74
71
  export declare class SinglyLinkedList<NodeData = any> {
72
+ /** The head of the list, the first node */
73
+ head: SinglyLinkedListNode<NodeData> | null;
74
+ /** The tail of the list, the last node */
75
+ tail: SinglyLinkedListNode<NodeData> | null;
76
+ /** Internal size reference */
77
+ private size;
78
+ constructor(...args: NodeData[]);
75
79
  /**
76
80
  * The length of the list
77
81
  */
@@ -85,13 +89,6 @@ export declare class SinglyLinkedList<NodeData = any> {
85
89
  * @param iterable Any iterable datatype like Array or Map
86
90
  */
87
91
  static from<T>(iterable: Iterable<T>): SinglyLinkedList<T>;
88
- /** The head of the list, the first node */
89
- head: SinglyLinkedListNode<NodeData> | null;
90
- /** The tail of the list, the last node */
91
- tail: SinglyLinkedListNode<NodeData> | null;
92
- /** Internal size reference */
93
- private size;
94
- constructor(...args: NodeData[]);
95
92
  /**
96
93
  * Get the node val at a specified index, zero based
97
94
  * ```ts
@@ -355,4 +352,3 @@ export declare class SinglyLinkedList<NodeData = any> {
355
352
  /** Private helper function to reduce duplication of pop() and shift() methods */
356
353
  private removeFromAnyEnd;
357
354
  }
358
- export {};