data-structure-typed 1.50.1 → 1.50.3

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 (196) hide show
  1. package/CHANGELOG.md +2 -1
  2. package/README.md +30 -28
  3. package/README_zh-CN.md +1 -1
  4. package/SPECIFICATION.md +56 -0
  5. package/SPONSOR-zh-CN.md +90 -0
  6. package/SPONSOR.md +54 -0
  7. package/benchmark/report.html +13 -13
  8. package/benchmark/report.json +149 -161
  9. package/dist/cjs/data-structures/base/iterable-base.d.ts +120 -9
  10. package/dist/cjs/data-structures/base/iterable-base.js +143 -7
  11. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +72 -47
  13. package/dist/cjs/data-structures/binary-tree/avl-tree.js +101 -72
  14. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  15. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
  16. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
  17. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  18. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
  19. package/dist/cjs/data-structures/binary-tree/binary-tree.js +484 -376
  20. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  21. package/dist/cjs/data-structures/binary-tree/bst.d.ts +92 -79
  22. package/dist/cjs/data-structures/binary-tree/bst.js +68 -76
  23. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  24. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +127 -57
  25. package/dist/cjs/data-structures/binary-tree/rb-tree.js +152 -99
  26. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  27. package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
  28. package/dist/cjs/data-structures/binary-tree/segment-tree.js +127 -10
  29. package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
  30. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +72 -58
  31. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +102 -85
  32. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  33. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -78
  34. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -189
  35. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  36. package/dist/cjs/data-structures/graph/directed-graph.d.ts +73 -0
  37. package/dist/cjs/data-structures/graph/directed-graph.js +131 -0
  38. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  39. package/dist/cjs/data-structures/graph/map-graph.d.ts +8 -0
  40. package/dist/cjs/data-structures/graph/map-graph.js +14 -0
  41. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  42. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +76 -7
  43. package/dist/cjs/data-structures/graph/undirected-graph.js +151 -18
  44. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  45. package/dist/cjs/data-structures/hash/hash-map.d.ts +254 -28
  46. package/dist/cjs/data-structures/hash/hash-map.js +347 -78
  47. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  48. package/dist/cjs/data-structures/heap/heap.d.ts +95 -25
  49. package/dist/cjs/data-structures/heap/heap.js +95 -26
  50. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  51. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +126 -63
  52. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +141 -77
  53. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  54. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +154 -106
  55. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +164 -115
  56. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  57. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  58. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +63 -36
  59. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  60. package/dist/cjs/data-structures/matrix/matrix.d.ts +35 -4
  61. package/dist/cjs/data-structures/matrix/matrix.js +50 -11
  62. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  63. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
  64. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +10 -0
  65. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  66. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
  67. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +11 -0
  68. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  69. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
  70. package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -0
  71. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  72. package/dist/cjs/data-structures/queue/deque.d.ts +139 -35
  73. package/dist/cjs/data-structures/queue/deque.js +200 -62
  74. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  75. package/dist/cjs/data-structures/queue/queue.d.ts +103 -49
  76. package/dist/cjs/data-structures/queue/queue.js +111 -49
  77. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  78. package/dist/cjs/data-structures/stack/stack.d.ts +51 -21
  79. package/dist/cjs/data-structures/stack/stack.js +58 -22
  80. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  81. package/dist/cjs/data-structures/tree/tree.d.ts +57 -3
  82. package/dist/cjs/data-structures/tree/tree.js +77 -11
  83. package/dist/cjs/data-structures/tree/tree.js.map +1 -1
  84. package/dist/cjs/data-structures/trie/trie.d.ts +135 -34
  85. package/dist/cjs/data-structures/trie/trie.js +153 -33
  86. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  87. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  88. package/dist/cjs/types/data-structures/hash/hash-map.d.ts +4 -3
  89. package/dist/cjs/types/utils/utils.d.ts +1 -0
  90. package/dist/mjs/data-structures/base/iterable-base.d.ts +120 -9
  91. package/dist/mjs/data-structures/base/iterable-base.js +143 -7
  92. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +72 -47
  93. package/dist/mjs/data-structures/binary-tree/avl-tree.js +102 -73
  94. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
  95. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
  96. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
  97. package/dist/mjs/data-structures/binary-tree/binary-tree.js +483 -375
  98. package/dist/mjs/data-structures/binary-tree/bst.d.ts +92 -79
  99. package/dist/mjs/data-structures/binary-tree/bst.js +68 -76
  100. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +127 -57
  101. package/dist/mjs/data-structures/binary-tree/rb-tree.js +153 -100
  102. package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
  103. package/dist/mjs/data-structures/binary-tree/segment-tree.js +127 -10
  104. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +72 -58
  105. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +102 -86
  106. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -78
  107. package/dist/mjs/data-structures/graph/abstract-graph.js +3 -188
  108. package/dist/mjs/data-structures/graph/directed-graph.d.ts +73 -0
  109. package/dist/mjs/data-structures/graph/directed-graph.js +131 -0
  110. package/dist/mjs/data-structures/graph/map-graph.d.ts +8 -0
  111. package/dist/mjs/data-structures/graph/map-graph.js +14 -0
  112. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +76 -7
  113. package/dist/mjs/data-structures/graph/undirected-graph.js +152 -19
  114. package/dist/mjs/data-structures/hash/hash-map.d.ts +254 -28
  115. package/dist/mjs/data-structures/hash/hash-map.js +353 -84
  116. package/dist/mjs/data-structures/heap/heap.d.ts +95 -25
  117. package/dist/mjs/data-structures/heap/heap.js +95 -26
  118. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +126 -63
  119. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +144 -80
  120. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +154 -106
  121. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +166 -117
  122. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  123. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +63 -36
  124. package/dist/mjs/data-structures/matrix/matrix.d.ts +35 -4
  125. package/dist/mjs/data-structures/matrix/matrix.js +50 -11
  126. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
  127. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +10 -0
  128. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
  129. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +11 -0
  130. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
  131. package/dist/mjs/data-structures/priority-queue/priority-queue.js +8 -0
  132. package/dist/mjs/data-structures/queue/deque.d.ts +139 -35
  133. package/dist/mjs/data-structures/queue/deque.js +205 -67
  134. package/dist/mjs/data-structures/queue/queue.d.ts +103 -49
  135. package/dist/mjs/data-structures/queue/queue.js +111 -49
  136. package/dist/mjs/data-structures/stack/stack.d.ts +51 -21
  137. package/dist/mjs/data-structures/stack/stack.js +58 -22
  138. package/dist/mjs/data-structures/tree/tree.d.ts +57 -3
  139. package/dist/mjs/data-structures/tree/tree.js +80 -14
  140. package/dist/mjs/data-structures/trie/trie.d.ts +135 -34
  141. package/dist/mjs/data-structures/trie/trie.js +156 -36
  142. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  143. package/dist/mjs/types/data-structures/hash/hash-map.d.ts +4 -3
  144. package/dist/mjs/types/utils/utils.d.ts +1 -0
  145. package/dist/umd/data-structure-typed.js +3121 -1583
  146. package/dist/umd/data-structure-typed.min.js +3 -3
  147. package/dist/umd/data-structure-typed.min.js.map +1 -1
  148. package/package.json +61 -55
  149. package/src/data-structures/base/iterable-base.ts +184 -19
  150. package/src/data-structures/binary-tree/avl-tree.ts +134 -100
  151. package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
  152. package/src/data-structures/binary-tree/binary-tree.ts +674 -671
  153. package/src/data-structures/binary-tree/bst.ts +127 -136
  154. package/src/data-structures/binary-tree/rb-tree.ts +199 -166
  155. package/src/data-structures/binary-tree/segment-tree.ts +145 -11
  156. package/src/data-structures/binary-tree/tree-multimap.ts +138 -115
  157. package/src/data-structures/graph/abstract-graph.ts +4 -211
  158. package/src/data-structures/graph/directed-graph.ts +152 -0
  159. package/src/data-structures/graph/map-graph.ts +15 -0
  160. package/src/data-structures/graph/undirected-graph.ts +171 -19
  161. package/src/data-structures/hash/hash-map.ts +389 -96
  162. package/src/data-structures/heap/heap.ts +97 -26
  163. package/src/data-structures/linked-list/doubly-linked-list.ts +156 -83
  164. package/src/data-structures/linked-list/singly-linked-list.ts +174 -120
  165. package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
  166. package/src/data-structures/matrix/matrix.ts +52 -12
  167. package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
  168. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
  169. package/src/data-structures/priority-queue/priority-queue.ts +8 -0
  170. package/src/data-structures/queue/deque.ts +225 -70
  171. package/src/data-structures/queue/queue.ts +118 -49
  172. package/src/data-structures/stack/stack.ts +63 -23
  173. package/src/data-structures/tree/tree.ts +89 -15
  174. package/src/data-structures/trie/trie.ts +173 -38
  175. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  176. package/src/types/data-structures/hash/hash-map.ts +4 -3
  177. package/src/types/utils/utils.ts +2 -0
  178. package/test/performance/data-structures/graph/directed-graph.test.ts +4 -4
  179. package/test/performance/data-structures/queue/deque.test.ts +26 -25
  180. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +37 -0
  181. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -17
  182. package/test/unit/data-structures/binary-tree/bst.test.ts +65 -1
  183. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +38 -1
  184. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -32
  185. package/test/unit/data-structures/graph/abstract-graph.test.ts +11 -0
  186. package/test/unit/data-structures/graph/directed-graph.test.ts +190 -5
  187. package/test/unit/data-structures/graph/undirected-graph.test.ts +263 -18
  188. package/test/unit/data-structures/hash/hash-map.test.ts +376 -353
  189. package/test/unit/data-structures/heap/heap.test.ts +18 -1
  190. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +24 -5
  191. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +20 -2
  192. package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
  193. package/test/unit/data-structures/queue/deque.test.ts +65 -5
  194. package/test/unit/data-structures/queue/queue.test.ts +24 -5
  195. package/test/unit/data-structures/stack/stack.test.ts +17 -0
  196. package/test/unit/data-structures/trie/trie.test.ts +17 -0
