Hash

Hash functions.

dmhash_t

dmhash_t type definition

typedef uint64_t dmhash_t


dmHashBuffer32(buffer, buffer_len)

Calculate 32-bit hash value from buffer

Calculate 32-bit hash value from buffer

PARAMETERS

buffer - Buffer

buffer_len - Length of buffer

RETURN

hash - hash value


dmHashBuffer64(buffer, buffer_len)

calculate 64-bit hash value from buffer

calculate 64-bit hash value from buffer

PARAMETERS

buffer - Buffer

buffer_len - Length of buffer

RETURN

hash - hash value


dmHashString32(string)

Calculate 32-bit hash value from string

Calculate 32-bit hash value from string

PARAMETERS

string - Null terminated string

RETURN

hash - hash value


dmHashString64(string)

calculate 64-bit hash value from string

calculate 64-bit hash value from string

PARAMETERS

string - Null terminated string

RETURN

hash - hash value


dmHashReverseSafe64(hash)

get string value from hash

Returns the original string used to produce a hash. Always returns a null terminated string. Returns "" if the original string wasn't found.

PARAMETERS

hash - hash value

RETURN

- Original string value or "" if it wasn't found.


dmHashReverseSafe64(hash, length)

get string value from hash

Reverse hash lookup. Maps hash to original data. It is guaranteed that the returned buffer is null-terminated. If the buffer contains a valid c-string it can safely be used in printf and friends.

PARAMETERS

hash - hash to lookup

length - original data length. Optional argument and NULL-pointer is accepted.

RETURN

- pointer to buffer. 0 if no reverse exists or if reverse lookup is disabled


dmHashReverseSafe32(hash)

get string value from hash

Returns the original string used to produce a hash. Always returns a null terminated string. Returns "" if the original string wasn't found.

PARAMETERS

hash - hash value

RETURN

- Original string value or "" if it wasn't found.


dmHashReverseSafe32(hash, length)

get string value from hash

Reverse hash lookup. Maps hash to original data. It is guaranteed that the returned buffer is null-terminated. If the buffer contains a valid c-string it can safely be used in printf and friends.

PARAMETERS

hash - hash to lookup

length - original data length. Optional argument and NULL-pointer is accepted.

RETURN

- pointer to buffer. 0 if no reverse exists or if reverse lookup is disabled


HashState32()

Hash state used for 32-bit incremental hashing

Hash state used for 32-bit incremental hashing


HashState64()

Hash state used for 64-bit incremental hashing

Hash state used for 64-bit incremental hashing


dmHashInit32(hash_state, reverse_hash)

Initialize hash-state for 32-bit incremental hashi...

Initialize hash-state for 32-bit incremental hashing

PARAMETERS

hash_state - Hash state

reverse_hash - true to enable reverse hashing of buffers up to ::DMHASH_MAX_REVERSE_LENGTH


dmHashClone32(hash_state, source_hash_state, reverse_hash)

Clone 32-bit incremental hash state

Clone 32-bit incremental hash state

PARAMETERS

hash_state - Hash state

source_hash_state - Source hash state

reverse_hash - true to enable reverse hashing of buffers up to ::DMHASH_MAX_REVERSE_LENGTH. Ignored if source state reverse hashing is disabled.


dmHashUpdateBuffer32(hash_state, buffer, buffer_len)

Incremental hashing

Incremental hashing

PARAMETERS

hash_state - Hash state

buffer - Buffer

buffer_len - Length of buffer


dmHashFinal32(hash_state)

Finalize incremental hashing and release associate...

Finalize incremental hashing and release associated resources

PARAMETERS

hash_state - Hash state

RETURN

hash - the hash value


dmHashRelease32(hash_state)

Release incremental hashing resources Used to rele...

Release incremental hashing resources Used to release assocciated resources for intermediate incremental hash states.

PARAMETERS

hash_state - Hash state


dmHashInit64(hash_state, reverse_hash)

Initialize hash-state for 64-bit incremental hashi...

Initialize hash-state for 64-bit incremental hashing

PARAMETERS

hash_state - Hash state

reverse_hash - true to enable reverse hashing of buffers up to ::DMHASH_MAX_REVERSE_LENGTH


dmHashClone64(hash_state, source_hash_state, reverse_hash)

Clone 64-bit incremental hash state

Clone 64-bit incremental hash state

PARAMETERS

hash_state - Hash state

source_hash_state - Source hash state

reverse_hash - true bool to enable reverse hashing of buffers up to ::DMHASH_MAX_REVERSE_LENGTH. Ignored if source state reverse hashing is disabled.


dmHashUpdateBuffer64(hash_state, buffer, buffer_len)

Incremental hashing

Incremental hashing

PARAMETERS

hash_state - Hash state

buffer - Buffer

buffer_len - Length of buffer


dmHashFinal64(hash_state)

Finalize incremental hashing and release associate...

Finalize incremental hashing and release associated resources

PARAMETERS

hash_state - Hash state

RETURN

hash - The hash value


dmHashRelease64(hash_state)

Release incremental hashing resources Used to rele...

Release incremental hashing resources Used to release assocciated resources for intermediate incremental hash states.

PARAMETERS

hash_state - Hash state


DM_HASH_REVERSE_MEM(name, size)

Allocate stack memory context for safely reversing...

Allocate stack memory context for safely reversing hash values into strings

PARAMETERS

name - The name of the dmAllocator struct

size - The max size of the stack allocated context


dmHashReverseSafe64Alloc(allocator, hash)

get string value from hash

Returns the original string used to produce a hash.

PARAMETERS

allocator - The reverse hash allocator

hash - hash value

RETURN

- Original string value or "" if it wasn't found, or "" if the allocator failed to allocate more memory. Always returns a null terminated string.

EXAMPLES

Get the string representaiton of a hash value

DM_HASH_REVERSE_MEM(hash_ctx, 128);
const char* reverse = (const char*) dmHashReverseSafe64Alloc(&hash_ctx, hash);


dmHashReverseSafe32Alloc(allocator, hash)

get string value from hash

Returns the original string used to produce a hash.

PARAMETERS

allocator - The reverse hash allocator

hash - hash value

RETURN

- Original string value or "" if it wasn't found, or "" if the allocator failed to allocate more memory. Always returns a null terminated string.

EXAMPLES

Get the string representaiton of a hash value

DM_HASH_REVERSE_MEM(hash_ctx, 128);
const char* reverse = (const char*) dmHashReverseSafe32Alloc(&hash_ctx, hash);