XxHash64

Namespace: SnowBank.IO.Hashing · class

Computes a 64-bit xxHash

Remarks

IMPORTANT: This hash is NOT cryptographic! It can leak information about the hashed data, and must therefore not be used publicly in a data-protection scenario! (you should rather use SHA or HMAC for that kind of thing)

Methods

AppendData

static int AppendData(ref StreamContext state, ReadOnlySpan<byte> input)

Append the next chunk of data to a running hash computation

  • state — Streaming context (created by StartStream)
  • input — New chunk of data to append

Returns: Number of bytes consumed from input.

This method will only consume multiples of 32 bytes chunks.

If input is smaller than 32 bytes, nothing will be done and the method will return 0.

If the method returns less than the size of input, the caller is responsible for keeping track the extra bytes that were not consume, and present them again on the next call, once more data is available.

CompleteStream

static ulong CompleteStream(ref StreamContext state, ReadOnlySpan<byte> final)

Append the last chunk of data and complete the hash computation for a stream

  • state — Streaming context (created by StartStream, and updated by calling AppendData)
  • final — Final chunk of data that MUST be smaller than 32 bytes.

Returns: Hashcode for the stream.

Continue

static ulong Continue(ulong seed, byte[] input)

static ulong Continue(ulong seed, Slice input)

static ulong Continue(ulong seed, ReadOnlySpan<byte> input)

ContinueUnsafe

static ulong ContinueUnsafe(ulong seed, Byte* input, uint len)

FromBytes

static ulong FromBytes(byte[] input)

static ulong FromBytes(Slice input)

static ulong FromBytes(ReadOnlySpan<byte> input)

FromBytesUnsafe

static ulong FromBytesUnsafe(Byte* input, uint len)

FromText

static ulong FromText(string text)

Computes the 64-bit xxHash of a string (from its in-memory UTF-16 representation)

  • text — Text string to convert

Returns: 64-bit xxHash code computed over the UTF-16 representation of the string. Warning: Not guaranteed to be unique!

static ulong FromText(ReadOnlySpan<char> buffer)

Computes the 64-bit xxHash of a string (from its in-memory UTF-16 representation)

Returns: 64-bit xxHash code computed over the UTF-16 representation of the string. Warning: Not guaranteed to be unique!

StartStream

static StreamContext StartStream(ulong seed = 0)

Start a new streaming context

  • seed — Seed for the computation

Returns: Instance that should be passed by reference to AppendData or CompleteStream

Fields

HASH0

const ulong HASH0

Hash of the empty buffer