Hyperlinkv0.8.0-beta.28

Hash

Hash.arrayconsteffect/Hash.ts:519
<A>(arr: Iterable<A>): number

Computes a hash value for an iterable by hashing all of its elements.

When to use

Use to hash the values yielded by an iterable with Effect hash semantics.

Details

The implementation folds element hashes from the seed 6151 with XOR and then optimizes the final hash.

Gotchas

A hash is not an equality proof. Because this implementation uses XOR, reordered inputs can produce the same hash.

Example (Hashing arrays)

import { Hash } from "effect"

const arr1 = [1, 2, 3]
const arr2 = [1, 2, 3]
const arr3 = [3, 2, 1]

console.log(Hash.array(arr1)) // hash of [1, 2, 3]
console.log(Hash.array(arr2)) // same hash as arr1
console.log(Hash.array(arr3)) // may match reordered inputs

console.log(Hash.array(arr1) === Hash.array(arr2)) // true
console.log(Hash.array(arr1) === Hash.array(arr3)) // true
hashinghash
Source effect/Hash.ts:5191 lines
export const array: <A>(arr: Iterable<A>) => number = iterableWith(6151, hash)
Referenced by 2 symbols