avl-tree-typed 2.1.0 → 2.1.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 (281) hide show
  1. package/dist/cjs/index.cjs +3859 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/esm/index.mjs +3852 -0
  4. package/dist/esm/index.mjs.map +1 -0
  5. package/dist/types/data-structures/base/index.d.ts +2 -1
  6. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -2
  7. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -2
  8. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -2
  9. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
  10. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
  11. package/dist/types/data-structures/binary-tree/bst.d.ts +413 -12
  12. package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
  13. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -3
  14. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
  15. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -2
  16. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +270 -2
  17. package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
  18. package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
  19. package/dist/types/data-structures/graph/index.d.ts +2 -1
  20. package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
  21. package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
  22. package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
  23. package/dist/types/data-structures/hash/index.d.ts +0 -1
  24. package/dist/types/data-structures/heap/heap.d.ts +503 -5
  25. package/dist/types/data-structures/heap/index.d.ts +2 -0
  26. package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
  27. package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
  28. package/dist/types/data-structures/index.d.ts +7 -7
  29. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
  30. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
  31. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
  32. package/dist/types/data-structures/matrix/index.d.ts +1 -1
  33. package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
  34. package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
  35. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
  36. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
  37. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
  38. package/dist/types/data-structures/queue/deque.d.ts +431 -4
  39. package/dist/types/data-structures/queue/queue.d.ts +308 -4
  40. package/dist/types/data-structures/stack/stack.d.ts +306 -2
  41. package/dist/types/data-structures/tree/tree.d.ts +62 -1
  42. package/dist/types/data-structures/trie/trie.d.ts +350 -4
  43. package/dist/types/index.d.ts +15 -3
  44. package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +3 -3
  45. package/dist/types/types/data-structures/base/index.d.ts +1 -0
  46. package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  47. package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
  48. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
  49. package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  50. package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  51. package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
  52. package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
  53. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  54. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  55. package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  56. package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
  57. package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
  58. package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
  59. package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
  60. package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
  61. package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
  62. package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
  63. package/dist/types/types/data-structures/hash/index.d.ts +2 -0
  64. package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
  65. package/dist/types/types/data-structures/heap/index.d.ts +1 -0
  66. package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
  67. package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
  68. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
  69. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
  70. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
  71. package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
  72. package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
  73. package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  74. package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  75. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
  76. package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
  77. package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
  78. package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
  79. package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
  80. package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
  81. package/dist/types/types/index.d.ts +3 -0
  82. package/dist/types/types/utils/index.d.ts +2 -0
  83. package/dist/types/types/utils/utils.d.ts +22 -0
  84. package/dist/types/utils/index.d.ts +1 -1
  85. package/dist/types/utils/utils.d.ts +209 -22
  86. package/dist/umd/avl-tree-typed.js +3852 -0
  87. package/dist/umd/avl-tree-typed.js.map +1 -0
  88. package/dist/umd/avl-tree-typed.min.js +13 -0
  89. package/dist/umd/avl-tree-typed.min.js.map +1 -0
  90. package/package.json +25 -5
  91. package/src/data-structures/binary-tree/avl-tree-counter.ts +8 -11
  92. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +6 -11
  93. package/src/data-structures/binary-tree/avl-tree.ts +6 -8
  94. package/src/data-structures/binary-tree/binary-tree.ts +13 -15
  95. package/src/data-structures/binary-tree/bst.ts +6 -11
  96. package/src/data-structures/binary-tree/red-black-tree.ts +6 -11
  97. package/src/data-structures/binary-tree/tree-counter.ts +8 -13
  98. package/src/data-structures/binary-tree/tree-multi-map.ts +6 -11
  99. package/src/data-structures/heap/heap.ts +5 -5
  100. package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
  101. package/src/interfaces/binary-tree.ts +3 -3
  102. package/tsconfig.base.json +23 -0
  103. package/tsconfig.json +8 -34
  104. package/tsconfig.test.json +8 -0
  105. package/tsconfig.types.json +15 -0
  106. package/tsup.config.js +28 -0
  107. package/tsup.node.config.js +37 -0
  108. package/dist/common/index.js +0 -28
  109. package/dist/constants/index.js +0 -8
  110. package/dist/data-structures/base/index.d.ts +0 -2
  111. package/dist/data-structures/base/index.js +0 -18
  112. package/dist/data-structures/base/iterable-element-base.js +0 -243
  113. package/dist/data-structures/base/iterable-entry-base.js +0 -183
  114. package/dist/data-structures/base/linear-base.js +0 -415
  115. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
  116. package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
  117. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
  118. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
  119. package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
  120. package/dist/data-structures/binary-tree/avl-tree.js +0 -611
  121. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
  122. package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
  123. package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
  124. package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
  125. package/dist/data-structures/binary-tree/bst.d.ts +0 -413
  126. package/dist/data-structures/binary-tree/bst.js +0 -903
  127. package/dist/data-structures/binary-tree/index.js +0 -26
  128. package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
  129. package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
  130. package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
  131. package/dist/data-structures/binary-tree/segment-tree.js +0 -297
  132. package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
  133. package/dist/data-structures/binary-tree/tree-counter.js +0 -413
  134. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
  135. package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
  136. package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
  137. package/dist/data-structures/graph/abstract-graph.js +0 -896
  138. package/dist/data-structures/graph/directed-graph.d.ts +0 -207
  139. package/dist/data-structures/graph/directed-graph.js +0 -525
  140. package/dist/data-structures/graph/index.js +0 -20
  141. package/dist/data-structures/graph/map-graph.d.ts +0 -78
  142. package/dist/data-structures/graph/map-graph.js +0 -107
  143. package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
  144. package/dist/data-structures/graph/undirected-graph.js +0 -424
  145. package/dist/data-structures/hash/hash-map.d.ts +0 -345
  146. package/dist/data-structures/hash/hash-map.js +0 -692
  147. package/dist/data-structures/hash/index.d.ts +0 -1
  148. package/dist/data-structures/hash/index.js +0 -17
  149. package/dist/data-structures/heap/heap.d.ts +0 -503
  150. package/dist/data-structures/heap/heap.js +0 -901
  151. package/dist/data-structures/heap/index.d.ts +0 -3
  152. package/dist/data-structures/heap/index.js +0 -19
  153. package/dist/data-structures/heap/max-heap.d.ts +0 -32
  154. package/dist/data-structures/heap/max-heap.js +0 -40
  155. package/dist/data-structures/heap/min-heap.d.ts +0 -33
  156. package/dist/data-structures/heap/min-heap.js +0 -31
  157. package/dist/data-structures/index.js +0 -28
  158. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
  159. package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
  160. package/dist/data-structures/linked-list/index.js +0 -19
  161. package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
  162. package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
  163. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
  164. package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
  165. package/dist/data-structures/matrix/index.js +0 -18
  166. package/dist/data-structures/matrix/matrix.d.ts +0 -168
  167. package/dist/data-structures/matrix/matrix.js +0 -448
  168. package/dist/data-structures/matrix/navigator.d.ts +0 -55
  169. package/dist/data-structures/matrix/navigator.js +0 -111
  170. package/dist/data-structures/priority-queue/index.js +0 -19
  171. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
  172. package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
  173. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
  174. package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
  175. package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
  176. package/dist/data-structures/priority-queue/priority-queue.js +0 -20
  177. package/dist/data-structures/queue/deque.d.ts +0 -431
  178. package/dist/data-structures/queue/deque.js +0 -879
  179. package/dist/data-structures/queue/index.js +0 -18
  180. package/dist/data-structures/queue/queue.d.ts +0 -308
  181. package/dist/data-structures/queue/queue.js +0 -473
  182. package/dist/data-structures/stack/index.js +0 -17
  183. package/dist/data-structures/stack/stack.d.ts +0 -306
  184. package/dist/data-structures/stack/stack.js +0 -401
  185. package/dist/data-structures/tree/index.js +0 -17
  186. package/dist/data-structures/tree/tree.d.ts +0 -62
  187. package/dist/data-structures/tree/tree.js +0 -107
  188. package/dist/data-structures/trie/index.js +0 -17
  189. package/dist/data-structures/trie/trie.d.ts +0 -350
  190. package/dist/data-structures/trie/trie.js +0 -610
  191. package/dist/index.d.ts +0 -15
  192. package/dist/index.js +0 -31
  193. package/dist/interfaces/binary-tree.js +0 -2
  194. package/dist/interfaces/doubly-linked-list.js +0 -2
  195. package/dist/interfaces/graph.js +0 -2
  196. package/dist/interfaces/heap.js +0 -2
  197. package/dist/interfaces/index.js +0 -24
  198. package/dist/interfaces/navigator.js +0 -2
  199. package/dist/interfaces/priority-queue.js +0 -2
  200. package/dist/interfaces/segment-tree.js +0 -2
  201. package/dist/interfaces/singly-linked-list.js +0 -2
  202. package/dist/types/common.js +0 -2
  203. package/dist/types/data-structures/base/base.js +0 -2
  204. package/dist/types/data-structures/base/index.js +0 -17
  205. package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
  206. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
  207. package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
  208. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
  209. package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
  210. package/dist/types/data-structures/binary-tree/bst.js +0 -2
  211. package/dist/types/data-structures/binary-tree/index.js +0 -25
  212. package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
  213. package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
  214. package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
  215. package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
  216. package/dist/types/data-structures/graph/abstract-graph.js +0 -2
  217. package/dist/types/data-structures/graph/directed-graph.js +0 -2
  218. package/dist/types/data-structures/graph/index.js +0 -19
  219. package/dist/types/data-structures/graph/map-graph.js +0 -2
  220. package/dist/types/data-structures/graph/undirected-graph.js +0 -2
  221. package/dist/types/data-structures/hash/hash-map.js +0 -2
  222. package/dist/types/data-structures/hash/index.js +0 -17
  223. package/dist/types/data-structures/heap/heap.js +0 -2
  224. package/dist/types/data-structures/heap/index.js +0 -17
  225. package/dist/types/data-structures/heap/max-heap.js +0 -2
  226. package/dist/types/data-structures/heap/min-heap.js +0 -2
  227. package/dist/types/data-structures/index.js +0 -28
  228. package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
  229. package/dist/types/data-structures/linked-list/index.js +0 -19
  230. package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
  231. package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
  232. package/dist/types/data-structures/matrix/index.js +0 -18
  233. package/dist/types/data-structures/matrix/matrix.js +0 -2
  234. package/dist/types/data-structures/matrix/navigator.js +0 -2
  235. package/dist/types/data-structures/priority-queue/index.js +0 -19
  236. package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
  237. package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
  238. package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
  239. package/dist/types/data-structures/queue/deque.js +0 -2
  240. package/dist/types/data-structures/queue/index.js +0 -18
  241. package/dist/types/data-structures/queue/queue.js +0 -2
  242. package/dist/types/data-structures/stack/index.js +0 -17
  243. package/dist/types/data-structures/stack/stack.js +0 -2
  244. package/dist/types/data-structures/tree/index.js +0 -17
  245. package/dist/types/data-structures/tree/tree.js +0 -2
  246. package/dist/types/data-structures/trie/index.js +0 -17
  247. package/dist/types/data-structures/trie/trie.js +0 -2
  248. package/dist/types/index.js +0 -19
  249. package/dist/types/utils/index.js +0 -18
  250. package/dist/types/utils/utils.js +0 -2
  251. package/dist/types/utils/validate-type.js +0 -2
  252. package/dist/utils/index.d.ts +0 -2
  253. package/dist/utils/index.js +0 -18
  254. package/dist/utils/number.js +0 -23
  255. package/dist/utils/utils.d.ts +0 -209
  256. package/dist/utils/utils.js +0 -353
  257. package/dist/{common → types/common}/index.d.ts +0 -0
  258. package/dist/{constants → types/constants}/index.d.ts +0 -0
  259. package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
  260. package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
  261. package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
  262. package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
  263. package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
  264. package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
  265. package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
  266. package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
  267. package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
  268. package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
  269. package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
  270. package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
  271. package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
  272. package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
  273. package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
  274. package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
  275. /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
  276. /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
  277. /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
  278. /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
  279. /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
  280. /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
  281. /package/dist/{utils → types/utils}/number.d.ts +0 -0
