Table of Contents

Class Hash

Namespace
Sdl3Sharp.Utilities
Assembly
Sdl3Sharp.dll

Provides methods to calculate checksums and hash values for data blocks

public static class Hash
Inheritance
Hash
Inherited Members

Methods

Crc16(ushort, Memory<byte>)

Calculates and accumulates a CRC-16 checksum hash value

public static ushort Crc16(ushort crc, Memory<byte> data)

Parameters

crc ushort

The current checksum for the data set, or 0 for a new data set

data Memory<byte>

The new block of data to be added to the checksum

Returns

ushort

A CRC-16 checksum hash value of all blocks in the data set

Remarks

Calls to this method can be chained by passing in the previous return value as the argument for the crc parameter to add a new block of data to the checksum. This allows for the data set to be streamed. If you want to start a new data set, you can simply pass in 0 as the argument for the crc parameter.

See Also

Crc32(uint, Memory<byte>)

Calculates and accumulates a CRC-32 checksum hash value

public static uint Crc32(uint crc, Memory<byte> data)

Parameters

crc uint

The current checksum for the data set, or 0 for a new data set

data Memory<byte>

The new block of data to be added to the checksum

Returns

uint

A CRC-32 checksum hash value of all blocks in the data set

Remarks

Calls to this method can be chained by passing in the previous return value as the argument for the crc parameter to add a new block of data to the checksum. This allows for the data set to be streamed. If you want to start a new data set, you can simply pass in 0 as the argument for the crc parameter.

See Also

Murmur3_32(Memory<byte>, uint)

Calculates a 32-bit MurmurHash3 hash value for a block of data

public static uint Murmur3_32(Memory<byte> data, uint seed = 0)

Parameters

data Memory<byte>

The block of data to be hashed

seed uint

A value that alters the resulting hash value

Returns

uint

A MurmurHash3 hash value for the given data

Remarks

A seed value may be specified, which changes the final results consistently, but this does not work like Crc16(ushort, Memory<byte>) or Crc32(uint, Memory<byte>), as you can't feed a previous result from a call to this method back into itself as the next seed value to calculate a hash in chunks; it won't produce the same hash as it would if the same data was provided in a single call.

If you aren't sure what to provide for the seed value, 0 is fine.

MurmurHash3 is not cryptographically secure, so it shouldn't be used for hashing top-secret data.

See Also