~/bend-docscommunity

hash.bend checks

raw source on the hub · import bend-kit-hash@0.3.2.2/hash.bend as Hash

Non-cryptographic hashes over Bytes: FNV-1a, xxHash, SipHash-1-3 and SipHash-2-4, CRC-32, and Adler-32. Source: https://github.com/paymog/bend-kit/tree/main/hash

2 imports
import Base
import bend-kit-bytes@0.3.3.1/bytes.bend as Bytes

Types

type W64 source · line 10 · raw

Data

A 64-bit value as two halves. Base has no native U64, and int's U64 is a bit list.

type V4 source · line 4399 · raw

Data

xxHash32 (XXH32, xxHash spec 0.1.1).

type V64 source · line 4454 · raw

Data

xxHash64 (XXH64, xxHash spec 0.1.1).

type S4 source · line 4546 · raw

Data

SipHash-c-d (Aumasson and Bernstein, 2012).

Definitions

def W64.of source · line 13 · raw

@+hi:U32 -> @+lo:U32 -> W64

def W64.xor source · line 16 · raw

@a:W64 -> @b:W64 -> W64

def W64.add.of source · line 21 · raw

@+ah:U32 -> @+bh:U32 -> @+al:U32 -> @+lo:U32 -> W64

def W64.add source · line 24 · raw

@a:W64 -> @b:W64 -> W64

def mul32.of source · line 30 · raw

@+p00:U32 -> @+p01:U32 -> @+p10:U32 -> @+p11:U32 -> W64

The full 64-bit product of two U32, from four 16-bit partial products.

def mul32 source · line 34 · raw

@+x:U32 -> @+y:U32 -> W64

def W64.mul.of source · line 41 · raw

@+cross:U32 -> @p:W64 -> W64

def W64.mul source · line 45 · raw

@a:W64 -> @b:W64 -> W64

def W64.rotl source · line 51 · raw

@+k:Nat -> @+j:Nat -> @a:W64 -> W64

Rotate left by k, for 0 < k < 32; j is 32 - k.

def W64.swap source · line 56 · raw

@a:W64 -> W64

def W64.shr source · line 62 · raw

@+k:Nat -> @+j:Nat -> @a:W64 -> W64

Shift right by k, for 0 < k < 32; j is 32 - k.

def W64.hi source · line 67 · raw

@a:W64 -> U32

def W64.lo source · line 72 · raw

@a:W64 -> U32

def rotl32 source · line 77 · raw

@+x:U32 -> @+k:Nat -> @+j:Nat -> U32

def get2.of source · line 95 · raw

@+lo:U32 -> @r:Pair(Array<U32>, U32) -> Pair(Array<U32>, W64)

Words i and i + 1 as one little-endian 64-bit lane.

def get2.lo source · line 99 · raw

@+i:U32 -> @r:Pair(Array<U32>, U32) -> Pair(Array<U32>, W64)

def get2 source · line 103 · raw

@a:Array<U32> -> @+i:U32 -> Pair(Array<U32>, W64)

def fnv32.byte source · line 142 · raw

@h:U32 -> @+c:U32 -> U32

FNV-1a (draft-eastlake-fnv), 32 and 64 bits.

def fnv32.word source · line 145 · raw

@h:U32 -> @+w:U32 -> U32

def fnv1a32 source · line 148 · raw

@b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, U32)

def fnv64.byte source · line 151 · raw

@h:W64 -> @+c:U32 -> W64

def fnv64.word source · line 156 · raw

@h:W64 -> @+w:U32 -> W64

def fnv1a64 source · line 159 · raw

@b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, W64)

def crc.tab source · line 164 · raw

@+i:U32 -> U32

CRC-32 (ISO-HDLC, as in gzip and zlib): reflected, polynomial 0xEDB88320. The 256-entry tables as matches, so no call rebuilds them. crc.tabK steps a byte K places further.

def crc.tab1 source · line 423 · raw

@+i:U32 -> U32

def crc.tab2 source · line 682 · raw

@+i:U32 -> U32

def crc.tab3 source · line 941 · raw

@+i:U32 -> U32

def crc.tab4 source · line 1200 · raw

@+i:U32 -> U32

def crc.tab5 source · line 1459 · raw

@+i:U32 -> U32

def crc.tab6 source · line 1718 · raw

@+i:U32 -> U32

def crc.tab7 source · line 1977 · raw

@+i:U32 -> U32

def crc.byte source · line 2236 · raw

@h:U32 -> @+c:U32 -> U32

def crc.word source · line 2240 · raw

@h:U32 -> @+w:U32 -> U32

def crc.lane source · line 2244 · raw

@h:U32 -> @+m:W64 -> U32

def crc.rest source · line 2253 · raw

@+len:U32 -> @r:Pair(Array<U32>, U32) -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, U32)

After the lanes: one word when len % 8 >= 4, then the bytes.

def crc.fin source · line 2257 · raw

@r:Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, U32) -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, U32)

def crc.tab8 source · line 2261 · raw

@i:U32 -> U32

def crc.tab9 source · line 2520 · raw

@i:U32 -> U32

