Skip to content

Commit

Permalink
style: Prettier version updated. Code style adhered to Prettier stric…
Browse files Browse the repository at this point in the history
…tly.
  • Loading branch information
zrwusa committed Aug 26, 2024
1 parent ac1712b commit 7e45aaf
Show file tree
Hide file tree
Showing 52 changed files with 1,660 additions and 558 deletions.
3 changes: 2 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ module.exports = {
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
"useTabs": false,
"semi": true,
}
26 changes: 13 additions & 13 deletions README.md

Large diffs are not rendered by default.

1,590 changes: 1,256 additions & 334 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-structure-typed",
"version": "1.52.1",
"version": "1.52.2",
"description": "Javascript Data Structure. Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack. Benchmark compared with C++ STL. API aligned with ES6 and Java.util. Usability is comparable to Python",
"main": "dist/cjs/index.js",
"module": "dist/mjs/index.js",
Expand Down Expand Up @@ -83,7 +83,7 @@
"istanbul-badges-readme": "^1.8.5",
"jest": "^29.7.0",
"js-sdsl": "^4.4.2",
"prettier": "^3.0.3",
"prettier": "^3.3.3",
"ts-jest": "^29.1.1",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
Expand Down
4 changes: 2 additions & 2 deletions src/data-structures/base/iterable-element-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export abstract class IterableElementBase<E, R, C> {
* allows the function to accept any number of arguments as an array. In this case, the `args`
* parameter is used to pass any number of arguments to the `_getIterator` method.
*/
* [Symbol.iterator](...args: any[]): IterableIterator<E> {
*[Symbol.iterator](...args: any[]): IterableIterator<E> {
yield* this._getIterator(...args);
}

Expand All @@ -56,7 +56,7 @@ export abstract class IterableElementBase<E, R, C> {
*
* The function returns an iterator that yields all the values in the object.
*/
* values(): IterableIterator<E> {
*values(): IterableIterator<E> {
for (const item of this) {
yield item;
}
Expand Down
8 changes: 4 additions & 4 deletions src/data-structures/base/iterable-entry-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
* allows the function to accept any number of arguments as an array. In this case, the `args`
* parameter is used to pass any additional arguments to the `_getIterator` method.
*/
* [Symbol.iterator](...args: any[]): IterableIterator<[K, V]> {
*[Symbol.iterator](...args: any[]): IterableIterator<[K, V]> {
yield* this._getIterator(...args);
}

Expand All @@ -50,7 +50,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
* The function returns an iterator that yields key-value pairs from the object, where the value can
* be undefined.
*/
* entries(): IterableIterator<[K, V | undefined]> {
*entries(): IterableIterator<[K, V | undefined]> {
for (const item of this) {
yield item;
}
Expand All @@ -66,7 +66,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
*
* The function returns an iterator that yields the keys of a data structure.
*/
* keys(): IterableIterator<K> {
*keys(): IterableIterator<K> {
for (const item of this) {
yield item[0];
}
Expand All @@ -82,7 +82,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
*
* The function returns an iterator that yields the values of a collection.
*/
* values(): IterableIterator<V> {
*values(): IterableIterator<V> {
for (const item of this) {
yield item[1];
}
Expand Down
25 changes: 13 additions & 12 deletions src/data-structures/binary-tree/avl-tree-multi-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,21 @@ export class AVLTreeMultiMapNode<
* The only distinction between a AVLTreeMultiMap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
*/
export class AVLTreeMultiMap<
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>,
TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap<
K,
V,
R,
NODE,
AVLTreeMultiMapNested<K, V, R, NODE>
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>,
TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap<
K,
V,
R,
NODE,
AVLTreeMultiMapNested<K, V, R, NODE>
>
>
>
extends AVLTree<K, V, R, NODE, TREE>
implements IBinaryTree<K, V, R, NODE, TREE> {
implements IBinaryTree<K, V, R, NODE, TREE>
{
/**
* The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
* @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
Expand Down
17 changes: 9 additions & 8 deletions src/data-structures/binary-tree/avl-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ export class AVLTreeNode<
* 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
*/
export class AVLTree<
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>,
TREE extends AVLTree<K, V, R, NODE, TREE> = AVLTree<K, V, R, NODE, AVLTreeNested<K, V, R, NODE>>
>
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>,
TREE extends AVLTree<K, V, R, NODE, TREE> = AVLTree<K, V, R, NODE, AVLTreeNested<K, V, R, NODE>>
>
extends BST<K, V, R, NODE, TREE>
implements IBinaryTree<K, V, R, NODE, TREE> {
implements IBinaryTree<K, V, R, NODE, TREE>
{
/**
* This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
* entries, or raw elements.
Expand Down Expand Up @@ -503,7 +504,7 @@ export class AVLTree<
// Balance Restoration: If a balance issue is discovered after inserting a node, it requires balance restoration operations. Balance restoration includes four basic cases where rotation operations need to be performed to fix the balance:
switch (
this._balanceFactor(A) // second O(1)
) {
) {
case -2:
if (A && A.left) {
if (this._balanceFactor(A.left) <= 0) {
Expand Down
21 changes: 11 additions & 10 deletions src/data-structures/binary-tree/binary-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,15 @@ export class BinaryTreeNode<
*/

export class BinaryTree<
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>,
TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTree<K, V, R, NODE, BinaryTreeNested<K, V, R, NODE>>
>
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>,
TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTree<K, V, R, NODE, BinaryTreeNested<K, V, R, NODE>>
>
extends IterableEntryBase<K, V | undefined>
implements IBinaryTree<K, V, R, NODE, TREE> {
implements IBinaryTree<K, V, R, NODE, TREE>
{
iterationType: IterationType = 'ITERATIVE';

/**
Expand Down Expand Up @@ -1155,8 +1156,8 @@ export class BinaryTree<
if (!this.isRealNode(node.right) || last === node.right) {
node = stack.pop();
if (this.isRealNode(node)) {
const leftMinHeight = this.isRealNode(node.left) ? depths.get(node.left) ?? -1 : -1;
const rightMinHeight = this.isRealNode(node.right) ? depths.get(node.right) ?? -1 : -1;
const leftMinHeight = this.isRealNode(node.left) ? (depths.get(node.left) ?? -1) : -1;
const rightMinHeight = this.isRealNode(node.right) ? (depths.get(node.right) ?? -1) : -1;
depths.set(node, 1 + Math.min(leftMinHeight, rightMinHeight));
last = node;
node = null;
Expand Down Expand Up @@ -1937,7 +1938,7 @@ export class BinaryTree<
* initially set to the root node of the tree.
* @returns an IterableIterator<[K, V | undefined]>.
*/
protected* _getIterator(node = this.root): IterableIterator<[K, V | undefined]> {
protected *_getIterator(node = this.root): IterableIterator<[K, V | undefined]> {
if (!node) return;

if (this.iterationType === 'ITERATIVE') {
Expand Down
19 changes: 10 additions & 9 deletions src/data-structures/binary-tree/bst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,15 @@ export class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNod
* 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
*/
export class BST<
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>,
TREE extends BST<K, V, R, NODE, TREE> = BST<K, V, R, NODE, BSTNested<K, V, R, NODE>>
>
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>,
TREE extends BST<K, V, R, NODE, TREE> = BST<K, V, R, NODE, BSTNested<K, V, R, NODE>>
>
extends BinaryTree<K, V, R, NODE, TREE>
implements IBinaryTree<K, V, R, NODE, TREE> {
implements IBinaryTree<K, V, R, NODE, TREE>
{
/**
* This is the constructor function for a Binary Search Tree class in TypeScript.
* @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
Expand Down Expand Up @@ -786,8 +787,8 @@ export class BST<
if (!node.right || last === node.right) {
node = stack.pop();
if (node) {
const left = node.left ? depths.get(node.left) ?? -1 : -1;
const right = node.right ? depths.get(node.right) ?? -1 : -1;
const left = node.left ? (depths.get(node.left) ?? -1) : -1;
const right = node.right ? (depths.get(node.right) ?? -1) : -1;
if (Math.abs(left - right) > 1) return false;
depths.set(node, 1 + Math.max(left, right));
last = node;
Expand Down
15 changes: 8 additions & 7 deletions src/data-structures/binary-tree/rb-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ export class RedBlackTreeNode<
}

export class RedBlackTree<
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>,
TREE extends RedBlackTree<K, V, R, NODE, TREE> = RedBlackTree<K, V, R, NODE, RedBlackTreeNested<K, V, R, NODE>>
>
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>,
TREE extends RedBlackTree<K, V, R, NODE, TREE> = RedBlackTree<K, V, R, NODE, RedBlackTreeNested<K, V, R, NODE>>
>
extends BST<K, V, R, NODE, TREE>
implements IBinaryTree<K, V, R, NODE, TREE> {
implements IBinaryTree<K, V, R, NODE, TREE>
{
/**
* This is the constructor function for a Red-Black Tree data structure in TypeScript.
* @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
Expand Down
15 changes: 8 additions & 7 deletions src/data-structures/binary-tree/tree-multi-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ export class TreeMultiMapNode<
}

export class TreeMultiMap<
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>,
TREE extends TreeMultiMap<K, V, R, NODE, TREE> = TreeMultiMap<K, V, R, NODE, TreeMultiMapNested<K, V, R, NODE>>
>
K = any,
V = any,
R = BTNEntry<K, V>,
NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>,
TREE extends TreeMultiMap<K, V, R, NODE, TREE> = TreeMultiMap<K, V, R, NODE, TreeMultiMapNested<K, V, R, NODE>>
>
extends RedBlackTree<K, V, R, NODE, TREE>
implements IBinaryTree<K, V, R, NODE, TREE> {
implements IBinaryTree<K, V, R, NODE, TREE>
{
/**
* The constructor function initializes a TreeMultiMap object with optional initial data.
* @param keysOrNodesOrEntriesOrRawElements - The parameter `keysOrNodesOrEntriesOrRawElements` is an
Expand Down
29 changes: 15 additions & 14 deletions src/data-structures/graph/abstract-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ export abstract class AbstractEdge<E = any> {
}

export abstract class AbstractGraph<
V = any,
E = any,
VO extends AbstractVertex<V> = AbstractVertex<V>,
EO extends AbstractEdge<E> = AbstractEdge<E>
>
V = any,
E = any,
VO extends AbstractVertex<V> = AbstractVertex<V>,
EO extends AbstractEdge<E> = AbstractEdge<E>
>
extends IterableEntryBase<VertexKey, V | undefined>
implements IGraph<V, E, VO, EO> {
implements IGraph<V, E, VO, EO>
{
constructor() {
super();
}
Expand Down Expand Up @@ -618,14 +619,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);

Expand Down Expand Up @@ -1069,7 +1070,7 @@ export abstract class AbstractGraph<
return mapped;
}

protected* _getIterator(): IterableIterator<[VertexKey, V | undefined]> {
protected *_getIterator(): IterableIterator<[VertexKey, V | undefined]> {
for (const vertex of this._vertexMap.values()) {
yield [vertex.key, vertex.value];
}
Expand Down
13 changes: 7 additions & 6 deletions src/data-structures/graph/directed-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ export class DirectedEdge<E = any> extends AbstractEdge<E> {
}

export class DirectedGraph<
V = any,
E = any,
VO extends DirectedVertex<V> = DirectedVertex<V>,
EO extends DirectedEdge<E> = DirectedEdge<E>
>
V = any,
E = any,
VO extends DirectedVertex<V> = DirectedVertex<V>,
EO extends DirectedEdge<E> = DirectedEdge<E>
>
extends AbstractGraph<V, E, VO, EO>
implements IGraph<V, E, VO, EO> {
implements IGraph<V, E, VO, EO>
{
/**
* The constructor function initializes an instance of a class.
*/
Expand Down
13 changes: 7 additions & 6 deletions src/data-structures/graph/undirected-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ export class UndirectedEdge<E = number> extends AbstractEdge<E> {
}

export class UndirectedGraph<
V = any,
E = any,
VO extends UndirectedVertex<V> = UndirectedVertex<V>,
EO extends UndirectedEdge<E> = UndirectedEdge<E>
>
V = any,
E = any,
VO extends UndirectedVertex<V> = UndirectedVertex<V>,
EO extends UndirectedEdge<E> = UndirectedEdge<E>
>
extends AbstractGraph<V, E, VO, EO>
implements IGraph<V, E, VO, EO> {
implements IGraph<V, E, VO, EO>
{
/**
* The constructor initializes a new Map object to store edgeMap.
*/
Expand Down
8 changes: 4 additions & 4 deletions src/data-structures/hash/hash-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
* The function returns an iterator that yields key-value pairs from both an object store and an
* object map.
*/
protected* _getIterator(): IterableIterator<[K, V]> {
protected *_getIterator(): IterableIterator<[K, V]> {
for (const node of Object.values(this.store)) {
yield [node.key, node.value] as [K, V];
}
Expand Down Expand Up @@ -537,7 +537,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
/**
* The `begin()` function in TypeScript iterates over a linked list and yields key-value pairs.
*/
* begin() {
*begin() {
let node = this.head;
while (node !== this._sentinel) {
yield [node.key, node.value];
Expand All @@ -549,7 +549,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
* The function `reverseBegin()` iterates over a linked list in reverse order, yielding each node's
* key and value.
*/
* reverseBegin() {
*reverseBegin() {
let node = this.tail;
while (node !== this._sentinel) {
yield [node.key, node.value];
Expand Down Expand Up @@ -942,7 +942,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
*
* The above function is an iterator that yields key-value pairs from a linked list.
*/
protected* _getIterator() {
protected *_getIterator() {
let node = this.head;
while (node !== this._sentinel) {
yield [node.key, node.value] as [K, V];
Expand Down
Loading

0 comments on commit 7e45aaf

Please sign in to comment.