data-structure-typed 1.39.6 → 1.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cjs/data-structures/binary-tree/avl-tree.js +0 -1
  3. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  4. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -3
  5. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +2 -11
  6. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +5 -20
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.js +8 -29
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  10. package/dist/cjs/data-structures/binary-tree/bst.d.ts +1 -1
  11. package/dist/cjs/data-structures/binary-tree/bst.js +3 -3
  12. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  13. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +1 -3
  14. package/dist/cjs/data-structures/binary-tree/rb-tree.js +1 -7
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  16. package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +10 -26
  17. package/dist/cjs/data-structures/binary-tree/segment-tree.js +10 -58
  18. package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
  19. package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +1 -1
  20. package/dist/cjs/data-structures/binary-tree/tree-multiset.js +6 -6
  21. package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
  22. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +5 -24
  23. package/dist/cjs/data-structures/graph/abstract-graph.js +4 -43
  24. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  25. package/dist/cjs/data-structures/graph/directed-graph.d.ts +4 -10
  26. package/dist/cjs/data-structures/graph/directed-graph.js +2 -20
  27. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  28. package/dist/cjs/data-structures/graph/map-graph.d.ts +4 -10
  29. package/dist/cjs/data-structures/graph/map-graph.js +2 -20
  30. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  31. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +1 -8
  32. package/dist/cjs/data-structures/graph/undirected-graph.js +1 -14
  33. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  34. package/dist/cjs/data-structures/hash/coordinate-map.d.ts +0 -1
  35. package/dist/cjs/data-structures/hash/coordinate-map.js +0 -3
  36. package/dist/cjs/data-structures/hash/coordinate-map.js.map +1 -1
  37. package/dist/cjs/data-structures/hash/coordinate-set.d.ts +0 -1
  38. package/dist/cjs/data-structures/hash/coordinate-set.js +0 -3
  39. package/dist/cjs/data-structures/hash/coordinate-set.js.map +1 -1
  40. package/dist/cjs/data-structures/hash/hash-map.d.ts +8 -14
  41. package/dist/cjs/data-structures/hash/hash-map.js +4 -22
  42. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  43. package/dist/cjs/data-structures/hash/hash-table.d.ts +6 -9
  44. package/dist/cjs/data-structures/hash/hash-table.js +0 -9
  45. package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
  46. package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
  47. package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
  48. package/dist/cjs/data-structures/heap/heap.d.ts +12 -6
  49. package/dist/cjs/data-structures/heap/heap.js +40 -22
  50. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  51. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  52. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  53. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +6 -14
  54. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +18 -42
  55. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  56. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +5 -11
  57. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +17 -35
  58. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  59. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +29 -10
  60. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +62 -17
  61. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  62. package/dist/cjs/data-structures/matrix/matrix.d.ts +1 -1
  63. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  64. package/dist/cjs/data-structures/matrix/matrix2d.d.ts +1 -1
  65. package/dist/cjs/data-structures/matrix/navigator.d.ts +4 -4
  66. package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
  67. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  68. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  69. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  70. package/dist/cjs/data-structures/queue/deque.d.ts +8 -12
  71. package/dist/cjs/data-structures/queue/deque.js +31 -43
  72. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  73. package/dist/cjs/data-structures/queue/queue.d.ts +20 -5
  74. package/dist/cjs/data-structures/queue/queue.js +35 -18
  75. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  76. package/dist/cjs/data-structures/stack/stack.d.ts +2 -1
  77. package/dist/cjs/data-structures/stack/stack.js +10 -7
  78. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  79. package/dist/cjs/data-structures/tree/tree.d.ts +3 -9
  80. package/dist/cjs/data-structures/tree/tree.js +3 -21
  81. package/dist/cjs/data-structures/tree/tree.js.map +1 -1
  82. package/dist/cjs/data-structures/trie/trie.d.ts +6 -12
  83. package/dist/cjs/data-structures/trie/trie.js +6 -24
  84. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  85. package/dist/cjs/interfaces/binary-tree.d.ts +1 -1
  86. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +1 -1
  87. package/dist/mjs/data-structures/binary-tree/avl-tree.js +0 -1
  88. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -3
  89. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +2 -11
  90. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +5 -20
  91. package/dist/mjs/data-structures/binary-tree/binary-tree.js +8 -29
  92. package/dist/mjs/data-structures/binary-tree/bst.d.ts +1 -1
  93. package/dist/mjs/data-structures/binary-tree/bst.js +3 -3
  94. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +1 -3
  95. package/dist/mjs/data-structures/binary-tree/rb-tree.js +2 -8
  96. package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +10 -26
  97. package/dist/mjs/data-structures/binary-tree/segment-tree.js +10 -58
  98. package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +1 -1
  99. package/dist/mjs/data-structures/binary-tree/tree-multiset.js +6 -6
  100. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +5 -24
  101. package/dist/mjs/data-structures/graph/abstract-graph.js +8 -47
  102. package/dist/mjs/data-structures/graph/directed-graph.d.ts +4 -10
  103. package/dist/mjs/data-structures/graph/directed-graph.js +4 -22
  104. package/dist/mjs/data-structures/graph/map-graph.d.ts +4 -10
  105. package/dist/mjs/data-structures/graph/map-graph.js +4 -22
  106. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +1 -8
  107. package/dist/mjs/data-structures/graph/undirected-graph.js +2 -15
  108. package/dist/mjs/data-structures/hash/coordinate-map.d.ts +0 -1
  109. package/dist/mjs/data-structures/hash/coordinate-map.js +0 -3
  110. package/dist/mjs/data-structures/hash/coordinate-set.d.ts +0 -1
  111. package/dist/mjs/data-structures/hash/coordinate-set.js +0 -3
  112. package/dist/mjs/data-structures/hash/hash-map.d.ts +8 -14
  113. package/dist/mjs/data-structures/hash/hash-map.js +4 -22
  114. package/dist/mjs/data-structures/hash/hash-table.d.ts +6 -9
  115. package/dist/mjs/data-structures/hash/hash-table.js +0 -9
  116. package/dist/mjs/data-structures/heap/heap.d.ts +12 -6
  117. package/dist/mjs/data-structures/heap/heap.js +44 -26
  118. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +6 -14
  119. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +21 -45
  120. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +5 -11
  121. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +19 -37
  122. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +29 -10
  123. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +62 -17
  124. package/dist/mjs/data-structures/matrix/matrix.d.ts +1 -1
  125. package/dist/mjs/data-structures/matrix/matrix2d.d.ts +1 -1
  126. package/dist/mjs/data-structures/matrix/navigator.d.ts +4 -4
  127. package/dist/mjs/data-structures/queue/deque.d.ts +8 -12
  128. package/dist/mjs/data-structures/queue/deque.js +31 -43
  129. package/dist/mjs/data-structures/queue/queue.d.ts +20 -5
  130. package/dist/mjs/data-structures/queue/queue.js +34 -17
  131. package/dist/mjs/data-structures/stack/stack.d.ts +2 -1
  132. package/dist/mjs/data-structures/stack/stack.js +11 -8
  133. package/dist/mjs/data-structures/tree/tree.d.ts +3 -9
  134. package/dist/mjs/data-structures/tree/tree.js +6 -24
  135. package/dist/mjs/data-structures/trie/trie.d.ts +6 -12
  136. package/dist/mjs/data-structures/trie/trie.js +10 -28
  137. package/dist/mjs/interfaces/binary-tree.d.ts +1 -1
  138. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +1 -1
  139. package/dist/umd/data-structure-typed.min.js +1 -1
  140. package/dist/umd/data-structure-typed.min.js.map +1 -1
  141. package/package.json +5 -5
  142. package/src/data-structures/binary-tree/avl-tree.ts +2 -4
  143. package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -15
  144. package/src/data-structures/binary-tree/binary-tree.ts +17 -42
  145. package/src/data-structures/binary-tree/bst.ts +5 -6
  146. package/src/data-structures/binary-tree/rb-tree.ts +13 -21
  147. package/src/data-structures/binary-tree/segment-tree.ts +16 -83
  148. package/src/data-structures/binary-tree/tree-multiset.ts +8 -9
  149. package/src/data-structures/graph/abstract-graph.ts +21 -67
  150. package/src/data-structures/graph/directed-graph.ts +13 -39
  151. package/src/data-structures/graph/map-graph.ts +7 -32
  152. package/src/data-structures/graph/undirected-graph.ts +9 -26
  153. package/src/data-structures/hash/coordinate-map.ts +0 -4
  154. package/src/data-structures/hash/coordinate-set.ts +0 -4
  155. package/src/data-structures/hash/hash-map.ts +13 -37
  156. package/src/data-structures/hash/hash-table.ts +6 -18
  157. package/src/data-structures/hash/tree-map.ts +2 -1
  158. package/src/data-structures/hash/tree-set.ts +2 -1
  159. package/src/data-structures/heap/heap.ts +58 -30
  160. package/src/data-structures/heap/max-heap.ts +1 -1
  161. package/src/data-structures/heap/min-heap.ts +1 -1
  162. package/src/data-structures/linked-list/doubly-linked-list.ts +26 -60
  163. package/src/data-structures/linked-list/singly-linked-list.ts +24 -49
  164. package/src/data-structures/linked-list/skip-linked-list.ts +73 -25
  165. package/src/data-structures/matrix/matrix.ts +2 -2
  166. package/src/data-structures/matrix/matrix2d.ts +1 -1
  167. package/src/data-structures/matrix/navigator.ts +4 -4
  168. package/src/data-structures/matrix/vector2d.ts +2 -1
  169. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  170. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  171. package/src/data-structures/priority-queue/priority-queue.ts +1 -1
  172. package/src/data-structures/queue/deque.ts +38 -53
  173. package/src/data-structures/queue/queue.ts +38 -20
  174. package/src/data-structures/stack/stack.ts +13 -9
  175. package/src/data-structures/tree/tree.ts +7 -33
  176. package/src/data-structures/trie/trie.ts +14 -40
  177. package/src/interfaces/binary-tree.ts +1 -1
  178. package/src/types/data-structures/binary-tree/bst.ts +1 -1
  179. package/src/types/data-structures/matrix/navigator.ts +1 -1
  180. package/src/types/utils/utils.ts +1 -1
  181. package/src/types/utils/validate-type.ts +2 -2
  182. package/test/integration/avl-tree.test.ts +1 -1
  183. package/test/integration/bst.test.ts +2 -2
  184. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +2 -2
  185. package/test/unit/data-structures/graph/abstract-graph.test.ts +4 -6
  186. package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
  187. package/test/unit/data-structures/graph/map-graph.test.ts +2 -2
  188. package/test/unit/data-structures/hash/coordinate-map.test.ts +1 -1
  189. package/test/unit/data-structures/hash/coordinate-set.test.ts +1 -1
  190. package/test/unit/data-structures/hash/hash-map.test.ts +0 -1
  191. package/test/unit/data-structures/hash/hash-table.test.ts +3 -3
  192. package/test/unit/data-structures/linked-list/skip-list.test.ts +31 -0
  193. package/test/unit/data-structures/queue/queue.test.ts +8 -8
