Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Sep 14, 2023
1 parent 6b27fab commit 451bd55
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/value/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ const F64 = new Float64Array(1)
const F64In = new DataView(F64.buffer)
const F64Out = new Uint8Array(F64.buffer)
// --------------------------------------------------------------------------
// NumberToBytes
// --------------------------------------------------------------------------
function* NumberToBytes(value: number): IterableIterator<number> {
const byteCount = value === 0 ? 1 : Math.ceil(Math.floor(Math.log2(value) + 1) / 8)
for (let i = 0; i < byteCount; i++) {
yield (value >> (8 * (byteCount - 1 - i))) & 0xff
}
}
// --------------------------------------------------------------------------
// Hashing Functions
// --------------------------------------------------------------------------
function ArrayType(value: Array<unknown>) {
Expand Down Expand Up @@ -105,7 +114,9 @@ function ObjectType(value: Record<string, unknown>) {
function StringType(value: string) {
FNV1A64(ByteMarker.String)
for (let i = 0; i < value.length; i++) {
FNV1A64(value.charCodeAt(i))
for (const byte of NumberToBytes(value.charCodeAt(i))) {
FNV1A64(byte)
}
}
}
function SymbolType(value: symbol) {
Expand Down

0 comments on commit 451bd55

Please sign in to comment.