directed-graph-typed
Advanced tools
Comparing version 1.38.7 to 1.38.8
@@ -16,3 +16,3 @@ /** | ||
} | ||
export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode> extends BST<V, N> implements IBinaryTree<V, N> { | ||
export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTreeNodeNested<V>>> extends BST<V, N> implements IBinaryTree<V, N> { | ||
/** | ||
@@ -19,0 +19,0 @@ * This is a constructor function for an AVL tree data structure in TypeScript. |
@@ -65,3 +65,3 @@ /** | ||
*/ | ||
export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode> implements IBinaryTree<V, N> { | ||
export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>> implements IBinaryTree<V, N> { | ||
/** | ||
@@ -289,6 +289,2 @@ * Creates a new instance of BinaryTree. | ||
* `BFSCallbackReturn<N>`. The default value for this parameter is `this._defaultCallbackByKey | ||
* @param {boolean} [withLevel=false] - The `withLevel` parameter is a boolean flag that determines | ||
* whether to include the level of each node in the callback function. If `withLevel` is set | ||
* to `true`, the level of each node will be passed as an argument to the callback function. If | ||
* `withLevel` is | ||
* @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first | ||
@@ -301,4 +297,20 @@ * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search | ||
*/ | ||
bfs<C extends BFSCallback<N> = BFSCallback<N, BinaryTreeNodeKey>>(callback?: C, withLevel?: boolean, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[]; | ||
bfs<C extends BFSCallback<N> = BFSCallback<N, BinaryTreeNodeKey>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[]; | ||
/** | ||
* The `listLevels` function takes a binary tree node and a callback function, and returns an array | ||
* of arrays representing the levels of the tree. | ||
* @param {C} callback - The `callback` parameter is a function that will be called on each node in | ||
* the tree. It takes a node as input and returns a value. The return type of the callback function | ||
* is determined by the generic type `C`. | ||
* @param {N | null} beginRoot - The `beginRoot` parameter represents the starting node of the binary tree | ||
* traversal. It can be any node in the binary tree. If no node is provided, the traversal will start | ||
* from the root node of the binary tree. | ||
* @param iterationType - The `iterationType` parameter determines whether the tree traversal is done | ||
* recursively or iteratively. It can have two possible values: | ||
* @returns The function `listLevels` returns an array of arrays, where each inner array represents a | ||
* level in a binary tree. Each inner array contains the return type of the provided callback | ||
* function `C` applied to the nodes at that level. | ||
*/ | ||
listLevels<C extends BFSCallback<N> = BFSCallback<N, BinaryTreeNodeKey>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[][]; | ||
/** | ||
* The function returns the predecessor node of a given node in a binary tree. | ||
@@ -305,0 +317,0 @@ * @param {N} node - The parameter "node" represents a node in a binary tree. |
@@ -824,6 +824,2 @@ "use strict"; | ||
* `BFSCallbackReturn<N>`. The default value for this parameter is `this._defaultCallbackByKey | ||
* @param {boolean} [withLevel=false] - The `withLevel` parameter is a boolean flag that determines | ||
* whether to include the level of each node in the callback function. If `withLevel` is set | ||
* to `true`, the level of each node will be passed as an argument to the callback function. If | ||
* `withLevel` is | ||
* @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first | ||
@@ -836,3 +832,3 @@ * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search | ||
*/ | ||
bfs(callback = this._defaultCallbackByKey, withLevel = false, beginRoot = this.root, iterationType = this.iterationType) { | ||
bfs(callback = this._defaultCallbackByKey, beginRoot = this.root, iterationType = this.iterationType) { | ||
if (!beginRoot) | ||
@@ -842,4 +838,56 @@ return []; | ||
if (iterationType === types_1.IterationType.RECURSIVE) { | ||
const queue = new queue_1.Queue([beginRoot]); | ||
function traverse(level) { | ||
if (queue.size === 0) | ||
return; | ||
const current = queue.shift(); | ||
ans.push(callback(current)); | ||
if (current.left) | ||
queue.push(current.left); | ||
if (current.right) | ||
queue.push(current.right); | ||
traverse(level + 1); | ||
} | ||
traverse(0); | ||
} | ||
else { | ||
const queue = new queue_1.Queue([beginRoot]); | ||
while (queue.size > 0) { | ||
const levelSize = queue.size; | ||
for (let i = 0; i < levelSize; i++) { | ||
const current = queue.shift(); | ||
ans.push(callback(current)); | ||
if (current.left) | ||
queue.push(current.left); | ||
if (current.right) | ||
queue.push(current.right); | ||
} | ||
} | ||
} | ||
return ans; | ||
} | ||
/** | ||
* The `listLevels` function takes a binary tree node and a callback function, and returns an array | ||
* of arrays representing the levels of the tree. | ||
* @param {C} callback - The `callback` parameter is a function that will be called on each node in | ||
* the tree. It takes a node as input and returns a value. The return type of the callback function | ||
* is determined by the generic type `C`. | ||
* @param {N | null} beginRoot - The `beginRoot` parameter represents the starting node of the binary tree | ||
* traversal. It can be any node in the binary tree. If no node is provided, the traversal will start | ||
* from the root node of the binary tree. | ||
* @param iterationType - The `iterationType` parameter determines whether the tree traversal is done | ||
* recursively or iteratively. It can have two possible values: | ||
* @returns The function `listLevels` returns an array of arrays, where each inner array represents a | ||
* level in a binary tree. Each inner array contains the return type of the provided callback | ||
* function `C` applied to the nodes at that level. | ||
*/ | ||
listLevels(callback = this._defaultCallbackByKey, beginRoot = this.root, iterationType = this.iterationType) { | ||
if (!beginRoot) | ||
return []; | ||
const levelsNodes = []; | ||
if (iterationType === types_1.IterationType.RECURSIVE) { | ||
const _recursive = (node, level) => { | ||
callback && ans.push(callback(node, withLevel ? level : undefined)); | ||
if (!levelsNodes[level]) | ||
levelsNodes[level] = []; | ||
levelsNodes[level].push(callback(node)); | ||
if (node.left) | ||
@@ -857,3 +905,5 @@ _recursive(node.left, level + 1); | ||
const [node, level] = head; | ||
callback && ans.push(callback(node, withLevel ? level : undefined)); | ||
if (!levelsNodes[level]) | ||
levelsNodes[level] = []; | ||
levelsNodes[level].push(callback(node)); | ||
if (node.right) | ||
@@ -865,3 +915,3 @@ stack.push([node.right, level + 1]); | ||
} | ||
return ans; | ||
return levelsNodes; | ||
} | ||
@@ -868,0 +918,0 @@ /** |
@@ -15,3 +15,3 @@ /** | ||
} | ||
export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode> extends BinaryTree<V, N> implements IBinaryTree<V, N> { | ||
export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>> extends BinaryTree<V, N> implements IBinaryTree<V, N> { | ||
/** | ||
@@ -18,0 +18,0 @@ * The constructor function initializes a binary search tree object with an optional comparator |
@@ -10,5 +10,5 @@ import { BinaryTreeNodeKey, RBColor, RBTreeNodeNested, RBTreeOptions } from '../../types'; | ||
} | ||
export declare class RBTree<V, N extends RBTreeNode<V, N> = RBTreeNode> extends BST<V, N> implements IBinaryTree<V, N> { | ||
export declare class RBTree<V, N extends RBTreeNode<V, N> = RBTreeNode<V, RBTreeNodeNested<V>>> extends BST<V, N> implements IBinaryTree<V, N> { | ||
constructor(options?: RBTreeOptions); | ||
createNode(key: BinaryTreeNodeKey, val?: V): N; | ||
} |
@@ -29,3 +29,3 @@ /** | ||
*/ | ||
export declare class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultisetNode> extends AVLTree<V, N> implements IBinaryTree<V, N> { | ||
export declare class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultisetNode<V, TreeMultisetNodeNested<V>>> extends AVLTree<V, N> implements IBinaryTree<V, N> { | ||
/** | ||
@@ -32,0 +32,0 @@ * The constructor function for a TreeMultiset class in TypeScript, which extends another class and sets an option to |
{ | ||
"name": "directed-graph-typed", | ||
"version": "1.38.7", | ||
"version": "1.38.8", | ||
"description": "Directed Graph. Javascript & Typescript Data Structure.", | ||
@@ -149,4 +149,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"data-structure-typed": "^1.38.7" | ||
"data-structure-typed": "^1.38.8" | ||
} | ||
} |
@@ -22,6 +22,5 @@ /** | ||
export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode> | ||
export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTreeNodeNested<V>>> | ||
extends BST<V, N> | ||
implements IBinaryTree<V, N> | ||
{ | ||
implements IBinaryTree<V, N> { | ||
/** | ||
@@ -165,3 +164,3 @@ * This is a constructor function for an AVL tree data structure in TypeScript. | ||
this._balanceFactor(A) // second O(1) | ||
) { | ||
) { | ||
case -2: | ||
@@ -168,0 +167,0 @@ if (A && A.left) { |
@@ -20,3 +20,3 @@ /** | ||
*/ | ||
constructor({frequency = 0, max}: {frequency?: number; max: number}) { | ||
constructor({frequency = 0, max}: { frequency?: number; max: number }) { | ||
this._freq = frequency; | ||
@@ -23,0 +23,0 @@ this._max = max; |
@@ -118,3 +118,3 @@ /** | ||
*/ | ||
export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode> implements IBinaryTree<V, N> { | ||
export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>> implements IBinaryTree<V, N> { | ||
/** | ||
@@ -408,3 +408,3 @@ * Creates a new instance of BinaryTree. | ||
const stack: {node: N; depth: number}[] = [{node: beginRoot, depth: 0}]; | ||
const stack: { node: N; depth: number }[] = [{node: beginRoot, depth: 0}]; | ||
let maxHeight = 0; | ||
@@ -892,3 +892,3 @@ | ||
// 0: visit, 1: print | ||
const stack: {opt: 0 | 1; node: N | null | undefined}[] = [{opt: 0, node: beginRoot}]; | ||
const stack: { opt: 0 | 1; node: N | null | undefined }[] = [{opt: 0, node: beginRoot}]; | ||
@@ -936,6 +936,2 @@ while (stack.length > 0) { | ||
* `BFSCallbackReturn<N>`. The default value for this parameter is `this._defaultCallbackByKey | ||
* @param {boolean} [withLevel=false] - The `withLevel` parameter is a boolean flag that determines | ||
* whether to include the level of each node in the callback function. If `withLevel` is set | ||
* to `true`, the level of each node will be passed as an argument to the callback function. If | ||
* `withLevel` is | ||
* @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first | ||
@@ -950,3 +946,2 @@ * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search | ||
callback: C = this._defaultCallbackByKey as C, | ||
withLevel: boolean = false, | ||
beginRoot: N | null = this.root, | ||
@@ -960,4 +955,62 @@ iterationType = this.iterationType | ||
if (iterationType === IterationType.RECURSIVE) { | ||
const queue = new Queue<N>([beginRoot]); | ||
function traverse(level: number) { | ||
if (queue.size === 0) return; | ||
const current = queue.shift()!; | ||
ans.push(callback(current)); | ||
if (current.left) queue.push(current.left); | ||
if (current.right) queue.push(current.right); | ||
traverse(level + 1); | ||
} | ||
traverse(0); | ||
} else { | ||
const queue = new Queue<N>([beginRoot]); | ||
while (queue.size > 0) { | ||
const levelSize = queue.size; | ||
for (let i = 0; i < levelSize; i++) { | ||
const current = queue.shift()!; | ||
ans.push(callback(current)); | ||
if (current.left) queue.push(current.left); | ||
if (current.right) queue.push(current.right); | ||
} | ||
} | ||
} | ||
return ans; | ||
} | ||
/** | ||
* The `listLevels` function takes a binary tree node and a callback function, and returns an array | ||
* of arrays representing the levels of the tree. | ||
* @param {C} callback - The `callback` parameter is a function that will be called on each node in | ||
* the tree. It takes a node as input and returns a value. The return type of the callback function | ||
* is determined by the generic type `C`. | ||
* @param {N | null} beginRoot - The `beginRoot` parameter represents the starting node of the binary tree | ||
* traversal. It can be any node in the binary tree. If no node is provided, the traversal will start | ||
* from the root node of the binary tree. | ||
* @param iterationType - The `iterationType` parameter determines whether the tree traversal is done | ||
* recursively or iteratively. It can have two possible values: | ||
* @returns The function `listLevels` returns an array of arrays, where each inner array represents a | ||
* level in a binary tree. Each inner array contains the return type of the provided callback | ||
* function `C` applied to the nodes at that level. | ||
*/ | ||
listLevels<C extends BFSCallback<N> = BFSCallback<N, BinaryTreeNodeKey>>( | ||
callback: C = this._defaultCallbackByKey as C, | ||
beginRoot: N | null = this.root, | ||
iterationType = this.iterationType | ||
): ReturnType<C>[][] { | ||
if (!beginRoot) return []; | ||
const levelsNodes: ReturnType<C>[][] = []; | ||
if (iterationType === IterationType.RECURSIVE) { | ||
const _recursive = (node: N, level: number) => { | ||
callback && ans.push(callback(node, withLevel ? level : undefined)); | ||
if (!levelsNodes[level]) levelsNodes[level] = []; | ||
levelsNodes[level].push(callback(node)); | ||
if (node.left) _recursive(node.left, level + 1); | ||
@@ -975,3 +1028,4 @@ if (node.right) _recursive(node.right, level + 1); | ||
callback && ans.push(callback(node, withLevel ? level : undefined)); | ||
if (!levelsNodes[level]) levelsNodes[level] = []; | ||
levelsNodes[level].push(callback(node)); | ||
if (node.right) stack.push([node.right, level + 1]); | ||
@@ -981,3 +1035,4 @@ if (node.left) stack.push([node.left, level + 1]); | ||
} | ||
return ans; | ||
return levelsNodes; | ||
} | ||
@@ -984,0 +1039,0 @@ |
@@ -27,3 +27,3 @@ /** | ||
export class BST<V = any, N extends BSTNode<V, N> = BSTNode> extends BinaryTree<V, N> implements IBinaryTree<V, N> { | ||
export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>> extends BinaryTree<V, N> implements IBinaryTree<V, N> { | ||
/** | ||
@@ -30,0 +30,0 @@ * The constructor function initializes a binary search tree object with an optional comparator |
@@ -22,3 +22,3 @@ import {BinaryTreeNodeKey, RBColor, RBTreeNodeNested, RBTreeOptions} from '../../types'; | ||
export class RBTree<V, N extends RBTreeNode<V, N> = RBTreeNode> extends BST<V, N> implements IBinaryTree<V, N> { | ||
export class RBTree<V, N extends RBTreeNode<V, N> = RBTreeNode<V, RBTreeNodeNested<V>>> extends BST<V, N> implements IBinaryTree<V, N> { | ||
constructor(options?: RBTreeOptions) { | ||
@@ -25,0 +25,0 @@ super(options); |
@@ -38,6 +38,5 @@ /** | ||
*/ | ||
export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultisetNode> | ||
export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultisetNode<V, TreeMultisetNodeNested<V>>> | ||
extends AVLTree<V, N> | ||
implements IBinaryTree<V, N> | ||
{ | ||
implements IBinaryTree<V, N> { | ||
/** | ||
@@ -44,0 +43,0 @@ * The constructor function for a TreeMultiset class in TypeScript, which extends another class and sets an option to |
@@ -108,4 +108,3 @@ /** | ||
E extends AbstractEdge<any> = AbstractEdge<any> | ||
> implements IGraph<V, E> | ||
{ | ||
> implements IGraph<V, E> { | ||
private _vertices: Map<VertexKey, V> = new Map<VertexKey, V>(); | ||
@@ -558,10 +557,10 @@ | ||
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; | ||
} | ||
}); | ||
} | ||
}); | ||
@@ -628,3 +627,3 @@ genPaths && getPaths(minDest); | ||
const heap = new PriorityQueue<{key: number; val: V}>((a, b) => a.key - b.key); | ||
const heap = new PriorityQueue<{ key: number; val: V }>((a, b) => a.key - b.key); | ||
heap.add({key: 0, val: srcVertex}); | ||
@@ -858,3 +857,3 @@ | ||
*/ | ||
floyd(): {costs: number[][]; predecessor: (V | null)[][]} { | ||
floyd(): { costs: number[][]; predecessor: (V | null)[][] } { | ||
const idAndVertices = [...this._vertices]; | ||
@@ -861,0 +860,0 @@ const n = idAndVertices.length; |
@@ -67,4 +67,3 @@ /** | ||
extends AbstractGraph<V, E> | ||
implements IGraph<V, E> | ||
{ | ||
implements IGraph<V, E> { | ||
/** | ||
@@ -71,0 +70,0 @@ * The constructor function initializes an instance of a class. |
@@ -54,8 +54,7 @@ /** | ||
export class UndirectedGraph< | ||
V extends UndirectedVertex<any> = UndirectedVertex, | ||
E extends UndirectedEdge<any> = UndirectedEdge | ||
> | ||
V extends UndirectedVertex<any> = UndirectedVertex, | ||
E extends UndirectedEdge<any> = UndirectedEdge | ||
> | ||
extends AbstractGraph<V, E> | ||
implements IGraph<V, E> | ||
{ | ||
implements IGraph<V, E> { | ||
/** | ||
@@ -62,0 +61,0 @@ * The constructor initializes a new Map object to store edges. |
@@ -160,3 +160,3 @@ import {HashFunction} from '../../types'; | ||
*entries(): IterableIterator<[K, V]> { | ||
* entries(): IterableIterator<[K, V]> { | ||
for (const bucket of this.table) { | ||
@@ -163,0 +163,0 @@ if (bucket) { |
@@ -1,1 +0,2 @@ | ||
export class TreeMap {} | ||
export class TreeMap { | ||
} |
@@ -1,1 +0,2 @@ | ||
export class TreeSet {} | ||
export class TreeSet { | ||
} |
@@ -488,3 +488,3 @@ /** | ||
*[Symbol.iterator]() { | ||
* [Symbol.iterator]() { | ||
let current = this.head; | ||
@@ -491,0 +491,0 @@ |
@@ -17,3 +17,3 @@ /** | ||
*/ | ||
constructor(options: {row: number; col: number; initialVal?: V}) { | ||
constructor(options: { row: number; col: number; initialVal?: V }) { | ||
const {row, col, initialVal} = options; | ||
@@ -20,0 +20,0 @@ this._matrix = new Array(row).fill(undefined).map(() => new Array(col).fill(initialVal || 0)); |
@@ -13,3 +13,4 @@ /** | ||
public w: number = 1 // needed for matrix multiplication | ||
) {} | ||
) { | ||
} | ||
@@ -16,0 +17,0 @@ /** |
@@ -12,3 +12,4 @@ /** | ||
// O(1) time complexity of adding at the beginning and the end | ||
export class Deque<E = any> extends DoublyLinkedList<E> {} | ||
export class Deque<E = any> extends DoublyLinkedList<E> { | ||
} | ||
@@ -23,5 +24,5 @@ // O(1) time complexity of obtaining the value | ||
private _nodes: {[key: number]: E} = {}; | ||
private _nodes: { [key: number]: E } = {}; | ||
get nodes(): {[p: number]: E} { | ||
get nodes(): { [p: number]: E } { | ||
return this._nodes; | ||
@@ -161,3 +162,3 @@ } | ||
protected _seNodes(value: {[p: number]: E}) { | ||
protected _seNodes(value: { [p: number]: E }) { | ||
this._nodes = value; | ||
@@ -164,0 +165,0 @@ } |
@@ -186,3 +186,3 @@ /** | ||
*[Symbol.iterator]() { | ||
* [Symbol.iterator]() { | ||
for (const item of this.nodes) { | ||
@@ -189,0 +189,0 @@ yield item; |
export type Direction = 'up' | 'right' | 'down' | 'left'; | ||
export type Turning = {[key in Direction]: Direction}; | ||
export type Turning = { [key in Direction]: Direction }; | ||
@@ -5,0 +5,0 @@ export type NavigatorParams<T = any> = { |
export type ToThunkFn = () => ReturnType<TrlFn>; | ||
export type Thunk = () => ReturnType<ToThunkFn> & {__THUNK__: symbol}; | ||
export type Thunk = () => ReturnType<ToThunkFn> & { __THUNK__: symbol }; | ||
export type TrlFn = (...args: any[]) => any; | ||
@@ -4,0 +4,0 @@ export type TrlAsyncFn = (...args: any[]) => any; |
@@ -1,4 +0,4 @@ | ||
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 }; | ||
@@ -5,0 +5,0 @@ export type NonNumberNonObjectButDefined = string | boolean | symbol | null; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1449798
25245
Updateddata-structure-typed@^1.38.8