Fnv1a64 structv0.1.0

Source
FNV-1a over 64 bits, computed one byte at a time.
pub struct Fnv1a64 {
    // private fields
}

The width to prefer: the same cost per byte as the 32-bit form on any 64-bit machine, and far enough from a birthday collision that an ordinary table will never see one by accident. Structural Copy; copying takes an independent snapshot of the accumulator.

Constructors

Fnv1a64

pub func Fnv1a64() -> Fnv1a64

Constructs a hasher with nothing written into it yet.

Returns: a hasher seeded with the 64-bit offset basis

Source

Methods

Reset

pub func Reset(self: &var Fnv1a64)

Puts the hasher back to where Fnv1a64() leaves one. self is borrowed mutably. Everything written so far is forgotten. Cannot fail. Runs in constant time and allocates nothing.

Source

Implements Hasher

Fnv1a64 conforms to Hasher.

Write

pub func Write(
    self: &var Fnv1a64,
    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. Runs in time proportional to length and allocates nothing. bytes must be readable for length bytes.

NameTypeDescription
bytes*bytethe bytes to absorb
lengthuinthow many bytes; zero absorbs nothing

Source

Finish

pub func Finish(self: &var Fnv1a64) -> uint64

The hash of everything written so far. self is borrowed. The hasher stays usable: asking twice gives the same answer, and writing more continues from here rather than starting over. Cannot fail. Runs in constant time and allocates nothing.

Returns: the hash of everything written since the last reset

Source

FnvOffsetBasis64

pub const FnvOffsetBasis64: uint64 = 0xCBF29CE484222325;

The 64-bit FNV-1a offset basis, which is what an empty input hashes to.

Source

FnvPrime64

pub const FnvPrime64: uint64 = 0x100000001B3;

The 64-bit FNV prime.

Source

Fnv1a64Of

pub func Fnv1a64Of(bytes: *byte, length: uint) -> uint64

The 64-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. Cannot fail. Runs in time proportional to length and allocates nothing. bytes must be readable for length bytes.

Source

Parameters

NameTypeDescription
bytes*bytethe bytes to hash
lengthuinthow many bytes

Returns: their 64-bit FNV-1a hash