def crc.tab10 source · line 2779 · raw

@i:U32 -> U32

def crc.tab11 source · line 3038 · raw

@i:U32 -> U32

def crc.tab12 source · line 3297 · raw

@i:U32 -> U32

def crc.tab13 source · line 3556 · raw

@i:U32 -> U32

def crc.tab14 source · line 3815 · raw

@i:U32 -> U32

def crc.tab15 source · line 4074 · raw

@i:U32 -> U32

def crc.block source · line 4333 · raw

@h:U32 -> @+m:W64 -> @+n:W64 -> U32

def crc.read16.hi source · line 4343 · raw

@h:U32 -> @+m:W64 -> @r:Pair(Array<U32>, W64) -> Pair(Array<U32>, U32)

def crc.read16.lo source · line 4347 · raw

@h:U32 -> @+i:U32 -> @r:Pair(Array<U32>, W64) -> Pair(Array<U32>, U32)

def crc.read16 source · line 4351 · raw

@+i:U32 -> @r:Pair(Array<U32>, U32) -> Pair(Array<U32>, U32)

def crc.fold16 source · line 4355 · raw

@n:Nat -> @r:Pair(Array<U32>, U32) -> @+i:U32 -> Pair(Array<U32>, U32)

def crc.rest16 source · line 4362 · raw

@+len:U32 -> @r:Pair(Array<U32>, U32) -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, U32)

def crc.choose source · line 4366 · raw

@short:Bool -> @+len:U32 -> @buf:Array<U32> -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, U32)

def crc32 source · line 4373 · raw

@b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, U32)

def adler.of source · line 4379 · raw

@+s1:U32 -> @+s2:U32 -> U32

Adler-32 (RFC 1950 §9). The state is the checksum itself: s2 << 16 | s1. A word takes mod 65521 once, after four bytes; no sum reaches 2^32 first.

def adler.byte source · line 4382 · raw

@h0:U32 -> @+c:U32 -> U32

def adler.word source · line 4387 · raw

@h0:U32 -> @+w:U32 -> U32

def adler32 source · line 4395 · raw

@b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, U32)

def x32.round source · line 4402 · raw

@+acc:U32 -> @+x:U32 -> U32

def x32.lane source · line 4406 · raw

@v:V4 -> @+w:U32 -> V4

The four accumulators take lanes in turn: v1 eats this word and moves to the back.

def x32.merge source · line 4411 · raw

@r:Pair(Array<U32>, V4) -> Pair(Array<U32>, U32)

def x32.word source · line 4415 · raw

@h:U32 -> @+w:U32 -> U32

def x32.byte source · line 4418 · raw

@h:U32 -> @+c:U32 -> U32

def x32.aval.c source · line 4421 · raw

@+h:U32 -> U32

def x32.aval.b source · line 4424 · raw

@+h:U32 -> U32

def x32.aval source · line 4427 · raw

@+h:U32 -> U32

def x32.tail source · line 4430 · raw

@+len:U32 -> @+h:U32 -> @r:Pair(Array<U32>, U32) -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, U32)

def x32.rest source · line 4434 · raw

@+len:U32 -> @r:Pair(Array<U32>, U32) -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, U32)

def x32.mid source · line 4438 · raw

@+len:U32 -> @r:Pair(Array<U32>, U32) -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, U32)

def x32.start source · line 4442 · raw

@big:Bool -> @+len:U32 -> @+seed:U32 -> @a:Array<U32> -> Pair(Array<U32>, U32)

def xxh32 source · line 4449 · raw

@b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @+seed:U32 -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, U32)

def x64.P1 source · line 4457 · raw

W64

def x64.P2 source · line 4460 · raw

W64

def x64.P3 source · line 4463 · raw

W64

def x64.P4 source · line 4466 · raw

W64

def x64.P5 source · line 4469 · raw

W64

def x64.round source · line 4472 · raw

@acc:W64 -> @x:W64 -> W64

def x64.lane source · line 4475 · raw

@v:V64 -> @+m:W64 -> V64

def x64.fold source · line 4480 · raw

@h:W64 -> @v:W64 -> W64

def x64.merge source · line 4483 · raw

@r:Pair(Array<U32>, V64) -> Pair(Array<U32>, W64)

def x64.word source · line 4488 · raw

@h:W64 -> @+m:W64 -> W64

def x64.byte source · line 4491 · raw

@h:W64 -> @+c:U32 -> W64

def x64.four source · line 4494 · raw

@h:W64 -> @+w:U32 -> W64

def x64.aval.c source · line 4497 · raw

@h:W64 -> W64

def x64.aval.b source · line 4502 · raw

@+h:W64 -> W64

def x64.aval source · line 4505 · raw

@h:W64 -> W64

def x64.bytes source · line 4511 · raw

@four:Bool -> @+k:Nat -> @h:W64 -> @m:W64 -> W64

The last len % 8 bytes: a 4-byte lane when there is one, then single bytes.

def x64.tail source · line 4522 · raw

@+len:U32 -> @+h:W64 -> @r:Pair(Array<U32>, W64) -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, W64)

