macro LFDS711_HASH_A_GET_USER_STATE_FROM_STATE

From liblfds.org
Jump to navigation Jump to search

Source File

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

Macro

#define LFDS711_HASH_A_GET_USER_STATE_FROM_STATE( hash_a_state )

Parameters

hash_a_state

An initialized struct lfds711_hash_a_state. Not a pointer to it - the struct itself.

Return Value

Returns a void *, the user_state argument from lfds711_hash_a_init_valid_on_current_logical_core.

Notes

The user state value can only be set the once, when the data structure instance is initialized.

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

Example

#include "liblfds711.h"
#include <stdio.h>
#include <string.h>

void key_hash_function( void const *key, lfds711_uint_t *hash )
{
  assert( key != NULL );
  assert( hash != NULL );

  *hash = 0;

  // TRD : assuming key is 16 bytes in length
  LFDS711_HASH_A_HASH_FUNCTION( key, 16, *hash );

  return;
}

int main()
{
  char
    hash_a_name[64] = "Fable Of The Brown Ape";

  struct lfds711_btree_au_state
    baus_array[16];

  struct lfds711_hash_a_state
    has;

  void
    *user_state;

  lfds711_misc_init();

  lfds711_hash_a_init_valid_on_current_logical_core( &has, baus_array, 16, strcmp, key_hash_fuction, LFDS711_HASH_A_EXISTING_KEY_OVERWRITE, (void *) hash_a_name );

  user_state = LFDS711_HASH_A_GET_USER_STATE_FROM_STATE( has );

  printf( "hash_a name is \"%s\"\n", (char *) user_state );

  lfds711_hash_a_cleanup( &has, NULL );

  lfds711_misc_cleanup();

  return( EXIT_SUCCESS );
}

See Also