heap-typed
Advanced tools
Comparing version 1.52.1 to 1.52.2
@@ -686,4 +686,4 @@ "use strict"; | ||
if (node) { | ||
const left = node.left ? (_a = depths.get(node.left)) !== null && _a !== void 0 ? _a : -1 : -1; | ||
const right = node.right ? (_b = depths.get(node.right)) !== null && _b !== void 0 ? _b : -1 : -1; | ||
const left = node.left ? ((_a = depths.get(node.left)) !== null && _a !== void 0 ? _a : -1) : -1; | ||
const right = node.right ? ((_b = depths.get(node.right)) !== null && _b !== void 0 ? _b : -1) : -1; | ||
if (Math.abs(left - right) > 1) | ||
@@ -690,0 +690,0 @@ return false; |
@@ -63,3 +63,15 @@ /** | ||
get last(): E | undefined; | ||
_autoCompactRatio: number; | ||
/** | ||
* This function returns the value of the autoCompactRatio property. | ||
* @returns The `autoCompactRatio` property of the object, which is a number. | ||
*/ | ||
get autoCompactRatio(): number; | ||
/** | ||
* The above function sets the autoCompactRatio property to a specified number in TypeScript. | ||
* @param {number} v - The parameter `v` represents the value that will be assigned to the | ||
* `_autoCompactRatio` property. | ||
*/ | ||
set autoCompactRatio(v: number); | ||
/** | ||
* Time Complexity: O(n) | ||
@@ -164,2 +176,8 @@ * Space Complexity: O(n) | ||
/** | ||
* The `compact` function in TypeScript slices the elements array based on the offset and resets the | ||
* offset to zero. | ||
* @returns The `compact()` method is returning a boolean value of `true`. | ||
*/ | ||
compact(): boolean; | ||
/** | ||
* Time Complexity: O(n) | ||
@@ -166,0 +184,0 @@ * Space Complexity: O(n) |
@@ -20,2 +20,7 @@ "use strict"; | ||
this._offset = 0; | ||
this._autoCompactRatio = 0.5; | ||
if (options) { | ||
const { autoCompactRatio = 0.5 } = options; | ||
this._autoCompactRatio = autoCompactRatio; | ||
} | ||
if (elements) { | ||
@@ -82,2 +87,17 @@ for (const el of elements) { | ||
/** | ||
* This function returns the value of the autoCompactRatio property. | ||
* @returns The `autoCompactRatio` property of the object, which is a number. | ||
*/ | ||
get autoCompactRatio() { | ||
return this._autoCompactRatio; | ||
} | ||
/** | ||
* The above function sets the autoCompactRatio property to a specified number in TypeScript. | ||
* @param {number} v - The parameter `v` represents the value that will be assigned to the | ||
* `_autoCompactRatio` property. | ||
*/ | ||
set autoCompactRatio(v) { | ||
this._autoCompactRatio = v; | ||
} | ||
/** | ||
* Time Complexity: O(n) | ||
@@ -132,8 +152,4 @@ * Space Complexity: O(n) | ||
this._offset += 1; | ||
if (this.offset * 2 < this.elements.length) | ||
return first; | ||
// only delete dequeued elements when reaching half size | ||
// to decrease latency of shifting elements. | ||
this._elements = this.elements.slice(this.offset); | ||
this._offset = 0; | ||
if (this.offset / this.elements.length > this.autoCompactRatio) | ||
this.compact(); | ||
return first; | ||
@@ -215,2 +231,12 @@ } | ||
/** | ||
* The `compact` function in TypeScript slices the elements array based on the offset and resets the | ||
* offset to zero. | ||
* @returns The `compact()` method is returning a boolean value of `true`. | ||
*/ | ||
compact() { | ||
this._elements = this.elements.slice(this.offset); | ||
this._offset = 0; | ||
return true; | ||
} | ||
/** | ||
* Time Complexity: O(n) | ||
@@ -217,0 +243,0 @@ * Space Complexity: O(n) |
import { IterableElementBaseOptions } from '../base'; | ||
export type QueueOptions<E, R> = IterableElementBaseOptions<E, R> & {}; | ||
export type QueueOptions<E, R> = IterableElementBaseOptions<E, R> & { | ||
autoCompactRatio?: number; | ||
}; |
{ | ||
"name": "heap-typed", | ||
"version": "1.52.1", | ||
"version": "1.52.2", | ||
"description": "Heap. Javascript & Typescript Data Structure.", | ||
@@ -134,4 +134,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"data-structure-typed": "^1.52.1" | ||
"data-structure-typed": "^1.52.2" | ||
} | ||
} |
@@ -45,3 +45,3 @@ import { ElementCallback, IterableElementBaseOptions, ReduceElementCallback } from '../../types'; | ||
*/ | ||
* [Symbol.iterator](...args: any[]): IterableIterator<E> { | ||
*[Symbol.iterator](...args: any[]): IterableIterator<E> { | ||
yield* this._getIterator(...args); | ||
@@ -60,3 +60,3 @@ } | ||
*/ | ||
* values(): IterableIterator<E> { | ||
*values(): IterableIterator<E> { | ||
for (const item of this) { | ||
@@ -63,0 +63,0 @@ yield item; |
@@ -38,3 +38,3 @@ import { EntryCallback, ReduceEntryCallback } from '../../types'; | ||
*/ | ||
* [Symbol.iterator](...args: any[]): IterableIterator<[K, V]> { | ||
*[Symbol.iterator](...args: any[]): IterableIterator<[K, V]> { | ||
yield* this._getIterator(...args); | ||
@@ -54,3 +54,3 @@ } | ||
*/ | ||
* entries(): IterableIterator<[K, V | undefined]> { | ||
*entries(): IterableIterator<[K, V | undefined]> { | ||
for (const item of this) { | ||
@@ -71,3 +71,3 @@ yield item; | ||
*/ | ||
* keys(): IterableIterator<K> { | ||
*keys(): IterableIterator<K> { | ||
for (const item of this) { | ||
@@ -88,3 +88,3 @@ yield item[0]; | ||
*/ | ||
* values(): IterableIterator<V> { | ||
*values(): IterableIterator<V> { | ||
for (const item of this) { | ||
@@ -91,0 +91,0 @@ yield item[1]; |
@@ -66,16 +66,17 @@ /** | ||
export class AVLTreeMultiMap< | ||
K = any, | ||
V = any, | ||
R = BTNEntry<K, V>, | ||
NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>, | ||
TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap< | ||
K, | ||
V, | ||
R, | ||
NODE, | ||
AVLTreeMultiMapNested<K, V, R, NODE> | ||
K = any, | ||
V = any, | ||
R = BTNEntry<K, V>, | ||
NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>, | ||
TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap< | ||
K, | ||
V, | ||
R, | ||
NODE, | ||
AVLTreeMultiMapNested<K, V, R, NODE> | ||
> | ||
> | ||
> | ||
extends AVLTree<K, V, R, NODE, TREE> | ||
implements IBinaryTree<K, V, R, NODE, TREE> { | ||
implements IBinaryTree<K, V, R, NODE, TREE> | ||
{ | ||
/** | ||
@@ -82,0 +83,0 @@ * The constructor initializes a new AVLTreeMultiMap object with optional initial elements. |
@@ -69,10 +69,11 @@ /** | ||
export class AVLTree< | ||
K = any, | ||
V = any, | ||
R = BTNEntry<K, V>, | ||
NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, | ||
TREE extends AVLTree<K, V, R, NODE, TREE> = AVLTree<K, V, R, NODE, AVLTreeNested<K, V, R, NODE>> | ||
> | ||
K = any, | ||
V = any, | ||
R = BTNEntry<K, V>, | ||
NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, | ||
TREE extends AVLTree<K, V, R, NODE, TREE> = AVLTree<K, V, R, NODE, AVLTreeNested<K, V, R, NODE>> | ||
> | ||
extends BST<K, V, R, NODE, TREE> | ||
implements IBinaryTree<K, V, R, NODE, TREE> { | ||
implements IBinaryTree<K, V, R, NODE, TREE> | ||
{ | ||
/** | ||
@@ -507,3 +508,3 @@ * This is a constructor function for an AVLTree class that initializes the tree with keys, nodes, | ||
this._balanceFactor(A) // second O(1) | ||
) { | ||
) { | ||
case -2: | ||
@@ -510,0 +511,0 @@ if (A && A.left) { |
@@ -97,10 +97,11 @@ /** | ||
export class BST< | ||
K = any, | ||
V = any, | ||
R = BTNEntry<K, V>, | ||
NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>, | ||
TREE extends BST<K, V, R, NODE, TREE> = BST<K, V, R, NODE, BSTNested<K, V, R, NODE>> | ||
> | ||
K = any, | ||
V = any, | ||
R = BTNEntry<K, V>, | ||
NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>, | ||
TREE extends BST<K, V, R, NODE, TREE> = BST<K, V, R, NODE, BSTNested<K, V, R, NODE>> | ||
> | ||
extends BinaryTree<K, V, R, NODE, TREE> | ||
implements IBinaryTree<K, V, R, NODE, TREE> { | ||
implements IBinaryTree<K, V, R, NODE, TREE> | ||
{ | ||
/** | ||
@@ -790,4 +791,4 @@ * This is the constructor function for a Binary Search Tree class in TypeScript. | ||
if (node) { | ||
const left = node.left ? depths.get(node.left) ?? -1 : -1; | ||
const right = node.right ? depths.get(node.right) ?? -1 : -1; | ||
const left = node.left ? (depths.get(node.left) ?? -1) : -1; | ||
const right = node.right ? (depths.get(node.right) ?? -1) : -1; | ||
if (Math.abs(left - right) > 1) return false; | ||
@@ -794,0 +795,0 @@ depths.set(node, 1 + Math.max(left, right)); |
@@ -56,10 +56,11 @@ import type { | ||
export class RedBlackTree< | ||
K = any, | ||
V = any, | ||
R = BTNEntry<K, V>, | ||
NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, | ||
TREE extends RedBlackTree<K, V, R, NODE, TREE> = RedBlackTree<K, V, R, NODE, RedBlackTreeNested<K, V, R, NODE>> | ||
> | ||
K = any, | ||
V = any, | ||
R = BTNEntry<K, V>, | ||
NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, | ||
TREE extends RedBlackTree<K, V, R, NODE, TREE> = RedBlackTree<K, V, R, NODE, RedBlackTreeNested<K, V, R, NODE>> | ||
> | ||
extends BST<K, V, R, NODE, TREE> | ||
implements IBinaryTree<K, V, R, NODE, TREE> { | ||
implements IBinaryTree<K, V, R, NODE, TREE> | ||
{ | ||
/** | ||
@@ -66,0 +67,0 @@ * This is the constructor function for a Red-Black Tree data structure in TypeScript. |
@@ -66,10 +66,11 @@ /** | ||
export class TreeMultiMap< | ||
K = any, | ||
V = any, | ||
R = BTNEntry<K, V>, | ||
NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>, | ||
TREE extends TreeMultiMap<K, V, R, NODE, TREE> = TreeMultiMap<K, V, R, NODE, TreeMultiMapNested<K, V, R, NODE>> | ||
> | ||
K = any, | ||
V = any, | ||
R = BTNEntry<K, V>, | ||
NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>, | ||
TREE extends TreeMultiMap<K, V, R, NODE, TREE> = TreeMultiMap<K, V, R, NODE, TreeMultiMapNested<K, V, R, NODE>> | ||
> | ||
extends RedBlackTree<K, V, R, NODE, TREE> | ||
implements IBinaryTree<K, V, R, NODE, TREE> { | ||
implements IBinaryTree<K, V, R, NODE, TREE> | ||
{ | ||
/** | ||
@@ -76,0 +77,0 @@ * The constructor function initializes a TreeMultiMap object with optional initial data. |
@@ -64,9 +64,10 @@ /** | ||
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() { | ||
@@ -622,10 +623,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; | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
@@ -1074,3 +1075,3 @@ genPaths && getPaths(minDest); | ||
protected* _getIterator(): IterableIterator<[VertexKey, V | undefined]> { | ||
protected *_getIterator(): IterableIterator<[VertexKey, V | undefined]> { | ||
for (const vertex of this._vertexMap.values()) { | ||
@@ -1077,0 +1078,0 @@ yield [vertex.key, vertex.value]; |
@@ -49,9 +49,10 @@ /** | ||
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> | ||
{ | ||
/** | ||
@@ -58,0 +59,0 @@ * The constructor function initializes an instance of a class. |
@@ -46,9 +46,10 @@ /** | ||
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> | ||
{ | ||
/** | ||
@@ -55,0 +56,0 @@ * The constructor initializes a new Map object to store edgeMap. |
@@ -325,3 +325,3 @@ /** | ||
*/ | ||
protected* _getIterator(): IterableIterator<[K, V]> { | ||
protected *_getIterator(): IterableIterator<[K, V]> { | ||
for (const node of Object.values(this.store)) { | ||
@@ -541,3 +541,3 @@ yield [node.key, node.value] as [K, V]; | ||
*/ | ||
* begin() { | ||
*begin() { | ||
let node = this.head; | ||
@@ -554,3 +554,3 @@ while (node !== this._sentinel) { | ||
*/ | ||
* reverseBegin() { | ||
*reverseBegin() { | ||
let node = this.tail; | ||
@@ -948,3 +948,3 @@ while (node !== this._sentinel) { | ||
*/ | ||
protected* _getIterator() { | ||
protected *_getIterator() { | ||
let node = this.head; | ||
@@ -951,0 +951,0 @@ while (node !== this._sentinel) { |
@@ -370,3 +370,3 @@ /** | ||
*/ | ||
protected* _getIterator(): IterableIterator<E> { | ||
protected *_getIterator(): IterableIterator<E> { | ||
for (const element of this.elements) { | ||
@@ -373,0 +373,0 @@ yield element; |
@@ -806,3 +806,3 @@ /** | ||
*/ | ||
protected* _getIterator(): IterableIterator<E> { | ||
protected *_getIterator(): IterableIterator<E> { | ||
let current = this.head; | ||
@@ -809,0 +809,0 @@ |
@@ -754,3 +754,3 @@ /** | ||
*/ | ||
protected* _getIterator(): IterableIterator<E> { | ||
protected *_getIterator(): IterableIterator<E> { | ||
let current = this.head; | ||
@@ -757,0 +757,0 @@ |
@@ -347,3 +347,3 @@ /** | ||
*/ | ||
* begin(): Generator<E> { | ||
*begin(): Generator<E> { | ||
let index = 0; | ||
@@ -360,3 +360,3 @@ while (index < this.size) { | ||
*/ | ||
* reverseBegin(): Generator<E> { | ||
*reverseBegin(): Generator<E> { | ||
let index = this.size - 1; | ||
@@ -853,3 +853,3 @@ while (index >= 0) { | ||
*/ | ||
protected* _getIterator(): IterableIterator<E> { | ||
protected *_getIterator(): IterableIterator<E> { | ||
for (let i = 0; i < this.size; ++i) { | ||
@@ -856,0 +856,0 @@ yield this.at(i); |
@@ -22,2 +22,8 @@ /** | ||
super(options); | ||
if (options) { | ||
const { autoCompactRatio = 0.5 } = options; | ||
this._autoCompactRatio = autoCompactRatio; | ||
} | ||
if (elements) { | ||
@@ -93,3 +99,22 @@ for (const el of elements) { | ||
_autoCompactRatio: number = 0.5; | ||
/** | ||
* This function returns the value of the autoCompactRatio property. | ||
* @returns The `autoCompactRatio` property of the object, which is a number. | ||
*/ | ||
get autoCompactRatio(): number { | ||
return this._autoCompactRatio; | ||
} | ||
/** | ||
* The above function sets the autoCompactRatio property to a specified number in TypeScript. | ||
* @param {number} v - The parameter `v` represents the value that will be assigned to the | ||
* `_autoCompactRatio` property. | ||
*/ | ||
set autoCompactRatio(v: number) { | ||
this._autoCompactRatio = v; | ||
} | ||
/** | ||
* Time Complexity: O(n) | ||
@@ -150,8 +175,3 @@ * Space Complexity: O(n) | ||
if (this.offset * 2 < this.elements.length) return first; | ||
// only delete dequeued elements when reaching half size | ||
// to decrease latency of shifting elements. | ||
this._elements = this.elements.slice(this.offset); | ||
this._offset = 0; | ||
if (this.offset / this.elements.length > this.autoCompactRatio) this.compact(); | ||
return first; | ||
@@ -244,2 +264,13 @@ } | ||
/** | ||
* The `compact` function in TypeScript slices the elements array based on the offset and resets the | ||
* offset to zero. | ||
* @returns The `compact()` method is returning a boolean value of `true`. | ||
*/ | ||
compact(): boolean { | ||
this._elements = this.elements.slice(this.offset); | ||
this._offset = 0; | ||
return true; | ||
} | ||
/** | ||
* Time Complexity: O(n) | ||
@@ -324,3 +355,3 @@ * Space Complexity: O(n) | ||
*/ | ||
protected* _getIterator(): IterableIterator<E> { | ||
protected *_getIterator(): IterableIterator<E> { | ||
for (const item of this.elements.slice(this.offset)) { | ||
@@ -327,0 +358,0 @@ yield item; |
@@ -277,3 +277,3 @@ /** | ||
*/ | ||
protected* _getIterator(): IterableIterator<E> { | ||
protected *_getIterator(): IterableIterator<E> { | ||
for (let i = 0; i < this.elements.length; i++) { | ||
@@ -280,0 +280,0 @@ yield this.elements[i]; |
@@ -563,3 +563,3 @@ /** | ||
*/ | ||
protected* _getIterator(): IterableIterator<string> { | ||
protected *_getIterator(): IterableIterator<string> { | ||
function* _dfs(node: TrieNode, path: string): IterableIterator<string> { | ||
@@ -566,0 +566,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; |
import { IterableElementBaseOptions } from '../base'; | ||
export type DequeOptions<E, R> = { | ||
bucketSize?: number, | ||
maxLen?: number | ||
bucketSize?: number; | ||
maxLen?: number; | ||
} & IterableElementBaseOptions<E, R>; |
import { IterableElementBaseOptions } from '../base'; | ||
export type QueueOptions<E, R> = IterableElementBaseOptions<E, R> & {}; | ||
export type QueueOptions<E, R> = IterableElementBaseOptions<E, R> & { | ||
autoCompactRatio?: number; | ||
}; |
@@ -16,7 +16,7 @@ export type ToThunkFn = () => ReturnType<TrlFn>; | ||
| ({ [key in string]: any } & { | ||
valueOf(): Comparable; | ||
}) | ||
valueOf(): Comparable; | ||
}) | ||
| ({ [key in string]: any } & { | ||
toString(): Comparable; | ||
}) | ||
toString(): Comparable; | ||
}) | ||
| (() => Comparable); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
2148330
41563
Updateddata-structure-typed@^1.52.2