@@ -4,8 +4,6 @@
4
4
  * @class
5
5
  */
6
6
  export class Stack<E = any> {
7
- protected _elements: E[];
8
-
9
7
  /**
10
8
  * The constructor initializes an array of elements, which can be provided as an optional parameter.
11
9
  * @param {E[]} [elements] - The `elements` parameter is an optional parameter of type `E[]`, which represents an array
@@ -16,6 +14,12 @@ export class Stack<E = any> {
16
14
  this._elements = Array.isArray(elements) ? elements : [];
17
15
  }
18
16
 
17
+ protected _elements: E[];
18
+
19
+ get elements(): E[] {
20
+ return this._elements;
21
+ }
22
+
19
23
  /**
20
24
  * The function "fromArray" creates a new Stack object from an array of elements.
21
25
  * @param {E[]} elements - The `elements` parameter is an array of elements of type `E`.
@@ -31,7 +35,7 @@ export class Stack<E = any> {
31
35
  * @returns A boolean value indicating whether the `_elements` array is empty or not.
32
36
  */
33
37
  isEmpty(): boolean {
34
- return this._elements.length === 0;
38
+ return this.elements.length === 0;
35
39
  }
36
40
 
37
41
  /**
@@ -39,7 +43,7 @@ export class Stack<E = any> {
39
43
  * @returns The size of the elements array.
40
44
  */
41
45
  size(): number {
42
- return this._elements.length;
46
+ return this.elements.length;
43
47
  }
44
48
 
45
49
  /**
@@ -49,7 +53,7 @@ export class Stack<E = any> {
49
53
  peek(): E | null {
50
54
  if (this.isEmpty()) return null;
51
55
 
52
- return this._elements[this._elements.length - 1];
56
+ return this.elements[this.elements.length - 1];
53
57
  }
54
58
 
55
59
  /**
@@ -58,7 +62,7 @@ export class Stack<E = any> {
58
62
  * @returns The `push` method is returning the updated `Stack<E>` object.
59
63
  */
60
64
  push(element: E): Stack<E> {
61
- this._elements.push(element);
65
+ this.elements.push(element);
62
66
  return this;
63
67
  }
64
68
 
@@ -70,7 +74,7 @@ export class Stack<E = any> {
70
74
  pop(): E | null {
71
75
  if (this.isEmpty()) return null;
72
76
 
73
- return this._elements.pop() || null;
77
+ return this.elements.pop() || null;
74
78
  }
75
79
 
76
80
  /**
@@ -78,7 +82,7 @@ export class Stack<E = any> {
78
82
  * @returns An array of type E.
79
83
  */
80
84
  toArray(): E[] {
81
- return this._elements.slice();
85
+ return this.elements.slice();
82
86
  }
83
87
 
84
88
  /**
@@ -93,6 +97,6 @@ export class Stack<E = any> {
93
97
  * @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
94
98
  */
95
99
  clone(): Stack<E> {
96
- return new Stack(this._elements.slice());
100
+ return new Stack(this.elements.slice());
97
101
  }
98
102
  }
@@ -1,38 +1,12 @@
1
1
  export class TreeNode<V = any> {
2
- constructor(key: string, value?: V, children?: TreeNode<V>[]) {
3
- this._key = key;
4
- this._value = value || undefined;
5
- this._children = children || [];
6
- }
7
-
8
- private _key: string;
9
-
10
- get key(): string {
11
- return this._key;
12
- }
13
-
14
- set key(value: string) {
15
- this._key = value;
16
- }
17
-
18
- private _value?: V | undefined;
2
+ key: string;
3
+ value?: V | undefined;
4
+ children?: TreeNode<V>[] | undefined;
19
5
 
20
- get value(): V | undefined {
21
- return this._value;
22
- }
23
-
24
- set value(value: V | undefined) {
25
- this._value = value;
26
- }
27
-
28
- private _children?: TreeNode<V>[] | undefined;
29
-
30
- get children(): TreeNode<V>[] | undefined {
31
- return this._children;
32
- }
33
-
34
- set children(value: TreeNode<V>[] | undefined) {
35
- this._children = value;
6
+ constructor(key: string, value?: V, children?: TreeNode<V>[]) {
7
+ this.key = key;
8
+ this.value = value || undefined;
9
+ this.children = children || [];
36
10
  }
37
11
 
38
12
  addChildren(children: TreeNode<V> | TreeNode<V>[]) {
@@ -11,40 +11,14 @@
11
11
  * and a flag indicating whether it's the end of a word.
12
12
  */
13
13
  export class TrieNode {
14
- constructor(key: string) {
15
- this._key = key;
16
- this._isEnd = false;
17
- this._children = new Map<string, TrieNode>();
18
- }
19
-
20
- private _key;
21
-
22
- get key(): string {
23
- return this._key;
24
- }
25
-
26
- set key(v: string) {
27
- this._key = v;
28
- }
29
-
30
- protected _children: Map<string, TrieNode>;
31
-
32
- get children(): Map<string, TrieNode> {
33
- return this._children;
34
- }
35
-
36
- set children(v: Map<string, TrieNode>) {
37
- this._children = v;
38
- }
39
-
40
- protected _isEnd: boolean;
41
-
42
- get isEnd(): boolean {
43
- return this._isEnd;
44
- }
14
+ key: string;
15
+ children: Map<string, TrieNode>;
16
+ isEnd: boolean;
45
17
 
46
- set isEnd(v: boolean) {
47
- this._isEnd = v;
18
+ constructor(key: string) {
19
+ this.key = key;
20
+ this.isEnd = false;
21
+ this.children = new Map<string, TrieNode>();
48
22
  }
49
23
  }
50
24
 
@@ -52,8 +26,6 @@ export class TrieNode {
52
26
  * Trie represents a Trie data structure. It provides basic Trie operations and additional methods.
53
27
  */
54
28
  export class Trie {
55
- private readonly _caseSensitive: boolean;
56
-
57
29
  constructor(words?: string[], caseSensitive = true) {
58
30
  this._root = new TrieNode('');
59
31
  this._caseSensitive = caseSensitive;
@@ -64,16 +36,18 @@ export class Trie {
64
36
  }
65
37
  }
66
38
 
39
+ protected _caseSensitive: boolean;
40
+
41
+ get caseSensitive(): boolean {
42
+ return this._caseSensitive;
43
+ }
44
+
67
45
  protected _root: TrieNode;
68
46
 
69
47
  get root() {
70
48
  return this._root;
71
49
  }
72
50
 
73
- set root(v: TrieNode) {
74
- this._root = v;
75
- }
76
-
77
51
  /**
78
52
  * Add a word to the Trie structure.
79
53
  * @param {string} word - The word to add.
@@ -277,7 +251,7 @@ export class Trie {
277
251
  return words;
278
252
  }
279
253
 
280
- private _caseProcess(str: string) {
254
+ protected _caseProcess(str: string) {
281
255
  if (!this._caseSensitive) {
282
256
  str = str.toLowerCase(); // Convert str to lowercase if case-insensitive
283
257
  }
@@ -1,5 +1,5 @@
1
1
  import {BinaryTreeNode} from '../data-structures';
2
- import {BinaryTreeDeletedResult, BTNKey, BinaryTreeNodeNested, BTNCallback} from '../types';
2
+ import {BinaryTreeDeletedResult, BinaryTreeNodeNested, BTNCallback, BTNKey} from '../types';
3
3
 
4
4
  export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>> {
5
5
  createNode(key: BTNKey, value?: N['value']): N;
@@ -1,5 +1,5 @@
1
1
  import {BSTNode} from '../../../data-structures';
2
- import type {BTNKey, BinaryTreeOptions} from './binary-tree';
2
+ import type {BinaryTreeOptions, BTNKey} from './binary-tree';
3
3
 
4
4
  export type BSTComparator = (a: BTNKey, b: BTNKey) => number;
5
5
 
@@ -1,6 +1,6 @@
1
1
  export type Direction = 'up' | 'right' | 'down' | 'left';
2
2
 
3
- export type Turning = {[key in Direction]: Direction};
3
+ export type Turning = { [key in Direction]: Direction };
4
4
 
5
5
  export type NavigatorParams<T = any> = {
6
6
  matrix: T[][];
@@ -1,5 +1,5 @@
1
1
  export type ToThunkFn = () => ReturnType<TrlFn>;
2
- export type Thunk = () => ReturnType<ToThunkFn> & {__THUNK__: symbol};
2
+ export type Thunk = () => ReturnType<ToThunkFn> & { __THUNK__: symbol };
3
3
  export type TrlFn = (...args: any[]) => any;
4
4
  export type TrlAsyncFn = (...args: any[]) => any;
5
5
 
@@ -1,6 +1,6 @@
1
- export type KeyValueObject = {[key: string]: any};
1
+ export type KeyValueObject = { [key: string]: any };
2
2
 
3
- export type KeyValueObjectWithKey = {[key: string]: any; key: string | number | symbol};
3
+ export type KeyValueObjectWithKey = { [key: string]: any; key: string | number | symbol };
4
4
 
5
5
  export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
6
6
 
@@ -31,7 +31,7 @@ describe('AVL Tree Test', () => {
31
31
  expect(lesserSum).toBe(45);
32
32
 
33
33
  // node15 has type problem. After the uniform design, the generics of containers (DirectedGraph, BST) are based on the type of value. However, this design has a drawback: when I attempt to inherit from the Vertex or BSTNode classes, the types of the results obtained by all methods are those of the parent class.
34
- expect(node15?.val).toBe(15);
34
+ expect(node15?.value).toBe(15);
35
35
 
36
36
  const dfs = tree.dfs(node => node, 'in');
37
37
  expect(dfs[0].key).toBe(1);
@@ -23,7 +23,7 @@ describe('Individual package BST operations test', () => {
23
23
  const nodeId10 = bst.get(10);
24
24
  expect(nodeId10?.key).toBe(10);
25
25
 
26
- const nodeVal9 = bst.get(9, node => node.val);
26
+ const nodeVal9 = bst.get(9, node => node.value);
27
27
  expect(nodeVal9?.key).toBe(9);
28
28
 
29
29
  const leftMost = bst.getLeftMost();
@@ -230,7 +230,7 @@ describe('Individual package BST operations test', () => {
230
230
  expect(leftMost?.key).toBe(1);
231
231
 
232
232
  const node15 = objBST.get(15);
233
- expect(node15?.val).toEqual({key: 15, keyA: 15});
233
+ expect(node15?.value).toEqual({key: 15, keyA: 15});
234
234
  const minNodeBySpecificNode = node15 && objBST.getLeftMost(node15);
235
235
  expect(minNodeBySpecificNode?.key).toBe(12);
236
236
 
@@ -286,8 +286,8 @@ function loopLowerBoundTests(bit: BinaryIndexedTree, values: number[]) {
286
286
 
287
287
  describe('', () => {
288
288
  class NumArrayDC {
289
- private _tree: BinaryIndexedTree;
290
- private readonly _nums: number[];
289
+ protected _tree: BinaryIndexedTree;
290
+ protected readonly _nums: number[];
291
291
 
292
292
  constructor(nums: number[]) {
293
293
  this._nums = nums;
@@ -19,7 +19,6 @@ class MyEdge<E = any> extends AbstractEdge<E> {
19
19
  this.src = srcOrV1;
20
20
  this.dest = destOrV2;
21
21
  this.data = value;
22
- this._setHashCode('');
23
22
  }
24
23
  }
25
24
 
@@ -54,12 +53,12 @@ class MyGraph<
54
53
  }
55
54
 
56
55
  edgesOf(vertexOrKey: VO | VertexKey): EO[] {
57
- const a = typeof vertexOrKey === "string" ? vertexOrKey : "a";
56
+ const a = typeof vertexOrKey === 'string' ? vertexOrKey : 'a';
58
57
  return [new MyEdge(a, 'b') as EO];
59
58
  }
60
59
 
61
60
  getNeighbors(vertexOrKey: VO | VertexKey): VO[] {
62
- const a = typeof vertexOrKey === "string" ? vertexOrKey : "a";
61
+ const a = typeof vertexOrKey === 'string' ? vertexOrKey : 'a';
63
62
  return [new MyVertex(a, 'b') as VO];
64
63
  }
65
64
 
@@ -75,8 +74,7 @@ class MyGraph<
75
74
  describe('AbstractGraph Operation Test', () => {
76
75
  const myGraph: MyGraph<number, string> = new MyGraph<number, string>();
77
76
 
78
- beforeEach(() => {
79
- });
77
+ beforeEach(() => {});
80
78
  it('should edge cases', function () {
81
79
  myGraph.addVertex('A', 1);
82
80
  myGraph.addVertex('B', 2);
@@ -97,6 +95,6 @@ describe('AbstractGraph Operation Test', () => {
97
95
  eAB!.value = eAB.value;
98
96
  const hs = eAB.hashCode;
99
97
 
100
- expect(hs).toBe('');
98
+ expect(hs.length).toBe(36);
101
99
  });
102
100
  });
@@ -98,7 +98,7 @@ class MyVertex<V = any> extends DirectedVertex<V> {
98
98
  this._data = value;
99
99
  }
100
100
 
101
- private _data: V | undefined;
101
+ protected _data: V | undefined;
102
102
 
103
103
  get data(): V | undefined {
104
104
  return this._data;
@@ -115,7 +115,7 @@ class MyEdge<E = any> extends DirectedEdge<E> {
115
115
  this._data = value;
116
116
  }
117
117
 
118
- private _data: E | undefined;
118
+ protected _data: E | undefined;
119
119
 
120
120
  get data(): E | undefined {
121
121
  return this._data;
@@ -141,11 +141,11 @@ class MyDirectedGraph<
141
141
  }
142
142
 
143
143
  setInEdgeMap(value: Map<VO, EO[]>) {
144
- super._setInEdgeMap(value);
144
+ this._inEdgeMap = value;
145
145
  }
146
146
 
147
147
  setOutEdgeMap(value: Map<VO, EO[]>) {
148
- super._setOutEdgeMap(value);
148
+ this._outEdgeMap = value;
149
149
  }
150
150
  }
151
151
 
@@ -88,8 +88,8 @@ describe('MapGraph', () => {
88
88
  const edgeAB = new MapEdge('A', 'B', 50, 'Edge from A to B');
89
89
  const edgeBC = new MapEdge('B', 'C', 60, 'Edge from B to C');
90
90
 
91
- mapGraph.origin = mapGraph.origin;
92
- mapGraph.bottomRight = mapGraph.bottomRight;
91
+ expect(mapGraph.origin).toEqual([0, 0]);
92
+ expect(mapGraph.bottomRight).toEqual([100, 100]);
93
93
 
94
94
  mapGraph.addVertex(locationA);
95
95
  mapGraph.addVertex(locationB);
@@ -57,7 +57,7 @@ describe('CoordinateMap', () => {
57
57
  class MyCoordinateMap<V = any> extends CoordinateMap<V> {
58
58
  constructor(joint?: string) {
59
59
  super(joint);
60
- this._setJoint((joint += '-'));
60
+ this._joint = joint += '-';
61
61
  }
62
62
  }
63
63
 
@@ -44,7 +44,7 @@ describe('MyCoordinateSet', () => {
44
44
  class MyCoordinateSet extends CoordinateSet {
45
45
  constructor(joint?: string) {
46
46
  super(joint);
47
- this._setJoint((joint += '-'));
47
+ this._joint = joint += '-';
48
48
  }
49
49
  }
50
50
 
@@ -28,7 +28,6 @@ describe('HashMap', () => {
28
28
 
29
29
  it('should handle key collisions', () => {
30
30
  // Force a collision by setting two different keys to the same bucket
31
- hashMap.hashFn = () => 0; // Override hash function to return the same index
32
31
  hashMap.set('key1', 1);
33
32
  hashMap.set('key2', 2);
34
33
 
@@ -15,9 +15,9 @@ describe('HashNode', () => {
15
15
  describe('HashTable', () => {
16
16
  it('should initialize with default capacity', () => {
17
17
  const hashTable = new HashTable<string, string>();
18
- hashTable.capacity = hashTable.capacity;
19
- hashTable.buckets = hashTable.buckets;
20
- hashTable.hashFn = hashTable.hashFn;
18
+ expect(hashTable.capacity).toBe(16);
19
+ expect(hashTable.buckets).toEqual(new Array(16).fill(null));
20
+ expect(hashTable.hashFn('a')).toBe(6);
21
21
  expect(hashTable.capacity).toBe(16);
22
22
  expect(hashTable.size).toBe(0);
23
23
  expect(hashTable.buckets.length).toBe(16);
@@ -53,3 +53,34 @@ describe('SkipList', () => {
53
53
  expect(skipList.get(4)).toBe('Four');
54
54
  });
55
55
  });
56
+
57
+ describe('SkipList', () => {
58
+ let skipList: SkipList<number, string>;
59
+
60
+ beforeEach(() => {
61
+ skipList = new SkipList();
62
+ skipList.add(1, 'One');
63
+ skipList.add(2, 'Two');
64
+ skipList.add(3, 'Three');
65
+ skipList.add(4, 'Four');
66
+ });
67
+
68
+ test('getFirst() should return the getFirst element', () => {
69
+ expect(skipList.getFirst()).toBe('One');
70
+ });
71
+
72
+ test('getLast() should return the getLast element', () => {
73
+ expect(skipList.getLast()).toBe('Four');
74
+ });
75
+
76
+ test('higher(key) should return the getFirst element greater than the given key', () => {
77
+ expect(skipList.higher(2)).toBe('Three');
78
+ expect(skipList.higher(3)).toBe('Four');
79
+ expect(skipList.higher(4)).toBeUndefined();
80
+ });
81
+
82
+ test('lower(key) should return the getLast element less than the given key', () => {
83
+ expect(skipList.lower(2)).toBe('One');
84
+ expect(skipList.lower(1)).toBe(null);
85
+ });
86
+ });
@@ -1,4 +1,4 @@
1
- import {SkipQueue, Queue} from '../../../../src';
1
+ import {LinkedListQueue, Queue} from '../../../../src';
2
2
  import {bigO, magnitude} from '../../../utils';
3
3
  import {isDebugTest} from '../../../config';
4
4
 
@@ -168,11 +168,11 @@ describe('Queue', () => {
168
168
  expect(values).toEqual([1, 2, 3]);
169
169
  });
170
170
  });
171
- describe('SkipQueue', () => {
172
- let queue: SkipQueue<string>;
171
+ describe('LinkedListQueue', () => {
172
+ let queue: LinkedListQueue<string>;
173
173
 
174
174
  beforeEach(() => {
175
- queue = new SkipQueue<string>();
175
+ queue = new LinkedListQueue<string>();
176
176
  });
177
177
 
178
178
  it('should enqueue elements to the end of the queue', () => {
@@ -197,7 +197,7 @@ describe('SkipQueue', () => {
197
197
  expect(queue.peek()).toBe('A');
198
198
  });
199
199
 
200
- // Add more test cases for other methods of SkipQueue.
200
+ // Add more test cases for other methods of LinkedListQueue.
201
201
  });
202
202
 
203
203
  describe('Queue Performance Test', () => {
@@ -228,16 +228,16 @@ describe('Queue Performance Test', () => {
228
228
  expect(performance.now() - startTime2).toBeLessThan(bigO.CUBED * 100);
229
229
  });
230
230
 
231
- it('should numeric SkipQueue be efficient', function () {
231
+ it('should numeric LinkedListQueue be efficient', function () {
232
232
  const startTime = performance.now();
233
- const queue = new SkipQueue<number>();
233
+ const queue = new LinkedListQueue<number>();
234
234
  for (let i = 0; i < dataSize; i++) {
235
235
  queue.enqueue(i);
236
236
  }
237
237
  for (let i = 0; i < dataSize; i++) {
238
238
  queue.dequeue();
239
239
  }
240
- console.log(`SkipQueue Performance Test: ${performance.now() - startTime} ms`);
240
+ console.log(`LinkedListQueue Performance Test: ${performance.now() - startTime} ms`);
241
241
  expect(performance.now() - startTime).toBeLessThan(bigO.LINEAR * 100);
242
242
  });
243
243
  });