# `Ascii.Kit.Hash`
[🔗](https://github.com/houllette/ascii_art/blob/main/lib/ascii/kit/hash.ex#L1)

The integer hashes that many upstream pieces share, word for word.

Each returns upstream's value: a float in [0, 1) or, for `distro/3`, the
unsigned integer. Arguments may be integers or floats (truncated, as JS's
`Math.imul` and `| 0` truncate). They run in unsigned arithmetic with the
multiply inlined, since `^`, `>>>`, `+` and `Math.imul` agree modulo 2^32
whatever the signs; that makes them several times faster than the same
steps through `Ascii.Int32`, which matters for scenes that hash tens of
thousands of times a frame.

A piece whose hash is not one of these writes its own with
`Ascii.Int32`.

# `distro`

```elixir
@spec distro(x :: number(), y :: number(), k :: number()) :: non_neg_integer()
```

The distros' scan noise, as an unsigned integer:

    let h = Math.imul(x, 73856093) ^ Math.imul(y, 19349663) ^ Math.imul(k, 83492791);
    h = Math.imul(h ^ (h >>> 13), 1274126177);
    return (h ^ (h >>> 16)) >>> 0;

# `murmur`

```elixir
@spec murmur(x :: number(), y :: number()) :: float()
```

A murmur-style hash of two (aurora, doom-fire, lightning, saptarishi,
aquarium, campfire, cherry-blossom):

    let h = Math.imul(x, 0x27d4eb2d) ^ Math.imul(y, 0x165667b1);
    h = Math.imul(h ^ (h >>> 15), 0x85ebca6b);
    h = Math.imul(h ^ (h >>> 13), 0xc2b2ae35);
    return ((h ^ (h >>> 16)) >>> 0) / 4294967296;

# `murmur`

```elixir
@spec murmur(a :: number(), b :: number(), c :: number()) :: float()
```

The same of three (sunrise, tv-static, wind):

    let h = Math.imul(a, 0x27d4eb2d) ^ Math.imul(b, 0x165667b1) ^ Math.imul(c, 0x2545f491);

then as `murmur/2`.

# `scene`

```elixir
@spec scene(x :: number(), y :: number()) :: float()
```

The scenes' hash (night-coast, alpine-dawn and every other scene, and
dissolve):

    let h = Math.imul(x | 0, 374761393) + Math.imul(y | 0, 668265263);
    h = Math.imul(h ^ (h >>> 13), 1274126177);
    return ((h ^ (h >>> 16)) >>> 0) / 4294967296;

# `short`

```elixir
@spec short(x :: number(), y :: number()) :: float()
```

One round of the murmur-style hash (lighthouse, train, windmill,
fractal-tree, landscape):

    let h = Math.imul(x, 0x27d4eb2d) ^ Math.imul(y, 0x165667b1);
    h = Math.imul(h ^ (h >>> 15), 0x85ebca6b);
    return ((h ^ (h >>> 13)) >>> 0) / 4294967296;

---

*Consult [api-reference.md](api-reference.md) for complete listing*
