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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "1.46.4",
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<WeakKey, HashMapLinkedNode<K, V | undefined>>();
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) => WeakKey;
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) => (<WeakKey>key)
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
- // const hash = this._objHashFn(key);
118
- const hash = key;
117
+ const hash = this._objHashFn(key);
119
118
  node = this._objMap.get(hash);
120
119
 
121
120
  if (node) {
@@ -8,5 +8,5 @@ export type HashMapLinkedNode<K, V> = {
8
8
  export type HashMapOptions<K, V> = {
9
9
  elements: Iterable<[K, V]>;
10
10
  hashFn: (key: K) => string;
11
- objHashFn: (key: K) => WeakKey
11
+ objHashFn: (key: K) => object
12
12
  }
@@ -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 WeakKey => {
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
  };