license import * as LongExports from 'long' ; const Long = ( LongExports as any ) . default || LongExports ; export function hexToLong ( hex ) { return Long . fromString ( hex , true , 16 ) ; } const k0 = hexToLong ( 'c3a5c85c97cb3127' ) ; const k1 = hexToLong ( 'b492b66fbe98f273' ) ; const k2 = hexToLong ( '9ae16a3b2f90404f' ) ; function shiftMix ( val ) { return val . xor ( val . shru ( 47 ) ) ; } function fetch ( s , offset , numBytes ) { const bytes = s . slice ( offset , offset + numBytes ) ; return Long . fromBytes ( Array . from ( bytes ) , true , true ) ; } function fetch64 ( s , offset ) { return fetch ( s , offset , 8 ) ; } function fetch32 ( s , offset ) { return fetch ( s , offset , 4 ) ; } function rotate64 ( val , shift ) { return shift === 0 ? val : val . shru ( shift ) . or ( val . shl ( 64 - shift ) ) ; } function hashLen16 ( u , v , mul = hexToLong ( '9ddfea08eb382d69' ) ) { let a = u . xor ( v ) . mul ( mul ) ; a = a . xor ( a . shru ( 47 ) ) ; let b = v . xor ( a ) . mul ( mul ) ; b = b . xor ( b . shru ( 47 ) ) ; b = b . mul ( mul ) ; return b ; } function weakHashLen32WithSeeds ( w , x , y , z , a , b ) { a = a . add ( w ) ; b = rotate64 ( b . add ( a ) . add ( z ) , 21 ) ; const c = a ; a = a . add ( x ) ; a = a . add ( y ) ; b = b . add ( rotate64 ( a , 44 ) ) ; return [ a . add ( z ) , b . add ( c ) ] ; } function weakHashLen32WithSeedsStr ( s , offset , a , b ) { return weakHashLen32WithSeeds ( fetch64 ( s , offset ) , fetch64 ( s , offset + 8 ) , fetch64 ( s , offset + 16 ) , fetch64 ( s , offset + 24 ) , a , b ) ; } function hashLen0to16 ( s , len = s . length ) { if ( len >= 8 ) { const mul = k2 . add ( len * 2 ) ; const a = fetch64 ( s , 0 ) . add ( k2 ) ; const b = fetch64 ( s , len - 8 ) ; const c = rotate64 ( b , 37 ) . mul ( mul ) . add ( a ) ; const d = rotate64 ( a , 25 ) . add ( b ) . mul ( mul ) ; return hashLen16 ( c , d , mul ) ; } if ( len >= 4 ) { const mul = k2 . add ( len * 2 ) ; const a = fetch32 ( s , 0 ) ; return hashLen16 ( a . shl ( 3 ) . add ( len ) , fetch32 ( s , len - 4 ) , mul ) ; } if ( len > 0 ) { const a = s [ 0 ] ; const b = s [ len >> 1 ] ; const c = s [ len - 1 ] ; const y = a + ( b << 8 ) ; const z = len + ( c << 2 ) ; return shiftMix ( k2 . mul ( y ) . xor ( k0 . mul ( z ) ) ) . mul ( k2 ) ; } return k2 ; } function hashLen17to32 ( s , len = s . length ) { const mul = k2 . add ( len * 2 ) ; const a = fetch64 ( s , 0 ) . mul ( k1 ) ; const b = fetch64 ( s , 8 ) ; const c = fetch64 ( s , len - 8 ) . mul ( mul ) ; const d = fetch64 ( s , len - 16 ) . mul ( k2 ) ; return hashLen16 ( rotate64 ( a . add ( b ) , 43 ) . add ( rotate64 ( c , 30 ) ) . add ( d ) , a . add ( rotate64 ( b . add ( k2 ) , 18 ) ) . add ( c ) , mul ) ; } function hashLen33to64 ( s , len = s . length ) { const mul = k2 . add ( len * 2 ) ; const a = fetch64 ( s , 0 ) . mul ( k2 ) ; const b = fetch64 ( s , 8 ) ; const c = fetch64 ( s , len - 8 ) . mul ( mul ) ; const d = fetch64 ( s , len - 16 ) . mul ( k2 ) ; const y = rotate64 ( a . add ( b ) , 43 ) . add ( rotate64 ( c , 30 ) ) . add ( d ) ; const z = hashLen16 ( y , a . add ( rotate64 ( b . add ( k2 ) , 18 ) ) . add ( c ) , mul ) ; const e = fetch64 ( s , 16 ) . mul ( mul ) ; const f = fetch64 ( s , 24 ) ; const g = y . add ( fetch64 ( s , len - 32 ) ) . mul ( mul ) ; const h = z . add ( fetch64 ( s , len - 24 ) ) . mul ( mul ) ; return hashLen16 ( rotate64 ( e . add ( f ) , 43 ) . add ( rotate64 ( g , 30 ) ) . add ( h ) , e . add ( rotate64 ( f . add ( a ) , 18 ) ) . add ( g ) , mul ) ; } export function fingerPrint64 ( s , len = s . length ) { const seed = Long . fromNumber ( 81 , true ) ; if ( len <= 32 ) { if ( len <= 16 ) { return hashLen0to16 ( s , len ) ; } else { return hashLen17to32 ( s , len ) ; } } else if ( len <= 64 ) { return hashLen33to64 ( s , len ) ; } let x = seed ; let y = seed . mul ( k1 ) . add ( 113 ) ; let z = shiftMix ( y . mul ( k2 ) . add ( 113 ) ) . mul ( k2 ) ; let v = [ Long . UZERO , Long . UZERO ] ; let w = [ Long . UZERO , Long . UZERO ] ; x = x . mul ( k2 ) . add ( fetch64 ( s , 0 ) ) ; let offset = 0 ; const end = ( ( len - 1 ) >> 6 ) * 64 ; const last64 = end + ( ( len - 1 ) & 63 ) - 63 ; do { x = rotate64 ( x . add ( y ) . add ( v [ 0 ] ) . add ( fetch64 ( s , offset + 8 ) ) , 37 ) . mul ( k1 ) ; y = rotate64 ( y . add ( v [ 1 ] ) . add ( fetch64 ( s , offset + 48 ) ) , 42 ) . mul ( k1 ) ; x = x . xor ( w [ 1 ] ) ; y = y . add ( v [ 0 ] ) . add ( fetch64 ( s , offset + 40 ) ) ; z = rotate64 ( z . add ( w [ 0 ] ) , 33 ) . mul ( k1 ) ; v = weakHashLen32WithSeedsStr ( s , offset , v [ 1 ] . mul ( k1 ) , x . add ( w [ 0 ] ) ) ; w = weakHashLen32WithSeedsStr ( s , offset + 32 , z . add ( w [ 1 ] ) , y . add ( fetch64 ( s , offset + 16 ) ) ) ; [ z , x ] = [ x , z ] ; offset += 64 ; } while ( offset !== end ) ; const mul = k1 . add ( z . and ( 0xff ) . shl ( 1 ) ) ; offset = last64 ; w [ 0 ] = w [ 0 ] . add ( ( len - 1 ) & 63 ) ; v [ 0 ] = v [ 0 ] . add ( w [ 0 ] ) ; w [ 0 ] = w [ 0 ] . add ( v [ 0 ] ) ; x = rotate64 ( x . add ( y ) . add ( v [ 0 ] ) . add ( fetch64 ( s , offset + 8 ) ) , 37 ) . mul ( mul ) ; y = rotate64 ( y . add ( v [ 1 ] ) . add ( fetch64 ( s , offset + 48 ) ) , 42 ) . mul ( mul ) ; x = x . xor ( w [ 1 ] . mul ( 9 ) ) ; y = y . add ( v [ 0 ] . mul ( 9 ) . add ( fetch64 ( s , offset + 40 ) ) ) ; z = rotate64 ( z . add ( w [ 0 ] ) , 33 ) . mul ( mul ) ; v = weakHashLen32WithSeedsStr ( s , offset , v [ 1 ] . mul ( mul ) , x . add ( w [ 0 ] ) ) ; w = weakHashLen32WithSeedsStr ( s , offset + 32 , z . add ( w [ 1 ] ) , y . add ( fetch64 ( s , offset + 16 ) ) ) ; [ z , x ] = [ x , z ] ; return hashLen16 ( hashLen16 ( v [ 0 ] , w [ 0 ] , mul ) . add ( shiftMix ( y ) . mul ( k0 ) ) . add ( z ) , hashLen16 ( v [ 1 ] , w [ 1 ] , mul ) . add ( x ) , mul ) ; }