data-structure-typed 1.39.6 → 1.40.0

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 (193) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cjs/data-structures/binary-tree/avl-tree.js +0 -1
  3. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  4. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -3
  5. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +2 -11
  6. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +5 -20
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.js +8 -29
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  10. package/dist/cjs/data-structures/binary-tree/bst.d.ts +1 -1
  11. package/dist/cjs/data-structures/binary-tree/bst.js +3 -3
  12. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  13. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +1 -3
  14. package/dist/cjs/data-structures/binary-tree/rb-tree.js +1 -7
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  16. package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +10 -26
  17. package/dist/cjs/data-structures/binary-tree/segment-tree.js +10 -58
  18. package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
  19. package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +1 -1
  20. package/dist/cjs/data-structures/binary-tree/tree-multiset.js +6 -6
  21. package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
  22. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +5 -24
  23. package/dist/cjs/data-structures/graph/abstract-graph.js +4 -43
  24. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  25. package/dist/cjs/data-structures/graph/directed-graph.d.ts +4 -10
  26. package/dist/cjs/data-structures/graph/directed-graph.js +2 -20
  27. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  28. package/dist/cjs/data-structures/graph/map-graph.d.ts +4 -10
  29. package/dist/cjs/data-structures/graph/map-graph.js +2 -20
  30. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  31. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +1 -8
  32. package/dist/cjs/data-structures/graph/undirected-graph.js +1 -14
  33. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  34. package/dist/cjs/data-structures/hash/coordinate-map.d.ts +0 -1
  35. package/dist/cjs/data-structures/hash/coordinate-map.js +0 -3
  36. package/dist/cjs/data-structures/hash/coordinate-map.js.map +1 -1
  37. package/dist/cjs/data-structures/hash/coordinate-set.d.ts +0 -1
  38. package/dist/cjs/data-structures/hash/coordinate-set.js +0 -3
  39. package/dist/cjs/data-structures/hash/coordinate-set.js.map +1 -1
  40. package/dist/cjs/data-structures/hash/hash-map.d.ts +8 -14
  41. package/dist/cjs/data-structures/hash/hash-map.js +4 -22
  42. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  43. package/dist/cjs/data-structures/hash/hash-table.d.ts +6 -9
  44. package/dist/cjs/data-structures/hash/hash-table.js +0 -9
  45. package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
  46. package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
  47. package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
  48. package/dist/cjs/data-structures/heap/heap.d.ts +12 -6
  49. package/dist/cjs/data-structures/heap/heap.js +40 -22
  50. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  51. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  52. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  53. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +6 -14
  54. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +18 -42
  55. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  56. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +5 -11
  57. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +17 -35
  58. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  59. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +29 -10
  60. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +62 -17
  61. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  62. package/dist/cjs/data-structures/matrix/matrix.d.ts +1 -1
  63. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  64. package/dist/cjs/data-structures/matrix/matrix2d.d.ts +1 -1
  65. package/dist/cjs/data-structures/matrix/navigator.d.ts +4 -4
  66. package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
  67. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  68. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  69. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  70. package/dist/cjs/data-structures/queue/deque.d.ts +8 -12
  71. package/dist/cjs/data-structures/queue/deque.js +31 -43
  72. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  73. package/dist/cjs/data-structures/queue/queue.d.ts +20 -5
  74. package/dist/cjs/data-structures/queue/queue.js +35 -18
  75. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  76. package/dist/cjs/data-structures/stack/stack.d.ts +2 -1
  77. package/dist/cjs/data-structures/stack/stack.js +10 -7
  78. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  79. package/dist/cjs/data-structures/tree/tree.d.ts +3 -9
  80. package/dist/cjs/data-structures/tree/tree.js +3 -21
  81. package/dist/cjs/data-structures/tree/tree.js.map +1 -1
  82. package/dist/cjs/data-structures/trie/trie.d.ts +6 -12
  83. package/dist/cjs/data-structures/trie/trie.js +6 -24
  84. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  85. package/dist/cjs/interfaces/binary-tree.d.ts +1 -1
  86. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +1 -1
  87. package/dist/mjs/data-structures/binary-tree/avl-tree.js +0 -1
  88. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -3
  89. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +2 -11
  90. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +5 -20
  91. package/dist/mjs/data-structures/binary-tree/binary-tree.js +8 -29
  92. package/dist/mjs/data-structures/binary-tree/bst.d.ts +1 -1
  93. package/dist/mjs/data-structures/binary-tree/bst.js +3 -3
  94. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +1 -3
  95. package/dist/mjs/data-structures/binary-tree/rb-tree.js +2 -8
  96. package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +10 -26
  97. package/dist/mjs/data-structures/binary-tree/segment-tree.js +10 -58
  98. package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +1 -1
  99. package/dist/mjs/data-structures/binary-tree/tree-multiset.js +6 -6
  100. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +5 -24
  101. package/dist/mjs/data-structures/graph/abstract-graph.js +8 -47
  102. package/dist/mjs/data-structures/graph/directed-graph.d.ts +4 -10
  103. package/dist/mjs/data-structures/graph/directed-graph.js +4 -22
  104. package/dist/mjs/data-structures/graph/map-graph.d.ts +4 -10
  105. package/dist/mjs/data-structures/graph/map-graph.js +4 -22
  106. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +1 -8
  107. package/dist/mjs/data-structures/graph/undirected-graph.js +2 -15
  108. package/dist/mjs/data-structures/hash/coordinate-map.d.ts +0 -1
  109. package/dist/mjs/data-structures/hash/coordinate-map.js +0 -3
  110. package/dist/mjs/data-structures/hash/coordinate-set.d.ts +0 -1
  111. package/dist/mjs/data-structures/hash/coordinate-set.js +0 -3
  112. package/dist/mjs/data-structures/hash/hash-map.d.ts +8 -14
  113. package/dist/mjs/data-structures/hash/hash-map.js +4 -22
  114. package/dist/mjs/data-structures/hash/hash-table.d.ts +6 -9
  115. package/dist/mjs/data-structures/hash/hash-table.js +0 -9
  116. package/dist/mjs/data-structures/heap/heap.d.ts +12 -6
  117. package/dist/mjs/data-structures/heap/heap.js +44 -26
  118. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +6 -14
  119. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +21 -45
  120. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +5 -11
  121. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +19 -37
  122. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +29 -10
  123. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +62 -17
  124. package/dist/mjs/data-structures/matrix/matrix.d.ts +1 -1
  125. package/dist/mjs/data-structures/matrix/matrix2d.d.ts +1 -1
  126. package/dist/mjs/data-structures/matrix/navigator.d.ts +4 -4
  127. package/dist/mjs/data-structures/queue/deque.d.ts +8 -12
  128. package/dist/mjs/data-structures/queue/deque.js +31 -43
  129. package/dist/mjs/data-structures/queue/queue.d.ts +20 -5
  130. package/dist/mjs/data-structures/queue/queue.js +34 -17
  131. package/dist/mjs/data-structures/stack/stack.d.ts +2 -1
  132. package/dist/mjs/data-structures/stack/stack.js +11 -8
  133. package/dist/mjs/data-structures/tree/tree.d.ts +3 -9
  134. package/dist/mjs/data-structures/tree/tree.js +6 -24
  135. package/dist/mjs/data-structures/trie/trie.d.ts +6 -12
  136. package/dist/mjs/data-structures/trie/trie.js +10 -28
  137. package/dist/mjs/interfaces/binary-tree.d.ts +1 -1
  138. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +1 -1
  139. package/dist/umd/data-structure-typed.min.js +1 -1
  140. package/dist/umd/data-structure-typed.min.js.map +1 -1
  141. package/package.json +5 -5
  142. package/src/data-structures/binary-tree/avl-tree.ts +2 -4
  143. package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -15
  144. package/src/data-structures/binary-tree/binary-tree.ts +17 -42
  145. package/src/data-structures/binary-tree/bst.ts +5 -6
  146. package/src/data-structures/binary-tree/rb-tree.ts +13 -21
  147. package/src/data-structures/binary-tree/segment-tree.ts +16 -83
  148. package/src/data-structures/binary-tree/tree-multiset.ts +8 -9
  149. package/src/data-structures/graph/abstract-graph.ts +21 -67
  150. package/src/data-structures/graph/directed-graph.ts +13 -39
  151. package/src/data-structures/graph/map-graph.ts +7 -32
  152. package/src/data-structures/graph/undirected-graph.ts +9 -26
  153. package/src/data-structures/hash/coordinate-map.ts +0 -4
  154. package/src/data-structures/hash/coordinate-set.ts +0 -4
  155. package/src/data-structures/hash/hash-map.ts +13 -37
  156. package/src/data-structures/hash/hash-table.ts +6 -18
  157. package/src/data-structures/hash/tree-map.ts +2 -1
  158. package/src/data-structures/hash/tree-set.ts +2 -1
  159. package/src/data-structures/heap/heap.ts +58 -30
  160. package/src/data-structures/heap/max-heap.ts +1 -1
  161. package/src/data-structures/heap/min-heap.ts +1 -1
  162. package/src/data-structures/linked-list/doubly-linked-list.ts +26 -60
  163. package/src/data-structures/linked-list/singly-linked-list.ts +24 -49
  164. package/src/data-structures/linked-list/skip-linked-list.ts +73 -25
  165. package/src/data-structures/matrix/matrix.ts +2 -2
  166. package/src/data-structures/matrix/matrix2d.ts +1 -1
  167. package/src/data-structures/matrix/navigator.ts +4 -4
  168. package/src/data-structures/matrix/vector2d.ts +2 -1
  169. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  170. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  171. package/src/data-structures/priority-queue/priority-queue.ts +1 -1
  172. package/src/data-structures/queue/deque.ts +38 -53
  173. package/src/data-structures/queue/queue.ts +38 -20
  174. package/src/data-structures/stack/stack.ts +13 -9
  175. package/src/data-structures/tree/tree.ts +7 -33
  176. package/src/data-structures/trie/trie.ts +14 -40
  177. package/src/interfaces/binary-tree.ts +1 -1
  178. package/src/types/data-structures/binary-tree/bst.ts +1 -1
  179. package/src/types/data-structures/matrix/navigator.ts +1 -1
  180. package/src/types/utils/utils.ts +1 -1
  181. package/src/types/utils/validate-type.ts +2 -2
  182. package/test/integration/avl-tree.test.ts +1 -1
  183. package/test/integration/bst.test.ts +2 -2
  184. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +2 -2
  185. package/test/unit/data-structures/graph/abstract-graph.test.ts +4 -6
  186. package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
  187. package/test/unit/data-structures/graph/map-graph.test.ts +2 -2
  188. package/test/unit/data-structures/hash/coordinate-map.test.ts +1 -1
  189. package/test/unit/data-structures/hash/coordinate-set.test.ts +1 -1
  190. package/test/unit/data-structures/hash/hash-map.test.ts +0 -1
  191. package/test/unit/data-structures/hash/hash-table.test.ts +3 -3
  192. package/test/unit/data-structures/linked-list/skip-list.test.ts +31 -0
  193. package/test/unit/data-structures/queue/queue.test.ts +8 -8
