diff --git a/.eslintrc.js b/.eslintrc.js index 05afdb4..701ce2c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -42,7 +42,9 @@ module.exports = { "{}": false } } - ] + ], + "brace-style": ["error", "1tbs", { "allowSingleLine": true }], + "object-curly-spacing": ["error", "always"] }, "settings": { "import/parsers": { diff --git a/.prettierrc.js b/.prettierrc.js index 124f598..8f951b7 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,6 +1,6 @@ module.exports = { "arrowParens": "avoid", - "bracketSpacing": false, + "bracketSpacing": true, "htmlWhitespaceSensitivity": "css", "insertPragma": false, "bracketSameLine": true, diff --git a/src/data-structures/binary-tree/avl-tree.ts b/src/data-structures/binary-tree/avl-tree.ts index 41da140..d218229 100644 --- a/src/data-structures/binary-tree/avl-tree.ts +++ b/src/data-structures/binary-tree/avl-tree.ts @@ -21,8 +21,7 @@ export class AVLTreeNode = AVLTreeNodeNeste export class AVLTree = AVLTreeNode>> extends BST - implements IBinaryTree -{ + implements IBinaryTree { /** * This is a constructor function for an AVL tree data structure in TypeScript. * @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the @@ -114,7 +113,7 @@ export class AVLTree = AVLTreeNode = AVLTreeNode = BinaryTreeNode } } + /** + * The `print` function is used to display a binary tree structure in a visually appealing way. + * @param {N | null | undefined} root - The `root` parameter is of type `BTNKey | N | null | + * undefined`. It represents the root node of a binary tree. The root node can have one of the + * following types: + */ + print(beginRoot: BTNKey | N | null | undefined = this.root): void { + beginRoot = this.ensureNotKey(beginRoot); + if (!beginRoot) return; + + const display = (root: N | null | undefined): void => { + const [lines, , ,] = _displayAux(root); + for (const line of lines) { + console.log(line); + } + }; + + const _displayAux = (node: N | null | undefined): [string[], number, number, number] => { + if (!this.isRealNode(node)) { + return [[], 0, 0, 0]; + } + + if (this.isRealNode(node) && !this.isRealNode(node.right) && !this.isRealNode(node.left)) { + const line = `${node.key}`; + const width = line.length; + const height = 1; + const middle = Math.floor(width / 2); + return [[line], width, height, middle]; + } + + if (this.isRealNode(node) && !this.isRealNode(node.right)) { + const [lines, n, p, x] = _displayAux(node.left); + const s = `${node.key}`; + const u = s.length; + const first_line = ' '.repeat(x + 1) + '_'.repeat(n - x - 1) + s; + const second_line = ' '.repeat(x) + '/' + ' '.repeat(n - x - 1 + u); + const shifted_lines = lines.map(line => line + ' '.repeat(u)); + return [[first_line, second_line, ...shifted_lines], n + u, p + 2, n + Math.floor(u / 2)]; + } + + if (this.isRealNode(node) && !this.isRealNode(node.left)) { + const [lines, n, p, u] = _displayAux(node.right); + const s = `${node.key}`; + const x = s.length; + const first_line = s + '_'.repeat(x) + ' '.repeat(n - x); + const second_line = ' '.repeat(u + x) + '\\' + ' '.repeat(n - x - 1); + const shifted_lines = lines.map(line => ' '.repeat(u) + line); + return [[first_line, second_line, ...shifted_lines], n + x, p + 2, Math.floor(u / 2)]; + } + + const [left, n, p, x] = _displayAux(node.left); + const [right, m, q, y] = _displayAux(node.right); + const s = `${node.key}`; + const u = s.length; + const first_line = ' '.repeat(x + 1) + '_'.repeat(n - x - 1) + s + '_'.repeat(y) + ' '.repeat(m - y); + const second_line = ' '.repeat(x) + '/' + ' '.repeat(n - x - 1 + u + y) + '\\' + ' '.repeat(m - y - 1); + if (p < q) { + left.push(...new Array(q - p).fill(' '.repeat(n))); + } else if (q < p) { + right.push(...new Array(p - q).fill(' '.repeat(m))); + } + const zipped_lines = left.map((a, i) => a + ' '.repeat(u) + right[i]); + return [[first_line, second_line, ...zipped_lines], n + m + u, Math.max(p, q) + 2, n + Math.floor(u / 2)]; + }; + + display(beginRoot); + } + protected _defaultOneParamCallback = (node: N) => node.key; /** @@ -1801,73 +1869,4 @@ export class BinaryTree = BinaryTreeNode } this._root = v; } - - - /** - * The `print` function is used to display a binary tree structure in a visually appealing way. - * @param {N | null | undefined} root - The `root` parameter is of type `BTNKey | N | null | - * undefined`. It represents the root node of a binary tree. The root node can have one of the - * following types: - */ - print(beginRoot: BTNKey | N | null | undefined = this.root): void { - beginRoot = this.ensureNotKey(beginRoot); - if (!beginRoot) return; - - const display = (root: N | null | undefined): void => { - const [lines, , ,] = _displayAux(root); - for (const line of lines) { - console.log(line); - } - }; - - const _displayAux = (node: N | null | undefined): [string[], number, number, number] => { - if (!this.isRealNode(node)) { - return [[], 0, 0, 0]; - } - - if (this.isRealNode(node) && !this.isRealNode(node.right) && !this.isRealNode(node.left)) { - const line = `${node.key}`; - const width = line.length; - const height = 1; - const middle = Math.floor(width / 2); - return [[line], width, height, middle]; - } - - if (this.isRealNode(node) && !this.isRealNode(node.right)) { - const [lines, n, p, x] = _displayAux(node.left); - const s = `${node.key}`; - const u = s.length; - const first_line = ' '.repeat(x + 1) + '_'.repeat(n - x - 1) + s; - const second_line = ' '.repeat(x) + '/' + ' '.repeat(n - x - 1 + u); - const shifted_lines = lines.map(line => line + ' '.repeat(u)); - return [[first_line, second_line, ...shifted_lines], n + u, p + 2, n + Math.floor(u / 2)]; - } - - if (this.isRealNode(node) && !this.isRealNode(node.left)) { - const [lines, n, p, u] = _displayAux(node.right); - const s = `${node.key}`; - const x = s.length; - const first_line = s + '_'.repeat(x) + ' '.repeat(n - x); - const second_line = ' '.repeat(u + x) + '\\' + ' '.repeat(n - x - 1); - const shifted_lines = lines.map(line => ' '.repeat(u) + line); - return [[first_line, second_line, ...shifted_lines], n + x, p + 2, Math.floor(u / 2)]; - } - - const [left, n, p, x] = _displayAux(node.left); - const [right, m, q, y] = _displayAux(node.right); - const s = `${node.key}`; - const u = s.length; - const first_line = ' '.repeat(x + 1) + '_'.repeat(n - x - 1) + s + '_'.repeat(y) + ' '.repeat(m - y); - const second_line = ' '.repeat(x) + '/' + ' '.repeat(n - x - 1 + u + y) + '\\' + ' '.repeat(m - y - 1); - if (p < q) { - left.push(...new Array(q - p).fill(' '.repeat(n))); - } else if (q < p) { - right.push(...new Array(p - q).fill(' '.repeat(m))); - } - const zipped_lines = left.map((a, i) => a + ' '.repeat(u) + right[i]); - return [[first_line, second_line, ...zipped_lines], n + m + u, Math.max(p, q) + 2, n + Math.floor(u / 2)]; - }; - - display(beginRoot); - } } diff --git a/src/data-structures/binary-tree/bst.ts b/src/data-structures/binary-tree/bst.ts index 0295b7d..a2e9b48 100644 --- a/src/data-structures/binary-tree/bst.ts +++ b/src/data-structures/binary-tree/bst.ts @@ -12,7 +12,7 @@ import {IBinaryTree} from '../../interfaces'; import {Queue} from '../queue'; export class BSTNode = BSTNodeNested> extends BinaryTreeNode { - override parent?: N ; + override parent?: N; constructor(key: BTNKey, value?: V) { super(key, value); @@ -21,7 +21,7 @@ export class BSTNode = BSTNodeNested> extend this._right = undefined; } - protected override _left?: N ; + protected override _left?: N; /** * Get the left child node. @@ -42,7 +42,7 @@ export class BSTNode = BSTNodeNested> extend } - protected override _right?: N ; + protected override _right?: N; /** * Get the right child node. @@ -83,7 +83,7 @@ export class BST = BSTNode> } } - protected override _root?: N ; + protected override _root?: N; /** * Get the root node of the binary tree. @@ -113,7 +113,7 @@ export class BST = BSTNode> /** * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n). * Space Complexity: O(1) - Constant space is used. - * + * * The `add` function adds a new node to a binary search tree based on the provided key and value. * @param {BTNKey | N | null | undefined} keyOrNode - The `keyOrNode` parameter can be one of the * following types: @@ -193,7 +193,7 @@ export class BST = BSTNode> * Time Complexity: O(n log n) - Adding each element individually in a balanced tree. * Space Complexity: O(n) - Additional space is required for the sorted array. */ - + /** * Time Complexity: O(n log n) - Adding each element individually in a balanced tree. * Space Complexity: O(n) - Additional space is required for the sorted array. @@ -228,12 +228,12 @@ export class BST = BSTNode> if (!isBalanceAdd || !hasNoUndefined(keysOrNodes)) { return super.addMany(keysOrNodes, data).map(n => n ?? undefined); } - + const inserted: (N | undefined)[] = []; const combinedArr: [BTNKey | N, V][] = keysOrNodes.map( (value: BTNKey | N, index) => [value, data?.[index]] as [BTNKey | N, V] ); - + let sorted = []; function _isNodeOrUndefinedTuple(arr: [BTNKey | N, V][]): arr is [N, V][] { @@ -344,7 +344,7 @@ export class BST = BSTNode> const _dfs = (cur: N): N | undefined => { if (cur.key === key) return cur; if (!cur.left && !cur.right) return; - + if (this._compare(cur.key, key) === CP.gt && cur.left) return _dfs(cur.left); if (this._compare(cur.key, key) === CP.lt && cur.right) return _dfs(cur.right); }; @@ -380,7 +380,7 @@ export class BST = BSTNode> * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key. * Space Complexity: O(log n) - Space for the recursive call stack in the worst case. */ - + /** * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key. * Space Complexity: O(log n) - Space for the recursive call stack in the worst case. diff --git a/src/data-structures/binary-tree/rb-tree.ts b/src/data-structures/binary-tree/rb-tree.ts index b9cc1e3..1658c8c 100644 --- a/src/data-structures/binary-tree/rb-tree.ts +++ b/src/data-structures/binary-tree/rb-tree.ts @@ -12,8 +12,8 @@ import { BTNKey, IterationType, RBTNColor, - RedBlackTreeNodeNested, - RBTreeOptions + RBTreeOptions, + RedBlackTreeNodeNested } from '../../types'; import {BST, BSTNode} from "./bst"; import {IBinaryTree} from "../../interfaces"; @@ -21,6 +21,7 @@ import {BinaryTreeNode} from "./binary-tree"; export class RedBlackTreeNode = RedBlackTreeNodeNested> extends BSTNode { color: RBTNColor; + constructor(key: BTNKey, value?: V, color: RBTNColor = RBTNColor.BLACK) { super(key, value); this.color = color; @@ -36,8 +37,9 @@ export class RedBlackTreeNode = RedBla */ export class RedBlackTree = RedBlackTreeNode>> extends BST - implements IBinaryTree -{ + implements IBinaryTree { + + NIL: N = new RedBlackTreeNode(NaN) as unknown as N; /** * The constructor function initializes a Red-Black Tree with an optional set of options. @@ -61,8 +63,6 @@ export class RedBlackTree = RedBlackTr return this._size; } - NIL: N = new RedBlackTreeNode(NaN) as unknown as N; - /** * Time Complexity: O(log n) on average (where n is the number of nodes in the tree) * Space Complexity: O(1) @@ -83,7 +83,7 @@ export class RedBlackTree = RedBlackTr let node: N; if (this.isNodeKey(keyOrNode)) { node = this.createNode(keyOrNode, value, RBTNColor.RED); - } else if(keyOrNode instanceof RedBlackTreeNode) { + } else if (keyOrNode instanceof RedBlackTreeNode) { node = keyOrNode; } else if (keyOrNode === null) { return; @@ -226,21 +226,21 @@ export class RedBlackTree = RedBlackTr callback?: C, beginRoot?: N | undefined, iterationType?: IterationType - ): N | undefined; + ): N | undefined; getNode>( identifier: N | undefined, callback?: C, beginRoot?: N | undefined, iterationType?: IterationType - ): N | undefined; + ): N | undefined; getNode>( identifier: ReturnType, callback: C, beginRoot?: N | undefined, iterationType?: IterationType - ): N | undefined; + ): N | undefined; /** * Time Complexity: O(log n) on average (where n is the number of nodes in the tree) diff --git a/src/data-structures/binary-tree/tree-multimap.ts b/src/data-structures/binary-tree/tree-multimap.ts index 5207159..f086a93 100644 --- a/src/data-structures/binary-tree/tree-multimap.ts +++ b/src/data-structures/binary-tree/tree-multimap.ts @@ -160,52 +160,6 @@ export class TreeMultimap = TreeMultim * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory. */ - /** - * Time Complexity: O(1) - constant time, as it performs basic pointer assignments. - * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory. - * - * The function adds a new node to a binary tree, either as the left child or the right child of a - * given parent node. - * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be - * added to the binary tree. It can be of type `N` (which represents a node in the binary tree) or - * `undefined` if there is no node to add. - * @param {BTNKey | N | undefined} parent - The `parent` parameter represents the parent node to - * which the new node will be added as a child. It can be either a node object (`N`) or a key value - * (`BTNKey`). - * @returns The method `_addTo` returns either the `parent.left` or `parent.right` node that was - * added, or `undefined` if no node was added. - */ - protected override _addTo(newNode: N | undefined, parent: BTNKey | N | undefined): N | undefined { - parent = this.ensureNotKey(parent); - if (parent) { - if (parent.left === undefined) { - parent.left = newNode; - if (newNode !== undefined) { - this._size = this.size + 1; - this._count += newNode.count; - } - - return parent.left; - } else if (parent.right === undefined) { - parent.right = newNode; - if (newNode !== undefined) { - this._size = this.size + 1; - this._count += newNode.count; - } - return parent.right; - } else { - return; - } - } else { - return; - } - } - - /** - * Time Complexity: O(k log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each. - * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size. - */ - /** * Time Complexity: O(k log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each. * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size. @@ -241,8 +195,8 @@ export class TreeMultimap = TreeMultim } /** - * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node. - * Space Complexity: O(n) - linear space, as it creates an array to store the sorted nodes. + * Time Complexity: O(k log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each. + * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size. */ /** @@ -295,8 +249,8 @@ export class TreeMultimap = TreeMultim } /** - * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (AVLTree) has logarithmic time complexity. - * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size. + * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node. + * Space Complexity: O(n) - linear space, as it creates an array to store the sorted nodes. */ /** @@ -330,7 +284,7 @@ export class TreeMultimap = TreeMultim if (!curr) return deletedResult; const parent: N | undefined = curr?.parent ? curr.parent : undefined; - let needBalanced: N | undefined = undefined,orgCurrent: N | undefined = curr; + let needBalanced: N | undefined = undefined, orgCurrent: N | undefined = curr; if (curr.count > 1 && !ignoreCount) { curr.count--; @@ -377,6 +331,11 @@ export class TreeMultimap = TreeMultim return deletedResult; } + /** + * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (AVLTree) has logarithmic time complexity. + * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size. + */ + /** * The clear() function clears the contents of a data structure and sets the count to zero. */ @@ -385,6 +344,47 @@ export class TreeMultimap = TreeMultim this._count = 0; } + /** + * Time Complexity: O(1) - constant time, as it performs basic pointer assignments. + * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory. + * + * The function adds a new node to a binary tree, either as the left child or the right child of a + * given parent node. + * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be + * added to the binary tree. It can be of type `N` (which represents a node in the binary tree) or + * `undefined` if there is no node to add. + * @param {BTNKey | N | undefined} parent - The `parent` parameter represents the parent node to + * which the new node will be added as a child. It can be either a node object (`N`) or a key value + * (`BTNKey`). + * @returns The method `_addTo` returns either the `parent.left` or `parent.right` node that was + * added, or `undefined` if no node was added. + */ + protected override _addTo(newNode: N | undefined, parent: BTNKey | N | undefined): N | undefined { + parent = this.ensureNotKey(parent); + if (parent) { + if (parent.left === undefined) { + parent.left = newNode; + if (newNode !== undefined) { + this._size = this.size + 1; + this._count += newNode.count; + } + + return parent.left; + } else if (parent.right === undefined) { + parent.right = newNode; + if (newNode !== undefined) { + this._size = this.size + 1; + this._count += newNode.count; + } + return parent.right; + } else { + return; + } + } else { + return; + } + } + /** * The `_swap` function swaps the key, value, count, and height properties between two nodes. * @param {BTNKey | N | undefined} srcNode - The `srcNode` parameter represents the source node from @@ -394,7 +394,7 @@ export class TreeMultimap = TreeMultim * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined` * if either `srcNode` or `destNode` is undefined. */ - protected _swap(srcNode: BTNKey | N | undefined, destNode:BTNKey | N | undefined): N | undefined{ + protected _swap(srcNode: BTNKey | N | undefined, destNode: BTNKey | N | undefined): N | undefined { srcNode = this.ensureNotKey(srcNode); destNode = this.ensureNotKey(destNode); if (srcNode && destNode) { @@ -416,6 +416,6 @@ export class TreeMultimap = TreeMultim return destNode; } - return undefined; + return undefined; } } \ No newline at end of file diff --git a/src/data-structures/graph/abstract-graph.ts b/src/data-structures/graph/abstract-graph.ts index 26b16fa..dbcafbd 100644 --- a/src/data-structures/graph/abstract-graph.ts +++ b/src/data-structures/graph/abstract-graph.ts @@ -64,8 +64,7 @@ export abstract class AbstractGraph< E = any, VO extends AbstractVertex = AbstractVertex, EO extends AbstractEdge = AbstractEdge -> implements IGraph -{ +> implements IGraph { protected _vertices: Map = new Map(); get vertices(): Map { @@ -301,7 +300,7 @@ export abstract class AbstractGraph< return []; } - const stack: {vertex: VO; path: VO[]}[] = []; + const stack: { vertex: VO; path: VO[] }[] = []; stack.push({vertex: vertex1, path: [vertex1]}); while (stack.length > 0) { @@ -496,7 +495,7 @@ export abstract class AbstractGraph< * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm). */ - /** + /** * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization). * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm). * @@ -615,14 +614,14 @@ export abstract class AbstractGraph< } getMinDist && - distMap.forEach((d, v) => { - if (v !== srcVertex) { - if (d < minDist) { - minDist = d; - if (genPaths) minDest = v; - } + distMap.forEach((d, v) => { + if (v !== srcVertex) { + if (d < minDist) { + minDist = d; + if (genPaths) minDest = v; } - }); + } + }); genPaths && getPaths(minDest); @@ -643,7 +642,7 @@ export abstract class AbstractGraph< * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap). */ - /** + /** * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap). * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap). * @@ -692,7 +691,7 @@ export abstract class AbstractGraph< if (vertexOrKey instanceof AbstractVertex) distMap.set(vertexOrKey, Infinity); } - const heap = new PriorityQueue<{key: number; value: VO}>({comparator: (a, b) => a.key - b.key}); + const heap = new PriorityQueue<{ key: number; value: VO }>({comparator: (a, b) => a.key - b.key}); heap.add({key: 0, value: srcVertex}); distMap.set(srcVertex, 0); @@ -924,7 +923,7 @@ export abstract class AbstractGraph< * `predecessor` property is a 2D array of vertices (or `null`) representing the predecessor vertices in the shortest * path between vertices in the */ - floydWarshall(): {costs: number[][]; predecessor: (VO | null)[][]} { + floydWarshall(): { costs: number[][]; predecessor: (VO | null)[][] } { const idAndVertices = [...this._vertices]; const n = idAndVertices.length; diff --git a/src/data-structures/graph/directed-graph.ts b/src/data-structures/graph/directed-graph.ts index ff9f524..a06d066 100644 --- a/src/data-structures/graph/directed-graph.ts +++ b/src/data-structures/graph/directed-graph.ts @@ -46,14 +46,13 @@ export class DirectedEdge extends AbstractEdge { } export class DirectedGraph< - V = any, - E = any, - VO extends DirectedVertex = DirectedVertex, - EO extends DirectedEdge = DirectedEdge - > + V = any, + E = any, + VO extends DirectedVertex = DirectedVertex, + EO extends DirectedEdge = DirectedEdge +> extends AbstractGraph - implements IGraph -{ + implements IGraph { /** * The constructor function initializes an instance of a class. */ diff --git a/src/data-structures/graph/undirected-graph.ts b/src/data-structures/graph/undirected-graph.ts index 21180f6..548a8c8 100644 --- a/src/data-structures/graph/undirected-graph.ts +++ b/src/data-structures/graph/undirected-graph.ts @@ -43,14 +43,13 @@ export class UndirectedEdge extends AbstractEdge { } export class UndirectedGraph< - V = any, - E = any, - VO extends UndirectedVertex = UndirectedVertex, - EO extends UndirectedEdge = UndirectedEdge - > + V = any, + E = any, + VO extends UndirectedVertex = UndirectedVertex, + EO extends UndirectedEdge = UndirectedEdge +> extends AbstractGraph - implements IGraph -{ + implements IGraph { /** * The constructor initializes a new Map object to store edges. */ diff --git a/src/data-structures/hash/hash-map.ts b/src/data-structures/hash/hash-map.ts index 9595be5..cb59fc3 100644 --- a/src/data-structures/hash/hash-map.ts +++ b/src/data-structures/hash/hash-map.ts @@ -133,7 +133,7 @@ export class HashMap { } } - *entries(): IterableIterator<[K, V]> { + * entries(): IterableIterator<[K, V]> { for (const bucket of this.table) { if (bucket) { for (const [key, value] of bucket) { diff --git a/src/data-structures/hash/tree-map.ts b/src/data-structures/hash/tree-map.ts index fe86360..a6d743d 100644 --- a/src/data-structures/hash/tree-map.ts +++ b/src/data-structures/hash/tree-map.ts @@ -1 +1,2 @@ -export class TreeMap {} +export class TreeMap { +} diff --git a/src/data-structures/hash/tree-set.ts b/src/data-structures/hash/tree-set.ts index 591aeda..65f14db 100644 --- a/src/data-structures/hash/tree-set.ts +++ b/src/data-structures/hash/tree-set.ts @@ -1 +1,2 @@ -export class TreeSet {} +export class TreeSet { +} diff --git a/src/data-structures/heap/heap.ts b/src/data-structures/heap/heap.ts index 88667a1..b4523c1 100644 --- a/src/data-structures/heap/heap.ts +++ b/src/data-structures/heap/heap.ts @@ -8,7 +8,7 @@ import type {Comparator, DFSOrderPattern} from '../../types'; export class Heap { - constructor(options: {comparator: Comparator; nodes?: E[]}) { + constructor(options: { comparator: Comparator; nodes?: E[] }) { this._comparator = options.comparator; if (options.nodes && options.nodes.length > 0) { this._nodes = options.nodes; @@ -48,7 +48,7 @@ export class Heap { * @returns A new Heap instance. * @param options */ - static heapify(options: {nodes: E[]; comparator: Comparator}): Heap { + static heapify(options: { nodes: E[]; comparator: Comparator }): Heap { return new Heap(options); } diff --git a/src/data-structures/heap/max-heap.ts b/src/data-structures/heap/max-heap.ts index be2c9b1..139ef64 100644 --- a/src/data-structures/heap/max-heap.ts +++ b/src/data-structures/heap/max-heap.ts @@ -11,7 +11,7 @@ import type {Comparator} from '../../types'; export class MaxHeap extends Heap { constructor( - options: {comparator: Comparator; nodes?: E[]} = { + options: { comparator: Comparator; nodes?: E[] } = { comparator: (a: E, b: E) => { if (!(typeof a === 'number' && typeof b === 'number')) { throw new Error('The a, b params of compare function must be number'); diff --git a/src/data-structures/heap/min-heap.ts b/src/data-structures/heap/min-heap.ts index dc86f87..5057017 100644 --- a/src/data-structures/heap/min-heap.ts +++ b/src/data-structures/heap/min-heap.ts @@ -11,7 +11,7 @@ import type {Comparator} from '../../types'; export class MinHeap extends Heap { constructor( - options: {comparator: Comparator; nodes?: E[]} = { + options: { comparator: Comparator; nodes?: E[] } = { comparator: (a: E, b: E) => { if (!(typeof a === 'number' && typeof b === 'number')) { throw new Error('The a, b params of compare function must be number'); diff --git a/src/data-structures/linked-list/doubly-linked-list.ts b/src/data-structures/linked-list/doubly-linked-list.ts index d877137..2499e87 100644 --- a/src/data-structures/linked-list/doubly-linked-list.ts +++ b/src/data-structures/linked-list/doubly-linked-list.ts @@ -826,7 +826,7 @@ export class DoublyLinkedList { /** * The function returns an iterator that iterates over the values of a linked list. */ - *[Symbol.iterator]() { + * [Symbol.iterator]() { let current = this.head; while (current) { diff --git a/src/data-structures/linked-list/singly-linked-list.ts b/src/data-structures/linked-list/singly-linked-list.ts index 58323ab..c1a26f0 100644 --- a/src/data-structures/linked-list/singly-linked-list.ts +++ b/src/data-structures/linked-list/singly-linked-list.ts @@ -773,7 +773,7 @@ export class SinglyLinkedList { /** * The function returns an iterator that iterates over the values of a linked list. */ - *[Symbol.iterator]() { + * [Symbol.iterator]() { let current = this.head; while (current) { diff --git a/src/data-structures/matrix/matrix.ts b/src/data-structures/matrix/matrix.ts index 3559d58..4f1b8b8 100644 --- a/src/data-structures/matrix/matrix.ts +++ b/src/data-structures/matrix/matrix.ts @@ -14,7 +14,7 @@ export class MatrixNTI2D { * given initial value or 0 if not provided. * @param options - An object containing the following properties: */ - constructor(options: {row: number; col: number; initialVal?: V}) { + constructor(options: { row: number; col: number; initialVal?: V }) { const {row, col, initialVal} = options; this._matrix = new Array(row).fill(undefined).map(() => new Array(col).fill(initialVal || 0)); } diff --git a/src/data-structures/matrix/vector2d.ts b/src/data-structures/matrix/vector2d.ts index 1b2ff44..2f62f4e 100644 --- a/src/data-structures/matrix/vector2d.ts +++ b/src/data-structures/matrix/vector2d.ts @@ -10,7 +10,8 @@ export class Vector2D { public x: number = 0, public y: number = 0, public w: number = 1 // needed for matrix multiplication - ) {} + ) { + } /** * The function checks if the x and y values of a point are both zero. diff --git a/src/data-structures/priority-queue/max-priority-queue.ts b/src/data-structures/priority-queue/max-priority-queue.ts index dbb0793..409c99f 100644 --- a/src/data-structures/priority-queue/max-priority-queue.ts +++ b/src/data-structures/priority-queue/max-priority-queue.ts @@ -10,7 +10,7 @@ import type {Comparator} from '../../types'; export class MaxPriorityQueue extends PriorityQueue { constructor( - options: {comparator: Comparator; nodes?: E[]} = { + options: { comparator: Comparator; nodes?: E[] } = { comparator: (a: E, b: E) => { if (!(typeof a === 'number' && typeof b === 'number')) { throw new Error('The a, b params of compare function must be number'); diff --git a/src/data-structures/priority-queue/min-priority-queue.ts b/src/data-structures/priority-queue/min-priority-queue.ts index 8b8386f..da8ab64 100644 --- a/src/data-structures/priority-queue/min-priority-queue.ts +++ b/src/data-structures/priority-queue/min-priority-queue.ts @@ -10,7 +10,7 @@ import type {Comparator} from '../../types'; export class MinPriorityQueue extends PriorityQueue { constructor( - options: {comparator: Comparator; nodes?: E[]} = { + options: { comparator: Comparator; nodes?: E[] } = { comparator: (a: E, b: E) => { if (!(typeof a === 'number' && typeof b === 'number')) { throw new Error('The a, b params of compare function must be number'); diff --git a/src/data-structures/priority-queue/priority-queue.ts b/src/data-structures/priority-queue/priority-queue.ts index edfbaf2..60deb98 100644 --- a/src/data-structures/priority-queue/priority-queue.ts +++ b/src/data-structures/priority-queue/priority-queue.ts @@ -10,7 +10,7 @@ import {Heap} from '../heap'; import {Comparator} from '../../types'; export class PriorityQueue extends Heap { - constructor(options: {comparator: Comparator; nodes?: E[]}) { + constructor(options: { comparator: Comparator; nodes?: E[] }) { super(options); } } diff --git a/src/data-structures/queue/deque.ts b/src/data-structures/queue/deque.ts index e3cb229..8dafdb0 100644 --- a/src/data-structures/queue/deque.ts +++ b/src/data-structures/queue/deque.ts @@ -9,7 +9,8 @@ import {DoublyLinkedList} from '../linked-list'; // O(n) time complexity of obtaining the value // O(1) time complexity of adding at the beginning and the end -export class Deque extends DoublyLinkedList {} +export class Deque extends DoublyLinkedList { +} // O(1) time complexity of obtaining the value // O(n) time complexity of adding at the beginning and the end @@ -19,9 +20,9 @@ export class ObjectDeque { if (capacity !== undefined) this._capacity = capacity; } - protected _nodes: {[key: number]: E} = {}; + protected _nodes: { [key: number]: E } = {}; - get nodes(): {[p: number]: E} { + get nodes(): { [p: number]: E } { return this._nodes; } diff --git a/src/data-structures/queue/queue.ts b/src/data-structures/queue/queue.ts index c846074..c584856 100644 --- a/src/data-structures/queue/queue.ts +++ b/src/data-structures/queue/queue.ts @@ -300,7 +300,7 @@ export class Queue { return new Queue(this.nodes.slice(this.offset)); } - *[Symbol.iterator]() { + * [Symbol.iterator]() { for (const item of this.nodes) { yield item; } diff --git a/src/interfaces/binary-tree.ts b/src/interfaces/binary-tree.ts index 18bf5d4..365e80a 100644 --- a/src/interfaces/binary-tree.ts +++ b/src/interfaces/binary-tree.ts @@ -1,5 +1,5 @@ import {BinaryTreeNode} from '../data-structures'; -import {BiTreeDeleteResult, BinaryTreeNodeNested, BTNCallback, BTNKey} from '../types'; +import {BinaryTreeNodeNested, BiTreeDeleteResult, BTNCallback, BTNKey} from '../types'; export interface IBinaryTree = BinaryTreeNodeNested> { createNode(key: BTNKey, value?: N['value']): N; diff --git a/src/types/data-structures/matrix/navigator.ts b/src/types/data-structures/matrix/navigator.ts index 9d8b9a9..34eddd9 100644 --- a/src/types/data-structures/matrix/navigator.ts +++ b/src/types/data-structures/matrix/navigator.ts @@ -1,6 +1,6 @@ export type Direction = 'up' | 'right' | 'down' | 'left'; -export type Turning = {[key in Direction]: Direction}; +export type Turning = { [key in Direction]: Direction }; export type NavigatorParams = { matrix: T[][]; diff --git a/src/types/utils/utils.ts b/src/types/utils/utils.ts index f4d26c4..1f3a505 100644 --- a/src/types/utils/utils.ts +++ b/src/types/utils/utils.ts @@ -1,5 +1,5 @@ export type ToThunkFn = () => ReturnType; -export type Thunk = () => ReturnType & {__THUNK__: symbol}; +export type Thunk = () => ReturnType & { __THUNK__: symbol }; export type TrlFn = (...args: any[]) => any; export type TrlAsyncFn = (...args: any[]) => any; diff --git a/src/types/utils/validate-type.ts b/src/types/utils/validate-type.ts index ac9ff28..3ebf451 100644 --- a/src/types/utils/validate-type.ts +++ b/src/types/utils/validate-type.ts @@ -1,6 +1,6 @@ -export type KeyValueObject = {[key: string]: any}; +export type KeyValueObject = { [key: string]: any }; -export type KeyValueObjectWithKey = {[key: string]: any; key: string | number | symbol}; +export type KeyValueObjectWithKey = { [key: string]: any; key: string | number | symbol }; export type NonNumberNonObjectButDefined = string | boolean | symbol | null; diff --git a/test/integration/bst.test.ts b/test/integration/bst.test.ts index 3eaa0f7..59022fc 100644 --- a/test/integration/bst.test.ts +++ b/test/integration/bst.test.ts @@ -183,7 +183,7 @@ describe('Individual package BST operations test', () => { }); it('should perform various operations on a Binary Search Tree with object values', () => { - const objBST = new BST<{key: number; keyA: number}>(); + const objBST = new BST<{ key: number; keyA: number }>(); expect(objBST).toBeInstanceOf(BST); objBST.add(11, {key: 11, keyA: 11}); objBST.add(3, {key: 3, keyA: 3}); diff --git a/test/integration/index.html b/test/integration/index.html index 8fe4df1..2ff1a4a 100644 --- a/test/integration/index.html +++ b/test/integration/index.html @@ -3,7 +3,7 @@ CDN Test - + @@ -56,7 +56,7 @@ const tree = new BinaryTree(); tree.add(3); tree.add(12); - tree.addMany([1, 6, 9, 8,5,2,3,4,7]) + tree.addMany([1, 6, 9, 8, 5, 2, 3, 4, 7]) tree.add(10); console.log(tree.isPerfectlyBalanced()); tree.print(); diff --git a/test/performance/data-structures/linked-list/doubly-linked-list.test.ts b/test/performance/data-structures/linked-list/doubly-linked-list.test.ts index e25be19..7155cc9 100644 --- a/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +++ b/test/performance/data-structures/linked-list/doubly-linked-list.test.ts @@ -15,25 +15,25 @@ suite list.unshift(i); } }) - if (isCompetitor) { - suite.add(`${LINEAR.toLocaleString()} competitor unshift`, () => { - const list = new CLinkedList(); - - for (let i = 0; i < LINEAR; i++) { - list.pushFront(i); - } - }) - } - suite.add(`${LINEAR.toLocaleString()} unshift & shift`, () => { - const list = new DoublyLinkedList(); +if (isCompetitor) { + suite.add(`${LINEAR.toLocaleString()} competitor unshift`, () => { + const list = new CLinkedList(); for (let i = 0; i < LINEAR; i++) { - list.unshift(i); - } - for (let i = 0; i < LINEAR; i++) { - list.shift(); + list.pushFront(i); } }) +} +suite.add(`${LINEAR.toLocaleString()} unshift & shift`, () => { + const list = new DoublyLinkedList(); + + for (let i = 0; i < LINEAR; i++) { + list.unshift(i); + } + for (let i = 0; i < LINEAR; i++) { + list.shift(); + } +}) .add(`${LINEAR.toLocaleString()} insertBefore`, () => { const doublyList = new DoublyLinkedList(); let midNode: DoublyLinkedListNode | null = null; diff --git a/test/performance/data-structures/queue/deque.test.ts b/test/performance/data-structures/queue/deque.test.ts index 3d6b774..94bf54f 100644 --- a/test/performance/data-structures/queue/deque.test.ts +++ b/test/performance/data-structures/queue/deque.test.ts @@ -14,18 +14,18 @@ suite deque.push(i); } }) - if (isCompetitor) { - suite.add(`${LINEAR.toLocaleString()} competitor push`, () => { - const deque = new CDeque(); - for (let i = 0; i < LINEAR; i++) { - deque.pushBack(i); - } - }) - } - suite.add(`${LINEAR.toLocaleString()} shift`, () => { - const deque = new Deque(); +if (isCompetitor) { + suite.add(`${LINEAR.toLocaleString()} competitor push`, () => { + const deque = new CDeque(); for (let i = 0; i < LINEAR; i++) { - deque.push(i); - deque.shift(); + deque.pushBack(i); } - }); + }) +} +suite.add(`${LINEAR.toLocaleString()} shift`, () => { + const deque = new Deque(); + for (let i = 0; i < LINEAR; i++) { + deque.push(i); + deque.shift(); + } +}); diff --git a/test/performance/data-structures/queue/queue.test.ts b/test/performance/data-structures/queue/queue.test.ts index 4e806a1..062bfaf 100644 --- a/test/performance/data-structures/queue/queue.test.ts +++ b/test/performance/data-structures/queue/queue.test.ts @@ -15,22 +15,22 @@ suite queue.push(i); } }) - if (isCompetitor) { - suite.add(`${LINEAR.toLocaleString()} competitor push`, () => { - const queue = new CQueue(); - - for (let i = 0; i < LINEAR; i++) { - queue.push(i); - } - }) - } - suite.add(`${LINEAR.toLocaleString()} push & shift`, () => { - const queue = new Queue(); +if (isCompetitor) { + suite.add(`${LINEAR.toLocaleString()} competitor push`, () => { + const queue = new CQueue(); for (let i = 0; i < LINEAR; i++) { queue.push(i); - queue.shift(); } - }); + }) +} +suite.add(`${LINEAR.toLocaleString()} push & shift`, () => { + const queue = new Queue(); + + for (let i = 0; i < LINEAR; i++) { + queue.push(i); + queue.shift(); + } +}); export {suite}; diff --git a/test/performance/reportor.ts b/test/performance/reportor.ts index 70401ad..4b5aeda 100644 --- a/test/performance/reportor.ts +++ b/test/performance/reportor.ts @@ -11,7 +11,7 @@ const reportDistPath = path.join(parentDirectory, 'benchmark'); const testDir = path.join(__dirname, 'data-structures'); const testFiles = fastGlob.sync(path.join(testDir, '**', '*.test.ts')); -const report: {[key: string]: any} = {}; +const report: { [key: string]: any } = {}; let completedCount = 0; diff --git a/test/performance/types/reportor.ts b/test/performance/types/reportor.ts index 4b65e75..e41166d 100644 --- a/test/performance/types/reportor.ts +++ b/test/performance/types/reportor.ts @@ -1,3 +1,3 @@ import * as Benchmark from 'benchmark'; -export type PerformanceTest = {testName: string; suite: Benchmark.Suite; file: string}; +export type PerformanceTest = { testName: string; suite: Benchmark.Suite; file: string }; diff --git a/test/types/utils/json2html.ts b/test/types/utils/json2html.ts index dbae264..bf4e9f4 100644 --- a/test/types/utils/json2html.ts +++ b/test/types/utils/json2html.ts @@ -1 +1 @@ -export type Json2htmlOptions = {plainHtml?: boolean} & Partial<{[key: string]: any}>; +export type Json2htmlOptions = { plainHtml?: boolean } & Partial<{ [key: string]: any }>; diff --git a/test/unit/data-structures/binary-tree/avl-tree.test.ts b/test/unit/data-structures/binary-tree/avl-tree.test.ts index e21e1a3..fb09a75 100644 --- a/test/unit/data-structures/binary-tree/avl-tree.test.ts +++ b/test/unit/data-structures/binary-tree/avl-tree.test.ts @@ -219,7 +219,7 @@ describe('AVL Tree Test recursively', () => { }); describe('AVLTree APIs test', () => { - const avl = new AVLTree<{id: number; text: string}>(); + const avl = new AVLTree<{ id: number; text: string }>(); beforeEach(() => { avl.clear(); }); @@ -268,7 +268,7 @@ describe('AVLTree', () => { }); describe('BinaryTree APIs test', () => { - const avl = new AVLTree<{id: number; text: string}>(); + const avl = new AVLTree<{ id: number; text: string }>(); beforeEach(() => { avl.clear(); }); diff --git a/test/unit/data-structures/binary-tree/binary-tree.test.ts b/test/unit/data-structures/binary-tree/binary-tree.test.ts index 077a02c..4301e03 100644 --- a/test/unit/data-structures/binary-tree/binary-tree.test.ts +++ b/test/unit/data-structures/binary-tree/binary-tree.test.ts @@ -247,10 +247,10 @@ describe('BinaryTree', () => { expect(tree.subTreeTraverse(node => node.key, tree.getNode(6), IterationType.ITERATIVE)).toEqual([6, 3, 7]); expect(tree.subTreeTraverse(node => node.key, tree.getNode(6), IterationType.RECURSIVE)).toEqual([6, 3, 7]); expect( - tree.subTreeTraverse(node => (node ? node.key : null ), tree.getNode(6), IterationType.ITERATIVE, true) + tree.subTreeTraverse(node => (node ? node.key : null), tree.getNode(6), IterationType.ITERATIVE, true) ).toEqual([6, 3, 7, null]); expect( - tree.subTreeTraverse(node => (node ? node.key : null ), tree.getNode(6), IterationType.RECURSIVE, true) + tree.subTreeTraverse(node => (node ? node.key : null), tree.getNode(6), IterationType.RECURSIVE, true) ).toEqual([6, 3, 7, null]); }); @@ -324,10 +324,10 @@ describe('BinaryTree traversals', () => { const arr = [35, 20, 40, 15, 29, null, 50, null, 16, 28, 30, 45, 55]; tree.refill(arr); expect( - tree.bfs(node => node, tree.root, IterationType.ITERATIVE, true).map(node => (node ? node.key : null )) + tree.bfs(node => node, tree.root, IterationType.ITERATIVE, true).map(node => (node ? node.key : null)) ).toEqual([35, 20, 40, 15, 29, null, 50, null, 16, 28, 30, 45, 55]); expect( - tree.bfs(node => node, tree.root, IterationType.RECURSIVE, true).map(node => (node ? node.key : null )) + tree.bfs(node => node, tree.root, IterationType.RECURSIVE, true).map(node => (node ? node.key : null)) ).toEqual([35, 20, 40, 15, 29, null, 50, null, 16, 28, 30, 45, 55]); expect( tree.bfs(node => node, tree.root, IterationType.ITERATIVE).map(node => (node === null ? null : node.key)) @@ -343,12 +343,12 @@ describe('BinaryTree traversals', () => { expect( tree .dfs(node => node, 'pre', tree.root, IterationType.ITERATIVE, true) - .map(node => (node ? node.key : null )) + .map(node => (node ? node.key : null)) ).toEqual([35, 20, 15, null, 16, 29, 28, 30, 40, null, 50, 45, 55]); expect( tree .dfs(node => node, 'pre', tree.root, IterationType.RECURSIVE, true) - .map(node => (node ? node.key : null )) + .map(node => (node ? node.key : null)) ).toEqual([35, 20, 15, null, 16, 29, 28, 30, 40, null, 50, 45, 55]); expect(tree.dfs(node => node.key, 'in')).toEqual([15, 16, 20, 28, 29, 30, 35, 40, 45, 50, 55]); @@ -371,13 +371,13 @@ describe('BinaryTree traversals', () => { [15, 29, 50], [16, 28, 30, 45, 55] ]); - expect(tree.listLevels(node => (node ? node.key : null ), tree.root, IterationType.ITERATIVE, true)).toEqual([ + expect(tree.listLevels(node => (node ? node.key : null), tree.root, IterationType.ITERATIVE, true)).toEqual([ [35], [20, 40], [15, 29, null, 50], [null, 16, 28, 30, 45, 55] ]); - expect(tree.listLevels(node => ( node ? node.key : null ), tree.root, IterationType.RECURSIVE, true)).toEqual([ + expect(tree.listLevels(node => (node ? node.key : null), tree.root, IterationType.RECURSIVE, true)).toEqual([ [35], [20, 40], [15, 29, null, 50], diff --git a/test/unit/data-structures/binary-tree/bst.test.ts b/test/unit/data-structures/binary-tree/bst.test.ts index ef80c31..6788e36 100644 --- a/test/unit/data-structures/binary-tree/bst.test.ts +++ b/test/unit/data-structures/binary-tree/bst.test.ts @@ -189,7 +189,7 @@ describe('BST operations test', () => { }); it('should perform various operations on a Binary Search Tree with object values', () => { - const objBST = new BST<{key: number; keyA: number}>(); + const objBST = new BST<{ key: number; keyA: number }>(); expect(objBST).toBeInstanceOf(BST); objBST.add(11, {key: 11, keyA: 11}); objBST.add(3, {key: 3, keyA: 3}); @@ -260,7 +260,7 @@ describe('BST operations test', () => { objBST.perfectlyBalance(); expect(objBST.isPerfectlyBalanced()).toBe(true); - const bfsNodesAfterBalanced: BSTNode<{key: number; keyA: number}>[] = []; + const bfsNodesAfterBalanced: BSTNode<{ key: number; keyA: number }>[] = []; objBST.bfs(node => bfsNodesAfterBalanced.push(node)); expect(bfsNodesAfterBalanced[0].key).toBe(8); expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16); @@ -385,7 +385,7 @@ describe('BST operations test', () => { expect(bfsIDs[1]).toBe(12); expect(bfsIDs[2]).toBe(16); - const bfsNodes: BSTNode<{key: number; keyA: number}>[] = []; + const bfsNodes: BSTNode<{ key: number; keyA: number }>[] = []; objBST.bfs(node => bfsNodes.push(node)); expect(bfsNodes[0].key).toBe(2); expect(bfsNodes[1].key).toBe(12); @@ -580,7 +580,7 @@ describe('BST operations test recursively', () => { }); it('should perform various operations on a Binary Search Tree with object values', () => { - const objBST = new BST<{key: number; keyA: number}>(); + const objBST = new BST<{ key: number; keyA: number }>(); expect(objBST).toBeInstanceOf(BST); objBST.add(11, {key: 11, keyA: 11}); objBST.add(3, {key: 3, keyA: 3}); @@ -652,7 +652,7 @@ describe('BST operations test recursively', () => { objBST.perfectlyBalance(); expect(objBST.isPerfectlyBalanced()).toBe(true); - const bfsNodesAfterBalanced: BSTNode<{key: number; keyA: number}>[] = []; + const bfsNodesAfterBalanced: BSTNode<{ key: number; keyA: number }>[] = []; objBST.bfs(node => bfsNodesAfterBalanced.push(node)); expect(bfsNodesAfterBalanced[0].key).toBe(8); expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16); @@ -777,7 +777,7 @@ describe('BST operations test recursively', () => { expect(bfsIDs[1]).toBe(12); expect(bfsIDs[2]).toBe(16); - const bfsNodes: BSTNode<{key: number; keyA: number}>[] = []; + const bfsNodes: BSTNode<{ key: number; keyA: number }>[] = []; objBST.bfs(node => bfsNodes.push(node)); expect(bfsNodes[0].key).toBe(2); expect(bfsNodes[1].key).toBe(12); diff --git a/test/unit/data-structures/binary-tree/overall.test.ts b/test/unit/data-structures/binary-tree/overall.test.ts index d168b1c..ee29844 100644 --- a/test/unit/data-structures/binary-tree/overall.test.ts +++ b/test/unit/data-structures/binary-tree/overall.test.ts @@ -29,7 +29,7 @@ describe('Overall BinaryTree Test', () => { bfsIDs[0] === 11; // true expect(bfsIDs[0]).toBe(11); - const objBST = new BST<{key: number; keyA: number}>(); + const objBST = new BST<{ key: number; keyA: number }>(); objBST.add(11, {key: 11, keyA: 11}); objBST.add(3, {key: 3, keyA: 3}); diff --git a/test/unit/data-structures/binary-tree/rb-tree.test.ts b/test/unit/data-structures/binary-tree/rb-tree.test.ts index bbf3e10..89f45fe 100644 --- a/test/unit/data-structures/binary-tree/rb-tree.test.ts +++ b/test/unit/data-structures/binary-tree/rb-tree.test.ts @@ -1,4 +1,4 @@ -import {IterationType, RBTNColor, RedBlackTreeNode, RedBlackTree} from '../../../../src'; +import {IterationType, RBTNColor, RedBlackTree, RedBlackTreeNode} from '../../../../src'; import {getRandomInt, getRandomIntArray, magnitude} from '../../../utils'; import {isDebugTest} from '../../../config'; import {OrderedMap} from "js-sdsl"; @@ -421,9 +421,9 @@ describe('RedBlackTree', () => { isDebug && tree.print(); expect(tree.dfs()).toEqual([ - 1, 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, - 19, 22, 23, 25, 28, 33, 50, 110, 111, + 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 22, 23, 25, 28, 33, 50, 110, 111, 155, 225 ]) @@ -441,14 +441,14 @@ describe('RedBlackTree', () => { expect(tree.size).toBe(51); expect(tree.isBST()).toBe(true); - expect(tree.dfs( n => n.key, "in", tree.root, IterationType.ITERATIVE)).toEqual([ + expect(tree.dfs(n => n.key, "in", tree.root, IterationType.ITERATIVE)).toEqual([ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99 ]) - expect(tree.dfs( n => n.key, "in", tree.root, IterationType.RECURSIVE)).toEqual([ + expect(tree.dfs(n => n.key, "in", tree.root, IterationType.RECURSIVE)).toEqual([ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, @@ -467,7 +467,7 @@ describe('RedBlackTree', () => { expect(tree.size).toBe(0); expect(tree.isBST()).toBe(true); - expect(tree.dfs( n => n.key, "in", tree.root, IterationType.ITERATIVE)).toEqual([]) + expect(tree.dfs(n => n.key, "in", tree.root, IterationType.ITERATIVE)).toEqual([]) tree.clear(); for (let i = 0; i < 1000; i++) { diff --git a/test/unit/data-structures/binary-tree/tree-multimap.test.ts b/test/unit/data-structures/binary-tree/tree-multimap.test.ts index b4d76f1..577eeb7 100644 --- a/test/unit/data-structures/binary-tree/tree-multimap.test.ts +++ b/test/unit/data-structures/binary-tree/tree-multimap.test.ts @@ -207,7 +207,7 @@ describe('TreeMultimap operations test', () => { }); it('should perform various operations on a Binary Search Tree with object values', () => { - const objTreeMultimap = new TreeMultimap<{key: number; keyA: number}>(); + const objTreeMultimap = new TreeMultimap<{ key: number; keyA: number }>(); expect(objTreeMultimap).toBeInstanceOf(TreeMultimap); objTreeMultimap.add(11, {key: 11, keyA: 11}); objTreeMultimap.add(3, {key: 3, keyA: 3}); @@ -447,7 +447,7 @@ describe('TreeMultimap operations test recursively', () => { }); it('should perform various operations on a Binary Search Tree with object values', () => { - const objTreeMultimap = new TreeMultimap<{key: number; keyA: number}>(); + const objTreeMultimap = new TreeMultimap<{ key: number; keyA: number }>(); expect(objTreeMultimap).toBeInstanceOf(TreeMultimap); objTreeMultimap.add(11, {key: 11, keyA: 11}); objTreeMultimap.add(3, {key: 3, keyA: 3}); diff --git a/test/unit/data-structures/graph/abstract-graph.test.ts b/test/unit/data-structures/graph/abstract-graph.test.ts index 5205c66..1e44c0b 100644 --- a/test/unit/data-structures/graph/abstract-graph.test.ts +++ b/test/unit/data-structures/graph/abstract-graph.test.ts @@ -74,7 +74,8 @@ class MyGraph< describe('AbstractGraph Operation Test', () => { const myGraph: MyGraph = new MyGraph(); - beforeEach(() => {}); + beforeEach(() => { + }); it('should edge cases', function () { myGraph.addVertex('A', 1); myGraph.addVertex('B', 2); diff --git a/test/unit/data-structures/graph/undirected-graph.test.ts b/test/unit/data-structures/graph/undirected-graph.test.ts index e8aad56..454b259 100644 --- a/test/unit/data-structures/graph/undirected-graph.test.ts +++ b/test/unit/data-structures/graph/undirected-graph.test.ts @@ -150,7 +150,7 @@ describe('UndirectedGraph', () => { }); it('should getAllPathsBetween work well in 66 vertexes 97 edges graph', () => { - const graph = new UndirectedGraph<{name: string}, number>(); + const graph = new UndirectedGraph<{ name: string }, number>(); for (const v of saltyVertexes) { graph.addVertex(v.name, v); } diff --git a/test/unit/data-structures/heap/heap.test.ts b/test/unit/data-structures/heap/heap.test.ts index 4b3763f..24ea8d6 100644 --- a/test/unit/data-structures/heap/heap.test.ts +++ b/test/unit/data-structures/heap/heap.test.ts @@ -22,7 +22,7 @@ describe('Heap Operation Test', () => { }); it('should object heap work well', function () { - const minHeap = new MinHeap<{a: string; key: number}>({comparator: (a, b) => a.key - b.key}); + const minHeap = new MinHeap<{ a: string; key: number }>({comparator: (a, b) => a.key - b.key}); minHeap.add({key: 1, a: 'a1'}); minHeap.add({key: 6, a: 'a6'}); minHeap.add({key: 2, a: 'a2'}); @@ -37,7 +37,7 @@ describe('Heap Operation Test', () => { i++; } - const maxHeap = new MaxHeap<{key: number; a: string}>({comparator: (a, b) => b.key - a.key}); + const maxHeap = new MaxHeap<{ key: number; a: string }>({comparator: (a, b) => b.key - a.key}); maxHeap.add({key: 1, a: 'a1'}); maxHeap.add({key: 6, a: 'a6'}); maxHeap.add({key: 5, a: 'a5'}); diff --git a/test/unit/data-structures/linked-list/doubly-linked-list.test.ts b/test/unit/data-structures/linked-list/doubly-linked-list.test.ts index 7ca69fa..139e4a3 100644 --- a/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +++ b/test/unit/data-structures/linked-list/doubly-linked-list.test.ts @@ -60,7 +60,7 @@ describe('DoublyLinkedList Operation Test', () => { describe('DoublyLinkedList Operation Test', () => { let list: DoublyLinkedList; - let objectList: DoublyLinkedList<{keyA: number}>; + let objectList: DoublyLinkedList<{ keyA: number }>; beforeEach(() => { list = new DoublyLinkedList(); diff --git a/test/unit/data-structures/linked-list/singly-linked-list.test.ts b/test/unit/data-structures/linked-list/singly-linked-list.test.ts index a80fb87..cff8104 100644 --- a/test/unit/data-structures/linked-list/singly-linked-list.test.ts +++ b/test/unit/data-structures/linked-list/singly-linked-list.test.ts @@ -11,10 +11,10 @@ describe('SinglyLinkedListNode', () => { describe('SinglyLinkedList Operation Test', () => { let list: SinglyLinkedList; - let objectList: SinglyLinkedList<{keyA: number}>; + let objectList: SinglyLinkedList<{ keyA: number }>; beforeEach(() => { list = new SinglyLinkedList(); - objectList = new SinglyLinkedList<{keyA: number}>(); + objectList = new SinglyLinkedList<{ keyA: number }>(); }); describe('push', () => { diff --git a/test/unit/data-structures/priority-queue/max-priority-queue.test.ts b/test/unit/data-structures/priority-queue/max-priority-queue.test.ts index 844c21b..b2609b6 100644 --- a/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +++ b/test/unit/data-structures/priority-queue/max-priority-queue.test.ts @@ -16,7 +16,7 @@ describe('MaxPriorityQueue Operation Test', () => { }); it('should add elements and maintain heap property in a object MaxPriorityQueue', () => { - const priorityQueue = new MaxPriorityQueue<{keyA: number}>({comparator: (a, b) => b.keyA - a.keyA}); + const priorityQueue = new MaxPriorityQueue<{ keyA: number }>({comparator: (a, b) => b.keyA - a.keyA}); priorityQueue.refill([{keyA: 5}, {keyA: 3}, {keyA: 1}]); priorityQueue.add({keyA: 7}); @@ -63,7 +63,7 @@ describe('MaxPriorityQueue Operation Test', () => { it('should correctly heapify an object array', () => { const nodes = [{keyA: 5}, {keyA: 3}, {keyA: 7}, {keyA: 1}]; - const maxPQ = MaxPriorityQueue.heapify<{keyA: number}>({nodes: nodes, comparator: (a, b) => b.keyA - a.keyA}); + const maxPQ = MaxPriorityQueue.heapify<{ keyA: number }>({nodes: nodes, comparator: (a, b) => b.keyA - a.keyA}); expect(maxPQ.poll()?.keyA).toBe(7); expect(maxPQ.poll()?.keyA).toBe(5); diff --git a/test/utils/big-o.ts b/test/utils/big-o.ts index 5d5d906..e46c2ff 100644 --- a/test/utils/big-o.ts +++ b/test/utils/big-o.ts @@ -32,7 +32,7 @@ export const bigO = { function findPotentialN(input: any): number { let longestArray: any[] = []; - let mostProperties: {[key: string]: any} = {}; + let mostProperties: { [key: string]: any } = {}; function recurse(obj: any) { if (Array.isArray(obj)) {