2 #define LFDS710_HASH_A_GET_KEY_FROM_ELEMENT( hash_a_element ) ( (hash_a_element).key )
3 #define LFDS710_HASH_A_SET_KEY_IN_ELEMENT( hash_a_element, new_key ) ( (hash_a_element).key = (void *) (lfds710_pal_uint_t) (new_key) )
4 #define LFDS710_HASH_A_GET_VALUE_FROM_ELEMENT( hash_a_element ) ( LFDS710_MISC_BARRIER_LOAD, (hash_a_element).value )
5 #define LFDS710_HASH_A_SET_VALUE_IN_ELEMENT( hash_a_element, new_value ) { LFDS710_PAL_ATOMIC_SET( &(hash_a_element).value, new_value ); }
6 #define LFDS710_HASH_A_GET_USER_STATE_FROM_STATE( hash_a_state ) ( (hash_a_state).user_state )
8 // TRD : a quality hash function, provided for user convenience - note hash must be initialized to 0 before the first call by the user
10 #if( LFDS710_PAL_ALIGN_SINGLE_POINTER == 4 )
11 // TRD : void *data, lfds710_pal_uint_t data_length_in_bytes, lfds710_pal_uint_t hash
12 #define LFDS710_HASH_A_HASH_FUNCTION( data, data_length_in_bytes, hash ) { \
16 for( loop = 0 ; loop < (data_length_in_bytes) ; loop++ ) \
18 (hash) += *( (char unsigned *) (data) + loop ); \
19 (hash) = ((hash) ^ ((hash) >> 16)) * 0x85ebca6bUL; \
20 (hash) = ((hash) ^ ((hash) >> 13)) * 0xc2b2ae35UL; \
21 (hash) = (hash ^ (hash >> 16)); \
26 #if( LFDS710_PAL_ALIGN_SINGLE_POINTER == 8 )
27 // TRD : void *data, lfds710_pal_uint_t data_length_in_bytes, lfds710_pal_uint_t hash
28 #define LFDS710_HASH_A_HASH_FUNCTION( data, data_length_in_bytes, hash ) { \
32 for( loop = 0 ; loop < (data_length_in_bytes) ; loop++ ) \
34 (hash) += *( (char unsigned *) (data) + loop ); \
35 (hash) = ((hash) ^ ((hash) >> 30)) * 0xBF58476D1CE4E5B9ULL; \
36 (hash) = ((hash) ^ ((hash) >> 27)) * 0x94D049BB133111EBULL; \
37 (hash) = (hash ^ (hash >> 31)); \
43 enum lfds710_hash_a_existing_key
45 LFDS710_HASH_A_EXISTING_KEY_OVERWRITE,
46 LFDS710_HASH_A_EXISTING_KEY_FAIL
49 enum lfds710_hash_a_insert_result
51 LFDS710_HASH_A_PUT_RESULT_FAILURE_EXISTING_KEY,
52 LFDS710_HASH_A_PUT_RESULT_SUCCESS_OVERWRITE,
53 LFDS710_HASH_A_PUT_RESULT_SUCCESS
56 enum lfds710_hash_a_query
58 LFDS710_HASH_A_QUERY_GET_POTENTIALLY_INACCURATE_COUNT,
59 LFDS710_HASH_A_QUERY_SINGLETHREADED_VALIDATE
63 struct lfds710_hash_a_element
65 struct lfds710_btree_au_element
71 void LFDS710_PAL_ALIGN(LFDS710_PAL_ALIGN_SINGLE_POINTER)
75 struct lfds710_hash_a_iterate
77 struct lfds710_btree_au_element
80 struct lfds710_btree_au_state
85 struct lfds710_hash_a_state
87 enum lfds710_hash_a_existing_key
91 (*key_compare_function)( void const *new_key, void const *existing_key );
96 struct lfds710_btree_au_state
100 (*element_cleanup_callback)( struct lfds710_hash_a_state *has, struct lfds710_hash_a_element *hae ),
101 (*key_hash_function)( void const *key, lfds710_pal_uint_t *hash ),
105 /***** public prototypes *****/
106 void lfds710_hash_a_init_valid_on_current_logical_core( struct lfds710_hash_a_state *has,
107 struct lfds710_btree_au_state *baus_array,
108 lfds710_pal_uint_t array_size,
109 int (*key_compare_function)(void const *new_key, void const *existing_key),
110 void (*key_hash_function)(void const *key, lfds710_pal_uint_t *hash),
111 enum lfds710_hash_a_existing_key existing_key,
113 // TRD : used in conjunction with the #define LFDS710_MISC_MAKE_VALID_ON_CURRENT_LOGICAL_CORE_INITS_COMPLETED_BEFORE_NOW_ON_ANY_OTHER_LOGICAL_CORE
115 void lfds710_hash_a_cleanup( struct lfds710_hash_a_state *has,
116 void (*element_cleanup_function)(struct lfds710_hash_a_state *has, struct lfds710_hash_a_element *hae) );
118 enum lfds710_hash_a_insert_result lfds710_hash_a_insert( struct lfds710_hash_a_state *has,
119 struct lfds710_hash_a_element *hae,
120 struct lfds710_hash_a_element **existing_hae );
121 // TRD : if existing_value is not NULL and the key exists, existing_hae is set to the hash element of the existing key
123 int lfds710_hash_a_get_by_key( struct lfds710_hash_a_state *has,
124 int (*key_compare_function)(void const *new_key, void const *existing_key),
125 void (*key_hash_function)(void const *key, lfds710_pal_uint_t *hash),
127 struct lfds710_hash_a_element **hae );
129 void lfds710_hash_a_iterate_init( struct lfds710_hash_a_state *has, struct lfds710_hash_a_iterate *hai );
130 int lfds710_hash_a_iterate( struct lfds710_hash_a_iterate *hai, struct lfds710_hash_a_element **hae );
132 void lfds710_hash_a_query( struct lfds710_hash_a_state *has,
133 enum lfds710_hash_a_query query_type,
135 void *query_output );