@@ -1,415 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LinearLinkedBase = exports.LinearBase = exports.LinkedListNode = void 0;
4
- const iterable_element_base_1 = require("./iterable-element-base");
5
- /**
6
- * Singly-linked list node.
7
- * @template E - Element type.
8
- * @remarks Time O(1), Space O(1)
9
- */
10
- class LinkedListNode {
11
- /**
12
- * Initialize a node.
13
- * @param value - Element value.
14
- * @remarks Time O(1), Space O(1)
15
- */
16
- constructor(value) {
17
- this._value = value;
18
- this._next = undefined;
19
- }
20
- /**
21
- * Element payload getter.
22
- * @returns Element value.
23
- * @remarks Time O(1), Space O(1)
24
- */
25
- get value() {
26
- return this._value;
27
- }
28
- /**
29
- * Element payload setter.
30
- * @param value - New value.
31
- * @remarks Time O(1), Space O(1)
32
- */
33
- set value(value) {
34
- this._value = value;
35
- }
36
- /**
37
- * Next node getter.
38
- * @returns Next node or `undefined`.
39
- * @remarks Time O(1), Space O(1)
40
- */
41
- get next() {
42
- return this._next;
43
- }
44
- /**
45
- * Next node setter.
46
- * @param value - Next node or `undefined`.
47
- * @remarks Time O(1), Space O(1)
48
- */
49
- set next(value) {
50
- this._next = value;
51
- }
52
- }
53
- exports.LinkedListNode = LinkedListNode;
54
- /**
55
- * Abstract linear container with array-like utilities.
56
- * @template E - Element type.
57
- * @template R - Return type for mapped/derived views.
58
- * @template NODE - Linked node type used by some implementations.
59
- * @remarks Time O(1), Space O(1)
60
- */
61
- class LinearBase extends iterable_element_base_1.IterableElementBase {
62
- /**
63
- * Construct a linear container with runtime options.
64
- * @param options - `{ maxLen?, ... }` bounds/behavior options.
65
- * @remarks Time O(1), Space O(1)
66
- */
67
- constructor(options) {
68
- super(options);
69
- this._maxLen = -1;
70
- if (options) {
71
- const { maxLen } = options;
72
- if (typeof maxLen === 'number' && maxLen > 0 && maxLen % 1 === 0)
73
- this._maxLen = maxLen;
74
- }
75
- }
76
- /**
77
- * Upper bound for length (if positive), or `-1` when unbounded.
78
- * @returns Maximum allowed length.
79
- * @remarks Time O(1), Space O(1)
80
- */
81
- get maxLen() {
82
- return this._maxLen;
83
- }
84
- /**
85
- * First index of a value from the left.
86
- * @param searchElement - Value to match.
87
- * @param fromIndex - Start position (supports negative index).
88
- * @returns Index or `-1` if not found.
89
- * @remarks Time O(n), Space O(1)
90
- */
91
- indexOf(searchElement, fromIndex = 0) {
92
- if (this.length === 0)
93
- return -1;
94
- if (fromIndex < 0)
95
- fromIndex = this.length + fromIndex;
96
- if (fromIndex < 0)
97
- fromIndex = 0;
98
- for (let i = fromIndex; i < this.length; i++) {
99
- const element = this.at(i);
100
- if (element === searchElement)
101
- return i;
102
- }
103
- return -1;
104
- }
105
- /**
106
- * Last index of a value from the right.
107
- * @param searchElement - Value to match.
108
- * @param fromIndex - Start position (supports negative index).
109
- * @returns Index or `-1` if not found.
110
- * @remarks Time O(n), Space O(1)
111
- */
112
- lastIndexOf(searchElement, fromIndex = this.length - 1) {
113
- if (this.length === 0)
114
- return -1;
115
- if (fromIndex >= this.length)
116
- fromIndex = this.length - 1;
117
- if (fromIndex < 0)
118
- fromIndex = this.length + fromIndex;
119
- for (let i = fromIndex; i >= 0; i--) {
120
- const element = this.at(i);
121
- if (element === searchElement)
122
- return i;
123
- }
124
- return -1;
125
- }
126
- /**
127
- * Find the first index matching a predicate.
128
- * @param predicate - `(element, index, self) => boolean`.
129
- * @param thisArg - Optional `this` for callback.
130
- * @returns Index or `-1`.
131
- * @remarks Time O(n), Space O(1)
132
- */
133
- findIndex(predicate, thisArg) {
134
- for (let i = 0; i < this.length; i++) {
135
- const item = this.at(i);
136
- if (item !== undefined && predicate.call(thisArg, item, i, this))
137
- return i;
138
- }
139
- return -1;
140
- }
141
- /**
142
- * Concatenate elements and/or containers.
143
- * @param items - Elements or other containers.
144
- * @returns New container with combined elements (`this` type).
145
- * @remarks Time O(sum(length)), Space O(sum(length))
146
- */
147
- concat(...items) {
148
- const newList = this.clone();
149
- for (const item of items) {
150
- if (item instanceof LinearBase) {
151
- newList.pushMany(item);
152
- }
153
- else {
154
- newList.push(item);
155
- }
156
- }
157
- return newList;
158
- }
159
- /**
160
- * In-place stable order via array sort semantics.
161
- * @param compareFn - Comparator `(a, b) => number`.
162
- * @returns This container.
163
- * @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
164
- */
165
- sort(compareFn) {
166
- const arr = this.toArray();
167
- arr.sort(compareFn);
168
- this.clear();
169
- for (const item of arr)
170
- this.push(item);
171
- return this;
172
- }
173
- /**
174
- * Remove and/or insert elements at a position (array-compatible).
175
- * @param start - Start index (supports negative index).
176
- * @param deleteCount - How many to remove.
177
- * @param items - Elements to insert.
178
- * @returns Removed elements as a new list (`this` type).
179
- * @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
180
- */
181
- splice(start, deleteCount = 0, ...items) {
182
- const removedList = this._createInstance();
183
- start = start < 0 ? this.length + start : start;
184
- start = Math.max(0, Math.min(start, this.length));
185
- deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
186
- for (let i = 0; i < deleteCount; i++) {
187
- const removed = this.deleteAt(start);
188
- if (removed !== undefined) {
189
- removedList.push(removed);
190
- }
191
- }
192
- for (let i = 0; i < items.length; i++) {
193
- this.addAt(start + i, items[i]);
194
- }
195
- return removedList;
196
- }
197
- /**
198
- * Join all elements into a string.
199
- * @param separator - Separator string.
200
- * @returns Concatenated string.
201
- * @remarks Time O(n), Space O(n)
202
- */
203
- join(separator = ',') {
204
- return this.toArray().join(separator);
205
- }
206
- /**
207
- * Snapshot elements into a reversed array.
208
- * @returns New reversed array.
209
- * @remarks Time O(n), Space O(n)
210
- */
211
- toReversedArray() {
212
- const array = [];
213
- for (let i = this.length - 1; i >= 0; i--) {
214
- array.push(this.at(i));
215
- }
216
- return array;
217
- }
218
- reduceRight(callbackfn, initialValue) {
219
- let accumulator = initialValue !== null && initialValue !== void 0 ? initialValue : 0;
220
- for (let i = this.length - 1; i >= 0; i--) {
221
- accumulator = callbackfn(accumulator, this.at(i), i, this);
222
- }
223
- return accumulator;
224
- }
225
- /**
226
- * Create a shallow copy of a subrange.
227
- * @param start - Inclusive start (supports negative index).
228
- * @param end - Exclusive end (supports negative index).
229
- * @returns New list with the range (`this` type).
230
- * @remarks Time O(n), Space O(n)
231
- */
232
- slice(start = 0, end = this.length) {
233
- start = start < 0 ? this.length + start : start;
234
- end = end < 0 ? this.length + end : end;
235
- const newList = this._createInstance();
236
- for (let i = start; i < end; i++) {
237
- newList.push(this.at(i));
238
- }
239
- return newList;
240
- }
241
- /**
242
- * Fill a range with a value.
243
- * @param value - Value to set.
244
- * @param start - Inclusive start.
245
- * @param end - Exclusive end.
246
- * @returns This list.
247
- * @remarks Time O(n), Space O(1)
248
- */
249
- fill(value, start = 0, end = this.length) {
250
- start = start < 0 ? this.length + start : start;
251
- end = end < 0 ? this.length + end : end;
252
- if (start < 0)
253
- start = 0;
254
- if (end > this.length)
255
- end = this.length;
256
- if (start >= end)
257
- return this;
258
- for (let i = start; i < end; i++) {
259
- this.setAt(i, value);
260
- }
261
- return this;
262
- }
263
- }
264
- exports.LinearBase = LinearBase;
265
- /**
266
- * Linked-list specialized linear container.
267
- * @template E - Element type.
268
- * @template R - Return type for mapped/derived views.
269
- * @template NODE - Linked node type.
270
- * @remarks Time O(1), Space O(1)
271
- */
272
- class LinearLinkedBase extends LinearBase {
273
- constructor(options) {
274
- super(options);
275
- if (options) {
276
- const { maxLen } = options;
277
- if (typeof maxLen === 'number' && maxLen > 0 && maxLen % 1 === 0)
278
- this._maxLen = maxLen;
279
- }
280
- }
281
- /**
282
- * Linked-list optimized `indexOf` (forwards scan).
283
- * @param searchElement - Value to match.
284
- * @param fromIndex - Start position.
285
- * @returns Index or `-1`.
286
- * @remarks Time O(n), Space O(1)
287
- */
288
- indexOf(searchElement, fromIndex = 0) {
289
- const iterator = this._getIterator();
290
- let current = iterator.next();
291
- let index = 0;
292
- while (index < fromIndex) {
293
- current = iterator.next();
294
- index++;
295
- }
296
- while (!current.done) {
297
- if (current.value === searchElement)
298
- return index;
299
- current = iterator.next();
300
- index++;
301
- }
302
- return -1;
303
- }
304
- /**
305
- * Linked-list optimized `lastIndexOf` (reverse scan).
306
- * @param searchElement - Value to match.
307
- * @param fromIndex - Start position.
308
- * @returns Index or `-1`.
309
- * @remarks Time O(n), Space O(1)
310
- */
311
- lastIndexOf(searchElement, fromIndex = this.length - 1) {
312
- const iterator = this._getReverseIterator();
313
- let current = iterator.next();
314
- let index = this.length - 1;
315
- while (index > fromIndex) {
316
- current = iterator.next();
317
- index--;
318
- }
319
- while (!current.done) {
320
- if (current.value === searchElement)
321
- return index;
322
- current = iterator.next();
323
- index--;
324
- }
325
- return -1;
326
- }
327
- concat(...items) {
328
- const newList = this.clone();
329
- for (const item of items) {
330
- if (item instanceof LinearBase) {
331
- newList.pushMany(item);
332
- }
333
- else {
334
- newList.push(item);
335
- }
336
- }
337
- return newList;
338
- }
339
- /**
340
- * Slice via forward iteration (no random access required).
341
- * @param start - Inclusive start (supports negative index).
342
- * @param end - Exclusive end (supports negative index).
343
- * @returns New list (`this` type).
344
- * @remarks Time O(n), Space O(n)
345
- */
346
- slice(start = 0, end = this.length) {
347
- start = start < 0 ? this.length + start : start;
348
- end = end < 0 ? this.length + end : end;
349
- const newList = this._createInstance();
350
- const iterator = this._getIterator();
351
- let current = iterator.next();
352
- let c = 0;
353
- while (c < start) {
354
- current = iterator.next();
355
- c++;
356
- }
357
- for (let i = start; i < end; i++) {
358
- newList.push(current.value);
359
- current = iterator.next();
360
- }
361
- return newList;
362
- }
363
- /**
364
- * Splice by walking node iterators from the start index.
365
- * @param start - Start index.
366
- * @param deleteCount - How many elements to remove.
367
- * @param items - Elements to insert after the splice point.
368
- * @returns Removed elements as a new list (`this` type).
369
- * @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
370
- */
371
- splice(start, deleteCount = 0, ...items) {
372
- const removedList = this._createInstance();
373
- start = start < 0 ? this.length + start : start;
374
- start = Math.max(0, Math.min(start, this.length));
375
- deleteCount = Math.max(0, deleteCount);
376
- let currentIndex = 0;
377
- let currentNode = undefined;
378
- let previousNode = undefined;
379
- const iterator = this._getNodeIterator();
380
- for (const node of iterator) {
381
- if (currentIndex === start) {
382
- currentNode = node;
383
- break;
384
- }
385
- previousNode = node;
386
- currentIndex++;
387
- }
388
- for (let i = 0; i < deleteCount && currentNode; i++) {
389
- removedList.push(currentNode.value);
390
- const nextNode = currentNode.next;
391
- this.delete(currentNode);
392
- currentNode = nextNode;
393
- }
394
- for (let i = 0; i < items.length; i++) {
395
- if (previousNode) {
396
- this.addAfter(previousNode, items[i]);
397
- previousNode = previousNode.next;
398
- }
399
- else {
400
- this.addAt(0, items[i]);
401
- previousNode = this._getNodeIterator().next().value;
402
- }
403
- }
404
- return removedList;
405
- }
406
- reduceRight(callbackfn, initialValue) {
407
- let accumulator = initialValue !== null && initialValue !== void 0 ? initialValue : 0;
408
- let index = this.length - 1;
409
- for (const item of this._getReverseIterator()) {
410
- accumulator = callbackfn(accumulator, item, index--, this);
411
- }
412
- return accumulator;
413
- }
414
- }
415
- exports.LinearLinkedBase = LinearLinkedBase;
@@ -1,182 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Pablo Zeng
5
- * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- import type { AVLTreeCounterOptions, BinaryTreeDeleteResult, BinaryTreeOptions, BSTNOptKeyOrNode, EntryCallback, IterationType } from '../../types';
9
- import { IBinaryTree } from '../../interfaces';
10
- import { AVLTree, AVLTreeNode } from './avl-tree';
11
- /**
12
- * AVL node with an extra 'count' field; keeps parent/child links.
13
- * @remarks Time O(1), Space O(1)
14
- * @template K
15
- * @template V
16
- */
17
- export declare class AVLTreeCounterNode<K = any, V = any> extends AVLTreeNode<K, V> {
18
- parent?: AVLTreeCounterNode<K, V>;
19
- /**
20
- * Create an AVL counter node.
21
- * @remarks Time O(1), Space O(1)
22
- * @param key - Key of the node.
23
- * @param [value] - Associated value (ignored in map mode).
24
- * @param [count] - Initial count for this node (default 1).
25
- * @returns New AVLTreeCounterNode instance.
26
- */
27
- constructor(key: K, value?: V, count?: number);
28
- _left?: AVLTreeCounterNode<K, V> | null | undefined;
29
- /**
30
- * Get the left child pointer.
31
- * @remarks Time O(1), Space O(1)
32
- * @returns Left child node, or null/undefined.
33
- */
34
- get left(): AVLTreeCounterNode<K, V> | null | undefined;
35
- /**
36
- * Set the left child and update its parent pointer.
37
- * @remarks Time O(1), Space O(1)
38
- * @param v - New left child node, or null/undefined.
39
- * @returns void
40
- */
41
- set left(v: AVLTreeCounterNode<K, V> | null | undefined);
42
- _right?: AVLTreeCounterNode<K, V> | null | undefined;
43
- /**
44
- * Get the right child pointer.
45
- * @remarks Time O(1), Space O(1)
46
- * @returns Right child node, or null/undefined.
47
- */
48
- get right(): AVLTreeCounterNode<K, V> | null | undefined;
49
- /**
50
- * Set the right child and update its parent pointer.
51
- * @remarks Time O(1), Space O(1)
52
- * @param v - New right child node, or null/undefined.
53
- * @returns void
54
- */
55
- set right(v: AVLTreeCounterNode<K, V> | null | undefined);
56
- }
57
- /**
58
- * AVL tree that tracks an aggregate 'count' across nodes; supports balanced insert/delete and map-like mode.
59
- * @remarks Time O(1), Space O(1)
60
- * @template K
61
- * @template V
62
- * @template R
63
- */
64
- export declare class AVLTreeCounter<K = any, V = any, R extends object = object> extends AVLTree<K, V, R> implements IBinaryTree<K, V, R> {
65
- /**
66
- * Create a AVLTreeCounter instance
67
- * @remarks Time O(n), Space O(n)
68
- * @param keysNodesEntriesOrRaws
69
- * @param options
70
- * @returns New AVLTreeCounterNode instance.
71
- */
72
- constructor(keysNodesEntriesOrRaws?: Iterable<K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: AVLTreeCounterOptions<K, V, R>);
73
- protected _count: number;
74
- get count(): number;
75
- /**
76
- * Compute the total count by traversing the tree (sums node.count).
77
- * @remarks Time O(N), Space O(H)
78
- * @returns Total count recomputed from nodes.
79
- */
80
- getComputedCount(): number;
81
- _createNode(key: K, value?: V, count?: number): AVLTreeCounterNode<K, V>;
82
- /**
83
- * Type guard: check whether the input is an AVLTreeCounterNode.
84
- * @remarks Time O(1), Space O(1)
85
- * @returns True if the value is an AVLTreeCounterNode.
86
- */
87
- isNode(keyNodeOrEntry: K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is AVLTreeCounterNode<K, V>;
88
- /**
89
- * Insert or increment a node and update aggregate count.
90
- * @remarks Time O(log N), Space O(1)
91
- * @param keyNodeOrEntry - Key, node, or [key, value] entry to insert.
92
- * @param [value] - Value when a bare key is provided (ignored in map mode).
93
- * @param [count] - How much to increase the node's count (default 1).
94
- * @returns True if inserted/updated; false if ignored.
95
- */
96
- add(keyNodeOrEntry: K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): boolean;
97
- /**
98
- * Delete a node (or decrement its count) and rebalance if needed.
99
- * @remarks Time O(log N), Space O(1)
100
- * @param keyNodeOrEntry - Key, node, or [key, value] entry identifying the node.
101
- * @param [ignoreCount] - If true, remove the node regardless of its count.
102
- * @returns Array of deletion results including deleted node and a rebalance hint when present.
103
- */
104
- delete(keyNodeOrEntry: K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, ignoreCount?: boolean): BinaryTreeDeleteResult<AVLTreeCounterNode<K, V>>[];
105
- /**
106
- * Remove all nodes and reset aggregate counters.
107
- * @remarks Time O(N), Space O(1)
108
- * @returns void
109
- */
110
- clear(): void;
111
- /**
112
- * Rebuild the tree into a perfectly balanced form using in-order nodes.
113
- * @remarks Time O(N), Space O(N)
114
- * @param [iterationType] - Traversal style to use when constructing the balanced tree.
115
- * @returns True if rebalancing succeeded (tree not empty).
116
- */
117
- perfectlyBalance(iterationType?: IterationType): boolean;
118
- /**
119
- * Deep copy this tree, preserving map mode and aggregate counts.
120
- * @remarks Time O(N), Space O(N)
121
- * @returns A deep copy of this tree.
122
- */
123
- clone(): this;
124
- /**
125
- * Create a new AVLTreeCounter by mapping each [key, value] entry.
126
- * @remarks Time O(N log N), Space O(N)
127
- * @template MK
128
- * @template MV
129
- * @template MR
130
- * @param callback - Function mapping (key, value, index, tree) → [newKey, newValue].
131
- * @param [options] - Options for the output tree.
132
- * @param [thisArg] - Value for `this` inside the callback.
133
- * @returns A new AVLTreeCounter with mapped entries.
134
- */
135
- map<MK = K, MV = V, MR extends object = object>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): AVLTreeCounter<MK, MV, MR>;
136
- /**
137
- * (Protected) Create an empty instance of the same concrete class.
138
- * @remarks Time O(1), Space O(1)
139
- * @template TK
140
- * @template TV
141
- * @template TR
142
- * @param [options] - Optional constructor options for the like-kind instance.
143
- * @returns An empty like-kind instance.
144
- */
145
- protected _createInstance<TK = K, TV = V, TR extends object = R>(options?: Partial<AVLTreeCounterOptions<TK, TV, TR>>): this;
146
- /**
147
- * (Protected) Create a like-kind instance and seed it from an iterable.
148
- * @remarks Time O(N log N), Space O(N)
149
- * @template TK
150
- * @template TV
151
- * @template TR
152
- * @param iter - Iterable used to seed the new tree.
153
- * @param [options] - Options merged with the current snapshot.
154
- * @returns A like-kind AVLTreeCounter built from the iterable.
155
- */
156
- protected _createLike<TK = K, TV = V, TR extends object = R>(iter?: Iterable<TK | AVLTreeCounterNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<AVLTreeCounterOptions<TK, TV, TR>>): AVLTreeCounter<TK, TV, TR>;
157
- /**
158
- * (Protected) Normalize input into a node plus its effective value and count.
159
- * @remarks Time O(1), Space O(1)
160
- * @param keyNodeOrEntry - Key, node, or [key, value] entry.
161
- * @param [value] - Value used when a bare key is provided.
162
- * @param [count] - Count increment to apply (default 1).
163
- * @returns Tuple [node, value] where node may be undefined.
164
- */
165
- protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): [AVLTreeCounterNode<K, V> | undefined, V | undefined];
166
- /**
167
- * (Protected) Swap keys/values/counters between the source and destination nodes.
168
- * @remarks Time O(1), Space O(1)
169
- * @param srcNode - Source node (or key) whose properties will be moved.
170
- * @param destNode - Destination node (or key) to receive properties.
171
- * @returns Destination node after swap, or undefined.
172
- */
173
- protected _swapProperties(srcNode: BSTNOptKeyOrNode<K, AVLTreeCounterNode<K, V>>, destNode: BSTNOptKeyOrNode<K, AVLTreeCounterNode<K, V>>): AVLTreeCounterNode<K, V> | undefined;
174
- /**
175
- * (Protected) Replace one node by another and adjust counters accordingly.
176
- * @remarks Time O(1), Space O(1)
177
- * @param oldNode - Node being replaced.
178
- * @param newNode - Replacement node.
179
- * @returns The new node after replacement.
180
- */
181
- protected _replaceNode(oldNode: AVLTreeCounterNode<K, V>, newNode: AVLTreeCounterNode<K, V>): AVLTreeCounterNode<K, V>;
182
- }