data-structure-typed 0.8.18 → 1.3.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 (272) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +690 -2
  3. package/dist/bundle.js +2 -0
  4. package/dist/bundle.js.LICENSE.txt +13 -0
  5. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +364 -0
  6. package/dist/data-structures/binary-tree/abstract-binary-tree.js +1308 -0
  7. package/dist/data-structures/binary-tree/avl-tree.d.ts +85 -18
  8. package/dist/data-structures/binary-tree/avl-tree.js +110 -37
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +40 -2
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.js +44 -2
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +29 -138
  12. package/dist/data-structures/binary-tree/binary-tree.js +27 -979
  13. package/dist/data-structures/binary-tree/bst.d.ts +118 -28
  14. package/dist/data-structures/binary-tree/bst.js +162 -124
  15. package/dist/data-structures/binary-tree/index.d.ts +1 -0
  16. package/dist/data-structures/binary-tree/index.js +1 -0
  17. package/dist/data-structures/binary-tree/rb-tree.d.ts +18 -1
  18. package/dist/data-structures/binary-tree/rb-tree.js +40 -2
  19. package/dist/data-structures/binary-tree/segment-tree.d.ts +63 -13
  20. package/dist/data-structures/binary-tree/segment-tree.js +80 -17
  21. package/dist/data-structures/binary-tree/tree-multiset.d.ts +213 -10
  22. package/dist/data-structures/binary-tree/tree-multiset.js +682 -9
  23. package/dist/data-structures/graph/abstract-graph.d.ts +270 -64
  24. package/dist/data-structures/graph/abstract-graph.js +365 -92
  25. package/dist/data-structures/graph/directed-graph.d.ts +175 -26
  26. package/dist/data-structures/graph/directed-graph.js +249 -95
  27. package/dist/data-structures/graph/index.d.ts +1 -0
  28. package/dist/data-structures/graph/index.js +1 -0
  29. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  30. package/dist/data-structures/graph/map-graph.js +111 -0
  31. package/dist/data-structures/graph/undirected-graph.d.ts +111 -8
  32. package/dist/data-structures/graph/undirected-graph.js +154 -44
  33. package/dist/data-structures/hash/coordinate-map.d.ts +39 -2
  34. package/dist/data-structures/hash/coordinate-map.js +44 -3
  35. package/dist/data-structures/hash/coordinate-set.d.ts +32 -2
  36. package/dist/data-structures/hash/coordinate-set.js +34 -0
  37. package/dist/data-structures/hash/hash-table.d.ts +2 -1
  38. package/dist/data-structures/hash/hash-table.js +4 -0
  39. package/dist/data-structures/hash/index.d.ts +5 -0
  40. package/dist/data-structures/hash/index.js +5 -0
  41. package/dist/data-structures/hash/pair.d.ts +2 -1
  42. package/dist/data-structures/hash/pair.js +4 -0
  43. package/dist/data-structures/hash/tree-map.d.ts +2 -1
  44. package/dist/data-structures/hash/tree-map.js +4 -0
  45. package/dist/data-structures/hash/tree-set.d.ts +2 -1
  46. package/dist/data-structures/hash/tree-set.js +4 -0
  47. package/dist/data-structures/heap/heap.d.ts +62 -51
  48. package/dist/data-structures/heap/heap.js +106 -63
  49. package/dist/data-structures/heap/max-heap.d.ts +13 -4
  50. package/dist/data-structures/heap/max-heap.js +10 -2
  51. package/dist/data-structures/heap/min-heap.d.ts +14 -4
  52. package/dist/data-structures/heap/min-heap.js +11 -2
  53. package/dist/data-structures/index.d.ts +1 -0
  54. package/dist/data-structures/index.js +1 -0
  55. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +193 -57
  56. package/dist/data-structures/linked-list/doubly-linked-list.js +461 -194
  57. package/dist/data-structures/linked-list/index.d.ts +1 -0
  58. package/dist/data-structures/linked-list/index.js +1 -0
  59. package/dist/data-structures/linked-list/singly-linked-list.d.ts +117 -319
  60. package/dist/data-structures/linked-list/singly-linked-list.js +338 -557
  61. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -1
  62. package/dist/data-structures/linked-list/skip-linked-list.js +4 -0
  63. package/dist/data-structures/matrix/matrix.d.ts +12 -0
  64. package/dist/data-structures/matrix/matrix.js +14 -0
  65. package/dist/data-structures/matrix/matrix2d.d.ts +87 -4
  66. package/dist/data-structures/matrix/matrix2d.js +91 -8
  67. package/dist/data-structures/matrix/navigator.d.ts +37 -16
  68. package/dist/data-structures/matrix/navigator.js +28 -0
  69. package/dist/data-structures/matrix/vector2d.d.ts +156 -29
  70. package/dist/data-structures/matrix/vector2d.js +184 -55
  71. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -1
  72. package/dist/data-structures/priority-queue/max-priority-queue.js +28 -4
  73. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -1
  74. package/dist/data-structures/priority-queue/min-priority-queue.js +29 -4
  75. package/dist/data-structures/priority-queue/priority-queue.d.ts +166 -22
  76. package/dist/data-structures/priority-queue/priority-queue.js +219 -75
  77. package/dist/data-structures/queue/deque.d.ts +141 -13
  78. package/dist/data-structures/queue/deque.js +151 -7
  79. package/dist/data-structures/queue/queue.d.ts +68 -42
  80. package/dist/data-structures/queue/queue.js +95 -51
  81. package/dist/data-structures/stack/stack.d.ts +30 -36
  82. package/dist/data-structures/stack/stack.js +31 -37
  83. package/dist/data-structures/tree/index.d.ts +1 -0
  84. package/dist/data-structures/tree/index.js +17 -0
  85. package/dist/data-structures/tree/tree.d.ts +14 -0
  86. package/dist/{types/utils.js → data-structures/tree/tree.js} +26 -19
  87. package/dist/data-structures/trie/trie.d.ts +39 -6
  88. package/dist/data-structures/trie/trie.js +81 -12
  89. package/dist/index.d.ts +3 -0
  90. package/dist/index.js +3 -0
  91. package/dist/interfaces/abstract-binary-tree.d.ts +90 -0
  92. package/dist/interfaces/abstract-binary-tree.js +2 -0
  93. package/dist/interfaces/abstract-graph.d.ts +17 -0
  94. package/dist/interfaces/abstract-graph.js +2 -0
  95. package/dist/interfaces/avl-tree.d.ts +9 -0
  96. package/dist/interfaces/avl-tree.js +2 -0
  97. package/dist/interfaces/binary-tree.d.ts +6 -0
  98. package/dist/interfaces/binary-tree.js +2 -0
  99. package/dist/interfaces/bst.d.ts +17 -0
  100. package/dist/interfaces/bst.js +2 -0
  101. package/dist/interfaces/directed-graph.d.ts +12 -0
  102. package/dist/interfaces/directed-graph.js +2 -0
  103. package/dist/interfaces/doubly-linked-list.js +2 -0
  104. package/dist/interfaces/heap.js +2 -0
  105. package/dist/interfaces/index.d.ts +15 -0
  106. package/dist/interfaces/index.js +31 -0
  107. package/dist/interfaces/navigator.js +2 -0
  108. package/dist/interfaces/priority-queue.js +2 -0
  109. package/dist/interfaces/rb-tree.d.ts +8 -0
  110. package/dist/interfaces/rb-tree.js +2 -0
  111. package/dist/interfaces/segment-tree.js +2 -0
  112. package/dist/interfaces/singly-linked-list.js +2 -0
  113. package/dist/interfaces/tree-multiset.d.ts +7 -0
  114. package/dist/interfaces/tree-multiset.js +2 -0
  115. package/dist/interfaces/undirected-graph.d.ts +5 -0
  116. package/dist/interfaces/undirected-graph.js +2 -0
  117. package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
  118. package/dist/types/data-structures/abstract-binary-tree.js +25 -0
  119. package/dist/types/data-structures/abstract-graph.d.ts +11 -0
  120. package/dist/types/data-structures/abstract-graph.js +2 -0
  121. package/dist/types/data-structures/avl-tree.d.ts +4 -0
  122. package/dist/types/data-structures/avl-tree.js +2 -0
  123. package/dist/types/data-structures/binary-tree.d.ts +4 -0
  124. package/dist/types/data-structures/binary-tree.js +2 -0
  125. package/dist/types/data-structures/bst.d.ts +13 -0
  126. package/dist/types/data-structures/bst.js +9 -0
  127. package/dist/types/data-structures/directed-graph.d.ts +6 -0
  128. package/dist/types/data-structures/directed-graph.js +9 -0
  129. package/dist/types/data-structures/doubly-linked-list.js +2 -0
  130. package/dist/types/data-structures/heap.d.ts +3 -0
  131. package/dist/types/data-structures/heap.js +2 -0
  132. package/dist/types/data-structures/index.d.ts +13 -7
  133. package/dist/types/data-structures/index.js +31 -0
  134. package/dist/types/data-structures/map-graph.d.ts +1 -0
  135. package/dist/types/data-structures/map-graph.js +2 -0
  136. package/dist/types/data-structures/navigator.d.ts +14 -0
  137. package/dist/types/data-structures/navigator.js +2 -0
  138. package/dist/types/data-structures/priority-queue.d.ts +7 -0
  139. package/dist/types/data-structures/priority-queue.js +2 -0
  140. package/dist/types/data-structures/rb-tree.d.ts +8 -0
  141. package/dist/types/data-structures/rb-tree.js +8 -0
  142. package/dist/types/data-structures/segment-tree.d.ts +1 -0
  143. package/dist/types/data-structures/segment-tree.js +2 -0
  144. package/dist/types/data-structures/singly-linked-list.js +2 -0
  145. package/dist/types/data-structures/tree-multiset.d.ts +4 -0
  146. package/dist/types/data-structures/tree-multiset.js +2 -0
  147. package/dist/types/helpers.d.ts +1 -0
  148. package/dist/types/helpers.js +2 -0
  149. package/dist/types/index.d.ts +2 -0
  150. package/dist/types/index.js +2 -0
  151. package/dist/types/utils/index.d.ts +2 -0
  152. package/dist/types/utils/index.js +18 -0
  153. package/dist/types/utils/utils.d.ts +7 -0
  154. package/dist/types/utils/utils.js +2 -0
  155. package/dist/types/utils/validate-type.d.ts +19 -0
  156. package/dist/types/utils/validate-type.js +2 -0
  157. package/dist/utils/index.js +17 -0
  158. package/dist/utils/utils.d.ts +19 -0
  159. package/dist/{data-structures/trampoline.js → utils/utils.js} +26 -12
  160. package/package.json +106 -55
  161. package/.idea/data-structure-typed.iml +0 -12
  162. package/.idea/modules.xml +0 -8
  163. package/.idea/vcs.xml +0 -6
  164. package/dist/data-structures/trampoline.d.ts +0 -25
  165. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  166. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  167. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  168. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  169. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  170. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  171. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  172. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  173. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  174. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  175. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  176. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  177. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  178. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  179. package/dist/types/data-structures/graph/index.d.ts +0 -3
  180. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  181. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  182. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  183. package/dist/types/data-structures/hash/index.d.ts +0 -1
  184. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  185. package/dist/types/data-structures/heap/index.d.ts +0 -3
  186. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  187. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  188. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  189. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  190. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  191. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  192. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  193. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  194. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  195. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  196. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  197. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  198. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  199. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  200. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  201. package/dist/types/data-structures/queue/index.d.ts +0 -1
  202. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  203. package/dist/types/data-structures/stack/index.d.ts +0 -1
  204. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  205. package/dist/types/data-structures/trampoline.d.ts +0 -25
  206. package/dist/types/data-structures/trie/index.d.ts +0 -1
  207. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  208. package/dist/types/types/utils.d.ts +0 -46
  209. package/dist/types/utils.d.ts +0 -46
  210. package/dist/utils.d.ts +0 -122
  211. package/dist/utils.js +0 -569
  212. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  213. package/src/data-structures/binary-tree/avl-tree.ts +0 -232
  214. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  215. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -33
  216. package/src/data-structures/binary-tree/binary-tree.ts +0 -1088
  217. package/src/data-structures/binary-tree/bst.ts +0 -404
  218. package/src/data-structures/binary-tree/index.ts +0 -11
  219. package/src/data-structures/binary-tree/rb-tree.ts +0 -3
  220. package/src/data-structures/binary-tree/segment-tree.ts +0 -164
  221. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  222. package/src/data-structures/binary-tree/tree-multiset.ts +0 -21
  223. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  224. package/src/data-structures/graph/abstract-graph.ts +0 -789
  225. package/src/data-structures/graph/directed-graph.ts +0 -322
  226. package/src/data-structures/graph/index.ts +0 -3
  227. package/src/data-structures/graph/undirected-graph.ts +0 -154
  228. package/src/data-structures/hash/coordinate-map.ts +0 -24
  229. package/src/data-structures/hash/coordinate-set.ts +0 -20
  230. package/src/data-structures/hash/hash-table.ts +0 -1
  231. package/src/data-structures/hash/index.ts +0 -1
  232. package/src/data-structures/heap/heap.ts +0 -136
  233. package/src/data-structures/heap/index.ts +0 -3
  234. package/src/data-structures/heap/max-heap.ts +0 -22
  235. package/src/data-structures/heap/min-heap.ts +0 -24
  236. package/src/data-structures/index.ts +0 -11
  237. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -258
  238. package/src/data-structures/linked-list/index.ts +0 -2
  239. package/src/data-structures/linked-list/singly-linked-list.ts +0 -750
  240. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  241. package/src/data-structures/matrix/index.ts +0 -4
  242. package/src/data-structures/matrix/matrix.ts +0 -13
  243. package/src/data-structures/matrix/matrix2d.ts +0 -125
  244. package/src/data-structures/matrix/navigator.ts +0 -99
  245. package/src/data-structures/matrix/vector2d.ts +0 -189
  246. package/src/data-structures/priority-queue/index.ts +0 -3
  247. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -12
  248. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -12
  249. package/src/data-structures/priority-queue/priority-queue.ts +0 -208
  250. package/src/data-structures/queue/deque.ts +0 -139
  251. package/src/data-structures/queue/index.ts +0 -2
  252. package/src/data-structures/queue/queue.ts +0 -123
  253. package/src/data-structures/stack/index.ts +0 -1
  254. package/src/data-structures/stack/stack.ts +0 -104
  255. package/src/data-structures/trampoline.ts +0 -91
  256. package/src/data-structures/trie/index.ts +0 -1
  257. package/src/data-structures/trie/trie.ts +0 -153
  258. package/src/index.ts +0 -1
  259. package/src/types/index.ts +0 -1
  260. package/src/types/patches/index.d.ts +0 -0
  261. package/src/types/utils.ts +0 -158
  262. package/src/utils.ts +0 -605
  263. package/tsconfig.json +0 -53
  264. /package/dist/{types/data-structures/hash/hash-table.d.ts → interfaces/doubly-linked-list.d.ts} +0 -0
  265. /package/dist/{types/data-structures/hash/pair.d.ts → interfaces/heap.d.ts} +0 -0
  266. /package/dist/{types/data-structures/hash/tree-map.d.ts → interfaces/navigator.d.ts} +0 -0
  267. /package/dist/{types/data-structures/hash/tree-set.d.ts → interfaces/priority-queue.d.ts} +0 -0
  268. /package/dist/{types/data-structures/linked-list/skip-linked-list.d.ts → interfaces/segment-tree.d.ts} +0 -0
  269. /package/{src/data-structures/hash/pair.ts → dist/interfaces/singly-linked-list.d.ts} +0 -0
  270. /package/{src/data-structures/hash/tree-map.ts → dist/types/data-structures/doubly-linked-list.d.ts} +0 -0
  271. /package/{src/data-structures/hash/tree-set.ts → dist/types/data-structures/singly-linked-list.d.ts} +0 -0
  272. /package/dist/{types/types → utils}/index.d.ts +0 -0
