mirror of
https://github.com/zrwusa/data-structure-typed.git
synced 2024-11-23 12:54:04 +00:00
[binary-tree] renamed _loopType to _iterationType
This commit is contained in:
parent
f2d3be7574
commit
af23af911a
|
@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file.
|
|||
- [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
|
||||
- [`auto-changelog`](https://github.com/CookPete/auto-changelog)
|
||||
|
||||
## [v1.38.5](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
|
||||
## [v1.38.6](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
|
||||
|
||||
### Changes
|
||||
|
||||
|
|
36
package-lock.json
generated
36
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "data-structure-typed",
|
||||
"version": "1.38.5",
|
||||
"version": "1.38.6",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "data-structure-typed",
|
||||
"version": "1.38.5",
|
||||
"version": "1.38.6",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/benchmark": "^2.1.3",
|
||||
|
@ -15,17 +15,17 @@
|
|||
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
||||
"@typescript-eslint/parser": "^6.7.4",
|
||||
"auto-changelog": "^2.4.0",
|
||||
"avl-tree-typed": "^1.38.4",
|
||||
"avl-tree-typed": "^1.38.5",
|
||||
"benchmark": "^2.1.4",
|
||||
"binary-tree-typed": "^1.38.4",
|
||||
"bst-typed": "^1.38.4",
|
||||
"binary-tree-typed": "^1.38.5",
|
||||
"bst-typed": "^1.38.5",
|
||||
"dependency-cruiser": "^14.1.0",
|
||||
"eslint": "^8.50.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-import-resolver-alias": "^1.1.2",
|
||||
"eslint-import-resolver-typescript": "^3.6.1",
|
||||
"eslint-plugin-import": "^2.28.1",
|
||||
"heap-typed": "^1.38.4",
|
||||
"heap-typed": "^1.38.5",
|
||||
"istanbul-badges-readme": "^1.8.5",
|
||||
"jest": "^29.7.0",
|
||||
"prettier": "^3.0.3",
|
||||
|
@ -2728,9 +2728,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/avl-tree-typed": {
|
||||
"version": "1.38.4",
|
||||
"resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.38.4.tgz",
|
||||
"integrity": "sha512-m4+vC3t52CnPqMB5dxZI016OKMCxitk6vDsdqSadPHUeZd92E9LEQSHzgjdZ380FGcIZuz9q0IS7VTHR4F3+gg==",
|
||||
"version": "1.38.5",
|
||||
"resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.38.5.tgz",
|
||||
"integrity": "sha512-rwVkzj8+N57YPCurFn+kmtxEd9xvE8QqYlOAkibRsEScN8E2z7cHkVlT0mxc26Q8HfLUvkqJjvEcwoLaHqYxzw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"data-structure-typed": "^1.38.4"
|
||||
|
@ -2927,9 +2927,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/binary-tree-typed": {
|
||||
"version": "1.38.4",
|
||||
"resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.38.4.tgz",
|
||||
"integrity": "sha512-InWS3ggQsmEyqgvaO+Veme/uTphUxaFQ1C7/9Bz07zcr8lV0riDsj0En9qwGTI8R4L32CpBL1cxQXJbk9Do45g==",
|
||||
"version": "1.38.5",
|
||||
"resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.38.5.tgz",
|
||||
"integrity": "sha512-ksluya1YOjzQWMJzCNWnkjw/iinYvYMQhZYLwcdhwuiSy7nlDJpSxil3dh3sc3ffZDjCDi+FtTe2TOlOKBNzHQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"data-structure-typed": "^1.38.4"
|
||||
|
@ -3011,9 +3011,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/bst-typed": {
|
||||
"version": "1.38.4",
|
||||
"resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.38.4.tgz",
|
||||
"integrity": "sha512-OCY+VQBfj8m8KYZullDuKrwYD8vzRBiIQ92hYDL3GWzuDMlTeEFUyIcDni0SR91JxRuUPbL7CuxN0fQRjDMKRg==",
|
||||
"version": "1.38.5",
|
||||
"resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.38.5.tgz",
|
||||
"integrity": "sha512-JrfBhfqx9VFFQ/EMjG+CHCnEoJdrR3BZ0AGCpT2y6NbBWOdjuLghorVnvy85kiEpU06xSQewhqf3cWNz0pSrPA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"data-structure-typed": "^1.38.4"
|
||||
|
@ -4771,9 +4771,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/heap-typed": {
|
||||
"version": "1.38.4",
|
||||
"resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.38.4.tgz",
|
||||
"integrity": "sha512-fI+xbxoC3jpkmwqKIFRoJ8BGojd7FitEeYhwrkGpKnNMs9zp5dxA2qmrk+Gof0lDMuRca5CplVyInvGgL7cjzw==",
|
||||
"version": "1.38.5",
|
||||
"resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.38.5.tgz",
|
||||
"integrity": "sha512-C9LQZScfnHGbhxL6wnUJEGwfg2oqdY10a0An3t/1pSVGEN91tmZzQS10BfYf5plQgF2fYNhZJbSkiuanUA0TgQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"data-structure-typed": "^1.38.4"
|
||||
|
|
10
package.json
10
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "data-structure-typed",
|
||||
"version": "1.38.5",
|
||||
"version": "1.38.6",
|
||||
"description": "Data Structures of Javascript & TypeScript. Binary Tree, BST, Graph, Heap, Priority Queue, Linked List, Queue, Deque, Stack, AVL Tree, Tree Multiset, Trie, Directed Graph, Undirected Graph, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue.",
|
||||
"main": "dist/cjs/index.js",
|
||||
"module": "dist/mjs/index.js",
|
||||
|
@ -61,17 +61,17 @@
|
|||
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
||||
"@typescript-eslint/parser": "^6.7.4",
|
||||
"auto-changelog": "^2.4.0",
|
||||
"avl-tree-typed": "^1.38.4",
|
||||
"avl-tree-typed": "^1.38.5",
|
||||
"benchmark": "^2.1.4",
|
||||
"binary-tree-typed": "^1.38.4",
|
||||
"bst-typed": "^1.38.4",
|
||||
"binary-tree-typed": "^1.38.5",
|
||||
"bst-typed": "^1.38.5",
|
||||
"dependency-cruiser": "^14.1.0",
|
||||
"eslint": "^8.50.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-import-resolver-alias": "^1.1.2",
|
||||
"eslint-import-resolver-typescript": "^3.6.1",
|
||||
"eslint-plugin-import": "^2.28.1",
|
||||
"heap-typed": "^1.38.4",
|
||||
"heap-typed": "^1.38.5",
|
||||
"istanbul-badges-readme": "^1.8.5",
|
||||
"jest": "^29.7.0",
|
||||
"prettier": "^3.0.3",
|
||||
|
|
|
@ -6,20 +6,12 @@
|
|||
* @license MIT License
|
||||
*/
|
||||
import {BST, BSTNode} from './bst';
|
||||
import type {
|
||||
AVLTreeNodeNested,
|
||||
AVLTreeOptions,
|
||||
BinaryTreeDeletedResult,
|
||||
BinaryTreeNodeKey,
|
||||
DefaultMapCallback
|
||||
} from '../../types';
|
||||
import type {AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeKey} from '../../types';
|
||||
import {MapCallback} from '../../types';
|
||||
import {IBinaryTree} from '../../interfaces';
|
||||
import {MapCallback} from "../../types";
|
||||
|
||||
export class AVLTreeNode<V = any, FAMILY extends AVLTreeNode<V, FAMILY> = AVLTreeNodeNested<V>> extends BSTNode<
|
||||
V,
|
||||
FAMILY
|
||||
> {
|
||||
export class AVLTreeNode<V = any, FAMILY extends AVLTreeNode<V, FAMILY> = AVLTreeNodeNested<V>> extends
|
||||
BSTNode<V, FAMILY> {
|
||||
height: number;
|
||||
|
||||
constructor(key: BinaryTreeNodeKey, val?: V) {
|
||||
|
@ -82,7 +74,8 @@ export class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends B
|
|||
*/
|
||||
override delete<C extends MapCallback<N>>(
|
||||
identifier: ReturnType<C>,
|
||||
callback: C = this._defaultCallbackByKey as C): BinaryTreeDeletedResult<N>[] {
|
||||
callback: C = this._defaultCallbackByKey as C
|
||||
): BinaryTreeDeletedResult<N>[] {
|
||||
const deletedResults = super.delete(identifier, callback);
|
||||
for (const {needBalanced} of deletedResults) {
|
||||
if (needBalanced) {
|
||||
|
@ -166,7 +159,7 @@ export class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends B
|
|||
// 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) {
|
||||
|
|
|
@ -17,7 +17,7 @@ export class BinaryIndexedTree {
|
|||
* @param - - `frequency`: The default frequency value. It is optional and has a default
|
||||
* value of 0.
|
||||
*/
|
||||
constructor({frequency = 0, max}: {frequency?: number; max: number}) {
|
||||
constructor({frequency = 0, max}: { frequency?: number; max: number }) {
|
||||
this._freq = frequency;
|
||||
this._max = max;
|
||||
this._freqMap = {0: 0};
|
||||
|
|
|
@ -116,8 +116,6 @@ export class BinaryTreeNode<V = any, FAMILY extends BinaryTreeNode<V, FAMILY> =
|
|||
* @template N - The type of the binary tree's nodes.
|
||||
*/
|
||||
export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode> implements IBinaryTree<N> {
|
||||
private _loopType: IterationType = IterationType.ITERATIVE;
|
||||
|
||||
/**
|
||||
* Creates a new instance of BinaryTree.
|
||||
* @param {BinaryTreeOptions} [options] - The options for the binary tree.
|
||||
|
@ -125,10 +123,27 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|||
constructor(options?: BinaryTreeOptions) {
|
||||
if (options !== undefined) {
|
||||
const {iterationType = IterationType.ITERATIVE} = options;
|
||||
this._loopType = iterationType;
|
||||
this._iterationType = iterationType;
|
||||
}
|
||||
}
|
||||
|
||||
private _iterationType: IterationType = IterationType.ITERATIVE;
|
||||
|
||||
/**
|
||||
* Get the iteration type used in the binary tree.
|
||||
*/
|
||||
get iterationType(): IterationType {
|
||||
return this._iterationType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the iteration type for the binary tree.
|
||||
* @param {IterationType} v - The new iteration type to set.
|
||||
*/
|
||||
set iterationType(v: IterationType) {
|
||||
this._iterationType = v;
|
||||
}
|
||||
|
||||
private _root: N | null = null;
|
||||
|
||||
/**
|
||||
|
@ -147,21 +162,6 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|||
return this._size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the iteration type used in the binary tree.
|
||||
*/
|
||||
get iterationType(): IterationType {
|
||||
return this._loopType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the iteration type for the binary tree.
|
||||
* @param {IterationType} v - The new iteration type to set.
|
||||
*/
|
||||
set iterationType(v: IterationType) {
|
||||
this._loopType = v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of BinaryTreeNode with the given key and value.
|
||||
* @param {BinaryTreeNodeKey} key - The key for the new node.
|
||||
|
@ -222,7 +222,7 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|||
return;
|
||||
}
|
||||
|
||||
const key = typeof keyOrNode === 'number' ? keyOrNode : keyOrNode ? keyOrNode.key: undefined;
|
||||
const key = typeof keyOrNode === 'number' ? keyOrNode : keyOrNode ? keyOrNode.key : undefined;
|
||||
const existNode = key !== undefined ? this.get(key, this._defaultCallbackByKey) : undefined;
|
||||
|
||||
if (this.root) {
|
||||
|
@ -284,14 +284,9 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|||
return keysOrNodes.length === this.addMany(keysOrNodes, data).length;
|
||||
}
|
||||
|
||||
delete<C extends MapCallback<N>>(
|
||||
identifier: ReturnType<C> | N
|
||||
): BinaryTreeDeletedResult<N>[];
|
||||
delete<C extends MapCallback<N>>(identifier: ReturnType<C> | N): BinaryTreeDeletedResult<N>[];
|
||||
|
||||
delete<C extends MapCallback<N>>(
|
||||
identifier: ReturnType<C> | N,
|
||||
callback: C
|
||||
): BinaryTreeDeletedResult<N>[];
|
||||
delete<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C): BinaryTreeDeletedResult<N>[];
|
||||
|
||||
/**
|
||||
* The `delete` function removes a node from a binary search tree and returns the deleted node along
|
||||
|
@ -309,7 +304,8 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|||
*/
|
||||
delete<C extends MapCallback<N>>(
|
||||
identifier: ReturnType<C> | N,
|
||||
callback: C = this._defaultCallbackByKey as C): BinaryTreeDeletedResult<N>[] {
|
||||
callback: C = this._defaultCallbackByKey as C
|
||||
): BinaryTreeDeletedResult<N>[] {
|
||||
const bstDeletedResult: BinaryTreeDeletedResult<N>[] = [];
|
||||
if (!this.root) return bstDeletedResult;
|
||||
if (identifier instanceof BinaryTreeNode) callback = (node => node) as C;
|
||||
|
@ -408,7 +404,7 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|||
return -1;
|
||||
}
|
||||
|
||||
const stack: {node: N; depth: number}[] = [{node: beginRoot, depth: 0}];
|
||||
const stack: { node: N; depth: number }[] = [{node: beginRoot, depth: 0}];
|
||||
let maxHeight = 0;
|
||||
|
||||
while (stack.length > 0) {
|
||||
|
@ -492,26 +488,13 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|||
return this.getMinHeight(beginRoot) + 1 >= this.getHeight(beginRoot);
|
||||
}
|
||||
|
||||
getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N): N[];
|
||||
|
||||
getNodes<C extends MapCallback<N>>(
|
||||
identifier: ReturnType<C> | N
|
||||
): N[];
|
||||
getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C): N[];
|
||||
|
||||
getNodes<C extends MapCallback<N>>(
|
||||
identifier: ReturnType<C> | N,
|
||||
callback: C
|
||||
): N[];
|
||||
getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N, onlyOne: boolean): N[];
|
||||
|
||||
getNodes<C extends MapCallback<N>>(
|
||||
identifier: ReturnType<C> | N,
|
||||
onlyOne: boolean
|
||||
): N[];
|
||||
|
||||
getNodes<C extends MapCallback<N>>(
|
||||
identifier: ReturnType<C> | N,
|
||||
callback: C,
|
||||
onlyOne: boolean
|
||||
): N[];
|
||||
getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C, onlyOne: boolean): N[];
|
||||
|
||||
getNodes<C extends MapCallback<N>>(
|
||||
identifier: ReturnType<C> | N,
|
||||
|
@ -528,7 +511,6 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|||
iterationType: IterationType
|
||||
): N[];
|
||||
|
||||
|
||||
/**
|
||||
* The function `getNodes` returns an array of nodes that match a given node property, using either
|
||||
* recursive or iterative traversal.
|
||||
|
@ -635,7 +617,12 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|||
|
||||
get<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C, beginRoot: N | null): N | null;
|
||||
|
||||
get<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C, beginRoot: N | null, iterationType: IterationType): N | null;
|
||||
get<C extends MapCallback<N>>(
|
||||
identifier: ReturnType<C> | N,
|
||||
callback: C,
|
||||
beginRoot: N | null,
|
||||
iterationType: IterationType
|
||||
): N | null;
|
||||
|
||||
/**
|
||||
* The function `get` returns the first node in a binary tree that matches the given property or key.
|
||||
|
@ -900,7 +887,7 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|||
_traverse(beginRoot);
|
||||
} else {
|
||||
// 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}];
|
||||
|
||||
while (stack.length > 0) {
|
||||
const cur = stack.pop();
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
||||
* @license MIT License
|
||||
*/
|
||||
import type {BinaryTreeNodeKey, DefaultMapCallback, TreeMultisetNodeNested, TreeMultisetOptions} from '../../types';
|
||||
import type {BinaryTreeNodeKey, TreeMultisetNodeNested, TreeMultisetOptions} from '../../types';
|
||||
import {BinaryTreeDeletedResult, CP, FamilyPosition, IterationType, MapCallback} from '../../types';
|
||||
import {IBinaryTree} from '../../interfaces';
|
||||
import {AVLTree, AVLTreeNode} from './avl-tree';
|
||||
|
@ -37,8 +37,7 @@ export class TreeMultisetNode<
|
|||
*/
|
||||
export class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = TreeMultisetNode>
|
||||
extends AVLTree<N>
|
||||
implements IBinaryTree<N>
|
||||
{
|
||||
implements IBinaryTree<N> {
|
||||
/**
|
||||
* The constructor function for a TreeMultiset class in TypeScript, which extends another class and sets an option to
|
||||
* merge duplicated values.
|
||||
|
@ -280,7 +279,9 @@ export class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = TreeMultiset
|
|||
*/
|
||||
override delete<C extends MapCallback<N>>(
|
||||
identifier: ReturnType<C>,
|
||||
callback: C = this._defaultCallbackByKey as C, ignoreCount = false): BinaryTreeDeletedResult<N>[] {
|
||||
callback: C = this._defaultCallbackByKey as C,
|
||||
ignoreCount = false
|
||||
): BinaryTreeDeletedResult<N>[] {
|
||||
const bstDeletedResult: BinaryTreeDeletedResult<N>[] = [];
|
||||
if (!this.root) return bstDeletedResult;
|
||||
|
||||
|
|
|
@ -105,8 +105,7 @@ export abstract class AbstractEdge<V = any> {
|
|||
export abstract class AbstractGraph<
|
||||
V extends AbstractVertex<any> = AbstractVertex<any>,
|
||||
E extends AbstractEdge<any> = AbstractEdge<any>
|
||||
> implements IGraph<V, E>
|
||||
{
|
||||
> implements IGraph<V, E> {
|
||||
private _vertices: Map<VertexKey, V> = new Map<VertexKey, V>();
|
||||
|
||||
get vertices(): Map<VertexKey, V> {
|
||||
|
@ -554,14 +553,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);
|
||||
|
||||
|
@ -623,7 +622,7 @@ export abstract class AbstractGraph<
|
|||
if (vertexOrKey instanceof AbstractVertex) distMap.set(vertexOrKey, Infinity);
|
||||
}
|
||||
|
||||
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});
|
||||
|
||||
distMap.set(srcVertex, 0);
|
||||
|
@ -852,7 +851,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
|
||||
*/
|
||||
floyd(): {costs: number[][]; predecessor: (V | null)[][]} {
|
||||
floyd(): { costs: number[][]; predecessor: (V | null)[][] } {
|
||||
const idAndVertices = [...this._vertices];
|
||||
const n = idAndVertices.length;
|
||||
|
||||
|
|
|
@ -64,8 +64,7 @@ export class DirectedEdge<V = any> extends AbstractEdge<V> {
|
|||
|
||||
export class DirectedGraph<V extends DirectedVertex<any> = DirectedVertex, E extends DirectedEdge<any> = DirectedEdge>
|
||||
extends AbstractGraph<V, E>
|
||||
implements IGraph<V, E>
|
||||
{
|
||||
implements IGraph<V, E> {
|
||||
/**
|
||||
* The constructor function initializes an instance of a class.
|
||||
*/
|
||||
|
|
|
@ -51,12 +51,11 @@ export class UndirectedEdge<V = number> extends AbstractEdge<V> {
|
|||
}
|
||||
|
||||
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> {
|
||||
/**
|
||||
* The constructor initializes a new Map object to store edges.
|
||||
*/
|
||||
|
|
|
@ -157,7 +157,7 @@ export class HashMap<K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
*entries(): IterableIterator<[K, V]> {
|
||||
* entries(): IterableIterator<[K, V]> {
|
||||
for (const bucket of this.table) {
|
||||
if (bucket) {
|
||||
for (const [key, value] of bucket) {
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
export class TreeMap {}
|
||||
export class TreeMap {
|
||||
}
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
export class TreeSet {}
|
||||
export class TreeSet {
|
||||
}
|
||||
|
|
|
@ -594,7 +594,6 @@ export class DoublyLinkedList<E = any> {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
||||
* @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
|
||||
|
|
|
@ -485,7 +485,7 @@ export class SinglyLinkedList<E = any> {
|
|||
return count;
|
||||
}
|
||||
|
||||
*[Symbol.iterator]() {
|
||||
* [Symbol.iterator]() {
|
||||
let current = this.head;
|
||||
|
||||
while (current) {
|
||||
|
|
|
@ -14,7 +14,7 @@ export class MatrixNTI2D<V = any> {
|
|||
* 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));
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<E = any> extends DoublyLinkedList<E> {}
|
||||
export class Deque<E = any> extends DoublyLinkedList<E> {
|
||||
}
|
||||
|
||||
// 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<E = number> {
|
|||
if (capacity !== undefined) this._capacity = capacity;
|
||||
}
|
||||
|
||||
private _nodes: {[key: number]: E} = {};
|
||||
private _nodes: { [key: number]: E } = {};
|
||||
|
||||
get nodes(): {[p: number]: E} {
|
||||
get nodes(): { [p: number]: E } {
|
||||
return this._nodes;
|
||||
}
|
||||
|
||||
|
@ -156,7 +157,7 @@ export class ObjectDeque<E = number> {
|
|||
return this._size <= 0;
|
||||
}
|
||||
|
||||
protected _seNodes(value: {[p: number]: E}) {
|
||||
protected _seNodes(value: { [p: number]: E }) {
|
||||
this._nodes = value;
|
||||
}
|
||||
|
||||
|
|
|
@ -183,7 +183,7 @@ export class Queue<E = any> {
|
|||
return new Queue(this.nodes.slice(this.offset));
|
||||
}
|
||||
|
||||
*[Symbol.iterator]() {
|
||||
* [Symbol.iterator]() {
|
||||
for (const item of this.nodes) {
|
||||
yield item;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import {BinaryTreeNode} from '../data-structures';
|
||||
import {BinaryTreeDeletedResult, BinaryTreeNodeKey} from '../types';
|
||||
import {BinaryTreeDeletedResult, BinaryTreeNodeKey, MapCallback} from '../types';
|
||||
|
||||
export interface IBinaryTree<N extends BinaryTreeNode<N['val'], N>> {
|
||||
createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
|
||||
|
||||
add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
|
||||
|
||||
// delete(keyOrNode: BinaryTreeNodeKey | N): BinaryTreeDeletedResult<N>[];
|
||||
delete<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C): BinaryTreeDeletedResult<N>[];
|
||||
}
|
||||
|
|
|
@ -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<T = any> = {
|
||||
matrix: T[][];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {BinaryTreeNodeKey} from "./data-structures";
|
||||
import {BinaryTreeNodeKey} from './data-structures';
|
||||
|
||||
export type Comparator<T> = (a: T, b: T) => number;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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;
|
||||
export type TrlAsyncFn = (...args: any[]) => any;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue