~/bend-docscommunity

hash.bend checks

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

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

2 imports
import Base
import 0x49814d83de8f70993a43e1002be29ecd/bytes.bend as Bytes

Types

type W64 source · line 11 · raw

Data

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

type Crc source · line 174 · raw

Type

The table and the running register.

type V4 source · line 217 · raw

Data

xxHash32 (XXH32, xxHash spec 0.1.1).

type V64 source · line 272 · raw

Data

xxHash64 (XXH64, xxHash spec 0.1.1).

type S4 source · line 364 · raw

Data

SipHash-1-3 (Aumasson and Bernstein, 2012): one round per block, three to finish.

Definitions

def W64.xor source · line 14 · raw

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

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

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

def W64.add source · line 22 · raw

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

def mul32.of source · line 28 · 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 32 · raw

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

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

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

def W64.mul source · line 43 · raw

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

def W64.rotl source · line 49 · 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 54 · raw

@a:W64 -> W64

def W64.shr source · line 60 · raw

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

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

def W64.lo source · line 65 · raw

@a:W64 -> U32

def rotl32 source · line 70 · raw

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

def get2.of source · line 88 · 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 92 · raw

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

def get2 source · line 96 · raw

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

def fnv32.byte source · line 135 · raw

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

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

def fnv32.word source · line 138 · raw

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

def fnv1a32 source · line 141 · raw

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

def fnv64.byte source · line 144 · raw

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

def fnv64.word source · line 149 · raw

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

def fnv1a64 source · line 152 · raw

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

def crc.bit source · line 156 · raw

@+c:U32 -> U32

CRC-32 (ISO-HDLC, as in gzip and zlib): reflected, polynomial 0xEDB88320.

def crc.bits source · line 159 · raw

@k:Nat -> @+c:U32 -> U32

def crc.fill source · line 166 · raw

@k:Nat -> @+i:U32 -> @a:Array<U32> -> Array<U32>

def crc.mix source · line 177 · raw

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

def crc.byte source · line 181 · raw

@st:Crc -> @+c:U32 -> Crc

def crc.word source · line 185 · raw

@st:Crc -> @+w:U32 -> Crc

def crc.fin source · line 188 · raw

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

def crc32 source · line 192 · raw

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

def adler.of source · line 197 · 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 200 · raw

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

def adler.word source · line 205 · raw

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

def adler32 source · line 213 · raw

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

def x32.round source · line 220 · raw

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

def x32.lane source · line 224 · 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 229 · raw

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

def x32.word source · line 233 · raw

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

def x32.byte source · line 236 · raw

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

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

@+h:U32 -> U32

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

@+h:U32 -> U32

def x32.aval source · line 245 · raw

@+h:U32 -> U32

def x32.tail source · line 248 · raw

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

def x32.rest source · line 252 · raw

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

def x32.mid source · line 256 · raw

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

def x32.start source · line 260 · raw

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

def xxh32 source · line 267 · raw

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

def x64.P1 source · line 275 · raw

W64

def x64.P2 source · line 278 · raw

W64

def x64.P3 source · line 281 · raw

W64

def x64.P4 source · line 284 · raw

W64

def x64.P5 source · line 287 · raw

W64

def x64.round source · line 290 · raw

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

def x64.lane source · line 293 · raw

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

def x64.fold source · line 298 · raw

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

def x64.merge source · line 301 · raw

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

def x64.word source · line 306 · raw

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

def x64.byte source · line 309 · raw

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

def x64.four source · line 312 · raw

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

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

@h:W64 -> W64

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

@+h:W64 -> W64

def x64.aval source · line 323 · raw

@h:W64 -> W64

def x64.bytes source · line 329 · 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 340 · raw

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

def x64.rest source · line 344 · raw

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

def x64.mid source · line 348 · raw

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

def x64.start source · line 352 · raw

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

def xxh64 source · line 359 · raw

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

def sip.round source · line 367 · raw

@s:S4 -> S4

def sip.post source · line 377 · raw

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

def sip.block source · line 381 · raw

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

def sip.fin source · line 385 · raw

@s:S4 -> W64

def sip.end source · line 389 · raw

@s:S4 -> W64

def sip.last source · line 394 · raw

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

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

def sip.rest source · line 400 · raw

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

def siphash13 source · line 404 · raw

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

def v32 source · line 409 · raw

@r:Pair(0x49814d83de8f70993a43e1002be29ecd/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 413 · raw

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

def fnv1a32.str source · line 417 · raw

@+s:String -> U32

def fnv1a64.str source · line 420 · raw

@+s:String -> W64

def xxh32.str source · line 423 · raw

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

def xxh64.str source · line 426 · raw

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

def siphash13.str source · line 429 · raw

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

def crc32.str source · line 432 · raw

@+s:String -> U32

def adler32.str source · line 435 · raw

@+s:String -> U32

Templates

template wfold source · line 74 · 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 84 · 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 100 · 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 110 · 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 114 · 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 121 · raw

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

template bytewise.rest source · line 125 · raw

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

template bytewise source · line 130 · raw

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

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