data-structure-typed 1.49.0 → 1.49.2

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 (195) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +16 -16
  3. package/README_zh-CN.md +2 -2
  4. package/benchmark/report.html +46 -1
  5. package/benchmark/report.json +457 -22
  6. package/dist/cjs/data-structures/base/iterable-base.d.ts +11 -0
  7. package/dist/cjs/data-structures/base/iterable-base.js +21 -0
  8. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  9. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +10 -12
  10. package/dist/cjs/data-structures/binary-tree/avl-tree.js +3 -4
  11. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +58 -58
  13. package/dist/cjs/data-structures/binary-tree/binary-tree.js +6 -6
  14. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  15. package/dist/cjs/data-structures/binary-tree/bst.d.ts +15 -15
  16. package/dist/cjs/data-structures/binary-tree/bst.js +3 -3
  17. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  18. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +11 -11
  19. package/dist/cjs/data-structures/binary-tree/rb-tree.js +5 -6
  20. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  21. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +14 -14
  22. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +3 -3
  23. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  24. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +9 -3
  25. package/dist/cjs/data-structures/graph/abstract-graph.js +27 -31
  26. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  27. package/dist/cjs/data-structures/graph/directed-graph.d.ts +8 -1
  28. package/dist/cjs/data-structures/graph/directed-graph.js +1 -8
  29. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  30. package/dist/cjs/data-structures/graph/map-graph.d.ts +1 -1
  31. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +8 -1
  32. package/dist/cjs/data-structures/graph/undirected-graph.js +1 -8
  33. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  34. package/dist/cjs/data-structures/hash/hash-map.d.ts +22 -10
  35. package/dist/cjs/data-structures/hash/hash-map.js +28 -16
  36. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  37. package/dist/cjs/data-structures/hash/hash-table.d.ts +2 -2
  38. package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
  39. package/dist/cjs/data-structures/heap/heap.d.ts +20 -38
  40. package/dist/cjs/data-structures/heap/heap.js +22 -42
  41. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  42. package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -1
  43. package/dist/cjs/data-structures/heap/max-heap.js +10 -7
  44. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  45. package/dist/cjs/data-structures/heap/min-heap.d.ts +11 -1
  46. package/dist/cjs/data-structures/heap/min-heap.js +10 -7
  47. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  48. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +95 -95
  49. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +132 -136
  50. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  51. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +18 -23
  52. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +42 -49
  53. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  54. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  55. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +2 -2
  56. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  57. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
  58. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +0 -7
  59. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  60. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
  61. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +0 -7
  62. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  63. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +9 -1
  64. package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -7
  65. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  66. package/dist/cjs/data-structures/queue/deque.d.ts +76 -80
  67. package/dist/cjs/data-structures/queue/deque.js +106 -122
  68. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  69. package/dist/cjs/data-structures/queue/queue.d.ts +30 -16
  70. package/dist/cjs/data-structures/queue/queue.js +31 -24
  71. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  72. package/dist/cjs/data-structures/stack/stack.d.ts +17 -8
  73. package/dist/cjs/data-structures/stack/stack.js +9 -9
  74. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  75. package/dist/cjs/data-structures/trie/trie.d.ts +14 -5
  76. package/dist/cjs/data-structures/trie/trie.js +13 -13
  77. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  78. package/dist/cjs/interfaces/binary-tree.d.ts +4 -4
  79. package/dist/cjs/types/common.d.ts +32 -8
  80. package/dist/cjs/types/common.js +22 -1
  81. package/dist/cjs/types/common.js.map +1 -1
  82. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
  83. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -22
  84. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
  85. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
  86. package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  87. package/dist/mjs/data-structures/base/iterable-base.d.ts +11 -0
  88. package/dist/mjs/data-structures/base/iterable-base.js +21 -0
  89. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +10 -12
  90. package/dist/mjs/data-structures/binary-tree/avl-tree.js +3 -4
  91. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +58 -58
  92. package/dist/mjs/data-structures/binary-tree/binary-tree.js +6 -6
  93. package/dist/mjs/data-structures/binary-tree/bst.d.ts +15 -15
  94. package/dist/mjs/data-structures/binary-tree/bst.js +3 -3
  95. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +11 -11
  96. package/dist/mjs/data-structures/binary-tree/rb-tree.js +5 -6
  97. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +14 -14
  98. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +3 -3
  99. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +9 -3
  100. package/dist/mjs/data-structures/graph/abstract-graph.js +27 -31
  101. package/dist/mjs/data-structures/graph/directed-graph.d.ts +8 -1
  102. package/dist/mjs/data-structures/graph/directed-graph.js +1 -8
  103. package/dist/mjs/data-structures/graph/map-graph.d.ts +1 -1
  104. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +8 -1
  105. package/dist/mjs/data-structures/graph/undirected-graph.js +1 -8
  106. package/dist/mjs/data-structures/hash/hash-map.d.ts +22 -10
  107. package/dist/mjs/data-structures/hash/hash-map.js +27 -15
  108. package/dist/mjs/data-structures/hash/hash-table.d.ts +2 -2
  109. package/dist/mjs/data-structures/heap/heap.d.ts +20 -38
  110. package/dist/mjs/data-structures/heap/heap.js +23 -43
  111. package/dist/mjs/data-structures/heap/max-heap.d.ts +11 -1
  112. package/dist/mjs/data-structures/heap/max-heap.js +9 -6
  113. package/dist/mjs/data-structures/heap/min-heap.d.ts +11 -1
  114. package/dist/mjs/data-structures/heap/min-heap.js +9 -6
  115. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +95 -95
  116. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +132 -136
  117. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +18 -23
  118. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +43 -50
  119. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  120. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +2 -2
  121. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
  122. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +0 -7
  123. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
  124. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +0 -7
  125. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +9 -1
  126. package/dist/mjs/data-structures/priority-queue/priority-queue.js +7 -6
  127. package/dist/mjs/data-structures/queue/deque.d.ts +76 -80
  128. package/dist/mjs/data-structures/queue/deque.js +106 -122
  129. package/dist/mjs/data-structures/queue/queue.d.ts +30 -16
  130. package/dist/mjs/data-structures/queue/queue.js +31 -24
  131. package/dist/mjs/data-structures/stack/stack.d.ts +17 -8
  132. package/dist/mjs/data-structures/stack/stack.js +10 -10
  133. package/dist/mjs/data-structures/trie/trie.d.ts +14 -5
  134. package/dist/mjs/data-structures/trie/trie.js +14 -14
  135. package/dist/mjs/interfaces/binary-tree.d.ts +4 -4
  136. package/dist/mjs/types/common.d.ts +32 -8
  137. package/dist/mjs/types/common.js +21 -0
  138. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
  139. package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +1 -21
  140. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
  141. package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  142. package/dist/umd/data-structure-typed.js +533 -558
  143. package/dist/umd/data-structure-typed.min.js +2 -2
  144. package/dist/umd/data-structure-typed.min.js.map +1 -1
  145. package/package.json +1 -1
  146. package/src/data-structures/base/iterable-base.ts +24 -0
  147. package/src/data-structures/binary-tree/avl-tree.ts +14 -14
  148. package/src/data-structures/binary-tree/binary-tree.ts +74 -77
  149. package/src/data-structures/binary-tree/bst.ts +18 -17
  150. package/src/data-structures/binary-tree/rb-tree.ts +17 -18
  151. package/src/data-structures/binary-tree/tree-multimap.ts +22 -20
  152. package/src/data-structures/graph/abstract-graph.ts +35 -25
  153. package/src/data-structures/graph/directed-graph.ts +2 -2
  154. package/src/data-structures/graph/map-graph.ts +1 -1
  155. package/src/data-structures/graph/undirected-graph.ts +2 -2
  156. package/src/data-structures/hash/hash-map.ts +40 -24
  157. package/src/data-structures/hash/hash-table.ts +3 -3
  158. package/src/data-structures/heap/heap.ts +33 -60
  159. package/src/data-structures/heap/max-heap.ts +11 -2
  160. package/src/data-structures/heap/min-heap.ts +11 -2
  161. package/src/data-structures/linked-list/doubly-linked-list.ts +147 -145
  162. package/src/data-structures/linked-list/singly-linked-list.ts +52 -52
  163. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  164. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  165. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  166. package/src/data-structures/priority-queue/priority-queue.ts +9 -2
  167. package/src/data-structures/queue/deque.ts +129 -144
  168. package/src/data-structures/queue/queue.ts +37 -26
  169. package/src/data-structures/stack/stack.ts +20 -14
  170. package/src/data-structures/trie/trie.ts +18 -13
  171. package/src/interfaces/binary-tree.ts +5 -5
  172. package/src/types/common.ts +37 -12
  173. package/src/types/data-structures/binary-tree/avl-tree.ts +0 -1
  174. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -26
  175. package/src/types/data-structures/binary-tree/bst.ts +0 -1
  176. package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
  177. package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
  178. package/test/performance/data-structures/comparison/comparison.test.ts +6 -6
  179. package/test/performance/data-structures/heap/heap.test.ts +2 -2
  180. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +2 -2
  181. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +2 -2
  182. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +2 -2
  183. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +2 -2
  184. package/test/unit/data-structures/graph/directed-graph.test.ts +21 -1
  185. package/test/unit/data-structures/graph/undirected-graph.test.ts +39 -1
  186. package/test/unit/data-structures/hash/hash-map.test.ts +2 -2
  187. package/test/unit/data-structures/heap/heap.test.ts +1 -1
  188. package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
  189. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -30
  190. package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
  191. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +21 -21
  192. package/test/unit/data-structures/linked-list/skip-list.test.ts +2 -2
  193. package/test/unit/data-structures/queue/deque.test.ts +5 -5
  194. package/test/unit/data-structures/queue/queue.test.ts +4 -4
  195. package/test/unit/data-structures/trie/trie.test.ts +1 -1
