Fnv1a32 structv0.1.0
pub struct Fnv1a32 {
// private fields
}
Copy, and holding only the accumulator, so passing one by value takes a snapshot of the hash so far — which is occasionally useful and never surprising, since there is nothing else in it.
Constructors
Fnv1a32
pub func Fnv1a32() -> Fnv1a32
Constructs a hasher with nothing written into it yet.
Returns: a hasher seeded with the 32-bit offset basis
Methods
Reset
pub func Reset(self: &var Fnv1a32)
Puts the hasher back to where Fnv1a32() leaves one.
self is borrowed mutably. Everything written so far is forgotten.
Cannot fail. Runs in constant time and allocates nothing.
Value
pub func Value(self: &Fnv1a32) -> uint32
The 32-bit hash of everything written so far.
self is borrowed. This is the algorithm's own width; Finish widens it to 64 bits for the Hasher
contract, which does not make it a 64-bit hash.
Cannot fail. Runs in constant time and allocates nothing.
Returns: the hash of everything written so far
Implements Hasher
Fnv1a32 conforms to Hasher.
Write
pub func Write(
self: &var Fnv1a32,
bytes: *byte,
length: uint
)
Adds length bytes at bytes to the hash.
bytes is borrowed and read; length is read by value. A zero length changes nothing and is the one case in
which bytes may be null. Splitting the same bytes across several writes gives the same answer as one write,
because there is no block to align to.
Runs in time proportional to length and allocates nothing.
bytes must be readable for length bytes.
| Name | Type | Description |
|---|---|---|
bytes | *byte | the bytes to absorb |
length | uint | how many bytes; zero absorbs nothing |
Finish
pub func Finish(self: &var Fnv1a32) -> uint64
The hash of everything written so far, widened to 64 bits.
self is borrowed. The hasher stays usable: asking twice gives the same answer, and writing more continues
from here. The upper 32 bits are always zero, which is what a 32-bit hash promoted to the contract looks
like — use Value when the 32-bit answer is what is wanted.
Cannot fail. Runs in constant time and allocates nothing.
Returns: the hash of everything written since the last reset
Related
FnvOffsetBasis32
pub const FnvOffsetBasis32: uint32 = 0x811C9DC5;
The 32-bit FNV-1a offset basis, which is what an empty input hashes to.
FnvPrime32
pub const FnvPrime32: uint32 = 16777619;
The 32-bit FNV prime.
Fnv1a32Of
pub func Fnv1a32Of(bytes: *byte, length: uint) -> uint32
The 32-bit FNV-1a hash of length bytes at bytes.
bytes is borrowed and read; length is read by value. A zero length gives the offset basis, and is the one
case in which bytes may be null.
The one-shot form of making a hasher, writing once and finishing. Identical in result and cost.
Cannot fail. Runs in time proportional to length and allocates nothing.
bytes must be readable for length bytes.
Parameters
| Name | Type | Description |
|---|---|---|
bytes | *byte | the bytes to hash |
length | uint | how many bytes |
Returns: their 32-bit FNV-1a hash