| 214 | /** |
| 215 | * A 128-bit digest of `s`, as 32 lowercase hexadecimal characters: the |
| 216 | * cyrb128 string hash — four 32-bit lanes mixed per character and finalized |
| 217 | * against each other. It is a key where `hashCode` is a bucket: on the |
| 218 | * inputs this engine feeds it (its own serializations, never adversarial |
| 219 | * text) a collision between distinct inputs is not expected in practice, |
| 220 | * though no cryptographic bound is claimed. It backs `Expression.digest`; |
| 221 | * see that contract for what may be assumed of it. Not stable across |
| 222 | * releases. |
| 223 | */ |
| 224 | export function digest128(s: string): string { |
| 225 | let h1 = 1779033703; |
| 226 | let h2 = 3144134277; |
| 227 | let h3 = 1013904242; |
| 228 | let h4 = 2773480762; |
| 229 | for (let i = 0; i < s.length; i++) { |
| 230 | const k = s.charCodeAt(i); |
| 231 | h1 = h2 ^ Math.imul(h1 ^ k, 597399067); |
| 232 | h2 = h3 ^ Math.imul(h2 ^ k, 2869860233); |
| 233 | h3 = h4 ^ Math.imul(h3 ^ k, 951274213); |
| 234 | h4 = h1 ^ Math.imul(h4 ^ k, 2716044179); |
| 235 | } |
| 236 | h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067); |
| 237 | h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233); |
| 238 | h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213); |
| 239 | h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179); |
| 240 | h1 ^= h2 ^ h3 ^ h4; |
| 241 | h2 ^= h1; |
| 242 | h3 ^= h1; |
| 243 | h4 ^= h1; |
| 244 | return ( |
| 245 | (h1 >>> 0).toString(16).padStart(8, '0') + |
| 246 | (h2 >>> 0).toString(16).padStart(8, '0') + |
| 247 | (h3 >>> 0).toString(16).padStart(8, '0') + |
| 248 | (h4 >>> 0).toString(16).padStart(8, '0') |
| 249 | ); |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * The expressions whose digest must be read fresh on every access because |
| 254 | * it depends on a MUTABLE object somewhere below them: an object's digest |
| 255 | * is that of its record snapshot, and a parent that memoized a digest over |