macro LFDS710_HASH_A_HASH_FUNCTION
Jump to navigation
Jump to search
Source File
└───liblfds710 └───inc └───liblfds710 lfds710_hash_addonly.h
Macro
#define LFDS710_HASH_A_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 lfds710_pal_uint_t. 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; }; lfds710_pal_uint_t hash = 0; struct test t = { 10, "Paul McKenney", 12 }; LFDS710_HASH_A_HASH_FUNCTION( &t.user_id, sizeof(int long long unsigned), hash ); LFDS710_HASH_A_HASH_FUNCTION( &t.user_name, t.user_name_length_in_bytes, hash );
Notes
This is a convenience macro implemented for users. It is provided to give users a high quality hash function to use in their key hash callbacks.