@@ -4,7 +4,7 @@
4
4
  * @class
5
5
  */
6
6
  import { SinglyLinkedList } from '../linked-list';
7
- export declare class SkipQueue<E = any> extends SinglyLinkedList<E> {
7
+ export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
8
8
  /**
9
9
  * The enqueue function adds a value to the end of an array.
10
10
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
@@ -15,6 +15,11 @@ export declare class SkipQueue<E = any> extends SinglyLinkedList<E> {
15
15
  * @returns The method is returning the element at the front of the queue, or null if the queue is empty.
16
16
  */
17
17
  dequeue(): E | undefined;
18
+ /**
19
+ * The `getFirst` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
20
+ * @returns The `getFirst()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
21
+ */
22
+ getFirst(): E | undefined;
18
23
  /**
19
24
  * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
20
25
  * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
@@ -29,12 +34,10 @@ export declare class Queue<E = any> {
29
34
  * initialized as an empty array.
30
35
  */
31
36
  constructor(elements?: E[]);
32
- private _nodes;
37
+ protected _nodes: E[];
33
38
  get nodes(): E[];
34
- set nodes(value: E[]);
35
- private _offset;
39
+ protected _offset: number;
36
40
  get offset(): number;
37
- set offset(value: number);
38
41
  /**
39
42
  * The size function returns the number of elements in an array.
40
43
  * @returns {number} The size of the array, which is the difference between the length of the array and the offset.
@@ -61,6 +64,12 @@ export declare class Queue<E = any> {
61
64
  * @returns The function `shift()` returns either the first element in the queue or `null` if the queue is empty.
62
65
  */
63
66
  shift(): E | undefined;
67
+ /**
68
+ * The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
69
+ * @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
70
+ * the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
71
+ */
72
+ getFirst(): E | undefined;
64
73
  /**
65
74
  * The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
66
75
  * @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
@@ -73,6 +82,12 @@ export declare class Queue<E = any> {
73
82
  * array is empty, it returns `null`.
74
83
  */
75
84
  getLast(): E | undefined;
85
+ /**
86
+ * The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
87
+ * @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
88
+ * array is empty, it returns `null`.
89
+ */
90
+ peekLast(): E | undefined;
76
91
  /**
77
92
  * The enqueue function adds a value to the end of a queue.
78
93
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Queue = exports.SkipQueue = void 0;
3
+ exports.Queue = exports.LinkedListQueue = void 0;
4
4
  /**
5
5
  * @license MIT
6
6
  * @copyright Tyler Zeng <zrwusa@gmail.com>
7
7
  * @class
8
8
  */
9
9
  const linked_list_1 = require("../linked-list");
10
- class SkipQueue extends linked_list_1.SinglyLinkedList {
10
+ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
11
11
  /**
12
12
  * The enqueue function adds a value to the end of an array.
13
13
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
@@ -22,15 +22,22 @@ class SkipQueue extends linked_list_1.SinglyLinkedList {
22
22
  dequeue() {
23
23
  return this.shift();
24
24
  }
25
+ /**
26
+ * The `getFirst` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
27
+ * @returns The `getFirst()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
28
+ */
29
+ getFirst() {
30
+ return this.head?.value;
31
+ }
25
32
  /**
26
33
  * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
27
34
  * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
28
35
  */
29
36
  peek() {
30
- return this.head?.value;
37
+ return this.getFirst();
31
38
  }
32
39
  }
33
- exports.SkipQueue = SkipQueue;
40
+ exports.LinkedListQueue = LinkedListQueue;
34
41
  class Queue {
35
42
  /**
36
43
  * The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
@@ -46,16 +53,10 @@ class Queue {
46
53
  get nodes() {
47
54
  return this._nodes;
48
55
  }
49
- set nodes(value) {
50
- this._nodes = value;
51
- }
52
56
  _offset;
53
57
  get offset() {
54
58
  return this._offset;
55
59
  }
56
- set offset(value) {
57
- this._offset = value;
58
- }
59
60
  /**
60
61
  * The size function returns the number of elements in an array.
61
62
  * @returns {number} The size of the array, which is the difference between the length of the array and the offset.
@@ -91,23 +92,31 @@ class Queue {
91
92
  shift() {
92
93
  if (this.size === 0)
93
94
  return undefined;
94
- const first = this.peek();
95
- this.offset += 1;
95
+ const first = this.getFirst();
96
+ this._offset += 1;
96
97
  if (this.offset * 2 < this.nodes.length)
97
98
  return first;
98
99
  // only delete dequeued elements when reaching half size
99
100
  // to decrease latency of shifting elements.
100
- this.nodes = this.nodes.slice(this.offset);
101
- this.offset = 0;
101
+ this._nodes = this.nodes.slice(this.offset);
102
+ this._offset = 0;
102
103
  return first;
103
104
  }
105
+ /**
106
+ * The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
107
+ * @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
108
+ * the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
109
+ */
110
+ getFirst() {
111
+ return this.size > 0 ? this.nodes[this.offset] : undefined;
112
+ }
104
113
  /**
105
114
  * The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
106
115
  * @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
107
116
  * the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
108
117
  */
109
118
  peek() {
110
- return this.size > 0 ? this.nodes[this.offset] : undefined;
119
+ return this.getFirst();
111
120
  }
112
121
  /**
113
122
  * The `getLast` function returns the last element in an array-like data structure, or null if the structure is empty.
@@ -117,6 +126,14 @@ class Queue {
117
126
  getLast() {
118
127
  return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
119
128
  }
129
+ /**
130
+ * The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
131
+ * @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
132
+ * array is empty, it returns `null`.
133
+ */
134
+ peekLast() {
135
+ return this.getLast();
136
+ }
120
137
  /**
121
138
  * The enqueue function adds a value to the end of a queue.
122
139
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
@@ -152,8 +169,8 @@ class Queue {
152
169
  * The clear function resets the nodes array and offset to their initial values.
153
170
  */
154
171
  clear() {
155
- this.nodes = [];
156
- this.offset = 0;
172
+ this._nodes = [];
173
+ this._offset = 0;
157
174
  }
158
175
  /**
159
176
  * The `clone()` function returns a new Queue object with the same elements as the original Queue.
@@ -4,7 +4,6 @@
4
4
  * @class
5
5
  */
6
6
  export declare class Stack<E = any> {
7
- protected _elements: E[];
8
7
  /**
9
8
  * The constructor initializes an array of elements, which can be provided as an optional parameter.
10
9
  * @param {E[]} [elements] - The `elements` parameter is an optional parameter of type `E[]`, which represents an array
@@ -12,6 +11,8 @@ export declare class Stack<E = any> {
12
11
  * is provided and is an array, it is assigned to the `_elements
13
12
  */
14
13
  constructor(elements?: E[]);
14
+ protected _elements: E[];
15
+ get elements(): E[];
15
16
  /**
16
17
  * The function "fromArray" creates a new Stack object from an array of elements.
17
18
  * @param {E[]} elements - The `elements` parameter is an array of elements of type `E`.
@@ -7,7 +7,6 @@ exports.Stack = void 0;
7
7
  * @class
8
8
  */
9
9
  class Stack {
10
- _elements;
11
10
  /**
12
11
  * The constructor initializes an array of elements, which can be provided as an optional parameter.
13
12
  * @param {E[]} [elements] - The `elements` parameter is an optional parameter of type `E[]`, which represents an array
@@ -17,6 +16,10 @@ class Stack {
17
16
  constructor(elements) {
18
17
  this._elements = Array.isArray(elements) ? elements : [];
19
18
  }
19
+ _elements;
20
+ get elements() {
21
+ return this._elements;
22
+ }
20
23
  /**
21
24
  * The function "fromArray" creates a new Stack object from an array of elements.
22
25
  * @param {E[]} elements - The `elements` parameter is an array of elements of type `E`.
@@ -31,14 +34,14 @@ class Stack {
31
34
  * @returns A boolean value indicating whether the `_elements` array is empty or not.
32
35
  */
33
36
  isEmpty() {
34
- return this._elements.length === 0;
37
+ return this.elements.length === 0;
35
38
  }
36
39
  /**
37
40
  * The size() function returns the number of elements in an array.
38
41
  * @returns The size of the elements array.
39
42
  */
40
43
  size() {
41
- return this._elements.length;
44
+ return this.elements.length;
42
45
  }
43
46
  /**
44
47
  * The `peek` function returns the last element of an array, or null if the array is empty.
@@ -47,7 +50,7 @@ class Stack {
47
50
  peek() {
48
51
  if (this.isEmpty())
49
52
  return null;
50
- return this._elements[this._elements.length - 1];
53
+ return this.elements[this.elements.length - 1];
51
54
  }
52
55
  /**
53
56
  * The push function adds an element to the stack and returns the updated stack.
@@ -55,7 +58,7 @@ class Stack {
55
58
  * @returns The `push` method is returning the updated `Stack<E>` object.
56
59
  */
57
60
  push(element) {
58
- this._elements.push(element);
61
+ this.elements.push(element);
59
62
  return this;
60
63
  }
61
64
  /**
@@ -66,14 +69,14 @@ class Stack {
66
69
  pop() {
67
70
  if (this.isEmpty())
68
71
  return null;
69
- return this._elements.pop() || null;
72
+ return this.elements.pop() || null;
70
73
  }
71
74
  /**
72
75
  * The toArray function returns a copy of the elements in an array.
73
76
  * @returns An array of type E.
74
77
  */
75
78
  toArray() {
76
- return this._elements.slice();
79
+ return this.elements.slice();
77
80
  }
78
81
  /**
79
82
  * The clear function clears the elements array.
@@ -86,7 +89,7 @@ class Stack {
86
89
  * @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
87
90
  */
88
91
  clone() {
89
- return new Stack(this._elements.slice());
92
+ return new Stack(this.elements.slice());
90
93
  }
91
94
  }
92
95
  exports.Stack = Stack;
@@ -1,14 +1,8 @@
1
1
  export declare class TreeNode<V = any> {
2
+ key: string;
3
+ value?: V | undefined;
4
+ children?: TreeNode<V>[] | undefined;
2
5
  constructor(key: string, value?: V, children?: TreeNode<V>[]);
3
- private _key;
4
- get key(): string;
5
- set key(value: string);
6
- private _value?;
7
- get value(): V | undefined;
8
- set value(value: V | undefined);
9
- private _children?;
10
- get children(): TreeNode<V>[] | undefined;
11
- set children(value: TreeNode<V>[] | undefined);
12
6
  addChildren(children: TreeNode<V> | TreeNode<V>[]): void;
13
7
  getHeight(): number;
14
8
  }
@@ -2,31 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TreeNode = void 0;
4
4
  class TreeNode {
5
+ key;
6
+ value;
7
+ children;
5
8
  constructor(key, value, children) {
6
- this._key = key;
7
- this._value = value || undefined;
8
- this._children = children || [];
9
- }
10
- _key;
11
- get key() {
12
- return this._key;
13
- }
14
- set key(value) {
15
- this._key = value;
16
- }
17
- _value;
18
- get value() {
19
- return this._value;
20
- }
21
- set value(value) {
22
- this._value = value;
23
- }
24
- _children;
25
- get children() {
26
- return this._children;
27
- }
28
- set children(value) {
29
- this._children = value;
9
+ this.key = key;
10
+ this.value = value || undefined;
11
+ this.children = children || [];
30
12
  }
31
13
  addChildren(children) {
32
14
  if (!this.children) {
@@ -10,26 +10,20 @@
10
10
  * and a flag indicating whether it's the end of a word.
11
11
  */
12
12
  export declare class TrieNode {
13
+ key: string;
14
+ children: Map<string, TrieNode>;
15
+ isEnd: boolean;
13
16
  constructor(key: string);
14
- private _key;
15
- get key(): string;
16
- set key(v: string);
17
- protected _children: Map<string, TrieNode>;
18
- get children(): Map<string, TrieNode>;
19
- set children(v: Map<string, TrieNode>);
20
- protected _isEnd: boolean;
21
- get isEnd(): boolean;
22
- set isEnd(v: boolean);
23
17
  }
24
18
  /**
25
19
  * Trie represents a Trie data structure. It provides basic Trie operations and additional methods.
26
20
  */
27
21
  export declare class Trie {
28
- private readonly _caseSensitive;
29
22
  constructor(words?: string[], caseSensitive?: boolean);
23
+ protected _caseSensitive: boolean;
24
+ get caseSensitive(): boolean;
30
25
  protected _root: TrieNode;
31
26
  get root(): TrieNode;
32
- set root(v: TrieNode);
33
27
  /**
34
28
  * Add a word to the Trie structure.
35
29
  * @param {string} word - The word to add.
@@ -81,5 +75,5 @@ export declare class Trie {
81
75
  * @returns {string[]} an array of strings.
82
76
  */
83
77
  getWords(prefix?: string, max?: number, isAllWhenEmptyPrefix?: boolean): string[];
84
- private _caseProcess;
78
+ protected _caseProcess(str: string): string;
85
79
  }
@@ -13,31 +13,13 @@ exports.Trie = exports.TrieNode = void 0;
13
13
  * and a flag indicating whether it's the end of a word.
14
14
  */
15
15
  class TrieNode {
16
+ key;
17
+ children;
18
+ isEnd;
16
19
  constructor(key) {
17
- this._key = key;
18
- this._isEnd = false;
19
- this._children = new Map();
20
- }
21
- _key;
22
- get key() {
23
- return this._key;
24
- }
25
- set key(v) {
26
- this._key = v;
27
- }
28
- _children;
29
- get children() {
30
- return this._children;
31
- }
32
- set children(v) {
33
- this._children = v;
34
- }
35
- _isEnd;
36
- get isEnd() {
37
- return this._isEnd;
38
- }
39
- set isEnd(v) {
40
- this._isEnd = v;
20
+ this.key = key;
21
+ this.isEnd = false;
22
+ this.children = new Map();
41
23
  }
42
24
  }
43
25
  exports.TrieNode = TrieNode;
@@ -45,7 +27,6 @@ exports.TrieNode = TrieNode;
45
27
  * Trie represents a Trie data structure. It provides basic Trie operations and additional methods.
46
28
  */
47
29
  class Trie {
48
- _caseSensitive;
49
30
  constructor(words, caseSensitive = true) {
50
31
  this._root = new TrieNode('');
51
32
  this._caseSensitive = caseSensitive;
@@ -55,13 +36,14 @@ class Trie {
55
36
  }
56
37
  }
57
38
  }
39
+ _caseSensitive;
40
+ get caseSensitive() {
41
+ return this._caseSensitive;
42
+ }
58
43
  _root;
59
44
  get root() {
60
45
  return this._root;
61
46
  }
62
- set root(v) {
63
- this._root = v;
64
- }
65
47
  /**
66
48
  * Add a word to the Trie structure.
67
49
  * @param {string} word - The word to add.
@@ -1,5 +1,5 @@
1
1
  import { BinaryTreeNode } from '../data-structures';
2
- import { BinaryTreeDeletedResult, BTNKey, BinaryTreeNodeNested, BTNCallback } from '../types';
2
+ import { BinaryTreeDeletedResult, BinaryTreeNodeNested, BTNCallback, BTNKey } from '../types';
3
3
  export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>> {
4
4
  createNode(key: BTNKey, value?: N['value']): N;
5
5
  add(keyOrNode: BTNKey | N | null, value?: N['value']): N | null | undefined;
@@ -1,5 +1,5 @@
1
1
  import { BSTNode } from '../../../data-structures';
2
- import type { BTNKey, BinaryTreeOptions } from './binary-tree';
2
+ import type { BinaryTreeOptions, BTNKey } from './binary-tree';
3
3
  export type BSTComparator = (a: BTNKey, b: BTNKey) => number;
4
4
  export type BSTNodeNested<T> = BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
5
  export type BSTOptions = BinaryTreeOptions & {