]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.1.0/liblfds710/src/lfds710_hash_addonly/lfds710_hash_addonly_get.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds7.1.0 / liblfds710 / src / lfds710_hash_addonly / lfds710_hash_addonly_get.c
1 /***** includes *****/
2 #include "lfds710_hash_addonly_internal.h"
3
4
5
6
7
8 /****************************************************************************/
9 int lfds710_hash_a_get_by_key( struct lfds710_hash_a_state *has,
10                                int (*key_compare_function)(void const *new_key, void const *existing_key),
11                                void (*key_hash_function)(void const *key, lfds710_pal_uint_t *hash),
12                                void *key,
13                                struct lfds710_hash_a_element **hae )
14 {
15   int
16     rv;
17
18   lfds710_pal_uint_t
19     hash = 0;
20
21   struct lfds710_btree_au_element
22     *baue;
23
24   LFDS710_PAL_ASSERT( has != NULL );
25   // TRD : key_compare_function can be NULL
26   // TRD : key_hash_function can be NULL
27   // TRD : key can be NULL
28   LFDS710_PAL_ASSERT( hae != NULL );
29
30   if( key_compare_function == NULL )
31     key_compare_function = has->key_compare_function;
32
33   if( key_hash_function == NULL )
34     key_hash_function = has->key_hash_function;
35
36   key_hash_function( key, &hash );
37
38   rv = lfds710_btree_au_get_by_key( has->baus_array + (hash % has->array_size), key_compare_function, key, &baue );
39
40   if( rv == 1 )
41     *hae = LFDS710_BTREE_AU_GET_VALUE_FROM_ELEMENT( *baue );
42   else
43     *hae = NULL;
44
45   return rv;
46 }
47