XxHash64 structv0.1.0
pub struct XxHash64 {
// private fields
}
Copy, but large: thirty-two bytes of pending input plus its accumulators. Borrow one by reference unless a snapshot of the hash so far is what is wanted.
Constructors
XxHash64
pub func XxHash64() -> XxHash64
Constructs an unseeded hasher with nothing written into it yet.
Returns: a hasher with a seed of zero
Associated functions
WithSeed
pub func WithSeed(seed: uint64) -> XxHash64
A hasher with nothing written into it yet, using seed.
seed is read by value. Two hashers with different seeds give unrelated answers for the same input, which is
enough to keep accidental collisions from following data from one table to another. It is not enough to stop
a deliberate collision: an adversary who knows the seed is no worse off than one hashing without it.
Cannot fail. Runs in constant time and allocates nothing.
| Name | Type | Description |
|---|---|---|
seed | uint64 | the seed to start from |
Returns: a hasher seeded with it
Methods
Reset
pub func Reset(self: &var XxHash64)
Puts the hasher back to where it started, keeping its seed.
self is borrowed mutably. Everything written so far is forgotten; the seed is not.
Cannot fail. Runs in constant time and allocates nothing.
Implements Hasher
XxHash64 conforms to Hasher.
Write
pub func Write(
self: &var XxHash64,
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. Input that does not fill a block is held until the rest of it arrives, so any
division of the same byte stream into writes gives the same answer.
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 XxHash64) -> uint64
The hash of everything written so far.
self is borrowed. Nothing is consumed: asking twice gives the same answer, and writing more continues from
where the writes left off rather than starting over.
Cannot fail. Runs in time proportional to what is held pending, which is under one block. Allocates nothing.
Returns: the hash of everything written since the last reset
Related
XxPrime1
pub const XxPrime1: uint64 = 0x9E3779B185EBCA87;
The first xxHash64 prime, which every round multiplies by.
XxPrime2
pub const XxPrime2: uint64 = 0xC2B2AE3D27D4EB4F;
The second xxHash64 prime, which scales each input lane before it is rotated in.
XxPrime3
pub const XxPrime3: uint64 = 0x165667B19E3779F9;
The third xxHash64 prime, used in the four-byte tail step and the avalanche.
XxPrime4
pub const XxPrime4: uint64 = 0x85EBCA77C2B2AE63;
The fourth xxHash64 prime, added after each merge and after each eight-byte tail step.
XxPrime5
pub const XxPrime5: uint64 = 0x27D4EB2F165667C5;
The fifth xxHash64 prime, which seeds an input too short to fill a block and mixes each trailing byte.
XxBlockSize
pub const XxBlockSize: uint = 32;
How many bytes one xxHash64 round consumes: four lanes of eight. An input shorter than this never touches the accumulators at all, which is why the short and long paths give different-looking code for the same algorithm.
ReadLittleEndian64
pub func ReadLittleEndian64(bytes: *byte) -> uint64
The eight bytes at bytes as a 64-bit value, least significant byte first.
bytes is borrowed and read. Assembled a byte at a time rather than read as a word, so the answer is the same at
any address on any machine — xxHash is defined on a little-endian byte stream, not on whatever the machine
happens to hold.
Cannot fail. Runs in constant time and allocates nothing.
bytes must be readable for eight bytes.
Parameters
| Name | Type | Description |
|---|---|---|
bytes | *byte | eight bytes to read |
Returns: them as a little-endian word
ReadLittleEndian32
pub func ReadLittleEndian32(bytes: *byte) -> uint32
The four bytes at bytes as a 32-bit value, least significant byte first.
bytes is borrowed and read. Assembled a byte at a time, for the same reason as ReadLittleEndian64.
Cannot fail. Runs in constant time and allocates nothing.
bytes must be readable for four bytes.
Parameters
| Name | Type | Description |
|---|---|---|
bytes | *byte | four bytes to read |
Returns: them as a little-endian half word
XxRound
pub func XxRound(
accumulator: uint64,
lane: uint64
) -> uint64
One accumulator round: mix lane into accumulator.
Both are read by value and the new accumulator is returned. This is the whole of xxHash64's inner loop — scale
the input, add, rotate, scale again — and it is what the four lanes each run independently.
Cannot fail. Runs in constant time and allocates nothing.
Parameters
| Name | Type | Description |
|---|---|---|
accumulator | uint64 | the lane's running value |
lane | uint64 | the input word to fold into it |
Returns: the lane's new value
XxMerge
pub func XxMerge(
hash: uint64,
accumulator: uint64
) -> uint64
Folds one finished accumulator into the running hash. Both are read by value and the new hash is returned. The accumulator is passed through a round from zero first, so a lane that happened to end at a convenient value does not stay convenient. Cannot fail. Runs in constant time and allocates nothing.
Parameters
| Name | Type | Description |
|---|---|---|
hash | uint64 | the running hash |
accumulator | uint64 | the lane to merge into it |
Returns: the merged hash
XxAvalanche
pub func XxAvalanche(hash: uint64) -> uint64
The final mixing step, which spreads every input bit across the whole result.
hash is read by value and the finished hash is returned. Without this a one-bit change in the input moves only
the bits the round function reached; with it, about half of them move.
Cannot fail. Runs in constant time and allocates nothing.
Parameters
| Name | Type | Description |
|---|---|---|
hash | uint64 | the value to mix |
Returns: it with every input bit spread across the output
XxHash64SeededOf
pub func XxHash64SeededOf(
bytes: *byte,
length: uint,
seed: uint64
) -> uint64
The xxHash64 of length bytes at bytes, using seed.
bytes is borrowed and read; length and seed are read by value. A zero length gives the hash of the empty
input for that seed, 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.
Parameters
| Name | Type | Description |
|---|---|---|
bytes | *byte | the bytes to hash |
length | uint | how many bytes |
seed | uint64 | the seed to start from |
Returns: their seeded hash
XxHash64Of
pub func XxHash64Of(bytes: *byte, length: uint) -> uint64
The xxHash64 of length bytes at bytes, seeded with zero.
bytes is borrowed and read; length is read by value. This is what every published xxHash64 test vector means
by "the hash of" an input.
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 hash, seeded with zero