function lfds700_hash_a_get_by_key
Jump to navigation
Jump to search
Source Files
└───liblfds700 ├───inc │ └───liblfds700 │ lfds700_hash_addonly.h └───src └───llfds700_freelist lfds700_hash_addonly_get.c
Opaque Structures
struct lfds700_hash_a_element; struct lfds700_hash_a_state;
Prototype
int lfds700_hash_a_get_by_key( struct lfds700_hash_a_state *has, void *key, struct lfds700_hash_a_element **hae );
Parameters
struct lfds700_hash_a_state *has
- A pointer to an initialized struct lfds700_hash_a_state.
void *key
- Points to (or is itself) a key.
struct lfds700_hash_a_element **hae
- *hae is set to point the element with the key key. This argument is NOT set to NULL if the key is not found.
Return Value
Returns 1 if the element was found, 0 if not.
Notes
No notes.
Example
#include <stdio.h> #include <string.h> #include "liblfds700.h" struct test_data { int long long unsigned unique_id; char payload[64]; struct lfds700_hash_a_element hae; }; int key_compare_function( void const *new_key, void const *existing_key ) { int cr = 0; int long long unsigned *new_key = (int long long unsigned *) new_key, *existing_key = (int long long unsigned *) existing_key; if( *new_key > *existing_key ) cr = 1; if( *new_key < *existing_key ) cr = -1; return( cr ); } void key_hash_function( void const *key, lfds700_pal_uint_t *hash ) { int unsigned temp_hash = 0; LFDS700_HASH_A_32BIT_HASH_FUNCTION( key, sizeof(int long long unsigned), temp_hash ); *hash = temp_hash; return; } int main() { int long long unsigned key, *key_temp; struct lfds700_btree_au_state baus_array[10]; struct lfds700_hash_a_element *hae; struct lfds700_hash_a_state has; struct lfds700_misc_prng_state ps; struct test_data td, *temp_td; lfds700_misc_library_init_valid_on_current_logical_core(); lfds700_misc_prng_init( &ps ); lfds700_hash_a_init_valid_on_current_logical_core( &has, baus_array, 10, key_compare_function, key_hash_function, LFDS700_HASH_A_EXISTING_KEY_FAIL, NULL ); td.unique_id = 15; strcpy( td.payload, "Linear A" ); LFDS700_HASH_A_SET_KEY_IN_ELEMENT( td.hae, &td.unique_id ); LFDS700_HASH_A_SET_VALUE_IN_ELEMENT( td.hae, &td ); lfds700_hash_a_insert_element( &has, &hae, NULL, &ps ); key = 15; lfds700_hash_a_get_by_key( &has, (void *) &key, &hae ); key_temp = LFDS700_HASH_A_GET_KEY_FROM_ELEMENT( *hae ); temp_td = LFDS700_HASH_A_GET_VALUE_FROM_ELEMENT( *hae ); printf( "key in element is %llu\n" "payload in element is \"%s\"\n", *key_temp, temp_td->payload ); lfds700_hash_a_cleanup( &has, NULL ); lfds700_misc_library_cleanup(); return( EXIT_SUCCESS ); }