Skip to content

Commit 5881618

Browse files
committed
Add optional seed parameter for hashString(), use nodenext module resolution in tsconfig.json
1 parent 34f39a2 commit 5881618

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ TypeScript interface for a read-only version of a `HashMap` which is compatible
9999

100100
TypeScript interface for a read-only version of a `HashSet` which is compatible with `ReadonlySet`.
101101

102-
#### `hashString(value: string): number` function
102+
#### `hashString(value: string, seed?: number): number` function
103103

104104
Utility function to compute a string hash using [FNV-32a](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function) algorithm.
105105

106+
Default seed is `0x811c9dc5`.
107+
106108
#### `hashNumber(value: number): number` function
107109

108110
Utility function to compute a hash for a JS number:

src/hashCode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export function dropHighestNonSignBit(i32: number): number {
2424
return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
2525
}
2626

27-
export function hashString(str: string): number {
28-
return hashFnv32a(str);
27+
export function hashString(str: string, seed?: number): number {
28+
return hashFnv32a(str, seed);
2929
}
3030

3131
const NUMBER_BITS = new ArrayBuffer(8);

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export {
22
chainHash, dropHighestNonSignBit, hashBigInt, hashNumber, hashString,
33
hashTuple, hashValue,
4-
} from './hashCode';
4+
} from './hashCode.js';
55
export {
66
HashMap, HashSet, type ReadonlyHashMap, type ReadonlyHashSet,
7-
} from './hashMap';
7+
} from './hashMap.js';

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"compilerOptions": {
33
"target": "es2021",
4-
"module": "ESNext",
5-
"moduleResolution": "bundler",
4+
"module": "NodeNext",
5+
"moduleResolution": "nodenext",
66
"forceConsistentCasingInFileNames": true,
77
"isolatedModules": true,
88
"strict": true,

0 commit comments

Comments
 (0)