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
@@ -9,28 +9,16 @@ exports.SinglyLinkedList = exports.SinglyLinkedListNode = void 0;
9
9
  * @license MIT License
10
10
  */
11
11
  class SinglyLinkedListNode {
12
+ value;
13
+ next;
12
14
  /**
13
15
  * The constructor function initializes an instance of a class with a given value and sets the next property to null.
14
16
  * @param {E} value - The "value" parameter is of type E, which means it can be any data type. It represents the value that
15
17
  * will be stored in the node of a linked list.
16
18
  */
17
19
  constructor(value) {
18
- this._value = value;
19
- this._next = null;
20
- }
21
- _value;
22
- get value() {
23
- return this._value;
24
- }
25
- set value(value) {
26
- this._value = value;
27
- }
28
- _next;
29
- get next() {
30
- return this._next;
31
- }
32
- set next(value) {
33
- this._next = value;
20
+ this.value = value;
21
+ this.next = null;
34
22
  }
35
23
  }
36
24
  exports.SinglyLinkedListNode = SinglyLinkedListNode;
@@ -47,16 +35,10 @@ class SinglyLinkedList {
47
35
  get head() {
48
36
  return this._head;
49
37
  }
50
- set head(value) {
51
- this._head = value;
52
- }
53
38
  _tail;
54
39
  get tail() {
55
40
  return this._tail;
56
41
  }
57
- set tail(value) {
58
- this._tail = value;
59
- }
60
42
  _length;
61
43
  get length() {
62
44
  return this._length;
@@ -82,12 +64,12 @@ class SinglyLinkedList {
82
64
  push(value) {
83
65
  const newNode = new SinglyLinkedListNode(value);
84
66
  if (!this.head) {
85
- this.head = newNode;
86
- this.tail = newNode;
67
+ this._head = newNode;
68
+ this._tail = newNode;
87
69
  }
88
70
  else {
89
71
  this.tail.next = newNode;
90
- this.tail = newNode;
72
+ this._tail = newNode;
91
73
  }
92
74
  this._length++;
93
75
  }
@@ -110,8 +92,8 @@ class SinglyLinkedList {
110
92
  return undefined;
111
93
  if (this.head === this.tail) {
112
94
  const value = this.head.value;
113
- this.head = null;
114
- this.tail = null;
95
+ this._head = null;
96
+ this._tail = null;
115
97
  this._length--;
116
98
  return value;
117
99
  }
@@ -121,7 +103,7 @@ class SinglyLinkedList {
121
103
  }
122
104
  const value = this.tail.value;
123
105
  current.next = null;
124
- this.tail = current;
106
+ this._tail = current;
125
107
  this._length--;
126
108
  return value;
127
109
  }
@@ -142,7 +124,7 @@ class SinglyLinkedList {
142
124
  if (!this.head)
143
125
  return undefined;
144
126
  const removedNode = this.head;
145
- this.head = this.head.next;
127
+ this._head = this.head.next;
146
128
  this._length--;
147
129
  return removedNode.value;
148
130
  }
@@ -161,12 +143,12 @@ class SinglyLinkedList {
161
143
  unshift(value) {
162
144
  const newNode = new SinglyLinkedListNode(value);
163
145
  if (!this.head) {
164
- this.head = newNode;
165
- this.tail = newNode;
146
+ this._head = newNode;
147
+ this._tail = newNode;
166
148
  }
167
149
  else {
168
150
  newNode.next = this.head;
169
- this.head = newNode;
151
+ this._head = newNode;
170
152
  }
171
153
  this._length++;
172
154
  }
@@ -249,15 +231,15 @@ class SinglyLinkedList {
249
231
  while (current) {
250
232
  if (current.value === value) {
251
233
  if (prev === null) {
252
- this.head = current.next;
234
+ this._head = current.next;
253
235
  if (current === this.tail) {
254
- this.tail = null;
236
+ this._tail = null;
255
237
  }
256
238
  }
257
239
  else {
258
240
  prev.next = current.next;
259
241
  if (current === this.tail) {
260
- this.tail = prev;
242
+ this._tail = prev;
261
243
  }
262
244
  }
263
245
  this._length--;
@@ -340,7 +322,7 @@ class SinglyLinkedList {
340
322
  prev = current;
341
323
  current = next;
342
324
  }
343
- [this.head, this.tail] = [this.tail, this.head];
325
+ [this._head, this._tail] = [this.tail, this.head];
344
326
  }
345
327
  /**
346
328
  * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
@@ -450,7 +432,7 @@ class SinglyLinkedList {
450
432
  newNode.next = existingNode.next;
451
433
  existingNode.next = newNode;
452
434
  if (existingNode === this.tail) {
453
- this.tail = newNode;
435
+ this._tail = newNode;
454
436
  }
455
437
  this._length++;
456
438
  return true;
@@ -20,18 +20,14 @@ export declare class SkipList<K, V> {
20
20
  * level in the skip list. It is used to determine the height of each node in the skip list.
21
21
  */
22
22
  constructor(maxLevel?: number, probability?: number);
23
- private _head;
23
+ protected _head: SkipListNode<K, V>;
24
24
  get head(): SkipListNode<K, V>;
25
- set head(value: SkipListNode<K, V>);
26
- private _level;
25
+ protected _level: number;
27
26
  get level(): number;
28
- set level(value: number);
29
- private _maxLevel;
27
+ protected _maxLevel: number;
30
28
  get maxLevel(): number;
31
- set maxLevel(value: number);
32
- private _probability;
29
+ protected _probability: number;
33
30
  get probability(): number;
34
- set probability(value: number);
35
31
  /**
36
32
  * The add function adds a new node with a given key and value to a Skip List data structure.
37
33
  * @param {K} key - The key parameter represents the key of the node that needs to be added to the skip list.
@@ -46,6 +42,7 @@ export declare class SkipList<K, V> {
46
42
  * otherwise it returns `undefined`.
47
43
  */
48
44
  get(key: K): V | undefined;
45
+ has(key: K): boolean;
49
46
  /**
50
47
  * The `delete` function removes a node with a specific key from a Skip List data structure.
51
48
  * @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
@@ -54,8 +51,30 @@ export declare class SkipList<K, V> {
54
51
  */
55
52
  delete(key: K): boolean;
56
53
  /**
57
- * The function "randomLevel" generates a random level based on a given probability and maximum level.
54
+ * Get the value of the first element (the smallest element) in the Skip List.
55
+ * @returns The value of the first element, or undefined if the Skip List is empty.
56
+ */
57
+ getFirst(): V | undefined;
58
+ /**
59
+ * Get the value of the last element (the largest element) in the Skip List.
60
+ * @returns The value of the last element, or undefined if the Skip List is empty.
61
+ */
62
+ getLast(): V | undefined;
63
+ /**
64
+ * Get the value of the first element in the Skip List that is greater than the given key.
65
+ * @param key - the given key.
66
+ * @returns The value of the first element greater than the given key, or undefined if there is no such element.
67
+ */
68
+ higher(key: K): V | undefined;
69
+ /**
70
+ * Get the value of the last element in the Skip List that is less than the given key.
71
+ * @param key - the given key.
72
+ * @returns The value of the last element less than the given key, or undefined if there is no such element.
73
+ */
74
+ lower(key: K): V | undefined;
75
+ /**
76
+ * The function "_randomLevel" generates a random level based on a given probability and maximum level.
58
77
  * @returns the level, which is a number.
59
78
  */
60
- private randomLevel;
79
+ protected _randomLevel(): number;
61
80
  }
@@ -37,30 +37,18 @@ class SkipList {
37
37
  get head() {
38
38
  return this._head;
39
39
  }
40
- set head(value) {
41
- this._head = value;
42
- }
43
40
  _level;
44
41
  get level() {
45
42
  return this._level;
46
43
  }
47
- set level(value) {
48
- this._level = value;
49
- }
50
44
  _maxLevel;
51
45
  get maxLevel() {
52
46
  return this._maxLevel;
53
47
  }
54
- set maxLevel(value) {
55
- this._maxLevel = value;
56
- }
57
48
  _probability;
58
49
  get probability() {
59
50
  return this._probability;
60
51
  }
61
- set probability(value) {
62
- this._probability = value;
63
- }
64
52
  /**
65
53
  * The add function adds a new node with a given key and value to a Skip List data structure.
66
54
  * @param {K} key - The key parameter represents the key of the node that needs to be added to the skip list.
@@ -68,7 +56,7 @@ class SkipList {
68
56
  * List.
69
57
  */
70
58
  add(key, value) {
71
- const newNode = new SkipListNode(key, value, this.randomLevel());
59
+ const newNode = new SkipListNode(key, value, this._randomLevel());
72
60
  const update = new Array(this.maxLevel).fill(this.head);
73
61
  let current = this.head;
74
62
  for (let i = this.level - 1; i >= 0; i--) {
@@ -82,7 +70,7 @@ class SkipList {
82
70
  update[i].forward[i] = newNode;
83
71
  }
84
72
  if (newNode.forward[0] !== null) {
85
- this.level = Math.max(this.level, newNode.forward.length);
73
+ this._level = Math.max(this.level, newNode.forward.length);
86
74
  }
87
75
  }
88
76
  /**
@@ -104,6 +92,9 @@ class SkipList {
104
92
  }
105
93
  return undefined;
106
94
  }
95
+ has(key) {
96
+ return this.get(key) !== undefined;
97
+ }
107
98
  /**
108
99
  * The `delete` function removes a node with a specific key from a Skip List data structure.
109
100
  * @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
@@ -128,17 +119,71 @@ class SkipList {
128
119
  update[i].forward[i] = current.forward[i];
129
120
  }
130
121
  while (this.level > 0 && this.head.forward[this.level - 1] === null) {
131
- this.level--;
122
+ this._level--;
132
123
  }
133
124
  return true;
134
125
  }
135
126
  return false;
136
127
  }
137
128
  /**
138
- * The function "randomLevel" generates a random level based on a given probability and maximum level.
129
+ * Get the value of the first element (the smallest element) in the Skip List.
130
+ * @returns The value of the first element, or undefined if the Skip List is empty.
131
+ */
132
+ getFirst() {
133
+ const firstNode = this.head.forward[0];
134
+ return firstNode ? firstNode.value : undefined;
135
+ }
136
+ /**
137
+ * Get the value of the last element (the largest element) in the Skip List.
138
+ * @returns The value of the last element, or undefined if the Skip List is empty.
139
+ */
140
+ getLast() {
141
+ let current = this.head;
142
+ for (let i = this.level - 1; i >= 0; i--) {
143
+ while (current.forward[i]) {
144
+ current = current.forward[i];
145
+ }
146
+ }
147
+ return current.value;
148
+ }
149
+ /**
150
+ * Get the value of the first element in the Skip List that is greater than the given key.
151
+ * @param key - the given key.
152
+ * @returns The value of the first element greater than the given key, or undefined if there is no such element.
153
+ */
154
+ higher(key) {
155
+ let current = this.head;
156
+ for (let i = this.level - 1; i >= 0; i--) {
157
+ while (current.forward[i] && current.forward[i].key <= key) {
158
+ current = current.forward[i];
159
+ }
160
+ }
161
+ const nextNode = current.forward[0];
162
+ return nextNode ? nextNode.value : undefined;
163
+ }
164
+ /**
165
+ * Get the value of the last element in the Skip List that is less than the given key.
166
+ * @param key - the given key.
167
+ * @returns The value of the last element less than the given key, or undefined if there is no such element.
168
+ */
169
+ lower(key) {
170
+ let current = this.head;
171
+ let lastLess = null;
172
+ for (let i = this.level - 1; i >= 0; i--) {
173
+ while (current.forward[i] && current.forward[i].key < key) {
174
+ current = current.forward[i];
175
+ }
176
+ if (current.key < key) {
177
+ lastLess = current;
178
+ }
179
+ }
180
+ return lastLess ? lastLess.value : undefined;
181
+ }
182
+ /**
183
+ * The function "_randomLevel" generates a random level based on a given probability and maximum level.
139
184
  * @returns the level, which is a number.
140
185
  */
141
- randomLevel() {
186
+ _randomLevel() {
142
187
  let level = 1;
143
188
  while (Math.random() < this.probability && level < this.maxLevel) {
144
189
  level++;
@@ -6,7 +6,7 @@
6
6
  * @license MIT License
7
7
  */
8
8
  export declare class MatrixNTI2D<V = any> {
9
- private readonly _matrix;
9
+ protected readonly _matrix: Array<Array<V>>;
10
10
  /**
11
11
  * The constructor creates a matrix with the specified number of rows and columns, and initializes all elements to a
12
12
  * given initial value or 0 if not provided.
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import { Vector2D } from './vector2d';
9
9
  export declare class Matrix2D {
10
- private readonly _matrix;
10
+ protected readonly _matrix: number[][];
11
11
  /**
12
12
  * The constructor function initializes a Matrix2D object with either a default identity matrix, or a provided matrix
13
13
  * or Vector2D object.
@@ -21,10 +21,10 @@ export declare class Character {
21
21
  }
22
22
  export declare class Navigator<T = number> {
23
23
  onMove: (cur: [number, number]) => void;
24
- private readonly _matrix;
25
- private readonly _cur;
26
- private _character;
27
- private readonly _VISITED;
24
+ protected readonly _matrix: T[][];
25
+ protected readonly _cur: [number, number];
26
+ protected _character: Character;
27
+ protected readonly _VISITED: T;
28
28
  /**
29
29
  * The constructor initializes the Navigator object with the given parameters and sets the current position as visited
30
30
  * in the matrix.
@@ -10,20 +10,19 @@ export declare class Deque<E = any> extends DoublyLinkedList<E> {
10
10
  }
11
11
  export declare class ObjectDeque<E = number> {
12
12
  constructor(capacity?: number);
13
- private _nodes;
13
+ protected _nodes: {
14
+ [key: number]: E;
15
+ };
14
16
  get nodes(): {
15
17
  [p: number]: E;
16
18
  };
17
- private _capacity;
19
+ protected _capacity: number;
18
20
  get capacity(): number;
19
- set capacity(value: number);
20
- private _first;
21
+ protected _first: number;
21
22
  get first(): number;
22
- set first(value: number);
23
- private _last;
23
+ protected _last: number;
24
24
  get last(): number;
25
- set last(value: number);
26
- private _size;
25
+ protected _size: number;
27
26
  get size(): number;
28
27
  /**
29
28
  * The "addFirst" function adds a value to the beginning of an array-like data structure.
@@ -69,13 +68,10 @@ export declare class ObjectDeque<E = number> {
69
68
  * @returns The method is returning a boolean value indicating whether the size of the object is less than or equal to 0.
70
69
  */
71
70
  isEmpty(): boolean;
72
- protected _seNodes(value: {
73
- [p: number]: E;
74
- }): void;
75
- protected _setSize(value: number): void;
76
71
  }
77
72
  export declare class ArrayDeque<E> {
78
73
  protected _nodes: E[];
74
+ get nodes(): E[];
79
75
  get size(): number;
80
76
  /**
81
77
  * O(n) time complexity of adding at the beginning and the end
@@ -30,23 +30,14 @@ class ObjectDeque {
30
30
  get capacity() {
31
31
  return this._capacity;
32
32
  }
33
- set capacity(value) {
34
- this._capacity = value;
35
- }
36
33
  _first = -1;
37
34
  get first() {
38
35
  return this._first;
39
36
  }
40
- set first(value) {
41
- this._first = value;
42
- }
43
37
  _last = -1;
44
38
  get last() {
45
39
  return this._last;
46
40
  }
47
- set last(value) {
48
- this._last = value;
49
- }
50
41
  _size = 0;
51
42
  get size() {
52
43
  return this._size;
@@ -57,15 +48,15 @@ class ObjectDeque {
57
48
  * structure.
58
49
  */
59
50
  addFirst(value) {
60
- if (this._size === 0) {
61
- const mid = Math.floor(this._capacity / 2);
51
+ if (this.size === 0) {
52
+ const mid = Math.floor(this.capacity / 2);
62
53
  this._first = mid;
63
54
  this._last = mid;
64
55
  }
65
56
  else {
66
57
  this._first--;
67
58
  }
68
- this._nodes[this._first] = value;
59
+ this.nodes[this.first] = value;
69
60
  this._size++;
70
61
  }
71
62
  /**
@@ -73,15 +64,15 @@ class ObjectDeque {
73
64
  * @param {E} value - The `value` parameter represents the value that you want to add to the end of the data structure.
74
65
  */
75
66
  addLast(value) {
76
- if (this._size === 0) {
77
- const mid = Math.floor(this._capacity / 2);
67
+ if (this.size === 0) {
68
+ const mid = Math.floor(this.capacity / 2);
78
69
  this._first = mid;
79
70
  this._last = mid;
80
71
  }
81
72
  else {
82
73
  this._last++;
83
74
  }
84
- this._nodes[this._last] = value;
75
+ this.nodes[this.last] = value;
85
76
  this._size++;
86
77
  }
87
78
  /**
@@ -89,10 +80,10 @@ class ObjectDeque {
89
80
  * @returns The value of the first element in the data structure.
90
81
  */
91
82
  popFirst() {
92
- if (!this._size)
83
+ if (!this.size)
93
84
  return;
94
85
  const value = this.getFirst();
95
- delete this._nodes[this._first];
86
+ delete this.nodes[this.first];
96
87
  this._first++;
97
88
  this._size--;
98
89
  return value;
@@ -102,18 +93,18 @@ class ObjectDeque {
102
93
  * @returns The element at the first position of the `_nodes` array.
103
94
  */
104
95
  getFirst() {
105
- if (this._size)
106
- return this._nodes[this._first];
96
+ if (this.size)
97
+ return this.nodes[this.first];
107
98
  }
108
99
  /**
109
100
  * The `popLast()` function removes and returns the last element in a data structure.
110
101
  * @returns The value that was removed from the data structure.
111
102
  */
112
103
  popLast() {
113
- if (!this._size)
104
+ if (!this.size)
114
105
  return;
115
106
  const value = this.getLast();
116
- delete this._nodes[this._last];
107
+ delete this.nodes[this.last];
117
108
  this._last--;
118
109
  this._size--;
119
110
  return value;
@@ -123,8 +114,8 @@ class ObjectDeque {
123
114
  * @returns The last element in the array "_nodes" is being returned.
124
115
  */
125
116
  getLast() {
126
- if (this._size)
127
- return this._nodes[this._last];
117
+ if (this.size)
118
+ return this.nodes[this.last];
128
119
  }
129
120
  /**
130
121
  * The get function returns the element at the specified index in an array-like data structure.
@@ -134,20 +125,14 @@ class ObjectDeque {
134
125
  * index, `null` is returned.
135
126
  */
136
127
  get(index) {
137
- return this._nodes[this._first + index] || null;
128
+ return this.nodes[this.first + index] || null;
138
129
  }
139
130
  /**
140
131
  * The function checks if the size of a data structure is less than or equal to zero.
141
132
  * @returns The method is returning a boolean value indicating whether the size of the object is less than or equal to 0.
142
133
  */
143
134
  isEmpty() {
144
- return this._size <= 0;
145
- }
146
- _seNodes(value) {
147
- this._nodes = value;
148
- }
149
- _setSize(value) {
150
- this._size = value;
135
+ return this.size <= 0;
151
136
  }
152
137
  }
153
138
  exports.ObjectDeque = ObjectDeque;
@@ -155,8 +140,11 @@ exports.ObjectDeque = ObjectDeque;
155
140
  // O(n) time complexity of adding at the beginning and the end
156
141
  class ArrayDeque {
157
142
  _nodes = [];
143
+ get nodes() {
144
+ return this._nodes;
145
+ }
158
146
  get size() {
159
- return this._nodes.length;
147
+ return this.nodes.length;
160
148
  }
161
149
  /**
162
150
  * O(n) time complexity of adding at the beginning and the end
@@ -167,14 +155,14 @@ class ArrayDeque {
167
155
  * @returns The return value is the new length of the array after the value has been added.
168
156
  */
169
157
  addLast(value) {
170
- return this._nodes.push(value);
158
+ return this.nodes.push(value);
171
159
  }
172
160
  /**
173
161
  * The function "popLast" returns and removes the last element from an array, or returns null if the array is empty.
174
162
  * @returns The method `popLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
175
163
  */
176
164
  popLast() {
177
- return this._nodes.pop() ?? null;
165
+ return this.nodes.pop() ?? null;
178
166
  }
179
167
  /**
180
168
  * The `popFirst` function removes and returns the first element from an array, or returns null if the array is empty.
@@ -182,7 +170,7 @@ class ArrayDeque {
182
170
  * empty.
183
171
  */
184
172
  popFirst() {
185
- return this._nodes.shift() ?? null;
173
+ return this.nodes.shift() ?? null;
186
174
  }
187
175
  /**
188
176
  * O(n) time complexity of adding at the beginning and the end
@@ -194,7 +182,7 @@ class ArrayDeque {
194
182
  * `value` at the beginning.
195
183
  */
196
184
  addFirst(value) {
197
- return this._nodes.unshift(value);
185
+ return this.nodes.unshift(value);
198
186
  }
199
187
  /**
200
188
  * The `getFirst` function returns the first element of an array or null if the array is empty.
@@ -202,14 +190,14 @@ class ArrayDeque {
202
190
  * empty, it will return `null`.
203
191
  */
204
192
  getFirst() {
205
- return this._nodes[0] ?? null;
193
+ return this.nodes[0] ?? null;
206
194
  }
207
195
  /**
208
196
  * The `getLast` function returns the last element of an array or null if the array is empty.
209
197
  * @returns The method `getLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
210
198
  */
211
199
  getLast() {
212
- return this._nodes[this._nodes.length - 1] ?? null;
200
+ return this.nodes[this.nodes.length - 1] ?? null;
213
201
  }
214
202
  /**
215
203
  * O(1) time complexity of obtaining the value
@@ -222,7 +210,7 @@ class ArrayDeque {
222
210
  * will be returned. If the element does not exist (i.e., the index is out of bounds), `null` will be returned.
223
211
  */
224
212
  get(index) {
225
- return this._nodes[index] ?? null;
213
+ return this.nodes[index] ?? null;
226
214
  }
227
215
  /**
228
216
  * The set function assigns a value to a specific index in an array.
@@ -233,7 +221,7 @@ class ArrayDeque {
233
221
  * @returns The value that is being set at the specified index in the `_nodes` array.
234
222
  */
235
223
  set(index, value) {
236
- return (this._nodes[index] = value);
224
+ return (this.nodes[index] = value);
237
225
  }
238
226
  /**
239
227
  * The insert function adds a value at a specified index in an array.
@@ -246,7 +234,7 @@ class ArrayDeque {
246
234
  * are being removed, an empty array will be returned.
247
235
  */
248
236
  insert(index, value) {
249
- return this._nodes.splice(index, 0, value);
237
+ return this.nodes.splice(index, 0, value);
250
238
  }
251
239
  /**
252
240
  * The delete function removes an element from an array at a specified index.
@@ -255,7 +243,7 @@ class ArrayDeque {
255
243
  * @returns The method is returning an array containing the removed element.
256
244
  */
257
245
  delete(index) {
258
- return this._nodes.splice(index, 1);
246
+ return this.nodes.splice(index, 1);
259
247
  }
260
248
  /**
261
249
  * The function checks if an array called "_nodes" is empty.
@@ -263,7 +251,7 @@ class ArrayDeque {
263
251
  * is 0, indicating that the array is empty. Otherwise, it returns `false`.
264
252
  */
265
253
  isEmpty() {
266
- return this._nodes.length === 0;
254
+ return this.nodes.length === 0;
267
255
  }
268
256
  }
269
257
  exports.ArrayDeque = ArrayDeque;