Veritable Lasagna
An Allocator & Data Structure Library for C.
Loading...
Searching...
No Matches
vl_hash.h File Reference
#include "vl_memory.h"
+ Include dependency graph for vl_hash.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define VL_HASH_STRING   vlHashString
 
#define VL_HASH_BYTES   vlHashString
 
#define VL_HASH_UINT8   vlHash8
 
#define VL_HASH_UINT16   vlHash16
 
#define VL_HASH_UINT32   vlHash32
 
#define VL_HASH_UINT64   vlHash64
 
#define VL_HASH_INT8   vlHash8
 
#define VL_HASH_INT16   vlHash16
 
#define VL_HASH_INT32   vlHash32
 
#define VL_HASH_INT64   vlHash64
 
#define VL_HASH_FLOAT   vlHashFloat
 
#define VL_HASH_DOUBLE   vlHashDouble
 
#define vlHashChar   vlHash8
 
#define vlHashShort   vlHash16
 
#define vlHashInt   vlHash32
 
#define vlHashLong   vlHash64
 
#define vlHashUChar   vlHash8
 
#define vlHashUShort   vlHash16
 
#define vlHashUInt   vlHash32
 
#define vlHashULong   vlHash64
 
#define vlHashCombine(a, b)   (vl_hash)(((a) ^ (b)) + 0b11101111100100101101101011001011 + ((a) << 6) + ((a) >> 2))
 Combine two instances of vl_hash.
 

Typedefs

typedef vl_ularge_t vl_hash
 Hash function return type.
 
typedef vl_hash(* vl_hash_function) (const void *data, vl_memsize_t dataSize)
 Hash function typedef.
 

Functions

vl_hash vlHashString (const void *data, vl_memsize_t dataSize)
 Hashes the specified string.
 
vl_hash vlHash8 (const void *data, vl_memsize_t)
 Generates a hash code for the 8-bit sequence at the specified address.
 
vl_hash vlHash16 (const void *data, vl_memsize_t)
 Generates a hash code for the 16-bit sequence at the specified address. This is a direct bitcast of an 8-bit sequence to a 64-bit sequence. The returned value will equal the value of the original sequence.
 
vl_hash vlHash32 (const void *data, vl_memsize_t)
 Generates a hash code for the 32-bit sequence at the specified address.
 
vl_hash vlHash64 (const void *data, vl_memsize_t)
 Generates a hash code for the 64-bit sequence at the specified address.
 

Macro Definition Documentation

◆ VL_HASH_BYTES

#define VL_HASH_BYTES   vlHashString

◆ VL_HASH_DOUBLE

#define VL_HASH_DOUBLE   vlHashDouble

◆ VL_HASH_FLOAT

#define VL_HASH_FLOAT   vlHashFloat

◆ VL_HASH_INT16

#define VL_HASH_INT16   vlHash16

◆ VL_HASH_INT32

#define VL_HASH_INT32   vlHash32

◆ VL_HASH_INT64

#define VL_HASH_INT64   vlHash64

◆ VL_HASH_INT8

#define VL_HASH_INT8   vlHash8

◆ VL_HASH_STRING

#define VL_HASH_STRING   vlHashString

◆ VL_HASH_UINT16

#define VL_HASH_UINT16   vlHash16

◆ VL_HASH_UINT32

#define VL_HASH_UINT32   vlHash32

◆ VL_HASH_UINT64

#define VL_HASH_UINT64   vlHash64

◆ VL_HASH_UINT8

#define VL_HASH_UINT8   vlHash8

◆ vlHashChar

#define vlHashChar   vlHash8

◆ vlHashCombine

#define vlHashCombine ( a,
b )   (vl_hash)(((a) ^ (b)) + 0b11101111100100101101101011001011 + ((a) << 6) + ((a) >> 2))

Combine two instances of vl_hash.

Based on the algorithm in the Boost C++ libraries by the same name. The magic number in this macro is intended to act as random bits, where each is equally likely to be a 1 or 0 with no relationships.

Parameters
avl_hash value
bvl_hash value
Returns
merged hash

◆ vlHashInt

#define vlHashInt   vlHash32

◆ vlHashLong

#define vlHashLong   vlHash64

◆ vlHashShort

#define vlHashShort   vlHash16

◆ vlHashUChar

#define vlHashUChar   vlHash8

◆ vlHashUInt

#define vlHashUInt   vlHash32

◆ vlHashULong

#define vlHashULong   vlHash64

◆ vlHashUShort

#define vlHashUShort   vlHash16

Typedef Documentation

◆ vl_hash

Hash function return type.

◆ vl_hash_function

typedef vl_hash(* vl_hash_function) (const void *data, vl_memsize_t dataSize)

Hash function typedef.

This function definition

Parameters
dataread-only pointer to the data that will be hashed
dataSizelength of the data, in bytes. Usually this can be ignored unless the data is variable in length.

Function Documentation

◆ vlHash16()

vl_hash vlHash16 ( const void * data,
vl_memsize_t s )

Generates a hash code for the 16-bit sequence at the specified address. This is a direct bitcast of an 8-bit sequence to a 64-bit sequence. The returned value will equal the value of the original sequence.

Parameters
datapointer
Returns
hash code

◆ vlHash32()

vl_hash vlHash32 ( const void * data,
vl_memsize_t s )

Generates a hash code for the 32-bit sequence at the specified address.

This is a direct bitcast of an 32-bit sequence to a 64-bit sequence. The returned value will equal the value of the original sequence.

Parameters
datapointer
Returns
hash code

◆ vlHash64()

vl_hash vlHash64 ( const void * data,
vl_memsize_t s )

Generates a hash code for the 64-bit sequence at the specified address.

The returned value will equal the value of the original sequence.

Parameters
datapointer
Returns
hash code

◆ vlHash8()

vl_hash vlHash8 ( const void * data,
vl_memsize_t s )

Generates a hash code for the 8-bit sequence at the specified address.

This is a direct bitcast of an 8-bit sequence to a 64-bit sequence. The returned value will equal the value of the original sequence.

Parameters
datapointer
Returns
hash code

◆ vlHashString()

vl_hash vlHashString ( const void * data,
vl_memsize_t dataSize )

Hashes the specified string.

Uses the FNV-1A-64 string hashing algorithm. See here: https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function

Parameters
dataread-only pointer to the data that will be hashed
dataSizelength of the data, in bytes. Usually this can be ignored unless the data is variable in length.
Returns
corresponding hash code.
+ Here is the caller graph for this function: