2828 * @module
2929 */
3030
31- import type { Scalar } from "../types.ts" ;
32- import { DataFrame } from "../core/frame.ts" ;
33- import { Series } from "../core/series.ts" ;
3431import { Dtype } from "../core/dtype.ts" ;
32+ import type { DataFrame } from "../core/frame.ts" ;
33+ import { Series } from "../core/series.ts" ;
34+ import type { Scalar } from "../types.ts" ;
3535
3636// ─── FNV-1a 64-bit constants ──────────────────────────────────────────────────
3737
@@ -46,21 +46,22 @@ function fnvByte(hash: bigint, byte: number): bigint {
4646
4747/** Hash an arbitrary string (UTF-8 bytes) into the FNV state. */
4848function fnvString ( hash : bigint , s : string ) : bigint {
49+ let h = hash ;
4950 for ( let i = 0 ; i < s . length ; i ++ ) {
50- let code = s . charCodeAt ( i ) ;
51+ const code = s . charCodeAt ( i ) ;
5152 // Encode as UTF-8 bytes
5253 if ( code < 0x80 ) {
53- hash = fnvByte ( hash , code ) ;
54+ h = fnvByte ( h , code ) ;
5455 } else if ( code < 0x800 ) {
55- hash = fnvByte ( hash , 0xc0 | ( code >> 6 ) ) ;
56- hash = fnvByte ( hash , 0x80 | ( code & 0x3f ) ) ;
56+ h = fnvByte ( h , 0xc0 | ( code >> 6 ) ) ;
57+ h = fnvByte ( h , 0x80 | ( code & 0x3f ) ) ;
5758 } else {
58- hash = fnvByte ( hash , 0xe0 | ( code >> 12 ) ) ;
59- hash = fnvByte ( hash , 0x80 | ( ( code >> 6 ) & 0x3f ) ) ;
60- hash = fnvByte ( hash , 0x80 | ( code & 0x3f ) ) ;
59+ h = fnvByte ( h , 0xe0 | ( code >> 12 ) ) ;
60+ h = fnvByte ( h , 0x80 | ( ( code >> 6 ) & 0x3f ) ) ;
61+ h = fnvByte ( h , 0x80 | ( code & 0x3f ) ) ;
6162 }
6263 }
63- return hash ;
64+ return h ;
6465}
6566
6667/** Hash a single scalar value into the FNV state. */
@@ -80,10 +81,11 @@ function fnvScalar(hash: bigint, val: Scalar): bigint {
8081 const buf = new ArrayBuffer ( 8 ) ;
8182 new DataView ( buf ) . setFloat64 ( 0 , val , true ) ;
8283 const bytes = new Uint8Array ( buf ) ;
84+ let h = hash ;
8385 for ( let i = 0 ; i < 8 ; i ++ ) {
84- hash = fnvByte ( hash , bytes [ i ] ! ) ;
86+ h = fnvByte ( h , bytes [ i ] ?? 0 ) ;
8587 }
86- return hash ;
88+ return h ;
8789 }
8890 if ( typeof val === "bigint" ) {
8991 return fnvString ( hash , val . toString ( ) ) ;
@@ -128,10 +130,7 @@ export interface HashPandasObjectOptions {
128130 * h.iat(0) !== h.iat(1); // true (with overwhelming probability)
129131 * ```
130132 */
131- export function hashPandasObject (
132- obj : Series ,
133- options ?: HashPandasObjectOptions ,
134- ) : Series < number > ;
133+ export function hashPandasObject ( obj : Series , options ?: HashPandasObjectOptions ) : Series < number > ;
135134
136135/**
137136 * Return a `Series<number>` of FNV-1a 64-bit row-hashes for each row of `df`.
@@ -150,10 +149,7 @@ export function hashPandasObject(
150149 * // h.iat(0) is the hash of row 0; h.iat(1) is the hash of row 1
151150 * ```
152151 */
153- export function hashPandasObject (
154- obj : DataFrame ,
155- options ?: HashPandasObjectOptions ,
156- ) : Series < number > ;
152+ export function hashPandasObject ( obj : DataFrame , options ?: HashPandasObjectOptions ) : Series < number > ;
157153
158154export function hashPandasObject (
159155 obj : Series | DataFrame ,
0 commit comments