priority-queue-typed 1.46.4 → 1.46.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/data-structures/hash/hash-map.js +1 -2
- package/dist/types/data-structures/hash/hash-map.d.ts +1 -1
- package/dist/utils/utils.d.ts +1 -1
- package/package.json +2 -2
- package/src/data-structures/hash/hash-map.ts +4 -5
- package/src/types/data-structures/hash/hash-map.ts +1 -1
- package/src/utils/utils.ts +1 -1
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
import { HashMapLinkedNode, HashMapOptions } from '../../types';
|
|
9
9
|
export declare class HashMap<K = any, V = any> {
|
|
10
10
|
protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>>;
|
|
11
|
-
protected _objMap: WeakMap<
|
|
11
|
+
protected _objMap: WeakMap<object, HashMapLinkedNode<K, V | undefined>>;
|
|
12
12
|
protected _head: HashMapLinkedNode<K, V | undefined>;
|
|
13
13
|
protected _tail: HashMapLinkedNode<K, V | undefined>;
|
|
14
14
|
protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
|
|
15
15
|
protected _hashFn: (key: K) => string;
|
|
16
|
-
protected _objHashFn: (key: K) =>
|
|
16
|
+
protected _objHashFn: (key: K) => object;
|
|
17
17
|
/**
|
|
18
18
|
* The constructor initializes a HashMapLinkedNode with an optional iterable of key-value pairs.
|
|
19
19
|
* @param options - The `options` parameter is an object that contains the `elements` property. The
|
|
@@ -99,8 +99,7 @@ class HashMap {
|
|
|
99
99
|
set(key, value) {
|
|
100
100
|
let node;
|
|
101
101
|
if ((0, utils_1.isWeakKey)(key)) {
|
|
102
|
-
|
|
103
|
-
const hash = key;
|
|
102
|
+
const hash = this._objHashFn(key);
|
|
104
103
|
node = this._objMap.get(hash);
|
|
105
104
|
if (node) {
|
|
106
105
|
// If the node already exists, update its value
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -20,5 +20,5 @@ export declare const trampolineAsync: (fn: TrlAsyncFn) => ((...args: [...Paramet
|
|
|
20
20
|
export declare const getMSB: (value: number) => number;
|
|
21
21
|
export declare const rangeCheck: (index: number, min: number, max: number, message?: string) => void;
|
|
22
22
|
export declare const throwRangeError: (message?: string) => void;
|
|
23
|
-
export declare const isWeakKey: (input: unknown) => input is
|
|
23
|
+
export declare const isWeakKey: (input: unknown) => input is object;
|
|
24
24
|
export declare const calcMinUnitsRequired: (totalQuantity: number, unitSize: number) => number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "priority-queue-typed",
|
|
3
|
-
"version": "1.46.
|
|
3
|
+
"version": "1.46.5",
|
|
4
4
|
"description": "Priority Queue, Min Priority Queue, Max Priority Queue. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -120,6 +120,6 @@
|
|
|
120
120
|
"typedoc": "^0.25.1"
|
|
121
121
|
},
|
|
122
122
|
"dependencies": {
|
|
123
|
-
"data-structure-typed": "^1.46.
|
|
123
|
+
"data-structure-typed": "^1.46.5"
|
|
124
124
|
}
|
|
125
125
|
}
|
|
@@ -12,12 +12,12 @@ import { HashMapLinkedNode, HashMapOptions } from '../../types';
|
|
|
12
12
|
export class HashMap<K = any, V = any> {
|
|
13
13
|
|
|
14
14
|
protected _noObjMap: Record<string, HashMapLinkedNode<K, V | undefined>> = {};
|
|
15
|
-
protected _objMap = new WeakMap<
|
|
15
|
+
protected _objMap = new WeakMap<object, HashMapLinkedNode<K, V | undefined>>();
|
|
16
16
|
protected _head: HashMapLinkedNode<K, V | undefined>;
|
|
17
17
|
protected _tail: HashMapLinkedNode<K, V | undefined>;
|
|
18
18
|
protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
|
|
19
19
|
protected _hashFn: (key: K) => string;
|
|
20
|
-
protected _objHashFn: (key: K) =>
|
|
20
|
+
protected _objHashFn: (key: K) => object;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* The constructor initializes a HashMapLinkedNode with an optional iterable of key-value pairs.
|
|
@@ -27,7 +27,7 @@ export class HashMap<K = any, V = any> {
|
|
|
27
27
|
constructor(options: HashMapOptions<K, V> = {
|
|
28
28
|
elements: [],
|
|
29
29
|
hashFn: (key: K) => String(key),
|
|
30
|
-
objHashFn: (key: K) => (<
|
|
30
|
+
objHashFn: (key: K) => (<object>key)
|
|
31
31
|
}) {
|
|
32
32
|
this._sentinel = <HashMapLinkedNode<K, V>>{};
|
|
33
33
|
this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
|
|
@@ -114,8 +114,7 @@ export class HashMap<K = any, V = any> {
|
|
|
114
114
|
let node;
|
|
115
115
|
|
|
116
116
|
if (isWeakKey(key)) {
|
|
117
|
-
|
|
118
|
-
const hash = key;
|
|
117
|
+
const hash = this._objHashFn(key);
|
|
119
118
|
node = this._objMap.get(hash);
|
|
120
119
|
|
|
121
120
|
if (node) {
|
package/src/utils/utils.ts
CHANGED
|
@@ -93,7 +93,7 @@ export const throwRangeError = (message = 'The value is off-limits.'): void => {
|
|
|
93
93
|
throw new RangeError(message);
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
-
export const isWeakKey = (input: unknown): input is
|
|
96
|
+
export const isWeakKey = (input: unknown): input is object => {
|
|
97
97
|
const inputType = typeof input;
|
|
98
98
|
return (inputType === 'object' && input !== null) || inputType === 'function';
|
|
99
99
|
};
|