@@ -13,46 +13,70 @@ export declare class SkipListNode<K, V> {
13
13
  constructor(key: K, value: V, level: number);
14
14
  }
15
15
  export declare class SkipList<K, V> {
16
+ /**
17
+ * The constructor function initializes a SkipLinkedList object with optional options and elements.
18
+ * @param elements - The `elements` parameter is an iterable containing key-value pairs `[K, V]`. It
19
+ * is used to initialize the SkipLinkedList with the given key-value pairs. If no elements are
20
+ * provided, the SkipLinkedList will be empty.
21
+ * @param {SkipLinkedListOptions} [options] - The `options` parameter is an optional object that can
22
+ * contain two properties:
23
+ */
16
24
  constructor(elements?: Iterable<[K, V]>, options?: SkipLinkedListOptions);
17
25
  protected _head: SkipListNode<K, V>;
26
+ /**
27
+ * The function returns the head node of a SkipList.
28
+ * @returns The method is returning a SkipListNode object with generic key type K and value type V.
29
+ */
18
30
  get head(): SkipListNode<K, V>;
19
31
  protected _level: number;
32
+ /**
33
+ * The function returns the value of the protected variable _level.
34
+ * @returns The level property of the object.
35
+ */
20
36
  get level(): number;
21
37
  protected _maxLevel: number;
38
+ /**
39
+ * The function returns the maximum level.
40
+ * @returns The value of the variable `_maxLevel` is being returned.
41
+ */
22
42
  get maxLevel(): number;
23
43
  protected _probability: number;
44
+ /**
45
+ * The function returns the probability value.
46
+ * @returns The probability value stored in the protected variable `_probability` is being returned.
47
+ */
24
48
  get probability(): number;
25
49
  /**
26
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
27
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
50
+ * Time Complexity: O(log n)
51
+ * Space Complexity: O(1)
28
52
  */
29
53
  /**
30
- * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
31
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
54
+ * Time Complexity: O(1)
55
+ * Space Complexity: O(1)
32
56
  *
33
57
  * Get the value of the first element (the smallest element) in the Skip List.
34
58
  * @returns The value of the first element, or undefined if the Skip List is empty.
35
59
  */
36
60
  get first(): V | undefined;
37
61
  /**
38
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
39
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
62
+ * Time Complexity: O(log n)
63
+ * Space Complexity: O(1)
40
64
  */
41
65
  /**
42
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
43
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
66
+ * Time Complexity: O(log n)
67
+ * Space Complexity: O(1)
44
68
  *
45
69
  * Get the value of the last element (the largest element) in the Skip List.
46
70
  * @returns The value of the last element, or undefined if the Skip List is empty.
47
71
  */
48
72
  get last(): V | undefined;
49
73
  /**
50
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
51
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
74
+ * Time Complexity: O(log n)
75
+ * Space Complexity: O(1)
52
76
  */
53
77
  /**
54
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
55
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
78
+ * Time Complexity: O(log n)
79
+ * Space Complexity: O(1)
56
80
  *
57
81
  * The add function adds a new node with a given key and value to a Skip List data structure.
58
82
  * @param {K} key - The key parameter represents the key of the node that needs to be added to the skip list.
@@ -61,12 +85,12 @@ export declare class SkipList<K, V> {
61
85
  */
62
86
  add(key: K, value: V): void;
63
87
  /**
64
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
65
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
88
+ * Time Complexity: O(log n)
89
+ * Space Complexity: O(1)
66
90
  */
67
91
  /**
68
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
69
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
92
+ * Time Complexity: O(log n)
93
+ * Space Complexity: O(1)
70
94
  *
71
95
  * The function `get` retrieves the value associated with a given key from a skip list data structure.
72
96
  * @param {K} key - The `key` parameter is the key of the element that we want to retrieve from the data structure.
@@ -75,21 +99,23 @@ export declare class SkipList<K, V> {
75
99
  */
76
100
  get(key: K): V | undefined;
77
101
  /**
78
- * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
79
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
102
+ * Time Complexity: O(log n)
103
+ * Space Complexity: O(1)
80
104
  */
81
105
  /**
82
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
83
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
106
+ * The function checks if a key exists in a data structure.
107
+ * @param {K} key - The parameter "key" is of type K, which represents the type of the key being
108
+ * checked.
109
+ * @returns a boolean value.
84
110
  */
85
111
  has(key: K): boolean;
86
112
  /**
87
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
88
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
113
+ * Time Complexity: O(log n)
114
+ * Space Complexity: O(1)
89
115
  */
90
116
  /**
91
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
92
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
117
+ * Time Complexity: O(log n)
118
+ * Space Complexity: O(1)
93
119
  *
94
120
  * The `delete` function removes a node with a specific key from a Skip List data structure.
95
121
  * @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
@@ -98,12 +124,12 @@ export declare class SkipList<K, V> {
98
124
  */
99
125
  delete(key: K): boolean;
100
126
  /**
101
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
102
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
127
+ * Time Complexity: O(log n)
128
+ * Space Complexity: O(1)
103
129
  */
104
130
  /**
105
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
106
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
131
+ * Time Complexity: O(log n)
132
+ * Space Complexity: O(1)
107
133
  *
108
134
  * Get the value of the first element in the Skip List that is greater than the given key.
109
135
  * @param key - the given key.
@@ -111,12 +137,12 @@ export declare class SkipList<K, V> {
111
137
  */
112
138
  higher(key: K): V | undefined;
113
139
  /**
114
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
115
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
140
+ * Time Complexity: O(log n)
141
+ * Space Complexity: O(1)
116
142
  */
117
143
  /**
118
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
119
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
144
+ * Time Complexity: O(log n)
145
+ * Space Complexity: O(1)
120
146
  *
121
147
  * Get the value of the last element in the Skip List that is less than the given key.
122
148
  * @param key - the given key.
@@ -124,12 +150,13 @@ export declare class SkipList<K, V> {
124
150
  */
125
151
  lower(key: K): V | undefined;
126
152
  /**
127
- * Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
128
- * Space Complexity: O(1) - constant space.
153
+ * Time Complexity: O(maxLevel)
154
+ * Space Complexity: O(1)
155
+ * where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
129
156
  */
130
157
  /**
131
- * Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
132
- * Space Complexity: O(1) - constant space.
158
+ * Time Complexity: O(maxLevel)
159
+ * Space Complexity: O(1)
133
160
  *
134
161
  * The function "_randomLevel" generates a random level based on a given probability and maximum level.
135
162
  * @returns the level, which is a number.
@@ -9,6 +9,14 @@ export class SkipListNode {
9
9
  }
10
10
  }
11
11
  export class SkipList {
12
+ /**
13
+ * The constructor function initializes a SkipLinkedList object with optional options and elements.
14
+ * @param elements - The `elements` parameter is an iterable containing key-value pairs `[K, V]`. It
15
+ * is used to initialize the SkipLinkedList with the given key-value pairs. If no elements are
16
+ * provided, the SkipLinkedList will be empty.
17
+ * @param {SkipLinkedListOptions} [options] - The `options` parameter is an optional object that can
18
+ * contain two properties:
19
+ */
12
20
  constructor(elements = [], options) {
13
21
  if (options) {
14
22
  const { maxLevel, probability } = options;
@@ -23,28 +31,44 @@ export class SkipList {
23
31
  }
24
32
  }
25
33
  _head = new SkipListNode(undefined, undefined, this.maxLevel);
34
+ /**
35
+ * The function returns the head node of a SkipList.
36
+ * @returns The method is returning a SkipListNode object with generic key type K and value type V.
37
+ */
26
38
  get head() {
27
39
  return this._head;
28
40
  }
29
41
  _level = 0;
42
+ /**
43
+ * The function returns the value of the protected variable _level.
44
+ * @returns The level property of the object.
45
+ */
30
46
  get level() {
31
47
  return this._level;
32
48
  }
33
49
  _maxLevel = 16;
50
+ /**
51
+ * The function returns the maximum level.
52
+ * @returns The value of the variable `_maxLevel` is being returned.
53
+ */
34
54
  get maxLevel() {
35
55
  return this._maxLevel;
36
56
  }
37
57
  _probability = 0.5;
58
+ /**
59
+ * The function returns the probability value.
60
+ * @returns The probability value stored in the protected variable `_probability` is being returned.
61
+ */
38
62
  get probability() {
39
63
  return this._probability;
40
64
  }
41
65
  /**
42
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
43
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
66
+ * Time Complexity: O(log n)
67
+ * Space Complexity: O(1)
44
68
  */
45
69
  /**
46
- * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
47
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
70
+ * Time Complexity: O(1)
71
+ * Space Complexity: O(1)
48
72
  *
49
73
  * Get the value of the first element (the smallest element) in the Skip List.
50
74
  * @returns The value of the first element, or undefined if the Skip List is empty.
@@ -54,12 +78,12 @@ export class SkipList {
54
78
  return firstNode ? firstNode.value : undefined;
55
79
  }
56
80
  /**
57
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
58
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
81
+ * Time Complexity: O(log n)
82
+ * Space Complexity: O(1)
59
83
  */
60
84
  /**
61
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
62
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
85
+ * Time Complexity: O(log n)
86
+ * Space Complexity: O(1)
63
87
  *
64
88
  * Get the value of the last element (the largest element) in the Skip List.
65
89
  * @returns The value of the last element, or undefined if the Skip List is empty.
@@ -74,12 +98,12 @@ export class SkipList {
74
98
  return current.value;
75
99
  }
76
100
  /**
77
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
78
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
101
+ * Time Complexity: O(log n)
102
+ * Space Complexity: O(1)
79
103
  */
80
104
  /**
81
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
82
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
105
+ * Time Complexity: O(log n)
106
+ * Space Complexity: O(1)
83
107
  *
84
108
  * The add function adds a new node with a given key and value to a Skip List data structure.
85
109
  * @param {K} key - The key parameter represents the key of the node that needs to be added to the skip list.
@@ -105,12 +129,12 @@ export class SkipList {
105
129
  }
106
130
  }
107
131
  /**
108
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
109
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
132
+ * Time Complexity: O(log n)
133
+ * Space Complexity: O(1)
110
134
  */
111
135
  /**
112
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
113
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
136
+ * Time Complexity: O(log n)
137
+ * Space Complexity: O(1)
114
138
  *
115
139
  * The function `get` retrieves the value associated with a given key from a skip list data structure.
116
140
  * @param {K} key - The `key` parameter is the key of the element that we want to retrieve from the data structure.
@@ -131,23 +155,25 @@ export class SkipList {
131
155
  return undefined;
132
156
  }
133
157
  /**
134
- * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
135
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
158
+ * Time Complexity: O(log n)
159
+ * Space Complexity: O(1)
136
160
  */
137
161
  /**
138
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
139
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
162
+ * The function checks if a key exists in a data structure.
163
+ * @param {K} key - The parameter "key" is of type K, which represents the type of the key being
164
+ * checked.
165
+ * @returns a boolean value.
140
166
  */
141
167
  has(key) {
142
168
  return this.get(key) !== undefined;
143
169
  }
144
170
  /**
145
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
146
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
171
+ * Time Complexity: O(log n)
172
+ * Space Complexity: O(1)
147
173
  */
148
174
  /**
149
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
150
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
175
+ * Time Complexity: O(log n)
176
+ * Space Complexity: O(1)
151
177
  *
152
178
  * The `delete` function removes a node with a specific key from a Skip List data structure.
153
179
  * @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
@@ -179,12 +205,12 @@ export class SkipList {
179
205
  return false;
180
206
  }
181
207
  /**
182
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
183
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
208
+ * Time Complexity: O(log n)
209
+ * Space Complexity: O(1)
184
210
  */
185
211
  /**
186
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
187
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
212
+ * Time Complexity: O(log n)
213
+ * Space Complexity: O(1)
188
214
  *
189
215
  * Get the value of the first element in the Skip List that is greater than the given key.
190
216
  * @param key - the given key.
@@ -201,12 +227,12 @@ export class SkipList {
201
227
  return nextNode ? nextNode.value : undefined;
202
228
  }
203
229
  /**
204
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
205
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
230
+ * Time Complexity: O(log n)
231
+ * Space Complexity: O(1)
206
232
  */
207
233
  /**
208
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
209
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
234
+ * Time Complexity: O(log n)
235
+ * Space Complexity: O(1)
210
236
  *
211
237
  * Get the value of the last element in the Skip List that is less than the given key.
212
238
  * @param key - the given key.
@@ -226,12 +252,13 @@ export class SkipList {
226
252
  return lastLess ? lastLess.value : undefined;
227
253
  }
228
254
  /**
229
- * Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
230
- * Space Complexity: O(1) - constant space.
255
+ * Time Complexity: O(maxLevel)
256
+ * Space Complexity: O(1)
257
+ * where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
231
258
  */
232
259
  /**
233
- * Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
234
- * Space Complexity: O(1) - constant space.
260
+ * Time Complexity: O(maxLevel)
261
+ * Space Complexity: O(1)
235
262
  *
236
263
  * The function "_randomLevel" generates a random level based on a given probability and maximum level.
237
264
  * @returns the level, which is a number.
@@ -16,13 +16,37 @@ export declare class Matrix {
16
16
  */
17
17
  constructor(data: number[][], options?: MatrixOptions);
18
18
  protected _rows: number;
19
+ /**
20
+ * The function returns the number of rows.
21
+ * @returns The number of rows.
22
+ */
19
23
  get rows(): number;
20
24
  protected _cols: number;
25
+ /**
26
+ * The function returns the value of the protected variable _cols.
27
+ * @returns The number of columns.
28
+ */
21
29
  get cols(): number;
22
30
  protected _data: number[][];
31
+ /**
32
+ * The function returns a two-dimensional array of numbers.
33
+ * @returns The data property, which is a two-dimensional array of numbers.
34
+ */
23
35
  get data(): number[][];
36
+ /**
37
+ * The above function returns the value of the _addFn property.
38
+ * @returns The value of the property `_addFn` is being returned.
39
+ */
24
40
  get addFn(): (a: number | undefined, b: number) => number | undefined;
41
+ /**
42
+ * The function returns the value of the _subtractFn property.
43
+ * @returns The `_subtractFn` property is being returned.
44
+ */
25
45
  get subtractFn(): (a: number, b: number) => number;
46
+ /**
47
+ * The function returns the value of the _multiplyFn property.
48
+ * @returns The `_multiplyFn` property is being returned.
49
+ */
26
50
  get multiplyFn(): (a: number, b: number) => number;
27
51
  /**
28
52
  * The `get` function returns the value at the specified row and column index if it is a valid index.
@@ -93,9 +117,6 @@ export declare class Matrix {
93
117
  * @returns a new Matrix object.
94
118
  */
95
119
  dot(matrix: Matrix): Matrix | undefined;
96
- protected _addFn(a: number | undefined, b: number): number | undefined;
97
- protected _subtractFn(a: number, b: number): number;
98
- protected _multiplyFn(a: number, b: number): number;
99
120
  /**
100
121
  * The function checks if a given row and column index is valid within a specified range.
101
122
  * @param {number} row - The `row` parameter represents the row index of a two-dimensional array or
@@ -104,7 +125,17 @@ export declare class Matrix {
104
125
  * or grid. It is used to check if the given column index is valid within the bounds of the grid.
105
126
  * @returns A boolean value is being returned.
106
127
  */
107
- protected isValidIndex(row: number, col: number): boolean;
128
+ isValidIndex(row: number, col: number): boolean;
129
+ /**
130
+ * The `clone` function returns a new instance of the Matrix class with the same data and properties
131
+ * as the original instance.
132
+ * @returns The `clone()` method is returning a new instance of the `Matrix` class with the same data
133
+ * and properties as the current instance.
134
+ */
135
+ clone(): Matrix;
136
+ protected _addFn(a: number | undefined, b: number): number | undefined;
137
+ protected _subtractFn(a: number, b: number): number;
138
+ protected _multiplyFn(a: number, b: number): number;
108
139
  /**
109
140
  * The function `_swapRows` swaps the positions of two rows in an array.
110
141
  * @param {number} row1 - The `row1` parameter is the index of the first row that you want to swap.
@@ -39,23 +39,47 @@ export class Matrix {
39
39
  }
40
40
  }
41
41
  _rows = 0;
42
+ /**
43
+ * The function returns the number of rows.
44
+ * @returns The number of rows.
45
+ */
42
46
  get rows() {
43
47
  return this._rows;
44
48
  }
45
49
  _cols = 0;
50
+ /**
51
+ * The function returns the value of the protected variable _cols.
52
+ * @returns The number of columns.
53
+ */
46
54
  get cols() {
47
55
  return this._cols;
48
56
  }
49
57
  _data;
58
+ /**
59
+ * The function returns a two-dimensional array of numbers.
60
+ * @returns The data property, which is a two-dimensional array of numbers.
61
+ */
50
62
  get data() {
51
63
  return this._data;
52
64
  }
65
+ /**
66
+ * The above function returns the value of the _addFn property.
67
+ * @returns The value of the property `_addFn` is being returned.
68
+ */
53
69
  get addFn() {
54
70
  return this._addFn;
55
71
  }
72
+ /**
73
+ * The function returns the value of the _subtractFn property.
74
+ * @returns The `_subtractFn` property is being returned.
75
+ */
56
76
  get subtractFn() {
57
77
  return this._subtractFn;
58
78
  }
79
+ /**
80
+ * The function returns the value of the _multiplyFn property.
81
+ * @returns The `_multiplyFn` property is being returned.
82
+ */
59
83
  get multiplyFn() {
60
84
  return this._multiplyFn;
61
85
  }
@@ -328,17 +352,6 @@ export class Matrix {
328
352
  multiplyFn: this.multiplyFn
329
353
  });
330
354
  }