@@ -3,9 +3,18 @@
3
3
  * @copyright Tyler Zeng <zrwusa@gmail.com>
4
4
  * @class
5
5
  */
6
- import { SinglyLinkedList } from '../linked-list';
6
+ import type { ElementCallback } from '../../types';
7
7
  import { IterableElementBase } from "../base";
8
- import { ElementCallback } from "../../types";
8
+ import { SinglyLinkedList } from '../linked-list';
9
+ /**
10
+ * 1. First In, First Out (FIFO): The core feature of a queue is its first in, first out nature. The element added to the queue first will be the one to be removed first.
11
+ * 2. Operations: The main operations include enqueue (adding an element to the end of the queue) and dequeue (removing and returning the element at the front of the queue). Typically, there is also a peek operation (looking at the front element without removing it).
12
+ * 3. Uses: Queues are commonly used to manage a series of tasks or elements that need to be processed in order. For example, managing task queues in a multi-threaded environment, or in algorithms for data structures like trees and graphs for breadth-first search.
13
+ * 4. Task Scheduling: Managing the order of task execution in operating systems or applications.
14
+ * 5. Data Buffering: Acting as a buffer for data packets in network communication.
15
+ * 6. Breadth-First Search (BFS): In traversal algorithms for graphs and trees, queues store nodes that are to be visited.
16
+ * 7. Real-time Queuing: Like queuing systems in banks or supermarkets.
17
+ */
9
18
  export declare class Queue<E = any> extends IterableElementBase<E> {
10
19
  /**
11
20
  * The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
@@ -44,7 +53,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
44
53
  * @param {E} element - The `element` parameter represents the element that you want to add to the queue.
45
54
  * @returns The `add` method is returning a `Queue<E>` object.
46
55
  */
47
- push(element: E): Queue<E>;
56
+ push(element: E): boolean;
48
57
  /**
49
58
  * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
50
59
  * Space Complexity: O(1) - no additional space is used.
@@ -66,11 +75,11 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
66
75
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
67
76
  * Space Complexity: O(1) - no additional space is used.
68
77
  *
69
- * The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
70
- * @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
78
+ * The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
79
+ * @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
71
80
  * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
72
81
  */
73
- getFirst(): E | undefined;
82
+ get first(): E | undefined;
74
83
  /**
75
84
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
76
85
  * Space Complexity: O(1) - no additional space is used.
@@ -92,11 +101,11 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
92
101
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
93
102
  * Space Complexity: O(1) - no additional space is used.
94
103
  *
95
- * The `getLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
96
- * @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
104
+ * The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
105
+ * @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
97
106
  * array is empty, it returns `undefined`.
98
107
  */
99
- getLast(): E | undefined;
108
+ get last(): E | undefined;
100
109
  /**
101
110
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
102
111
  * Space Complexity: O(1) - no additional space is used.
@@ -121,7 +130,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
121
130
  * The enqueue function adds a value to the end of a queue.
122
131
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
123
132
  */
124
- enqueue(value: E): void;
133
+ enqueue(value: E): boolean;
125
134
  /**
126
135
  * Time Complexity: O(n) - same as shift().
127
136
  * Space Complexity: O(1) - same as shift().
@@ -185,7 +194,6 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
185
194
  * @returns The `clone()` method is returning a new instance of the `Queue` class.
186
195
  */
187
196
  clone(): Queue<E>;
188
- print(): void;
189
197
  /**
190
198
  * Time Complexity: O(n)
191
199
  * Space Complexity: O(n)
@@ -230,24 +238,30 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
230
238
  * Time Complexity: O(n)
231
239
  * Space Complexity: O(n)
232
240
  */
233
- protected _getIterator(): Generator<E, void, unknown>;
241
+ protected _getIterator(): IterableIterator<E>;
234
242
  }
