max-priority-queue-typed
Advanced tools
Comparing version 1.49.8 to 1.49.9
@@ -16,3 +16,3 @@ /** | ||
*/ | ||
export declare class HashMap<K = any, V = any> extends IterableEntryBase<K, V> { | ||
export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> { | ||
protected _store: { | ||
@@ -22,11 +22,13 @@ [key: string]: HashMapStoreItem<K, V>; | ||
protected _objMap: Map<object, V>; | ||
protected _toEntryFn: (rawElement: R) => [K, V]; | ||
get toEntryFn(): (rawElement: R) => [K, V]; | ||
isEntry(rawElement: any): rawElement is [K, V]; | ||
/** | ||
* The constructor function initializes a new instance of a class with optional entries and options. | ||
* @param entries - The `entries` parameter is an iterable containing key-value pairs `[K, V]`. It | ||
* is optional and defaults to an empty array `[]`. This parameter is used to initialize the map with | ||
* key-value pairs. | ||
* @param [options] - The `options` parameter is an optional object that can contain additional | ||
* configuration options for the constructor. In this case, it has one property: | ||
* The constructor function initializes a HashMap object with an optional initial collection and | ||
* options. | ||
* @param rawCollection - The `rawCollection` parameter is an iterable collection of elements of type | ||
* `T`. It is an optional parameter and its default value is an empty array `[]`. | ||
* @param [options] - The `options` parameter is an optional object that can contain two properties: | ||
*/ | ||
constructor(entries?: Iterable<[K, V]>, options?: HashMapOptions<K>); | ||
constructor(rawCollection?: Iterable<R>, options?: HashMapOptions<K, V, R>); | ||
protected _size: number; | ||
@@ -47,7 +49,9 @@ get size(): number; | ||
/** | ||
* The function "setMany" sets multiple key-value pairs in a map. | ||
* @param entries - The `entries` parameter is an iterable containing key-value pairs. Each | ||
* key-value pair is represented as an array with two entries: the key and the value. | ||
* The function `setMany` takes an iterable collection of objects, maps each object to a key-value | ||
* pair using a mapping function, and sets each key-value pair in the current object. | ||
* @param rawCollection - The `rawCollection` parameter is an iterable collection of elements of type | ||
* `T`. | ||
* @returns The `setMany` function is returning an array of booleans. | ||
*/ | ||
setMany(entries: Iterable<[K, V]>): boolean[]; | ||
setMany(rawCollection: Iterable<R>): boolean[]; | ||
/** | ||
@@ -54,0 +58,0 @@ * The `get` function retrieves a value from a map based on a given key, either from an object map or |
@@ -13,24 +13,41 @@ "use strict"; | ||
class HashMap extends base_1.IterableEntryBase { | ||
get toEntryFn() { | ||
return this._toEntryFn; | ||
} | ||
isEntry(rawElement) { | ||
return Array.isArray(rawElement) && rawElement.length === 2; | ||
} | ||
/** | ||
* The constructor function initializes a new instance of a class with optional entries and options. | ||
* @param entries - The `entries` parameter is an iterable containing key-value pairs `[K, V]`. It | ||
* is optional and defaults to an empty array `[]`. This parameter is used to initialize the map with | ||
* key-value pairs. | ||
* @param [options] - The `options` parameter is an optional object that can contain additional | ||
* configuration options for the constructor. In this case, it has one property: | ||
* The constructor function initializes a HashMap object with an optional initial collection and | ||
* options. | ||
* @param rawCollection - The `rawCollection` parameter is an iterable collection of elements of type | ||
* `T`. It is an optional parameter and its default value is an empty array `[]`. | ||
* @param [options] - The `options` parameter is an optional object that can contain two properties: | ||
*/ | ||
constructor(entries = [], options) { | ||
constructor(rawCollection = [], options) { | ||
super(); | ||
this._store = {}; | ||
this._objMap = new Map(); | ||
this._toEntryFn = (rawElement) => { | ||
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."); | ||
} | ||
}; | ||
this._size = 0; | ||
this._hashFn = (key) => String(key); | ||
if (options) { | ||
const { hashFn } = options; | ||
const { hashFn, toEntryFn } = options; | ||
if (hashFn) { | ||
this._hashFn = hashFn; | ||
} | ||
if (toEntryFn) { | ||
this._toEntryFn = toEntryFn; | ||
} | ||
} | ||
if (entries) { | ||
this.setMany(entries); | ||
if (rawCollection) { | ||
this.setMany(rawCollection); | ||
} | ||
@@ -75,10 +92,14 @@ } | ||
/** | ||
* The function "setMany" sets multiple key-value pairs in a map. | ||
* @param entries - The `entries` parameter is an iterable containing key-value pairs. Each | ||
* key-value pair is represented as an array with two entries: the key and the value. | ||
* The function `setMany` takes an iterable collection of objects, maps each object to a key-value | ||
* pair using a mapping function, and sets each key-value pair in the current object. | ||
* @param rawCollection - The `rawCollection` parameter is an iterable collection of elements of type | ||
* `T`. | ||
* @returns The `setMany` function is returning an array of booleans. | ||
*/ | ||
setMany(entries) { | ||
setMany(rawCollection) { | ||
const results = []; | ||
for (const [key, value] of entries) | ||
for (const rawEle of rawCollection) { | ||
const [key, value] = this.toEntryFn(rawEle); | ||
results.push(this.set(key, value)); | ||
} | ||
return results; | ||
@@ -85,0 +106,0 @@ } |
@@ -11,4 +11,5 @@ export type HashMapLinkedNode<K, V> = { | ||
}; | ||
export type HashMapOptions<K> = { | ||
export type HashMapOptions<K, V, T> = { | ||
hashFn?: (key: K) => string; | ||
toEntryFn?: (rawElement: T) => [K, V]; | ||
}; | ||
@@ -15,0 +16,0 @@ export type HashMapStoreItem<K, V> = { |
{ | ||
"name": "max-priority-queue-typed", | ||
"version": "1.49.8", | ||
"version": "1.49.9", | ||
"description": "Max Priority Queue. Javascript & Typescript Data Structure.", | ||
@@ -130,4 +130,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"data-structure-typed": "^1.49.8" | ||
"data-structure-typed": "^1.49.9" | ||
} | ||
} |
@@ -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,9 +43,10 @@ /** | ||
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> | ||
{ | ||
/** | ||
@@ -281,3 +282,3 @@ * The constructor function initializes an AVLTree object with optional keysOrNodesOrEntries and options. | ||
this._balanceFactor(A) // second O(1) | ||
) { | ||
) { | ||
case -2: | ||
@@ -284,0 +285,0 @@ if (A && A.left) { |
@@ -86,9 +86,10 @@ /** | ||
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> | ||
{ | ||
/** | ||
@@ -95,0 +96,0 @@ * This is the constructor function for a binary search tree class in TypeScript, which initializes |
@@ -44,9 +44,10 @@ /** | ||
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; | ||
@@ -53,0 +54,0 @@ |
@@ -48,9 +48,10 @@ /** | ||
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>) { | ||
@@ -57,0 +58,0 @@ super([], options); |
@@ -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() { | ||
@@ -614,10 +615,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; | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
@@ -1277,3 +1278,3 @@ genPaths && getPaths(minDest); | ||
protected* _getIterator(): IterableIterator<[VertexKey, V | undefined]> { | ||
protected *_getIterator(): IterableIterator<[VertexKey, V | undefined]> { | ||
for (const vertex of this._vertexMap.values()) { | ||
@@ -1280,0 +1281,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. |
@@ -24,24 +24,44 @@ /** | ||
*/ | ||
export class HashMap<K = any, V = any> extends IterableEntryBase<K, V> { | ||
export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K, V> { | ||
protected _store: { [key: string]: HashMapStoreItem<K, V> } = {}; | ||
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; | ||
} | ||
/** | ||
* The constructor function initializes a new instance of a class with optional entries and options. | ||
* @param entries - The `entries` parameter is an iterable containing key-value pairs `[K, V]`. It | ||
* is optional and defaults to an empty array `[]`. This parameter is used to initialize the map with | ||
* key-value pairs. | ||
* @param [options] - The `options` parameter is an optional object that can contain additional | ||
* configuration options for the constructor. In this case, it has one property: | ||
* The constructor function initializes a HashMap object with an optional initial collection and | ||
* options. | ||
* @param rawCollection - The `rawCollection` parameter is an iterable collection of elements of type | ||
* `T`. It is an optional parameter and its default value is an empty array `[]`. | ||
* @param [options] - The `options` parameter is an optional object that can contain two properties: | ||
*/ | ||
constructor(entries: Iterable<[K, V]> = [], options?: HashMapOptions<K>) { | ||
constructor(rawCollection: Iterable<R> = [], options?: HashMapOptions<K, V, R>) { | ||
super(); | ||
if (options) { | ||
const { hashFn } = options; | ||
const { hashFn, toEntryFn } = options; | ||
if (hashFn) { | ||
this._hashFn = hashFn; | ||
} | ||
if (toEntryFn) { | ||
this._toEntryFn = toEntryFn; | ||
} | ||
} | ||
if (entries) { | ||
this.setMany(entries); | ||
if (rawCollection) { | ||
this.setMany(rawCollection); | ||
} | ||
@@ -92,9 +112,14 @@ } | ||
/** | ||
* The function "setMany" sets multiple key-value pairs in a map. | ||
* @param entries - The `entries` parameter is an iterable containing key-value pairs. Each | ||
* key-value pair is represented as an array with two entries: the key and the value. | ||
* The function `setMany` takes an iterable collection of objects, maps each object to a key-value | ||
* pair using a mapping function, and sets each key-value pair in the current object. | ||
* @param rawCollection - The `rawCollection` parameter is an iterable collection of elements of type | ||
* `T`. | ||
* @returns The `setMany` function is returning an array of booleans. | ||
*/ | ||
setMany(entries: Iterable<[K, V]>): boolean[] { | ||
setMany(rawCollection: Iterable<R>): boolean[] { | ||
const results: boolean[] = []; | ||
for (const [key, value] of entries) results.push(this.set(key, value)); | ||
for (const rawEle of rawCollection) { | ||
const [key, value] = this.toEntryFn(rawEle); | ||
results.push(this.set(key, value)); | ||
} | ||
return results; | ||
@@ -228,3 +253,3 @@ } | ||
*/ | ||
protected* _getIterator(): IterableIterator<[K, V]> { | ||
protected *_getIterator(): IterableIterator<[K, V]> { | ||
for (const node of Object.values(this._store)) { | ||
@@ -328,3 +353,3 @@ yield [node.key, node.value] as [K, V]; | ||
*/ | ||
* begin() { | ||
*begin() { | ||
let node = this._head; | ||
@@ -341,3 +366,3 @@ while (node !== this._sentinel) { | ||
*/ | ||
* reverseBegin() { | ||
*reverseBegin() { | ||
let node = this._tail; | ||
@@ -643,3 +668,3 @@ while (node !== this._sentinel) { | ||
*/ | ||
protected* _getIterator() { | ||
protected *_getIterator() { | ||
let node = this._head; | ||
@@ -646,0 +671,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; |
@@ -13,6 +13,7 @@ export type HashMapLinkedNode<K, V> = { | ||
export type HashMapOptions<K> = { | ||
export type HashMapOptions<K, V, T> = { | ||
hashFn?: (key: K) => string; | ||
toEntryFn?: (rawElement: T) => [K, V]; | ||
}; | ||
export type HashMapStoreItem<K, V> = { key: K; value: V }; |
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
1754916
35426
Updateddata-structure-typed@^1.49.9