331
- _addFn(a, b) {
332
- if (a === undefined)
333
- return b;
334
- return a + b;
335
- }
336
- _subtractFn(a, b) {
337
- return a - b;
338
- }
339
- _multiplyFn(a, b) {
340
- return a * b;
341
- }
342
355
  /**
343
356
  * The function checks if a given row and column index is valid within a specified range.
344
357
  * @param {number} row - The `row` parameter represents the row index of a two-dimensional array or
@@ -350,6 +363,32 @@ export class Matrix {
350
363
  isValidIndex(row, col) {
351
364
  return row >= 0 && row < this.rows && col >= 0 && col < this.cols;
352
365
  }
366
+ /**
367
+ * The `clone` function returns a new instance of the Matrix class with the same data and properties
368
+ * as the original instance.
369
+ * @returns The `clone()` method is returning a new instance of the `Matrix` class with the same data
370
+ * and properties as the current instance.
371
+ */
372
+ clone() {
373
+ return new Matrix(this.data, {
374
+ rows: this.rows,
375
+ cols: this.cols,
376
+ addFn: this.addFn,
377
+ subtractFn: this.subtractFn,
378
+ multiplyFn: this.multiplyFn
379
+ });
380
+ }
381
+ _addFn(a, b) {
382
+ if (a === undefined)
383
+ return b;
384
+ return a + b;
385
+ }
386
+ _subtractFn(a, b) {
387
+ return a - b;
388
+ }
389
+ _multiplyFn(a, b) {
390
+ return a * b;
391
+ }
353
392
  /**
354
393
  * The function `_swapRows` swaps the positions of two rows in an array.
355
394
  * @param {number} row1 - The `row1` parameter is the index of the first row that you want to swap.
@@ -8,5 +8,15 @@
8
8
  import type { PriorityQueueOptions } from '../../types';
9
9
  import { PriorityQueue } from './priority-queue';
10
10
  export declare class MaxPriorityQueue<E = any> extends PriorityQueue<E> {
11
+ /**
12
+ * The constructor initializes a PriorityQueue with optional elements and options, including a
13
+ * comparator function.
14
+ * @param elements - The `elements` parameter is an iterable object that contains the initial
15
+ * elements to be added to the priority queue. It is optional and defaults to an empty array if not
16
+ * provided.
17
+ * @param options - The `options` parameter is an object that contains additional configuration
18
+ * options for the priority queue. In this case, it has a property called `comparator` which is a
19
+ * function used to compare elements in the priority queue.
20
+ */
11
21
  constructor(elements?: Iterable<E>, options?: PriorityQueueOptions<E>);
