Hyperlinkv0.8.0-beta.28

Hash

Hash.optimizeconsteffect/Hash.ts:270
(n: number): number

Applies bit manipulation techniques to optimize a hash value.

When to use

Use to improve the bit distribution of a raw numeric hash value.

Details

This function takes a hash value and applies bitwise operations to improve the distribution of hash values, reducing the likelihood of collisions.

Example (Optimizing a hash value)

import { Hash } from "effect"

const rawHash = 1234567890
const optimizedHash = Hash.optimize(rawHash)
console.log(optimizedHash) // optimized hash value

// Often used internally by other hash functions
const stringHash = Hash.optimize(Hash.string("hello"))
hashing
Source effect/Hash.ts:2701 lines
export const optimize = (n: number): number => (n & 0xbfffffff) | ((n >>> 1) & 0x40000000)
Referenced by 3 symbols