macro LFDS711_HASH_A_HASH_FUNCTION

From liblfds.org
Revision as of 18:12, 16 February 2017 by Admin (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Source File

└───liblfds711
    └───inc
        └───liblfds711
                lfds711_hash_addonly.h

Macro

#define LFDS711_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 lfds711_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;
};

lfds711_pal_uint_t
  hash = 0;

struct test
  t = { 10, "Paul McKenney", 12 };
 
LFDS711_HASH_A_HASH_FUNCTION( &t.user_id, sizeof(int long long unsigned), hash );
LFDS711_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.

See Also

Hash (add-only)