Fnv1aHash32

Namespace: SnowBank.IO.Hashing · class

Helper for computing 32-bits FNV-1a hashes (aka "Alternative" Fowler–Noll–Vo)

Methods

Continue

static uint Continue(uint hash, byte[] bytes)

Continues computing the 32-bits FNV-1a hash on an additional chunk of data

  • hash — Hash computed for all previous chunks, or the initial seed (FNV1_32_OFFSET_BASIS) if this is the first chunk.
  • bytes — New chunk of bytes to process

Returns: Updated FNV-1a 32-bit hash that will include the additional data

static uint Continue(uint hash, ReadOnlySpan<byte> bytes)

Continues computing the 32-bits FNV-1a hash on an additional chunk of data

  • hash — Hash computed for all previous chunks, or the initial seed (FNV1_32_OFFSET_BASIS) if this is the first chunk.
  • bytes — New chunk of bytes to process

Returns: Updated FNV-1a 32-bit hash that will include the additional data

static uint Continue(uint hash, Slice bytes)

Continues computing the 32-bits FNV-1a hash on an additional chunk of data

  • hash — Hash computed for all previous chunks, or the initial seed (FNV1_32_OFFSET_BASIS) if this is the first chunk.
  • bytes — New chunk of bytes to process

Returns: Updated FNV-1a 32-bit hash that will include the additional data

static uint Continue(uint hash, byte x)

Continues computing the 32-bits FNV-1a hash on the next byte of data

  • hash — Hash computed for all previous chunks, or the initial seed (FNV1_32_OFFSET_BASIS) if this is the first byte.
  • x — Additional byte

Returns: Updated FNV-1a 32-bit hash that will include the additional byte

static uint Continue(uint hash, byte[] buffer, int offset, int count)

Continues computing the 32-bits FNV-1a hash on an additional chunk of data

  • hash — Hash computed for all previous chunks, or the initial seed (FNV1_32_OFFSET_BASIS) if this is the first chunk.
  • buffer — Backing store for the buffer that contains the bytes to process
  • offset — Offset of the first byte to process
  • count — Number of bytes to process

Returns: Updated FNV-1a 32-bit hash that will include the additional data

ContinueUnsafe

static uint ContinueUnsafe(uint hash, Byte* bytes, int count)

Continues computing the 32-bits FNV-1a hash on an additional chunk of data

  • hash — Hash computed for all previous chunks, or the initial seed (FNV1_32_OFFSET_BASIS) if this is the first chunk.
  • bytes — Point to the start of the new chunk to process
  • count — Size (in bytes) of the chunk

Returns: Updated FNV-1a 32-bit hash that will include the additional data

Diffuse

static int Diffuse(uint hash)

Converts a 32-bits FNV-1a hash into a usable Hashcode by mixing the bits

  • hash — 32-bits FNV-1 Hash

Returns: Mixed hash that can be used as a Hashcode

FromBytes

static uint FromBytes(byte[] bytes)

Computes the 32-bits FNV-1a hash of a byte array

  • bytes — Bytes to process

Returns: Corresponding FNV-1a 32-bit hash

static uint FromBytes(ReadOnlySpan<byte> bytes)

Computes the 32-bits FNV-1a hash of a span of bytes

  • bytes — Bytes to process

Returns: Corresponding FNV-1a 32-bit hash

static uint FromBytes(Slice bytes)

Computes the 32-bits FNV-1a hash of a Slice

  • bytes — Bytes to process

Returns: Corresponding FNV-1a 32-bit hash

static uint FromBytes(uint seed, byte[] bytes)

Computes the 32-bits FNV-1a hash of a byte array, with a custom initial seed

  • seed — Initial seed (0 for default)
  • bytes — Bytes to process

Returns: Corresponding FNV-1a 32-bit hash

FromBytesUnsafe

static uint FromBytesUnsafe(Byte* buffer, int count)

Computes the 32-bits FNV-1a hash of a span of bytes

  • buffer — Pointer to the start of the data in memory
  • count — Size (in bytes) of the buffer

Returns: Corresponding FNV-1a 32-bit hash

FromString

static uint FromString(string text, bool ignoreCase = false, Encoding encoding = null)

Computes the 32-bits FNV-1a hash of the utf-8 representation of a string

  • text — String to process
  • ignoreCase — If true, the string is converted to lowercase (invariant) before conversion to utf-8
  • encoding — Encoding used to convert the string into bytes (utf-8 by default)

Returns: Corresponding FNV-1a 32-bit hash

GetHashCode

static int GetHashCode(byte[] buffer)

Computes a hashcode of a byte array, derived from 32-bits FNV-1a hash of its content

Returns: Corresponding FNV-1a 32-bit hash

static int GetHashCode(byte[] buffer, int offset, int count)

Computes a hashcode of a byte array segment, derived from 32-bits FNV-1a hash of its content

Returns: Corresponding FNV-1a 32-bit hash

Fields

FNV1_32_OFFSET_BASIS

const uint FNV1_32_OFFSET_BASIS

FNV1_32_PRIME

const uint FNV1_32_PRIME