UniqueHash Struct Reference

#include <hash.h>

Detailed Description

UniqueHash is used as return type of GetUniqueHashCode functions. It has a size of 128 bits. For reasonable hash code functions it's a practically safe assumption that there are no hash collisions, so one can consider such a hash to be unique.

Public Member Functions

 UniqueHash ()=default
 
constexpr UniqueHash (UInt64 l, UInt64 h)
 
Bool operator== (const UniqueHash &other) const
 
Bool operator!= (const UniqueHash &other) const
 
Bool operator< (const UniqueHash &other) const
 
 MAXON_OPERATOR_INEQUALITY (UniqueHash)
 
HashInt GetHashCode () const
 
const UniqueHashGetUniqueHashCode () const
 
constexpr UInt operator& (UInt mask) const
 
String ToString (const FormatStatement *fs=nullptr) const
 
CharWriteHex (Char *hexbuf) const
 
void CombineUnordered (const UniqueHash &other)
 

Static Public Member Functions

static constexpr Bool TriviallyHashable ()
 
static Result< UniqueHashFromString (const String &str)
 
static UniqueHash GetUniqueHashCode (const Byte *ptr, Int count)
 
static UniqueHash GetUniqueHashCode (const Block< const Byte > &bytes)
 

Public Attributes

UInt64 low
 
UInt64 high
 

Static Public Attributes

static constexpr Int HEXBUF_LENGTH
 

Constructor & Destructor Documentation

◆ UniqueHash() [1/2]

UniqueHash ( )
default

◆ UniqueHash() [2/2]

constexpr UniqueHash ( UInt64  l,
UInt64  h 
)
constexpr

Member Function Documentation

◆ TriviallyHashable()

static constexpr Bool TriviallyHashable ( )
staticconstexpr

◆ operator==()

Bool operator== ( const UniqueHash other) const

◆ operator!=()

Bool operator!= ( const UniqueHash other) const

◆ operator<()

Bool operator< ( const UniqueHash other) const

◆ MAXON_OPERATOR_INEQUALITY()

MAXON_OPERATOR_INEQUALITY ( UniqueHash  )

◆ GetHashCode()

HashInt GetHashCode ( ) const

◆ GetUniqueHashCode()

const UniqueHash& GetUniqueHashCode ( ) const

◆ operator&()

constexpr UInt operator& ( UInt  mask) const
constexpr

Returns the bitwise and of the low bits of this UniqueHash and the given mask.

Parameters
[in]maskA bit mask.
Returns
Bitwise and of low bits and mask.

◆ ToString()

String ToString ( const FormatStatement fs = nullptr) const

Returns this UniqueHash as a string of 32 hexadecimal digits in little endian order (least significant byte first).

Returns
Hexadecimal string representation of this UniqueHash.

◆ FromString()

static Result<UniqueHash> FromString ( const String str)
static

Parses hexadecimal string representation into a UniqueHash. str is expected to consist of exactly 32 hexadecimal digits in little endian order (least significant byte first).

Parameters
[in]strHexadecimal string.
Returns
str parsed into a UniqueHash.

◆ WriteHex()

Char* WriteHex ( Char hexbuf) const

Converts this UniqueHash to a Char string of HEXBUF_LENGTH (32) hexadecimal digits (little endian, least significant byte first).

Parameters
[out]hexbufThe Char string will be written to hexbuf (without null terminator). hexbuf has to provide space for at least HEXBUF_LENGTH characters.
Returns
Pointer to the first character in hexbuf behind the written characters.

◆ CombineUnordered()

void CombineUnordered ( const UniqueHash other)

Combines the other UniqueHash with this UniqueHash in an unordered way, which means that the effect of multiple calls to CombineUnordered doesn't depend on the order of those calls. You can use this function to compute a UniqueHash of a sequence of UniqueHashes when the sequence order shall be irrelevant.

Parameters
[in]otherAnother UniqueHash.

Member Data Documentation

◆ low

UInt64 low

The lower 64 bits of the UniqueHash.

◆ high

UInt64 high

The higher 64 bits of the UniqueHash.

◆ HEXBUF_LENGTH

constexpr Int HEXBUF_LENGTH
staticconstexpr

Minimal size of hexbuf argument for WriteHex (number of hexadecimal digits of a UniqueHash).