macro LFDS700_HASH_A_32BIT_HASH_FUNCTION
Jump to navigation
Jump to search
Source File
└───liblfds700 └───inc └───liblfds700 lfds700_hash_addonly.h
Macro
#define LFDS700_HASH_A_32BIT_HASH_FUNCTION( data, data_length_in_bytes, hash )
Parameters
data
- A pointer of any kind, to the data to be hashed. This is cast to a char unsigned pointer in the macro, which iterates over every byte pointed to by data.
data_length_in_bytes
- The length of the data pointed to by *data, in bytes.
hash
- A 32 bit unsigned integer. It is important this is a 32 bit value - the hash constantly overflows the unsigned ranged and this is part of how it works. Using a longer type will affect how the hash behaves, and that means all bets are off. This argument is the output of the hashing function. It is NOT initialized to zero by the macro, so that the user can call the macro many tiems, perhaps on multiple members of a structure, to build up a hash. As such, the user needs to ensure this variable is set to zero before building the hash.
Return Value
No return value.
Example
In this example, we have an example structure which contains data we wish to hash on. The hash is initialized to zero, so we always end up with the same hash for the same data. We the call the macro twice, accumulating the result in hash. At the end of it,
struct test { int long long unsigned user_id; char user_name[64]; size_t user_name_length_in_bytes; }; int unsigned hash = 0; struct test t = { 10, "Paul McKenney", 12 }; LFDS700_HASH_A_32BIT_HASH_FUNCTION( &t.user_id, sizeof(int long long unsigned), hash ); LFDS700_HASH_A_32BIT_HASH_FUNCTION( &t.user_name, t.user_name_length_in_bytes, hash );
Notes
This is a convenience macro implemented for users. It implements the [one-at-a-time] hash, which emits to a 32 bit hash. It is provided to give users a high quality hash function to use in their key hash callbacks.