Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

max-priority-queue-typed

Package Overview
Dependencies
Maintainers
1
Versions
169
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

max-priority-queue-typed - npm Package Compare versions

Comparing version 1.49.9 to 1.50.0

7

dist/data-structures/binary-tree/avl-tree.d.ts

@@ -60,9 +60,2 @@ /**

/**
* The function "isNotNodeInstance" checks if a potential key is a K.
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
* data type.
* @returns a boolean value indicating whether the potentialKey is of type number or not.
*/
isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K;
/**
* Time Complexity: O(log n)

@@ -69,0 +62,0 @@ * Space Complexity: O(1)

@@ -74,11 +74,2 @@ "use strict";

/**
* The function "isNotNodeInstance" checks if a potential key is a K.
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
* data type.
* @returns a boolean value indicating whether the potentialKey is of type number or not.
*/
isNotNodeInstance(potentialKey) {
return !(potentialKey instanceof AVLTreeNode);
}
/**
* Time Complexity: O(log n)

@@ -85,0 +76,0 @@ * Space Complexity: O(1)

27

dist/data-structures/binary-tree/binary-tree.d.ts

@@ -139,9 +139,2 @@ /**

/**
* The function "isNotNodeInstance" checks if a potential key is a K.
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
* data type.
* @returns a boolean value indicating whether the potentialKey is of type number or not.
*/
isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K;
/**
* Time Complexity O(log n) - O(n)

@@ -348,3 +341,3 @@ * Space Complexity O(1)

* structure, with the option to reverse the order of the nodes.
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
* @param {K | N | null | undefined} beginNode - The `beginRoot` parameter represents the
* starting node from which you want to find the path to the root. It can be of type `K`, `N`,

@@ -357,3 +350,3 @@ * `null`, or `undefined`.

*/
getPathToRoot(beginRoot: KeyOrNodeOrEntry<K, V, N>, isReverse?: boolean): N[];
getPathToRoot(beginNode: KeyOrNodeOrEntry<K, V, N>, isReverse?: boolean): N[];
/**

@@ -415,12 +408,4 @@ * Time Complexity: O(log n)

isBST(beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): boolean;
/**
* Time complexity: O(n)
* Space complexity: O(log n)
*/
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
dfs<C extends BTNCallback<N | null | undefined>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
dfs<C extends BTNCallback<N | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
/**

@@ -431,4 +416,3 @@ * Time complexity: O(n)

bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
bfs<C extends BTNCallback<N | null>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
/**

@@ -439,4 +423,3 @@ * Time complexity: O(n)

listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[][];
listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
listLevels<C extends BTNCallback<N | null>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
/**

@@ -443,0 +426,0 @@ * Time Complexity: O(log n)

116

dist/data-structures/binary-tree/bst.d.ts

@@ -9,3 +9,3 @@ /**

import type { BSTNested, BSTNodeNested, BSTOptions, BTNCallback, KeyOrNodeOrEntry } from '../../types';
import { BSTVariant, CP, IterationType } from '../../types';
import { BSTVariant, CP, DFSOrderPattern, IterationType } from '../../types';
import { BinaryTree, BinaryTreeNode } from './binary-tree';

@@ -105,9 +105,2 @@ import { IBinaryTree } from '../../interfaces';

/**
* The function "isNotNodeInstance" checks if a potential key is a K.
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
* data type.
* @returns a boolean value indicating whether the potentialKey is of type number or not.
*/
isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K;
/**
* The function checks if an keyOrNodeOrEntry is an instance of BSTNode.

@@ -163,21 +156,2 @@ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, N>`.

/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
* Adding each element individually in a balanced tree. Additional space is required for the sorted array.
*/
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
*
* The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
* leftmost node if the comparison result is greater than.
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
* type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
* the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
* @returns the key of the rightmost node in the binary tree if the comparison result is less than,
* the key of the leftmost node if the comparison result is greater than, and the key of the
* rightmost node otherwise. If no node is found, it returns 0.
*/
lastKey(beginRoot?: KeyOrNodeOrEntry<K, V, N>): K | undefined;
/**
* Time Complexity: O(log n)

@@ -232,2 +206,90 @@ * Space Complexity: O(1)

/**
* Time complexity: O(n)
* Space complexity: O(n)
*/
/**
* Time complexity: O(n)
* Space complexity: O(n)
*
* The function overrides the depth-first search method and returns an array of the return types of
* the callback function.
* @param {C} callback - The `callback` parameter is a function that will be called for each node
* during the depth-first search traversal. It is an optional parameter and if not provided, a
* default callback function will be used.
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter specifies the order in which the
* nodes are visited during the depth-first search. It can have one of the following values:
* @param beginRoot - The `beginRoot` parameter is used to specify the starting point for the
* Depth-First Search (DFS) traversal. It can be either a key, a node, or an entry in the tree. If no
* value is provided, the DFS traversal will start from the root of the tree.
* @param {IterationType} iterationType - The `iterationType` parameter specifies the type of
* iteration to be used during the Depth-First Search (DFS) traversal. It can have one of the
* following values:
* @returns The method is returning an array of the return type of the callback function.
*/
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): ReturnType<C>[];
/**
* Time complexity: O(n)
* Space complexity: O(n)
*/
/**
* Time complexity: O(n)
* Space complexity: O(n)
*
* The function overrides the breadth-first search method and returns an array of the return types of
* the callback function.
* @param {C} callback - The `callback` parameter is a function that will be called for each node
* visited during the breadth-first search traversal. It is an optional parameter and if not
* provided, a default callback function will be used.
* @param beginRoot - The `beginRoot` parameter is the starting point for the breadth-first search
* traversal. It can be either a key, a node, or an entry in the tree. If not specified, the root of
* the tree is used as the starting point.
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
* be performed during the breadth-first search (BFS) traversal. It determines the order in which the
* nodes are visited.
* @returns The method is returning an array of the return type of the callback function.
*/
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): ReturnType<C>[];
/**
* Time complexity: O(n)
* Space complexity: O(n)
*/
/**
* Time complexity: O(n)
* Space complexity: O(n)
*
* The function overrides the listLevels method and returns an array of arrays containing the return
* type of the callback function for each level of the tree.
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
* `BTNCallback<N>`. It represents a callback function that will be called for each node in the tree
* during the level listing process.
* @param beginRoot - The `beginRoot` parameter is used to specify the starting point for listing the
* levels of a binary tree. It can be either a key, a node, or an entry in the binary tree. If not
* provided, the root of the binary tree is used as the starting point.
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
* be performed on the tree. It determines the order in which the nodes are visited during the
* iteration.
* @returns The method is returning a two-dimensional array of the return type of the callback
* function.
*/
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): ReturnType<C>[][];
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
* Adding each element individually in a balanced tree. Additional space is required for the sorted array.
*/
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
*
* The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
* leftmost node if the comparison result is greater than.
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
* type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
* the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
* @returns the key of the rightmost node in the binary tree if the comparison result is less than,
* the key of the leftmost node if the comparison result is greater than, and the key of the
* rightmost node otherwise. If no node is found, it returns 0.
*/
lastKey(beginRoot?: KeyOrNodeOrEntry<K, V, N>): K | undefined;
/**
* Time Complexity: O(log n)

@@ -234,0 +296,0 @@ * Space Complexity: O(log n)

@@ -130,3 +130,3 @@ "use strict";

}
else if (this.isNotNodeInstance(keyOrNodeOrEntry)) {
else if (!this.isNode(keyOrNodeOrEntry)) {
node = this.createNode(keyOrNodeOrEntry, value);

@@ -172,11 +172,2 @@ }

/**
* The function "isNotNodeInstance" checks if a potential key is a K.
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
* data type.
* @returns a boolean value indicating whether the potentialKey is of type number or not.
*/
isNotNodeInstance(potentialKey) {
return !(potentialKey instanceof BSTNode);
}
/**
* The function checks if an keyOrNodeOrEntry is an instance of BSTNode.

@@ -349,38 +340,2 @@ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, N>`.

/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
* Adding each element individually in a balanced tree. Additional space is required for the sorted array.
*/
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
*
* The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
* leftmost node if the comparison result is greater than.
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
* type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
* the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
* @returns the key of the rightmost node in the binary tree if the comparison result is less than,
* the key of the leftmost node if the comparison result is greater than, and the key of the
* rightmost node otherwise. If no node is found, it returns 0.
*/
lastKey(beginRoot = this.root) {
let current = this.ensureNode(beginRoot);
if (!current)
return undefined;
if (this._variant === types_1.BSTVariant.STANDARD) {
// For BSTVariant.MIN, find the rightmost node
while (current.right !== undefined) {
current = current.right;
}
}
else {
// For BSTVariant.MAX, find the leftmost node
while (current.left !== undefined) {
current = current.left;
}
}
return current.key;
}
/**
* Time Complexity: O(log n)

@@ -519,3 +474,133 @@ * Space Complexity: O(1)

}
// /**
// * The function overrides the subTreeTraverse method and returns the result of calling the super
// * method with the provided arguments.
// * @param {C} callback - The `callback` parameter is a function that will be called for each node in
// * the subtree traversal. It should accept a single parameter of type `N`, which represents a node in
// * the tree. The return type of the callback function can be any type.
// * @param beginRoot - The `beginRoot` parameter is the starting point for traversing the subtree. It
// * can be either a key, a node, or an entry.
// * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
// * be performed during the traversal of the subtree. It can have one of the following values:
// * @returns The method is returning an array of the return type of the callback function.
// */
// override subTreeTraverse<C extends BTNCallback<N>>(
// callback: C = this._defaultOneParamCallback as C,
// beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root,
// iterationType = this.iterationType
// ): ReturnType<C>[] {
// return super.subTreeTraverse(callback, beginRoot, iterationType, false);
// }
/**
* Time complexity: O(n)
* Space complexity: O(n)
*/
/**
* Time complexity: O(n)
* Space complexity: O(n)
*
* The function overrides the depth-first search method and returns an array of the return types of
* the callback function.
* @param {C} callback - The `callback` parameter is a function that will be called for each node
* during the depth-first search traversal. It is an optional parameter and if not provided, a
* default callback function will be used.
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter specifies the order in which the
* nodes are visited during the depth-first search. It can have one of the following values:
* @param beginRoot - The `beginRoot` parameter is used to specify the starting point for the
* Depth-First Search (DFS) traversal. It can be either a key, a node, or an entry in the tree. If no
* value is provided, the DFS traversal will start from the root of the tree.
* @param {IterationType} iterationType - The `iterationType` parameter specifies the type of
* iteration to be used during the Depth-First Search (DFS) traversal. It can have one of the
* following values:
* @returns The method is returning an array of the return type of the callback function.
*/
dfs(callback = this._defaultOneParamCallback, pattern = 'in', beginRoot = this.root, iterationType = types_1.IterationType.ITERATIVE) {
return super.dfs(callback, pattern, beginRoot, iterationType, false);
}
/**
* Time complexity: O(n)
* Space complexity: O(n)
*/
/**
* Time complexity: O(n)
* Space complexity: O(n)
*
* The function overrides the breadth-first search method and returns an array of the return types of
* the callback function.
* @param {C} callback - The `callback` parameter is a function that will be called for each node
* visited during the breadth-first search traversal. It is an optional parameter and if not
* provided, a default callback function will be used.
* @param beginRoot - The `beginRoot` parameter is the starting point for the breadth-first search
* traversal. It can be either a key, a node, or an entry in the tree. If not specified, the root of
* the tree is used as the starting point.
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
* be performed during the breadth-first search (BFS) traversal. It determines the order in which the
* nodes are visited.
* @returns The method is returning an array of the return type of the callback function.
*/
bfs(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
return super.bfs(callback, beginRoot, iterationType, false);
}
/**
* Time complexity: O(n)
* Space complexity: O(n)
*/
/**
* Time complexity: O(n)
* Space complexity: O(n)
*
* The function overrides the listLevels method and returns an array of arrays containing the return
* type of the callback function for each level of the tree.
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
* `BTNCallback<N>`. It represents a callback function that will be called for each node in the tree
* during the level listing process.
* @param beginRoot - The `beginRoot` parameter is used to specify the starting point for listing the
* levels of a binary tree. It can be either a key, a node, or an entry in the binary tree. If not
* provided, the root of the binary tree is used as the starting point.
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
* be performed on the tree. It determines the order in which the nodes are visited during the
* iteration.
* @returns The method is returning a two-dimensional array of the return type of the callback
* function.
*/
listLevels(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
return super.listLevels(callback, beginRoot, iterationType, false);
}
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
* Adding each element individually in a balanced tree. Additional space is required for the sorted array.
*/
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
*
* The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
* leftmost node if the comparison result is greater than.
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
* type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
* the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
* @returns the key of the rightmost node in the binary tree if the comparison result is less than,
* the key of the leftmost node if the comparison result is greater than, and the key of the
* rightmost node otherwise. If no node is found, it returns 0.
*/
lastKey(beginRoot = this.root) {
let current = this.ensureNode(beginRoot);
if (!current)
return undefined;
if (this._variant === types_1.BSTVariant.STANDARD) {
// For BSTVariant.MIN, find the rightmost node
while (current.right !== undefined) {
current = current.right;
}
}
else {
// For BSTVariant.MAX, find the leftmost node
while (current.left !== undefined) {
current = current.left;
}
}
return current.key;
}
/**
* Time Complexity: O(log n)

@@ -522,0 +607,0 @@ * Space Complexity: O(log n)

@@ -83,9 +83,2 @@ /**

/**
* The function "isNotNodeInstance" checks if a potential key is a K.
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
* data type.
* @returns a boolean value indicating whether the potentialKey is of type number or not.
*/
isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K;
/**
* Time Complexity: O(log n)

@@ -92,0 +85,0 @@ * Space Complexity: O(1)

@@ -103,3 +103,3 @@ "use strict";

}
else if (this.isNotNodeInstance(keyOrNodeOrEntry)) {
else if (!this.isNode(keyOrNodeOrEntry)) {
node = this.createNode(keyOrNodeOrEntry, value, types_1.RBTNColor.RED);

@@ -131,11 +131,2 @@ }

/**
* The function "isNotNodeInstance" checks if a potential key is a K.
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
* data type.
* @returns a boolean value indicating whether the potentialKey is of type number or not.
*/
isNotNodeInstance(potentialKey) {
return !(potentialKey instanceof RedBlackTreeNode);
}
/**
* Time Complexity: O(log n)

@@ -142,0 +133,0 @@ * Space Complexity: O(1)

@@ -64,9 +64,2 @@ /**

/**
* The function "isNotNodeInstance" checks if a potential key is a K.
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
* data type.
* @returns a boolean value indicating whether the potentialKey is of type number or not.
*/
isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K;
/**
* Time Complexity: O(log n)

@@ -73,0 +66,0 @@ * Space Complexity: O(1)

@@ -36,3 +36,3 @@ "use strict";

let sum = 0;
this.subTreeTraverse(node => (sum += node.count));
this.dfs(node => (sum += node.count));
return sum;

@@ -83,3 +83,3 @@ }

}
else if (this.isNotNodeInstance(keyOrNodeOrEntry)) {
else if (!this.isNode(keyOrNodeOrEntry)) {
node = this.createNode(keyOrNodeOrEntry, value, count);

@@ -102,11 +102,2 @@ }

/**
* The function "isNotNodeInstance" checks if a potential key is a K.
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
* data type.
* @returns a boolean value indicating whether the potentialKey is of type number or not.
*/
isNotNodeInstance(potentialKey) {
return !(potentialKey instanceof TreeMultimapNode);
}
/**
* Time Complexity: O(log n)

@@ -113,0 +104,0 @@ * Space Complexity: O(1)

@@ -21,5 +21,2 @@ /**

protected _objMap: Map<object, V>;
protected _toEntryFn: (rawElement: R) => [K, V];
get toEntryFn(): (rawElement: R) => [K, V];
isEntry(rawElement: any): rawElement is [K, V];
/**

@@ -33,4 +30,7 @@ * The constructor function initializes a HashMap object with an optional initial collection and

constructor(rawCollection?: Iterable<R>, options?: HashMapOptions<K, V, R>);
protected _toEntryFn: (rawElement: R) => [K, V];
get toEntryFn(): (rawElement: R) => [K, V];
protected _size: number;
get size(): number;
isEntry(rawElement: any): rawElement is [K, V];
isEmpty(): boolean;

@@ -37,0 +37,0 @@ clear(): void;

@@ -13,8 +13,2 @@ "use strict";

class HashMap extends base_1.IterableEntryBase {
get toEntryFn() {
return this._toEntryFn;
}
isEntry(rawElement) {
return Array.isArray(rawElement) && rawElement.length === 2;
}
/**

@@ -55,5 +49,11 @@ * The constructor function initializes a HashMap object with an optional initial collection and

}
get toEntryFn() {
return this._toEntryFn;
}
get size() {
return this._size;
}
isEntry(rawElement) {
return Array.isArray(rawElement) && rawElement.length === 2;
}
isEmpty() {

@@ -60,0 +60,0 @@ return this.size === 0;

{
"name": "max-priority-queue-typed",
"version": "1.49.9",
"version": "1.50.0",
"description": "Max Priority Queue. Javascript & Typescript Data Structure.",

@@ -130,4 +130,4 @@ "main": "dist/index.js",

"dependencies": {
"data-structure-typed": "^1.49.9"
"data-structure-typed": "^1.50.0"
}
}

@@ -18,3 +18,3 @@ import { ElementCallback, EntryCallback, ReduceElementCallback, ReduceEntryCallback } from '../../types';

*/
*[Symbol.iterator](...args: any[]): IterableIterator<[K, V]> {
* [Symbol.iterator](...args: any[]): IterableIterator<[K, V]> {
yield* this._getIterator(...args);

@@ -34,3 +34,3 @@ }

*/
*entries(): IterableIterator<[K, V | undefined]> {
* entries(): IterableIterator<[K, V | undefined]> {
for (const item of this) {

@@ -51,3 +51,3 @@ yield item;

*/
*keys(): IterableIterator<K> {
* keys(): IterableIterator<K> {
for (const item of this) {

@@ -68,3 +68,3 @@ yield item[0];

*/
*values(): IterableIterator<V> {
* values(): IterableIterator<V> {
for (const item of this) {

@@ -219,3 +219,3 @@ yield item[1];

*/
*[Symbol.iterator](...args: any[]): IterableIterator<V> {
* [Symbol.iterator](...args: any[]): IterableIterator<V> {
yield* this._getIterator(...args);

@@ -234,3 +234,3 @@ }

*/
*values(): IterableIterator<V> {
* values(): IterableIterator<V> {
for (const item of this) {

@@ -237,0 +237,0 @@ yield item;

@@ -43,10 +43,9 @@ /**

export class AVLTree<
K = any,
V = any,
N extends AVLTreeNode<K, V, N> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>,
TREE extends AVLTree<K, V, N, TREE> = AVLTree<K, V, N, AVLTreeNested<K, V, N>>
>
K = any,
V = any,
N extends AVLTreeNode<K, V, N> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>,
TREE extends AVLTree<K, V, N, TREE> = AVLTree<K, V, N, AVLTreeNested<K, V, N>>
>
extends BST<K, V, N, TREE>
implements IBinaryTree<K, V, N, TREE>
{
implements IBinaryTree<K, V, N, TREE> {
/**

@@ -104,12 +103,2 @@ * The constructor function initializes an AVLTree object with optional keysOrNodesOrEntries and options.

/**
* The function "isNotNodeInstance" checks if a potential key is a K.
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
* data type.
* @returns a boolean value indicating whether the potentialKey is of type number or not.
*/
override isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K {
return !(potentialKey instanceof AVLTreeNode);
}
/**
* Time Complexity: O(log n)

@@ -283,3 +272,3 @@ * Space Complexity: O(1)

this._balanceFactor(A) // second O(1)
) {
) {
case -2:

@@ -286,0 +275,0 @@ if (A && A.left) {

@@ -16,3 +16,3 @@ /**

} from '../../types';
import { BSTVariant, CP, IterationType } from '../../types';
import { BSTVariant, CP, DFSOrderPattern, IterationType } from '../../types';
import { BinaryTree, BinaryTreeNode } from './binary-tree';

@@ -87,10 +87,9 @@ import { IBinaryTree } from '../../interfaces';

export class BST<
K = any,
V = any,
N extends BSTNode<K, V, N> = BSTNode<K, V, BSTNodeNested<K, V>>,
TREE extends BST<K, V, N, TREE> = BST<K, V, N, BSTNested<K, V, N>>
>
K = any,
V = any,
N extends BSTNode<K, V, N> = BSTNode<K, V, BSTNodeNested<K, V>>,
TREE extends BST<K, V, N, TREE> = BST<K, V, N, BSTNested<K, V, N>>
>
extends BinaryTree<K, V, N, TREE>
implements IBinaryTree<K, V, N, TREE>
{
implements IBinaryTree<K, V, N, TREE> {
/**

@@ -177,3 +176,3 @@ * This is the constructor function for a binary search tree class in TypeScript, which initializes

}
} else if (this.isNotNodeInstance(keyOrNodeOrEntry)) {
} else if (!this.isNode(keyOrNodeOrEntry)) {
node = this.createNode(keyOrNodeOrEntry, value);

@@ -220,12 +219,2 @@ } else {

/**
* The function "isNotNodeInstance" checks if a potential key is a K.
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
* data type.
* @returns a boolean value indicating whether the potentialKey is of type number or not.
*/
override isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K {
return !(potentialKey instanceof BSTNode);
}
/**
* The function checks if an keyOrNodeOrEntry is an instance of BSTNode.

@@ -416,39 +405,2 @@ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, N>`.

/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
* Adding each element individually in a balanced tree. Additional space is required for the sorted array.
*/
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
*
* The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
* leftmost node if the comparison result is greater than.
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
* type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
* the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
* @returns the key of the rightmost node in the binary tree if the comparison result is less than,
* the key of the leftmost node if the comparison result is greater than, and the key of the
* rightmost node otherwise. If no node is found, it returns 0.
*/
lastKey(beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root): K | undefined {
let current = this.ensureNode(beginRoot);
if (!current) return undefined;
if (this._variant === BSTVariant.STANDARD) {
// For BSTVariant.MIN, find the rightmost node
while (current.right !== undefined) {
current = current.right;
}
} else {
// For BSTVariant.MAX, find the leftmost node
while (current.left !== undefined) {
current = current.left;
}
}
return current.key;
}
/**
* Time Complexity: O(log n)

@@ -582,3 +534,154 @@ * Space Complexity: O(1)

// /**
// * The function overrides the subTreeTraverse method and returns the result of calling the super
// * method with the provided arguments.
// * @param {C} callback - The `callback` parameter is a function that will be called for each node in
// * the subtree traversal. It should accept a single parameter of type `N`, which represents a node in
// * the tree. The return type of the callback function can be any type.
// * @param beginRoot - The `beginRoot` parameter is the starting point for traversing the subtree. It
// * can be either a key, a node, or an entry.
// * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
// * be performed during the traversal of the subtree. It can have one of the following values:
// * @returns The method is returning an array of the return type of the callback function.
// */
// override subTreeTraverse<C extends BTNCallback<N>>(
// callback: C = this._defaultOneParamCallback as C,
// beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root,
// iterationType = this.iterationType
// ): ReturnType<C>[] {
// return super.subTreeTraverse(callback, beginRoot, iterationType, false);
// }
/**
* Time complexity: O(n)
* Space complexity: O(n)
*/
/**
* Time complexity: O(n)
* Space complexity: O(n)
*
* The function overrides the depth-first search method and returns an array of the return types of
* the callback function.
* @param {C} callback - The `callback` parameter is a function that will be called for each node
* during the depth-first search traversal. It is an optional parameter and if not provided, a
* default callback function will be used.
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter specifies the order in which the
* nodes are visited during the depth-first search. It can have one of the following values:
* @param beginRoot - The `beginRoot` parameter is used to specify the starting point for the
* Depth-First Search (DFS) traversal. It can be either a key, a node, or an entry in the tree. If no
* value is provided, the DFS traversal will start from the root of the tree.
* @param {IterationType} iterationType - The `iterationType` parameter specifies the type of
* iteration to be used during the Depth-First Search (DFS) traversal. It can have one of the
* following values:
* @returns The method is returning an array of the return type of the callback function.
*/
override dfs<C extends BTNCallback<N>>(
callback: C = this._defaultOneParamCallback as C,
pattern: DFSOrderPattern = 'in',
beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root,
iterationType: IterationType = IterationType.ITERATIVE
): ReturnType<C>[] {
return super.dfs(callback, pattern, beginRoot, iterationType, false);
}
/**
* Time complexity: O(n)
* Space complexity: O(n)
*/
/**
* Time complexity: O(n)
* Space complexity: O(n)
*
* The function overrides the breadth-first search method and returns an array of the return types of
* the callback function.
* @param {C} callback - The `callback` parameter is a function that will be called for each node
* visited during the breadth-first search traversal. It is an optional parameter and if not
* provided, a default callback function will be used.
* @param beginRoot - The `beginRoot` parameter is the starting point for the breadth-first search
* traversal. It can be either a key, a node, or an entry in the tree. If not specified, the root of
* the tree is used as the starting point.
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
* be performed during the breadth-first search (BFS) traversal. It determines the order in which the
* nodes are visited.
* @returns The method is returning an array of the return type of the callback function.
*/
override bfs<C extends BTNCallback<N>>(
callback: C = this._defaultOneParamCallback as C,
beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root,
iterationType = this.iterationType
): ReturnType<C>[] {
return super.bfs(callback, beginRoot, iterationType, false);
}
/**
* Time complexity: O(n)
* Space complexity: O(n)
*/
/**
* Time complexity: O(n)
* Space complexity: O(n)
*
* The function overrides the listLevels method and returns an array of arrays containing the return
* type of the callback function for each level of the tree.
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
* `BTNCallback<N>`. It represents a callback function that will be called for each node in the tree
* during the level listing process.
* @param beginRoot - The `beginRoot` parameter is used to specify the starting point for listing the
* levels of a binary tree. It can be either a key, a node, or an entry in the binary tree. If not
* provided, the root of the binary tree is used as the starting point.
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
* be performed on the tree. It determines the order in which the nodes are visited during the
* iteration.
* @returns The method is returning a two-dimensional array of the return type of the callback
* function.
*/
override listLevels<C extends BTNCallback<N>>(
callback: C = this._defaultOneParamCallback as C,
beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root,
iterationType = this.iterationType
): ReturnType<C>[][] {
return super.listLevels(callback, beginRoot, iterationType, false);
}
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
* Adding each element individually in a balanced tree. Additional space is required for the sorted array.
*/
/**
* Time Complexity: O(n log n)
* Space Complexity: O(n)
*
* The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
* leftmost node if the comparison result is greater than.
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
* type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
* the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
* @returns the key of the rightmost node in the binary tree if the comparison result is less than,
* the key of the leftmost node if the comparison result is greater than, and the key of the
* rightmost node otherwise. If no node is found, it returns 0.
*/
lastKey(beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root): K | undefined {
let current = this.ensureNode(beginRoot);
if (!current) return undefined;
if (this._variant === BSTVariant.STANDARD) {
// For BSTVariant.MIN, find the rightmost node
while (current.right !== undefined) {
current = current.right;
}
} else {
// For BSTVariant.MAX, find the leftmost node
while (current.left !== undefined) {
current = current.left;
}
}
return current.key;
}
/**
* Time Complexity: O(log n)

@@ -585,0 +688,0 @@ * Space Complexity: O(log n)

@@ -44,10 +44,9 @@ /**

export class RedBlackTree<
K = any,
V = any,
N extends RedBlackTreeNode<K, V, N> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>,
TREE extends RedBlackTree<K, V, N, TREE> = RedBlackTree<K, V, N, RedBlackTreeNested<K, V, N>>
>
K = any,
V = any,
N extends RedBlackTreeNode<K, V, N> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>,
TREE extends RedBlackTree<K, V, N, TREE> = RedBlackTree<K, V, N, RedBlackTreeNested<K, V, N>>
>
extends BST<K, V, N, TREE>
implements IBinaryTree<K, V, N, TREE>
{
implements IBinaryTree<K, V, N, TREE> {
Sentinel: N = new RedBlackTreeNode<K, V>(NaN as K) as unknown as N;

@@ -137,3 +136,3 @@

}
} else if (this.isNotNodeInstance(keyOrNodeOrEntry)) {
} else if (!this.isNode(keyOrNodeOrEntry)) {
node = this.createNode(keyOrNodeOrEntry, value, RBTNColor.RED);

@@ -167,12 +166,2 @@ } else {

/**
* The function "isNotNodeInstance" checks if a potential key is a K.
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
* data type.
* @returns a boolean value indicating whether the potentialKey is of type number or not.
*/
override isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K {
return !(potentialKey instanceof RedBlackTreeNode);
}
/**
* Time Complexity: O(log n)

@@ -179,0 +168,0 @@ * Space Complexity: O(1)

@@ -48,10 +48,9 @@ /**

export class TreeMultimap<
K = any,
V = any,
N extends TreeMultimapNode<K, V, N> = TreeMultimapNode<K, V, TreeMultimapNodeNested<K, V>>,
TREE extends TreeMultimap<K, V, N, TREE> = TreeMultimap<K, V, N, TreeMultimapNested<K, V, N>>
>
K = any,
V = any,
N extends TreeMultimapNode<K, V, N> = TreeMultimapNode<K, V, TreeMultimapNodeNested<K, V>>,
TREE extends TreeMultimap<K, V, N, TREE> = TreeMultimap<K, V, N, TreeMultimapNested<K, V, N>>
>
extends AVLTree<K, V, N, TREE>
implements IBinaryTree<K, V, N, TREE>
{
implements IBinaryTree<K, V, N, TREE> {
constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>> = [], options?: TreeMultimapOptions<K>) {

@@ -67,3 +66,3 @@ super([], options);

let sum = 0;
this.subTreeTraverse(node => (sum += node.count));
this.dfs(node => (sum += node.count));
return sum;

@@ -117,3 +116,3 @@ }

}
} else if (this.isNotNodeInstance(keyOrNodeOrEntry)) {
} else if (!this.isNode(keyOrNodeOrEntry)) {
node = this.createNode(keyOrNodeOrEntry, value, count);

@@ -137,12 +136,2 @@ } else {

/**
* The function "isNotNodeInstance" checks if a potential key is a K.
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
* data type.
* @returns a boolean value indicating whether the potentialKey is of type number or not.
*/
override isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K {
return !(potentialKey instanceof TreeMultimapNode);
}
/**
* Time Complexity: O(log n)

@@ -149,0 +138,0 @@ * Space Complexity: O(1)

@@ -64,10 +64,9 @@ /**

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() {

@@ -615,10 +614,10 @@ super();

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;
}
});
}
});

@@ -1278,3 +1277,3 @@ genPaths && getPaths(minDest);

protected *_getIterator(): IterableIterator<[VertexKey, V | undefined]> {
protected* _getIterator(): IterableIterator<[VertexKey, V | undefined]> {
for (const vertex of this._vertexMap.values()) {

@@ -1281,0 +1280,0 @@ yield [vertex.key, vertex.value];

@@ -49,10 +49,9 @@ /**

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> {
/**

@@ -59,0 +58,0 @@ * The constructor function initializes an instance of a class.

@@ -46,10 +46,9 @@ /**

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> {
/**

@@ -56,0 +55,0 @@ * The constructor initializes a new Map object to store edgeMap.

@@ -27,21 +27,3 @@ /**

protected _objMap: Map<object, V> = new Map();
protected _toEntryFn: (rawElement: R) => [K, V] = (rawElement: R) => {
if (this.isEntry(rawElement)) {
// TODO, For performance optimization, it may be necessary to only inspect the first element traversed.
return rawElement;
} else {
throw new Error(
"If the provided rawCollection does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified."
);
}
};
get toEntryFn() {
return this._toEntryFn;
}
isEntry(rawElement: any): rawElement is [K, V] {
return Array.isArray(rawElement) && rawElement.length === 2;
}
/**

@@ -70,2 +52,17 @@ * The constructor function initializes a HashMap object with an optional initial collection and

protected _toEntryFn: (rawElement: R) => [K, V] = (rawElement: R) => {
if (this.isEntry(rawElement)) {
// TODO, For performance optimization, it may be necessary to only inspect the first element traversed.
return rawElement;
} else {
throw new Error(
"If the provided rawCollection does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified."
);
}
};
get toEntryFn() {
return this._toEntryFn;
}
protected _size = 0;

@@ -77,2 +74,6 @@

isEntry(rawElement: any): rawElement is [K, V] {
return Array.isArray(rawElement) && rawElement.length === 2;
}
isEmpty(): boolean {

@@ -254,3 +255,3 @@ return this.size === 0;

*/
protected *_getIterator(): IterableIterator<[K, V]> {
protected* _getIterator(): IterableIterator<[K, V]> {
for (const node of Object.values(this._store)) {

@@ -354,3 +355,3 @@ yield [node.key, node.value] as [K, V];

*/
*begin() {
* begin() {
let node = this._head;

@@ -367,3 +368,3 @@ while (node !== this._sentinel) {

*/
*reverseBegin() {
* reverseBegin() {
let node = this._tail;

@@ -669,3 +670,3 @@ while (node !== this._sentinel) {

*/
protected *_getIterator() {
protected* _getIterator() {
let node = this._head;

@@ -672,0 +673,0 @@ while (node !== this._sentinel) {

@@ -394,3 +394,3 @@ /**

protected *_getIterator(): IterableIterator<E> {
protected* _getIterator(): IterableIterator<E> {
for (const element of this.elements) {

@@ -397,0 +397,0 @@ yield element;

@@ -811,3 +811,3 @@ /**

*/
protected *_getIterator(): IterableIterator<E> {
protected* _getIterator(): IterableIterator<E> {
let current = this.head;

@@ -814,0 +814,0 @@

@@ -744,3 +744,3 @@ /**

protected *_getIterator(): IterableIterator<E> {
protected* _getIterator(): IterableIterator<E> {
let current = this.head;

@@ -747,0 +747,0 @@

@@ -235,3 +235,3 @@ /**

*/
*begin(): Generator<E> {
* begin(): Generator<E> {
let index = 0;

@@ -248,3 +248,3 @@ while (index < this.size) {

*/
*reverseBegin(): Generator<E> {
* reverseBegin(): Generator<E> {
let index = this.size - 1;

@@ -740,3 +740,3 @@ while (index >= 0) {

*/
protected *_getIterator(): IterableIterator<E> {
protected* _getIterator(): IterableIterator<E> {
for (let i = 0; i < this.size; ++i) {

@@ -743,0 +743,0 @@ yield this.getAt(i);

@@ -348,3 +348,3 @@ /**

protected *_getIterator(): IterableIterator<E> {
protected* _getIterator(): IterableIterator<E> {
for (const item of this.elements) {

@@ -351,0 +351,0 @@ yield item;

@@ -232,3 +232,3 @@ /**

*/
protected *_getIterator(): IterableIterator<E> {
protected* _getIterator(): IterableIterator<E> {
for (let i = 0; i < this.elements.length; i++) {

@@ -235,0 +235,0 @@ yield this.elements[i];

@@ -413,3 +413,3 @@ /**

protected *_getIterator(): IterableIterator<string> {
protected* _getIterator(): IterableIterator<string> {
function* _dfs(node: TrieNode, path: string): IterableIterator<string> {

@@ -416,0 +416,0 @@ if (node.isEnd) {

@@ -5,10 +5,10 @@ export type VertexKey = string | number;

| {
distMap: Map<V, number>;
distPaths?: Map<V, V[]>;
preMap: Map<V, V | undefined>;
seen: Set<V>;
paths: V[][];
minDist: number;
minPath: V[];
}
distMap: Map<V, number>;
distPaths?: Map<V, V[]>;
preMap: Map<V, V | undefined>;
seen: Set<V>;
paths: V[][];
minDist: number;
minPath: V[];
}
| undefined;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc