macro LFDS700_HASH_A_GET_USER_STATE_FROM_STATE

From liblfds.org
Revision as of 18:00, 10 December 2015 by Admin (talk | contribs) (→‎Example)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Source File

└───liblfds700
    └───inc
        └───liblfds700
                lfds700_hash_addonly.h

Macro

#define LFDS700_HASH_A_GET_USER_STATE_FROM_STATE( hash_a_state )

Parameters

hash_a_state

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

Return Value

Returns a void *, the user_state argument from lfds700_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 "liblfds700.h"
#include <stdio.h>
#include <string.h>

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

  *hash = 0;

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

  return;
}

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

  struct lfds700_btree_au_state
    baus_array[16];

  struct lfds700_hash_a_state
    has;

  void
    *user_state;

  lfds700_misc_init();

  lfds700_hash_a_init_valid_on_current_logical_core( &has, baus_array, 16, strcmp, key_hash_fuction, LFDS700_HASH_A_EXISTING_KEY_OVERWRITE, (void *) hash_a_name );

  user_state = LFDS700_HASH_A_GET_USER_STATE_FROM_STATE( has );

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

  lfds700_hash_a_cleanup( &has, NULL );

  lfds700_misc_cleanup();

  return( EXIT_SUCCESS );
}

See Also