macro LFDS710_HASH_A_SET_KEY_IN_ELEMENT

From liblfds.org
Revision as of 21:04, 7 May 2016 by Admin (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Source File

└───liblfds710
    └───inc
        └───liblfds710
                lfds710_hash_addonly.h

Macro

#define LFDS710_HASH_A_SET_KEY_IN_ELEMENT( hash_a_element, new_key )

Parameters

hash_a_element

A struct lfds710_hash_a_element. Not a pointer to it - the struct itself.

new_key

A void pointer, which the key in hash_a_element is set to.

Return Value

No return value.

Example

char
  unqiue_user_id = 10;

struct lfds710_hash_a_element
  hae;

LFDS710_HASH_A_SET_KEY_IN_ELEMENT( hae, (void *) &unique_user_id );

Notes

As with all liblfds macros, the macro operates on the structure itself, not a pointer to it.

The key can only be set before an element enters the hash. If it is set after, the hash will likely be broken (as the new key, being different to the old key, would most likely require the element to be in a different position in the hash, and this element movement is not supported) and also, key is not set atomically, so that even if a change was made, there is in principle no guarantee any other logical core would see that change anyway.

Key is not set atomically because it is known it will only be set before an element enters the hash. Matters can be (and have been) arranged to ensure key is despite the lack of an atomic set correctly propagated to other logical cores, but this is a behaviour of the code which adds an element into the hash, not of the macro which sets key.

See Also

Hash (add-only)