data-structure-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/CHANGELOG.md +1 -1
- package/README.md +47 -61
- package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/cjs/data-structures/hash/hash-map.js +1 -2
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/types/data-structures/hash/hash-map.d.ts +1 -1
- package/dist/cjs/utils/utils.d.ts +1 -1
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/mjs/data-structures/hash/hash-map.js +1 -2
- package/dist/mjs/types/data-structures/hash/hash-map.d.ts +1 -1
- package/dist/mjs/utils/utils.d.ts +1 -1
- package/dist/umd/data-structure-typed.js +1 -1
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "1.46.
|
|
3
|
+
"version": "1.46.5",
|
|
4
4
|
"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.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/mjs/index.js",
|
|
@@ -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
|
};
|