@@ -1,37 +1,165 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
1
8
  import { DoublyLinkedList } from '../linked-list';
2
9
  export declare class Deque<T> extends DoublyLinkedList<T> {
3
10
  }
4
- export declare class ObjectDeque<T> {
5
- protected _nodes: {
6
- [key: number]: T;
7
- };
8
- protected _capacity: number;
9
- protected _first: number;
10
- protected _last: number;
11
- protected _size: number;
11
+ export declare class ObjectDeque<T = number> {
12
12
  constructor(capacity?: number);
13
- size(): number;
14
- offerFirst(value: T): void;
15
- offerLast(value: T): void;
13
+ private _nodes;
14
+ get nodes(): {
15
+ [p: number]: T;
16
+ };
17
+ private _capacity;
18
+ get capacity(): number;
19
+ set capacity(value: number);
20
+ private _first;
21
+ get first(): number;
22
+ set first(value: number);
23
+ private _last;
24
+ get last(): number;
25
+ set last(value: number);
26
+ private _size;
27
+ get size(): number;
28
+ /**
29
+ * The "addFirst" function adds a value to the beginning of an array-like data structure.
30
+ * @param {T} value - The `value` parameter represents the value that you want to add to the beginning of the data
31
+ * structure.
32
+ */
33
+ addFirst(value: T): void;
34
+ /**
35
+ * The addLast function adds a value to the end of an array-like data structure.
36
+ * @param {T} value - The `value` parameter represents the value that you want to add to the end of the data structure.
37
+ */
38
+ addLast(value: T): void;
39
+ /**
40
+ * The function `pollFirst()` removes and returns the first element in a data structure.
41
+ * @returns The value of the first element in the data structure.
42
+ */
16
43
  pollFirst(): T | undefined;
44
+ /**
45
+ * The `peekFirst` function returns the first element in an array-like data structure if it exists.
46
+ * @returns The element at the first position of the `_nodes` array.
47
+ */
17
48
  peekFirst(): T | undefined;
49
+ /**
50
+ * The `pollLast()` function removes and returns the last element in a data structure.
51
+ * @returns The value that was removed from the data structure.
52
+ */
18
53
  pollLast(): T | undefined;
54
+ /**
55
+ * The `peekLast()` function returns the last element in an array-like data structure.
56
+ * @returns The last element in the array "_nodes" is being returned.
57
+ */
19
58
  peekLast(): T | undefined;
59
+ /**
60
+ * The get function returns the element at the specified index in an array-like data structure.
61
+ * @param {number} index - The index parameter is a number that represents the position of the element you want to
62
+ * retrieve from the array.
63
+ * @returns The element at the specified index in the `_nodes` array is being returned. If there is no element at that
64
+ * index, `null` is returned.
65
+ */
20
66
  get(index: number): NonNullable<T> | null;
67
+ /**
68
+ * The function checks if the size of a data structure is less than or equal to zero.
69
+ * @returns The method is returning a boolean value indicating whether the size of the object is less than or equal to 0.
70
+ */
21
71
  isEmpty(): boolean;
72
+ protected _seNodes(value: {
73
+ [p: number]: T;
74
+ }): void;
75
+ protected _setSize(value: number): void;
22
76
  }
23
77
  export declare class ArrayDeque<T> {
24
78
  protected _nodes: T[];
25
79
  get size(): number;
26
- offerLast(value: T): number;
80
+ /**
81
+ * O(n) time complexity of adding at the beginning and the end
82
+ */
83
+ /**
84
+ * The function "addLast" adds a value to the end of an array.
85
+ * @param {T} value - The value parameter represents the value that you want to add to the end of the array.
86
+ * @returns The return value is the new length of the array after the value has been added.
87
+ */
88
+ addLast(value: T): number;
89
+ /**
90
+ * The function "pollLast" returns and removes the last element from an array, or returns null if the array is empty.
91
+ * @returns The method `pollLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
92
+ */
27
93
  pollLast(): T | null;
94
+ /**
95
+ * The `pollFirst` function removes and returns the first element from an array, or returns null if the array is empty.
96
+ * @returns The `pollFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
97
+ * empty.
98
+ */
28
99
  pollFirst(): T | null;
29
- offerFirst(value: T): number;
100
+ /**
101
+ * O(n) time complexity of adding at the beginning and the end
102
+ */
103
+ /**
104
+ * The function "addFirst" adds a value to the beginning of an array.
105
+ * @param {T} value - The value parameter represents the value that you want to add to the beginning of the array.
106
+ * @returns The return value of the `addFirst` function is the new length of the array `_nodes` after adding the
107
+ * `value` at the beginning.
108
+ */
109
+ addFirst(value: T): number;
110
+ /**
111
+ * The `peekFirst` function returns the first element of an array or null if the array is empty.
112
+ * @returns The function `peekFirst()` is returning the first element (`T`) of the `_nodes` array. If the array is
113
+ * empty, it will return `null`.
114
+ */
30
115
  peekFirst(): T | null;
116
+ /**
117
+ * The `peekLast` function returns the last element of an array or null if the array is empty.
118
+ * @returns The method `peekLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
119
+ */
31
120
  peekLast(): T | null;
121
+ /**
122
+ * O(1) time complexity of obtaining the value
123
+ */
124
+ /**
125
+ * The get function returns the element at the specified index in an array, or null if the index is out of bounds.
126
+ * @param {number} index - The index parameter is a number that represents the position of the element you want to
127
+ * retrieve from the array.
128
+ * @returns The method is returning the element at the specified index in the `_nodes` array. If the element exists, it
129
+ * will be returned. If the element does not exist (i.e., the index is out of bounds), `null` will be returned.
130
+ */
32
131
  get(index: number): T | null;
132
+ /**
133
+ * The set function assigns a value to a specific index in an array.
134
+ * @param {number} index - The index parameter is a number that represents the position of the element in the array
135
+ * that you want to set a new value for.
136
+ * @param {T} value - The value parameter represents the new value that you want to set at the specified index in the
137
+ * _nodes array.
138
+ * @returns The value that is being set at the specified index in the `_nodes` array.
139
+ */
33
140
  set(index: number, value: T): T;
141
+ /**
142
+ * The insert function adds a value at a specified index in an array.
143
+ * @param {number} index - The index parameter specifies the position at which the value should be inserted in the
144
+ * array. It is a number that represents the index of the array where the value should be inserted. The index starts
145
+ * from 0, so the first element of the array has an index of 0, the second element has
146
+ * @param {T} value - The value parameter represents the value that you want to insert into the array at the specified
147
+ * index.
148
+ * @returns The splice method returns an array containing the removed elements, if any. In this case, since no elements
149
+ * are being removed, an empty array will be returned.
150
+ */
34
151
  insert(index: number, value: T): T[];
152
+ /**
153
+ * The remove function removes an element from an array at a specified index.
154
+ * @param {number} index - The index parameter specifies the position of the element to be removed from the array. It
155
+ * is a number that represents the index of the element to be removed.
156
+ * @returns The method is returning an array containing the removed element.
157
+ */
35
158
  remove(index: number): T[];
159
+ /**
160
+ * The function checks if an array called "_nodes" is empty.
161
+ * @returns The method `isEmpty()` is returning a boolean value. It returns `true` if the length of the `_nodes` array
162
+ * is 0, indicating that the array is empty. Otherwise, it returns `false`.
163
+ */
36
164
  isEmpty(): boolean;
37
165
  }
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ArrayDeque = exports.ObjectDeque = exports.Deque = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
4
11
  const linked_list_1 = require("../linked-list");
5
12
  // O(n) time complexity of obtaining the value
6
13
  // O(1) time complexity of adding at the beginning and the end
@@ -20,10 +27,36 @@ class ObjectDeque {
20
27
  if (capacity !== undefined)
21
28
  this._capacity = capacity;
22
29
  }
23
- size() {
30
+ get nodes() {
31
+ return this._nodes;
32
+ }
33
+ get capacity() {
34
+ return this._capacity;
35
+ }
36
+ set capacity(value) {
37
+ this._capacity = value;
38
+ }
39
+ get first() {
40
+ return this._first;
41
+ }
42
+ set first(value) {
43
+ this._first = value;
44
+ }
45
+ get last() {
46
+ return this._last;
47
+ }
48
+ set last(value) {
49
+ this._last = value;
50
+ }
51
+ get size() {
24
52
  return this._size;
25
53
  }
26
- offerFirst(value) {
54
+ /**
55
+ * The "addFirst" function adds a value to the beginning of an array-like data structure.
56
+ * @param {T} value - The `value` parameter represents the value that you want to add to the beginning of the data
57
+ * structure.
58
+ */
59
+ addFirst(value) {
27
60
  if (this._size === 0) {
28
61
  const mid = Math.floor(this._capacity / 2);
29
62
  this._first = mid;
@@ -35,7 +68,11 @@ class ObjectDeque {
35
68
  this._nodes[this._first] = value;
36
69
  this._size++;
37
70
  }
38
- offerLast(value) {
71
+ /**
72
+ * The addLast function adds a value to the end of an array-like data structure.
73
+ * @param {T} value - The `value` parameter represents the value that you want to add to the end of the data structure.
74
+ */
75
+ addLast(value) {
39
76
  if (this._size === 0) {
40
77
  const mid = Math.floor(this._capacity / 2);
41
78
  this._first = mid;
@@ -47,38 +84,71 @@ class ObjectDeque {
47
84
  this._nodes[this._last] = value;
48
85
  this._size++;
49
86
  }
87
+ /**
88
+ * The function `pollFirst()` removes and returns the first element in a data structure.
89
+ * @returns The value of the first element in the data structure.
90
+ */
50
91
  pollFirst() {
51
92
  if (!this._size)
52
93
  return;
53
- let value = this.peekFirst();
94
+ const value = this.peekFirst();
54
95
  delete this._nodes[this._first];
55
96
  this._first++;
56
97
  this._size--;
57
98
  return value;
58
99
  }
100
+ /**
101
+ * The `peekFirst` function returns the first element in an array-like data structure if it exists.
102
+ * @returns The element at the first position of the `_nodes` array.
103
+ */
59
104
  peekFirst() {
60
105
  if (this._size)
61
106
  return this._nodes[this._first];
62
107
  }
108
+ /**
109
+ * The `pollLast()` function removes and returns the last element in a data structure.
110
+ * @returns The value that was removed from the data structure.
111
+ */
63
112
  pollLast() {
64
113
  if (!this._size)
65
114
  return;
66
- let value = this.peekLast();
115
+ const value = this.peekLast();
67
116
  delete this._nodes[this._last];
68
117
  this._last--;
69
118
  this._size--;
70
119
  return value;
71
120
  }
121
+ /**
122
+ * The `peekLast()` function returns the last element in an array-like data structure.
123
+ * @returns The last element in the array "_nodes" is being returned.
124
+ */
72
125
  peekLast() {
73
126
  if (this._size)
74
127
  return this._nodes[this._last];
75
128
  }
129
+ /**
130
+ * The get function returns the element at the specified index in an array-like data structure.
131
+ * @param {number} index - The index parameter is a number that represents the position of the element you want to
132
+ * retrieve from the array.
133
+ * @returns The element at the specified index in the `_nodes` array is being returned. If there is no element at that
134
+ * index, `null` is returned.
135
+ */
76
136
  get(index) {
77
137
  return this._nodes[this._first + index] || null;
78
138
  }
139
+ /**
140
+ * The function checks if the size of a data structure is less than or equal to zero.
141
+ * @returns The method is returning a boolean value indicating whether the size of the object is less than or equal to 0.
142
+ */
79
143
  isEmpty() {
80
144
  return this._size <= 0;
81
145
  }
146
+ _seNodes(value) {
147
+ this._nodes = value;
148
+ }
149
+ _setSize(value) {
150
+ this._size = value;
151
+ }
82
152
  }
83
153
  exports.ObjectDeque = ObjectDeque;
84
154
  // O(1) time complexity of obtaining the value
@@ -90,41 +160,115 @@ class ArrayDeque {
90
160
  get size() {
91
161
  return this._nodes.length;
92
162
  }
93
- offerLast(value) {
163
+ /**
164
+ * O(n) time complexity of adding at the beginning and the end
165
+ */
166
+ /**
167
+ * The function "addLast" adds a value to the end of an array.
168
+ * @param {T} value - The value parameter represents the value that you want to add to the end of the array.
169
+ * @returns The return value is the new length of the array after the value has been added.
170
+ */
171
+ addLast(value) {
94
172
  return this._nodes.push(value);
95
173
  }
174
+ /**
175
+ * The function "pollLast" returns and removes the last element from an array, or returns null if the array is empty.
176
+ * @returns The method `pollLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
177
+ */
96
178
  pollLast() {
97
179
  var _a;
98
180
  return (_a = this._nodes.pop()) !== null && _a !== void 0 ? _a : null;
99
181
  }
182
+ /**
183
+ * The `pollFirst` function removes and returns the first element from an array, or returns null if the array is empty.
184
+ * @returns The `pollFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
185
+ * empty.
186
+ */
100
187
  pollFirst() {
101
188
  var _a;
102
189
  return (_a = this._nodes.shift()) !== null && _a !== void 0 ? _a : null;
103
190
  }
104
- offerFirst(value) {
191
+ /**
192
+ * O(n) time complexity of adding at the beginning and the end
193
+ */
194
+ /**
195
+ * The function "addFirst" adds a value to the beginning of an array.
196
+ * @param {T} value - The value parameter represents the value that you want to add to the beginning of the array.
197
+ * @returns The return value of the `addFirst` function is the new length of the array `_nodes` after adding the
198
+ * `value` at the beginning.
199
+ */
200
+ addFirst(value) {
105
201
  return this._nodes.unshift(value);
106
202
  }
203
+ /**
204
+ * The `peekFirst` function returns the first element of an array or null if the array is empty.
205
+ * @returns The function `peekFirst()` is returning the first element (`T`) of the `_nodes` array. If the array is
206
+ * empty, it will return `null`.
207
+ */
107
208
  peekFirst() {
108
209
  var _a;
109
210
  return (_a = this._nodes[0]) !== null && _a !== void 0 ? _a : null;
110
211
  }
212
+ /**
213
+ * The `peekLast` function returns the last element of an array or null if the array is empty.
214
+ * @returns The method `peekLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
215
+ */
111
216
  peekLast() {
112
217
  var _a;
113
218
  return (_a = this._nodes[this._nodes.length - 1]) !== null && _a !== void 0 ? _a : null;
114
219
  }
220
+ /**
221
+ * O(1) time complexity of obtaining the value
222
+ */
223
+ /**
224
+ * The get function returns the element at the specified index in an array, or null if the index is out of bounds.
225
+ * @param {number} index - The index parameter is a number that represents the position of the element you want to
226
+ * retrieve from the array.
227
+ * @returns The method is returning the element at the specified index in the `_nodes` array. If the element exists, it
228
+ * will be returned. If the element does not exist (i.e., the index is out of bounds), `null` will be returned.
229
+ */
115
230
  get(index) {
116
231
  var _a;
117
232
  return (_a = this._nodes[index]) !== null && _a !== void 0 ? _a : null;
118
233
  }
234
+ /**
235
+ * The set function assigns a value to a specific index in an array.
236
+ * @param {number} index - The index parameter is a number that represents the position of the element in the array
237
+ * that you want to set a new value for.
238
+ * @param {T} value - The value parameter represents the new value that you want to set at the specified index in the
239
+ * _nodes array.
240
+ * @returns The value that is being set at the specified index in the `_nodes` array.
241
+ */
119
242
  set(index, value) {
120
243
  return this._nodes[index] = value;
121
244
  }
245
+ /**
246
+ * The insert function adds a value at a specified index in an array.
247
+ * @param {number} index - The index parameter specifies the position at which the value should be inserted in the
248
+ * array. It is a number that represents the index of the array where the value should be inserted. The index starts
249
+ * from 0, so the first element of the array has an index of 0, the second element has
250
+ * @param {T} value - The value parameter represents the value that you want to insert into the array at the specified
251
+ * index.
252
+ * @returns The splice method returns an array containing the removed elements, if any. In this case, since no elements
253
+ * are being removed, an empty array will be returned.
254
+ */
122
255
  insert(index, value) {
123
256
  return this._nodes.splice(index, 0, value);
124
257
  }
258
+ /**
259
+ * The remove function removes an element from an array at a specified index.
260
+ * @param {number} index - The index parameter specifies the position of the element to be removed from the array. It
261
+ * is a number that represents the index of the element to be removed.
262
+ * @returns The method is returning an array containing the removed element.
263
+ */
125
264
  remove(index) {
126
265
  return this._nodes.splice(index, 1);
127
266
  }
267
+ /**
268
+ * The function checks if an array called "_nodes" is empty.
269
+ * @returns The method `isEmpty()` is returning a boolean value. It returns `true` if the length of the `_nodes` array
270
+ * is 0, indicating that the array is empty. Otherwise, it returns `false`.
271
+ */
128
272
  isEmpty() {
129
273
  return this._nodes.length === 0;
130
274
  }
@@ -1,76 +1,102 @@
1
1
  /**
2
2
  * @license MIT
3
- * @copyright 2020 Pablo
4
- *
3
+ * @copyright Tyler Zeng <zrwusa@gmail.com>
5
4
  * @class
6
5
  */
7
- export declare class Queue<T> {
6
+ import { SinglyLinkedList } from '../linked-list';
7
+ export declare class Queue<T = any> extends SinglyLinkedList<T> {
8
+ /**
9
+ * The enqueue function adds a value to the end of an array.
10
+ * @param {T} value - The value parameter represents the value that you want to add to the queue.
11
+ */
12
+ enqueue(value: T): void;
13
+ /**
14
+ * The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
15
+ * @returns The method is returning the element at the front of the queue, or null if the queue is empty.
16
+ */
17
+ dequeue(): T | undefined;
18
+ /**
19
+ * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
20
+ * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
21
+ */
22
+ peek(): T | undefined;
23
+ [Symbol.iterator](): Generator<T, void, unknown>;
24
+ }
25
+ export declare class ArrayQueue<T = number> {
8
26
  protected _nodes: T[];
9
27
  protected _offset: number;
10
28
  /**
11
- * Creates a queue.
12
- * @param {array} [elements]
29
+ * The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
30
+ * @param {T[]} [elements] - The `elements` parameter is an optional array of elements of type `T`. If provided, it
31
+ * will be used to initialize the `_nodes` property of the class. If not provided, the `_nodes` property will be
32
+ * initialized as an empty array.
13
33
  */
14
34
  constructor(elements?: T[]);
15
35
  /**
16
- * Adds an element at the back of the queue.
17
- * @public
18
- * @param {any} element
36
+ * The size function returns the number of elements in an array.
37
+ * @returns {number} The size of the array, which is the difference between the length of the array and the offset.
19
38
  */
20
- offer(element: T): Queue<T>;
39
+ get size(): number;
21
40
  /**
22
- * Dequeues the front element in the queue.
41
+ * The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
23
42
  * @public
24
- * @returns {any}
43
+ * @static
44
+ * @param {T[]} elements - The "elements" parameter is an array of elements of type T.
45
+ * @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
46
+ * array.
25
47
  */
26
- poll(): T | null;
48
+ static fromArray<T>(elements: T[]): ArrayQueue<T>;
27
49
  /**
28
- * Returns the front element of the queue.
29
- * @public
30
- * @returns {any}
50
+ * The push function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
51
+ * @param {T} element - The `element` parameter represents the element that you want to add to the queue.
52
+ * @returns The `add` method is returning a `Queue<T>` object.
53
+ */
54
+ push(element: T): ArrayQueue<T>;
55
+ /**
56
+ * The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
57
+ * necessary to optimize performance.
58
+ * @returns The function `shift()` returns either the first element in the queue or `null` if the queue is empty.
59
+ */
60
+ shift(): T | null;
61
+ /**
62
+ * The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
63
+ * @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
64
+ * the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
31
65
  */
32
66
  peek(): T | null;
33
67
  /**
34
- * Returns the back element of the queue.
35
- * @public
36
- * @returns {any}
68
+ * The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
69
+ * @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
70
+ * array is empty, it returns `null`.
37
71
  */
38
72
  peekLast(): T | null;
39
73
  /**
40
- * Returns the number of elements in the queue.
41
- * @public
42
- * @returns {number}
74
+ * The enqueue function adds a value to the end of a queue.
75
+ * @param {T} value - The value parameter represents the value that you want to add to the queue.
43
76
  */
44
- size(): number;
77
+ enqueue(value: T): void;
45
78
  /**
46
- * Checks if the queue is empty.
47
- * @public
48
- * @returns {boolean}
79
+ * The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
80
+ * @returns The method is returning a value of type T or null.
81
+ */
82
+ dequeue(): T | null;
83
+ /**
84
+ * The function checks if a data structure is empty by comparing its size to zero.
85
+ * @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
49
86
  */
50
87
  isEmpty(): boolean;
51
88
  /**
52
- * Returns the remaining elements in the queue as an array.
53
- * @public
54
- * @returns {array}
89
+ * The toArray() function returns an array of elements from the current offset to the end of the _nodes array.
90
+ * @returns An array of type T is being returned.
55
91
  */
56
92
  toArray(): T[];
57
93
  /**
58
- * Clears the queue.
59
- * @public
94
+ * The clear function resets the nodes array and offset to their initial values.
60
95
  */
61
96
  clear(): void;
62
97
  /**
63
- * Creates a shallow copy of the queue.
64
- * @public
65
- * @return {Queue}
66
- */
67
- clone(): Queue<T>;
68
- /**
69
- * Creates a queue from an existing array.
70
- * @public
71
- * @static
72
- * @param {array} elements
73
- * @return {Queue}
98
+ * The `clone()` function returns a new Queue object with the same elements as the original Queue.
99
+ * @returns The `clone()` method is returning a new instance of the `Queue` class.
74
100
  */
75
- static fromArray<T>(elements: T[]): Queue<T>;
101
+ clone(): ArrayQueue<T>;
76
102
  }