243
+ /**
244
+ * 1. First In, First Out (FIFO) Strategy: Like other queue implementations, LinkedListQueue follows the first in, first out principle, meaning the element that is added to the queue first will be the first to be removed.
245
+ * 2. Based on Linked List: LinkedListQueue uses a linked list to store elements. Each node in the linked list contains data and a pointer to the next node.
246
+ * 3. Memory Usage: Since each element requires additional space to store a pointer to the next element, linked lists may use more memory compared to arrays.
247
+ * 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
248
+ */
235
249
  export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
236
250
  /**
237
251
  * The enqueue function adds a value to the end of an array.
238
252
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
239
253
  */
240
- enqueue(value: E): void;
254
+ enqueue(value: E): boolean;
241
255
  /**
242
256
  * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
243
257
  * @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
244
258
  */
245
259
  dequeue(): E | undefined;
246
260
  /**
247
- * The `getFirst` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
248
- * @returns The `getFirst()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
261
+ * The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
262
+ * @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
249
263
  */
250
- getFirst(): E | undefined;
264
+ get first(): E | undefined;
251
265
  /**
252
266
  * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
253
267
  * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
@@ -1,13 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LinkedListQueue = exports.Queue = void 0;
4
+ const base_1 = require("../base");
5
+ const linked_list_1 = require("../linked-list");
4
6
  /**
5
- * @license MIT
6
- * @copyright Tyler Zeng <zrwusa@gmail.com>
7
- * @class
7
+ * 1. First In, First Out (FIFO): The core feature of a queue is its first in, first out nature. The element added to the queue first will be the one to be removed first.
8
+ * 2. Operations: The main operations include enqueue (adding an element to the end of the queue) and dequeue (removing and returning the element at the front of the queue). Typically, there is also a peek operation (looking at the front element without removing it).
9
+ * 3. Uses: Queues are commonly used to manage a series of tasks or elements that need to be processed in order. For example, managing task queues in a multi-threaded environment, or in algorithms for data structures like trees and graphs for breadth-first search.
10
+ * 4. Task Scheduling: Managing the order of task execution in operating systems or applications.
11
+ * 5. Data Buffering: Acting as a buffer for data packets in network communication.
12
+ * 6. Breadth-First Search (BFS): In traversal algorithms for graphs and trees, queues store nodes that are to be visited.
13
+ * 7. Real-time Queuing: Like queuing systems in banks or supermarkets.
8
14
  */