def x64.rest source · line 4526 · raw

@+len:U32 -> @r:Pair(Array<U32>, W64) -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, W64)

def x64.mid source · line 4530 · raw

@+len:U32 -> @r:Pair(Array<U32>, W64) -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, W64)

def x64.start source · line 4534 · raw

@big:Bool -> @+len:U32 -> @+seed:W64 -> @a:Array<U32> -> Pair(Array<U32>, W64)

def xxh64 source · line 4541 · raw

@b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @+seed:W64 -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, W64)

def sip.round source · line 4549 · raw

@s:S4 -> S4

def sip.rounds source · line 4559 · raw

@n:Nat -> @s:S4 -> S4

def sip.post source · line 4566 · raw

@+m:W64 -> @s:S4 -> S4

def sip.fin source · line 4574 · raw

@s:S4 -> W64

def sip.keep source · line 4583 · raw

@+w:U32 -> @+n:U32 -> U32

The low n bytes of w, for n <= 4, so bytes past len never reach the hash.

def siphash13 source · line 4601 · raw

@b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @+k0:W64 -> @+k1:W64 -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, W64)

def siphash24 source · line 4604 · raw

@b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @+k0:W64 -> @+k1:W64 -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, W64)

def v32 source · line 4608 · raw

@r:Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, U32) -> U32

The same hashes over a byte string. ponytail: copies to Bytes; hash short strings in place if the copy shows up in profiles.

def v64 source · line 4612 · raw

@r:Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, W64) -> W64

def fnv1a32.str source · line 4616 · raw

@+s:String -> U32

def fnv1a64.str source · line 4619 · raw

@+s:String -> W64

def xxh32.str source · line 4622 · raw

@+s:String -> @+seed:U32 -> U32

def xxh64.str source · line 4625 · raw

@+s:String -> @+seed:W64 -> W64

def siphash13.str source · line 4628 · raw

@+s:String -> @+k0:W64 -> @+k1:W64 -> W64

def siphash24.str source · line 4631 · raw

@+s:String -> @+k0:W64 -> @+k1:W64 -> W64

def crc32.str source · line 4634 · raw

@+s:String -> U32

def adler32.str source · line 4637 · raw

@+s:String -> U32

Templates

template wfold source · line 81 · raw

@-T:Type -> @-f:(@_:T -> @+c:U32 -> T) -> @n:Nat -> @r:Pair(Array<U32>, U32) -> @+i:U32 -> @acc:T -> Pair(Array<U32>, T)

Folds f over n words from word i on. r holds the array and word i.

template wfrom source · line 91 · raw

@-T:Type -> @-f:(@_:T -> @+c:U32 -> T) -> @n:Nat -> @a:Array<U32> -> @+i:U32 -> @acc:T -> Pair(Array<U32>, T)

template dfold source · line 107 · raw

@-T:Type -> @-f:(@_:T -> @+m:W64 -> T) -> @n:Nat -> @r:Pair(Array<U32>, W64) -> @+i:U32 -> @acc:T -> Pair(Array<U32>, T)

Folds f over n 64-bit lanes from word i on. r holds the array and the lane at i.

template dfrom source · line 117 · raw

@-T:Type -> @-f:(@_:T -> @+m:W64 -> T) -> @n:Nat -> @a:Array<U32> -> @+i:U32 -> @acc:T -> Pair(Array<U32>, T)

template tail source · line 121 · raw

@-T:Type -> @-f:(@_:T -> @+c:U32 -> T) -> @k:Nat -> @+w:U32 -> @acc:T -> T

Folds f over the low k bytes of w, lowest first.

template bytewise.last source · line 128 · raw

@-T:Type -> @-byte:(@_:T -> @+c:U32 -> T) -> @+len:U32 -> @acc:T -> @r:Pair(Array<U32>, U32) -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, T)

template bytewise.rest source · line 132 · raw

@-T:Type -> @-byte:(@_:T -> @+c:U32 -> T) -> @+len:U32 -> @r:Pair(Array<U32>, T) -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, T)

template bytewise source · line 137 · raw

@-T:Type -> @-byte:(@_:T -> @+c:U32 -> T) -> @-word:(@_:T -> @+c:U32 -> T) -> @b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @acc:T -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, T)

A hash that eats one byte at a time: word takes the four bytes of a word, byte one.

template sip.block source · line 4570 · raw

@-c:Nat -> @s:S4 -> @+m:W64 -> S4

template sip.end source · line 4578 · raw

@-d:Nat -> @s:S4 -> W64

template sip.last source · line 4587 · raw

@-c:Nat -> @-d:Nat -> @+len:U32 -> @r:Pair(Array<U32>, W64) -> @s:S4 -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, W64)

The last block: the len % 8 bytes left, and len mod 256 in the top byte.

template sip.rest source · line 4593 · raw

@-c:Nat -> @-d:Nat -> @+len:U32 -> @r:Pair(Array<U32>, S4) -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, W64)

template sip.hash source · line 4597 · raw

@-c:Nat -> @-d:Nat -> @b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @+k0:W64 -> @+k1:W64 -> Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, W64)