12
22
  }
@@ -1,5 +1,15 @@
1
1
  import { PriorityQueue } from './priority-queue';
2
2
  export class MaxPriorityQueue extends PriorityQueue {
3
+ /**
4
+ * The constructor initializes a PriorityQueue with optional elements and options, including a
5
+ * comparator function.
6
+ * @param elements - The `elements` parameter is an iterable object that contains the initial
7
+ * elements to be added to the priority queue. It is optional and defaults to an empty array if not
8
+ * provided.
9
+ * @param options - The `options` parameter is an object that contains additional configuration
10
+ * options for the priority queue. In this case, it has a property called `comparator` which is a
11
+ * function used to compare elements in the priority queue.
12
+ */
3
13
  constructor(elements = [], options = {
4
14
  comparator: (a, b) => {
5
15
  if (!(typeof a === 'number' && typeof b === 'number')) {
@@ -8,5 +8,16 @@
8
8
  import type { PriorityQueueOptions } from '../../types';
9
9
  import { PriorityQueue } from './priority-queue';
10
10
  export declare class MinPriorityQueue<E = any> extends PriorityQueue<E> {
11
+ /**
12
+ * The constructor initializes a PriorityQueue with optional elements and options, including a
13
+ * comparator function.
14
+ * @param elements - The `elements` parameter is an iterable object that contains the initial
15
+ * elements to be added to the priority queue. It is optional and defaults to an empty array if not
16
+ * provided.
17
+ * @param options - The `options` parameter is an object that contains additional configuration
18
+ * options for the priority queue. In this case, it has a property called `comparator` which is a
19
+ * function used to compare elements in the priority queue. The `comparator` function takes two
20
+ * parameters `a` and `b`,
21
+ */
11
22
  constructor(elements?: Iterable<E>, options?: PriorityQueueOptions<E>);
12
23
  }
@@ -1,5 +1,16 @@
1
1
  import { PriorityQueue } from './priority-queue';
2
2
  export class MinPriorityQueue extends PriorityQueue {
3
+ /**
4
+ * The constructor initializes a PriorityQueue with optional elements and options, including a
5
+ * comparator function.
6
+ * @param elements - The `elements` parameter is an iterable object that contains the initial
7
+ * elements to be added to the priority queue. It is optional and defaults to an empty array if not
8
+ * provided.
9
+ * @param options - The `options` parameter is an object that contains additional configuration
10
+ * options for the priority queue. In this case, it has a property called `comparator` which is a
11
+ * function used to compare elements in the priority queue. The `comparator` function takes two
12
+ * parameters `a` and `b`,
13
+ */
3
14
  constructor(elements = [], options = {
4
15
  comparator: (a, b) => {
5
16
  if (!(typeof a === 'number' && typeof b === 'number')) {
@@ -16,5 +16,13 @@ import { Heap } from '../heap';
16
16
  * 6. Kth Largest Element in a Data Stream: Used to maintain a min-heap of size K for quickly finding the Kth largest element in stream data
17
17
  */
18
18
  export declare class PriorityQueue<E = any> extends Heap<E> {
19
+ /**
20
+ * The constructor initializes a priority queue with optional elements and options.
21
+ * @param elements - The `elements` parameter is an iterable object that contains the initial
22
+ * elements to be added to the priority queue. It is an optional parameter and if not provided, the
23
+ * priority queue will be initialized as empty.
24
+ * @param [options] - The `options` parameter is an optional object that can be used to customize the
25
+ * behavior of the priority queue. It can contain the following properties:
26
+ */
19
27
  constructor(elements?: Iterable<E>, options?: PriorityQueueOptions<E>);
20
28
  }
@@ -8,6 +8,14 @@ import { Heap } from '../heap';
8
8
  * 6. Kth Largest Element in a Data Stream: Used to maintain a min-heap of size K for quickly finding the Kth largest element in stream data
9
9
  */
10
10
  export class PriorityQueue extends Heap {
11
+ /**
12
+ * The constructor initializes a priority queue with optional elements and options.
13
+ * @param elements - The `elements` parameter is an iterable object that contains the initial
14
+ * elements to be added to the priority queue. It is an optional parameter and if not provided, the
15
+ * priority queue will be initialized as empty.
16
+ * @param [options] - The `options` parameter is an optional object that can be used to customize the
17
+ * behavior of the priority queue. It can contain the following properties:
18
+ */
11
19
  constructor(elements = [], options) {
12
20
  super(elements, options);
13
21
  }