9
- const linked_list_1 = require("../linked-list");
10
- const base_1 = require("../base");
11
15
  class Queue extends base_1.IterableElementBase {
12
16
  /**
13
17
  * The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
@@ -58,7 +62,7 @@ class Queue extends base_1.IterableElementBase {
58
62
  */
59
63
  push(element) {
60
64
  this.nodes.push(element);
61
- return this;
65
+ return true;
62
66
  }
63
67
  /**
64
68
  * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
@@ -75,7 +79,7 @@ class Queue extends base_1.IterableElementBase {
75
79
  shift() {
76
80
  if (this.size === 0)
77
81
  return undefined;
78
- const first = this.getFirst();
82
+ const first = this.first;
79
83
  this._offset += 1;
80
84
  if (this.offset * 2 < this.nodes.length)
81
85
  return first;
@@ -93,11 +97,11 @@ class Queue extends base_1.IterableElementBase {
93
97
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
94
98
  * Space Complexity: O(1) - no additional space is used.
95
99
  *
96
- * The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
97
- * @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
100
+ * The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
101
+ * @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
98
102
  * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
99
103
  */
100
- getFirst() {
104
+ get first() {
101
105
  return this.size > 0 ? this.nodes[this.offset] : undefined;
102
106
  }
103
107
  /**
@@ -113,7 +117,7 @@ class Queue extends base_1.IterableElementBase {
113
117
  * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
114
118
  */
115
119
  peek() {
116
- return this.getFirst();
120
+ return this.first;
117
121
  }
118
122
  /**
119
123
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
@@ -123,11 +127,11 @@ class Queue extends base_1.IterableElementBase {
123
127
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
124
128
  * Space Complexity: O(1) - no additional space is used.
125
129
  *
126
- * The `getLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
127
- * @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
130
+ * The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
131
+ * @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
128
132
  * array is empty, it returns `undefined`.
129
133
  */
130
- getLast() {
134
+ get last() {
131
135
  return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
132
136
  }
133
137
  /**
@@ -143,7 +147,7 @@ class Queue extends base_1.IterableElementBase {
143
147
  * array is empty, it returns `undefined`.
144
148
  */
145
149
  peekLast() {
146
- return this.getLast();
150
+ return this.last;
147
151
  }
148
152
  /**
149
153
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
@@ -157,7 +161,7 @@ class Queue extends base_1.IterableElementBase {
157
161
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
158
162
  */
159
163
  enqueue(value) {
160
- this.push(value);
164
+ return this.push(value);
161
165
  }
162
166
  /**
163
167
  * Time Complexity: O(n) - same as shift().
@@ -235,9 +239,6 @@ class Queue extends base_1.IterableElementBase {
235
239
  clone() {
236
240
  return new Queue(this.nodes.slice(this.offset));
237
241
  }
238
- print() {
239
- console.log([...this]);
240
- }
241
242
  /**
242
243
  * Time Complexity: O(n)
243
244
  * Space Complexity: O(n)
@@ -307,13 +308,19 @@ class Queue extends base_1.IterableElementBase {
307
308
  }
308
309
  }
309
310
  exports.Queue = Queue;
311
+ /**
312
+ * 1. First In, First Out (FIFO) Strategy: Like other queue implementations, LinkedListQueue follows the first in, first out principle, meaning the element that is added to the queue first will be the first to be removed.
313
+ * 2. Based on Linked List: LinkedListQueue uses a linked list to store elements. Each node in the linked list contains data and a pointer to the next node.
314
+ * 3. Memory Usage: Since each element requires additional space to store a pointer to the next element, linked lists may use more memory compared to arrays.
315
+ * 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
316
+ */
310
317
  class LinkedListQueue extends linked_list_1.SinglyLinkedList {
311
318
  /**
312
319
  * The enqueue function adds a value to the end of an array.
313
320
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
314
321
  */
315
322
  enqueue(value) {
316
- this.push(value);
323
+ return this.push(value);
317
324
  }
318
325
  /**
319
326
  * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
@@ -323,10 +330,10 @@ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
323
330
  return this.shift();
324
331
  }
325
332
  /**
326
- * The `getFirst` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
327
- * @returns The `getFirst()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
333
+ * The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
334
+ * @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
328
335
  */
329
- getFirst() {
336
+ get first() {
330
337
  var _a;
331
338
  return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
332
339
  }
@@ -335,7 +342,7 @@ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
335
342
  * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
336
343
  */
337
344
  peek() {
338
- return this.getFirst();
345
+ return this.first;
339
346
  }
340
347
  }
341
348
  exports.LinkedListQueue = LinkedListQueue;
@@ -1 +1 @@
1
- {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../src/data-structures/queue/queue.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,gDAAkD;AAClD,kCAA8C;AAG9C,MAAa,KAAe,SAAQ,0BAAsB;IACxD;;;;;OAKG;IACH,YAAY,QAAc;QACxB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,QAAQ,IAAI,EAAE,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,C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KAAK,CAAC,CAAC;IACnB,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,QAAQ;;QACN,OAAO,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;CACF;AAhCD,0CAgCC"}
1
+ {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../src/data-structures/queue/queue.ts"],"names":[],"mappings":";;;AAMA,kCAA8C;AAC9C,gDAAkD;AAElD;;;;;;;;GAQG;AACH,MAAa,KAAe,SAAQ,0BAAsB;IACxD;;;;;OAKG;IACH,YAAY,QAAc;QACxB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,QAAQ,IAAI,EAAE,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;IACnB,CAAC;IAID,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAID,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACzC,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,SAAS,CAAI,QAAa;QAC/B,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;IAED;;;OAGG;IAEH;;;;;;;OAOG;IACH,IAAI,CAAC,OAAU;QACb,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IAEH;;;;;;;OAOG;IACH,KAAK;QACH,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC;YAAE,OAA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AK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;YACtB,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YACvD,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;OAGG;IAEM,CAAE,YAAY;QACrB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC;QACb,CAAC;IACH,CAAC;CACF;AA7UD,sBA6UC;AAED;;;;;GAKG;AACH,MAAa,eAAyB,SAAQ,8BAAmB;IAC/D;;;OAGG;IACH,OAAO,CAAC,KAAQ;QACd,OAAQ,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,IAAI,KAAK;;QACP,OAAO,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF;AAhCD,0CAgCC"}
@@ -1,9 +1,19 @@
1
- import { IterableElementBase } from "../base";
2
- import { ElementCallback } from "../../types";
3
1
  /**
4
- * @license MIT
5
- * @copyright Tyler Zeng <zrwusa@gmail.com>
6
- * @class
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { ElementCallback } from '../../types';
9
+ import { IterableElementBase } from '../base';
10
+ /**
11
+ * 1. Last In, First Out (LIFO): The core characteristic of a stack is its last in, first out nature, meaning the last element added to the stack will be the first to be removed.
12
+ * 2. Uses: Stacks are commonly used for managing a series of tasks or elements that need to be processed in a last in, first out manner. They are widely used in various scenarios, such as in function calls in programming languages, evaluation of arithmetic expressions, and backtracking algorithms.
13
+ * 3. Performance: Stack operations are typically O(1) in time complexity, meaning that regardless of the stack's size, adding, removing, and viewing the top element are very fast operations.
14
+ * 4. Function Calls: In most modern programming languages, the records of function calls are managed through a stack. When a function is called, its record (including parameters, local variables, and return address) is 'pushed' into the stack. When the function returns, its record is 'popped' from the stack.
15
+ * 5. Expression Evaluation: Used for the evaluation of arithmetic or logical expressions, especially when dealing with parenthesis matching and operator precedence.
16
+ * 6. Backtracking Algorithms: In problems where multiple branches need to be explored but only one branch can be explored at a time, stacks can be used to save the state at each branching point.
7
17
  */
8
18
  export declare class Stack<E = any> extends IterableElementBase<E> {
9
19
  /**
@@ -63,7 +73,7 @@ export declare class Stack<E = any> extends IterableElementBase<E> {
63
73
  * @param {E} element - The parameter "element" is of type E, which means it can be any data type.
64
74
  * @returns The `push` method is returning the updated `Stack<E>` object.
65
75
  */
66
- push(element: E): Stack<E>;
76
+ push(element: E): boolean;
67
77
  /**
68
78
  * Time Complexity: O(1), as it only involves accessing the last element of the array.
69
79
  * Space Complexity: O(1), as it does not use any additional space.
@@ -144,10 +154,9 @@ export declare class Stack<E = any> extends IterableElementBase<E> {
144
154
  * @returns The `map` method is returning a new `Stack` object.
145
155
  */
146
156
  map<T>(callback: ElementCallback<E, T>, thisArg?: any): Stack<T>;
147
- print(): void;
148
157
  /**
149
158
  * Custom iterator for the Stack class.
150
159
  * @returns An iterator object.
151
160
  */
152
- protected _getIterator(): Generator<E, void, unknown>;
161
+ protected _getIterator(): IterableIterator<E>;
153
162
  }
@@ -3,9 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Stack = void 0;
4
4
  const base_1 = require("../base");
5
5
  /**
6
- * @license MIT
7
- * @copyright Tyler Zeng <zrwusa@gmail.com>
8
- * @class
6
+ * 1. Last In, First Out (LIFO): The core characteristic of a stack is its last in, first out nature, meaning the last element added to the stack will be the first to be removed.
7
+ * 2. Uses: Stacks are commonly used for managing a series of tasks or elements that need to be processed in a last in, first out manner. They are widely used in various scenarios, such as in function calls in programming languages, evaluation of arithmetic expressions, and backtracking algorithms.
8
+ * 3. Performance: Stack operations are typically O(1) in time complexity, meaning that regardless of the stack's size, adding, removing, and viewing the top element are very fast operations.
9
+ * 4. Function Calls: In most modern programming languages, the records of function calls are managed through a stack. When a function is called, its record (including parameters, local variables, and return address) is 'pushed' into the stack. When the function returns, its record is 'popped' from the stack.
10
+ * 5. Expression Evaluation: Used for the evaluation of arithmetic or logical expressions, especially when dealing with parenthesis matching and operator precedence.
11
+ * 6. Backtracking Algorithms: In problems where multiple branches need to be explored but only one branch can be explored at a time, stacks can be used to save the state at each branching point.
9
12
  */
10
13
  class Stack extends base_1.IterableElementBase {
11
14
  /**
@@ -86,7 +89,7 @@ class Stack extends base_1.IterableElementBase {
86
89
  */
87
90
  push(element) {
88
91
  this.elements.push(element);
89
- return this;
92
+ return true;
90
93
  }
91
94
  /**
92
95
  * Time Complexity: O(1), as it only involves accessing the last element of the array.
@@ -102,8 +105,8 @@ class Stack extends base_1.IterableElementBase {
102
105
  */
103
106
  pop() {
104
107
  if (this.isEmpty())
105
- return undefined;
106
- return this.elements.pop() || undefined;
108
+ return;
109
+ return this.elements.pop();
107
110
  }
108
111
  /**
109
112
  * Time Complexity: O(n)
@@ -196,9 +199,6 @@ class Stack extends base_1.IterableElementBase {
196
199
  }
197
200
  return newStack;
198
201
  }
199
- print() {
200
- console.log([...this]);
201
- }
202
202
  /**
203
203
  * Custom iterator for the Stack class.
204
204
  * @returns An iterator object.
@@ -1 +1 @@
1
- {"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../../src/data-structures/stack/stack.ts"],"names":[],"mappings":";;;AAAA,kCAA8C;AAG9C;;;;GAIG;AACH,MAAa,KAAe,SAAQ,0BAAsB;IACxD;;;;;OAKG;IACH,YAAY,QAAsB;QAChC,KAAK,EA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,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YACvD,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;OAGG;IACM,CAAE,YAAY;QACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9C,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;CACF;AA7ND,sBA6NC"}
@@ -5,8 +5,8 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { IterableElementBase } from "../base";
9
- import { ElementCallback } from "../../types";
8
+ import type { ElementCallback } from '../../types';
9
+ import { IterableElementBase } from '../base';
10
10
  /**
11
11
  * TrieNode represents a node in the Trie data structure. It holds a character key, a map of children nodes,
12
12
  * and a flag indicating whether it's the end of a word.
@@ -18,7 +18,17 @@ export declare class TrieNode {
18
18
  constructor(key: string);
19
19
  }
20
20
  /**
21
- * Trie represents a Trie data structure. It provides basic Trie operations and additional methods.
21
+ * 1. Node Structure: Each node in a Trie represents a string (or a part of a string). The root node typically represents an empty string.
22
+ * 2. Child Node Relationship: Each node's children represent the strings that can be formed by adding one character to the string at the current node. For example, if a node represents the string 'ca', one of its children might represent 'cat'.
23
+ * 3. Fast Retrieval: Trie allows retrieval in O(m) time complexity, where m is the length of the string to be searched.
24
+ * 4. Space Efficiency: Trie can store a large number of strings very space-efficiently, especially when these strings share common prefixes.
25
+ * 5. Autocomplete and Prediction: Trie can be used for implementing autocomplete and word prediction features, as it can quickly find all strings with a common prefix.
26
+ * 6. Sorting: Trie can be used to sort a set of strings in alphabetical order.
27
+ * 7. String Retrieval: For example, searching for a specific string in a large set of strings.
28
+ * 8. Autocomplete: Providing recommended words or phrases as a user types.
29
+ * 9. Spell Check: Checking the spelling of words.
30
+ * 10. IP Routing: Used in certain types of IP routing algorithms.
31
+ * 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
22
32
  */
23
33
  export declare class Trie extends IterableElementBase<string> {
24
34
  constructor(words?: string[], caseSensitive?: boolean);
@@ -162,7 +172,7 @@ export declare class Trie extends IterableElementBase<string> {
162
172
  * specific object as the context for the `predicate` function. If `thisArg` is provided, it will be
163
173
  * @returns The `filter` method is returning an array of strings (`string[]`).
164
174
  */
165
- filter(predicate: ElementCallback<string, boolean>, thisArg?: any): string[];
175
+ filter(predicate: ElementCallback<string, boolean>, thisArg?: any): Trie;
166
176
  /**
167
177
  * Time Complexity: O(n)
168
178
  * Space Complexity: O(n)
@@ -181,7 +191,6 @@ export declare class Trie extends IterableElementBase<string> {
181
191
  * @returns The `map` function is returning a new Trie object.
182
192
  */
183
193
  map(callback: ElementCallback<string, string>, thisArg?: any): Trie;
184
- print(): void;
185
194
  protected _getIterator(): IterableIterator<string>;
186
195
  /**
187
196
  * Time Complexity: O(M), where M is the length of the input string.
@@ -1,11 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * data-structure-typed
4
- *
5
- * @author Tyler Zeng
6
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
7
- * @license MIT License
8
- */
9
2
  Object.defineProperty(exports, "__esModule", { value: true });
10
3
  exports.Trie = exports.TrieNode = void 0;
11
4
  const base_1 = require("../base");
@@ -22,7 +15,17 @@ class TrieNode {
22
15
  }
23
16
  exports.TrieNode = TrieNode;
24
17
  /**
25
- * Trie represents a Trie data structure. It provides basic Trie operations and additional methods.
18
+ * 1. Node Structure: Each node in a Trie represents a string (or a part of a string). The root node typically represents an empty string.
19
+ * 2. Child Node Relationship: Each node's children represent the strings that can be formed by adding one character to the string at the current node. For example, if a node represents the string 'ca', one of its children might represent 'cat'.
20
+ * 3. Fast Retrieval: Trie allows retrieval in O(m) time complexity, where m is the length of the string to be searched.
21
+ * 4. Space Efficiency: Trie can store a large number of strings very space-efficiently, especially when these strings share common prefixes.
22
+ * 5. Autocomplete and Prediction: Trie can be used for implementing autocomplete and word prediction features, as it can quickly find all strings with a common prefix.
23
+ * 6. Sorting: Trie can be used to sort a set of strings in alphabetical order.
24
+ * 7. String Retrieval: For example, searching for a specific string in a large set of strings.
25
+ * 8. Autocomplete: Providing recommended words or phrases as a user types.
26
+ * 9. Spell Check: Checking the spelling of words.
27
+ * 10. IP Routing: Used in certain types of IP routing algorithms.
28
+ * 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
26
29
  */
27
30
  class Trie extends base_1.IterableElementBase {
28
31
  constructor(words, caseSensitive = true) {
@@ -338,11 +341,11 @@ class Trie extends base_1.IterableElementBase {
338
341
  * @returns The `filter` method is returning an array of strings (`string[]`).
339
342
  */
340
343
  filter(predicate, thisArg) {
341
- const results = [];
344
+ const results = new Trie();
342
345
  let index = 0;
343
346
  for (const word of this) {
344
347
  if (predicate.call(thisArg, word, index, this)) {
345
- results.push(word);
348
+ results.add(word);
346
349
  }
347
350
  index++;
348
351
  }
@@ -374,9 +377,6 @@ class Trie extends base_1.IterableElementBase {
374
377
  }
375
378
  return newTrie;
376
379
  }
377
- print() {
378
- console.log([...this]);
379
- }
380
380
  *_getIterator() {
381
381
  function* _dfs(node, path) {
382
382
  if (node.isEnd) {
@@ -1 +1 @@
1
- {"version":3,"file":"trie.js","sourceRoot":"","sources":["../../../../src/data-structures/trie/trie.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,kCAA8C;AAG9C;;;GAGG;AACH,MAAa,QAAQ;IAKnB,YAAY,GAAW;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC9C,CAAC;CACF;AAVD,4BAUC;AAED;;GAE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,CAAC;QAED,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED;;;OAGG;IAEH;;;;;;OAMG;IACO,YAAY,CAAC,GAAW;QAChC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,+CAA+C;QAC1E,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AArZD,oBAqZC"}
@@ -1,9 +1,9 @@
1
1
  import { BinaryTree, BinaryTreeNode } from '../data-structures';
2
- import { BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BiTreeDeleteResult, BTNCallback, BTNodeExemplar } from '../types';
2
+ import { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNExemplar } from '../types';
3
3
  export interface IBinaryTree<K = number, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNodeNested<K, V>, TREE extends BinaryTree<K, V, N, TREE> = BinaryTreeNested<K, V, N>> {
4
4
  createNode(key: K, value?: N['value']): N;
5
5
  createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
6
- add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V, count?: number): N | null | undefined;
7
- addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[];
8
- delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BiTreeDeleteResult<N>[];
6
+ add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V, count?: number): N | null | undefined;
7
+ addMany(nodes: Iterable<BTNExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[];
8
+ delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeleteResult<N>[];
9
9
  }
@@ -1,15 +1,35 @@
1
- export type Comparator<K> = (a: K, b: K) => number;
2
1
  export declare enum BSTVariant {
3
2
  MIN = "MIN",
4
3
  MAX = "MAX"
5
4
  }
6
- export type DFSOrderPattern = 'pre' | 'in' | 'post';
7
- export type BTNCallback<N, D = any> = (node: N) => D;
8
5
  export declare enum CP {
9
6
  lt = "lt",
10
7
  eq = "eq",
11
8
  gt = "gt"
12
9
  }
10
+ /**
11
+ * Enum representing different loop types.
12
+ *
13
+ * - `iterative`: Indicates the iterative loop type (with loops that use iterations).
14
+ * - `recursive`: Indicates the recursive loop type (with loops that call themselves).
15
+ */
16
+ export declare enum IterationType {
17
+ ITERATIVE = "ITERATIVE",
18
+ RECURSIVE = "RECURSIVE"
19
+ }
20
+ export declare enum FamilyPosition {
21
+ ROOT = "ROOT",
22
+ LEFT = "LEFT",
23
+ RIGHT = "RIGHT",
24
+ ROOT_LEFT = "ROOT_LEFT",
25
+ ROOT_RIGHT = "ROOT_RIGHT",
26
+ ISOLATED = "ISOLATED",
27
+ MAL_NODE = "MAL_NODE"
28
+ }
29
+ export type Comparator<K> = (a: K, b: K) => number;
30
+ export type DFSOrderPattern = 'pre' | 'in' | 'post';
31
+ export type NodeDisplayLayout = [string[], number, number, number];
32
+ export type BTNCallback<N, D = any> = (node: N) => D;
13
33
  export interface IterableWithSize<T> extends Iterable<T> {
14
34
  size: number | ((...args: any[]) => number);
15
35
  }
@@ -22,9 +42,13 @@ export type BinaryTreePrintOptions = {
22
42
  isShowNull?: boolean;
23
43
  isShowRedBlackNIL?: boolean;
24
44
  };
25
- export type BTNodeEntry<K, V> = [K | null | undefined, V | undefined];
26
- export type BTNodeKeyOrNode<K, N> = K | null | undefined | N;
27
- export type BTNodeExemplar<K, V, N> = BTNodeEntry<K, V> | BTNodeKeyOrNode<K, N>;
28
- export type BTNodePureExemplar<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>;
45
+ export type BTNEntry<K, V> = [K | null | undefined, V | undefined];
46
+ export type BTNKeyOrNode<K, N> = K | null | undefined | N;
47
+ export type BTNExemplar<K, V, N> = BTNEntry<K, V> | BTNKeyOrNode<K, N>;
29
48
  export type BTNodePureKeyOrNode<K, N> = K | N;
30
- export type BSTNodeKeyOrNode<K, N> = K | undefined | N;
49
+ export type BTNodePureExemplar<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>;
50
+ export type BSTNKeyOrNode<K, N> = K | undefined | N;
51
+ export type BinaryTreeDeleteResult<N> = {
52
+ deleted: N | null | undefined;
53
+ needBalanced: N | null | undefined;
54
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CP = exports.BSTVariant = void 0;
3
+ exports.FamilyPosition = exports.IterationType = exports.CP = exports.BSTVariant = void 0;
4
4
  var BSTVariant;
5
5
  (function (BSTVariant) {
6
6
  BSTVariant["MIN"] = "MIN";
@@ -12,4 +12,25 @@ var CP;
12
12
  CP["eq"] = "eq";
13
13
  CP["gt"] = "gt";
14
14
  })(CP || (exports.CP = CP = {}));
15
+ /**
16
+ * Enum representing different loop types.
17
+ *
18
+ * - `iterative`: Indicates the iterative loop type (with loops that use iterations).
19
+ * - `recursive`: Indicates the recursive loop type (with loops that call themselves).
20
+ */
21
+ var IterationType;
22
+ (function (IterationType) {
23
+ IterationType["ITERATIVE"] = "ITERATIVE";
24
+ IterationType["RECURSIVE"] = "RECURSIVE";
25
+ })(IterationType || (exports.IterationType = IterationType = {}));
26
+ var FamilyPosition;
27
+ (function (FamilyPosition) {
28
+ FamilyPosition["ROOT"] = "ROOT";
29
+ FamilyPosition["LEFT"] = "LEFT";
30
+ FamilyPosition["RIGHT"] = "RIGHT";
31
+ FamilyPosition["ROOT_LEFT"] = "ROOT_LEFT";
32
+ FamilyPosition["ROOT_RIGHT"] = "ROOT_RIGHT";
33
+ FamilyPosition["ISOLATED"] = "ISOLATED";
34
+ FamilyPosition["MAL_NODE"] = "MAL_NODE";
35
+ })(FamilyPosition || (exports.FamilyPosition = FamilyPosition = {}));
15
36
  //# sourceMappingURL=common.js.map