7 struct lfds700_btree_au_element
16 enum lfds700_misc_flag
19 struct lfds700_hash_a_state
26 /***** private prototypes *****/
27 static int key_compare_function( void const *new_key, void const *existing_key );
28 static void key_hash_function( void const *key, lfds700_pal_uint_t *hash );
34 /****************************************************************************/
35 void test_lfds700_hash_a_iterate( void )
37 enum lfds700_misc_validity
38 dvs = LFDS700_MISC_VALIDITY_VALID;
44 struct lfds700_hash_a_element
47 struct lfds700_hash_a_iterate
50 struct lfds700_hash_a_state
53 struct lfds700_hash_a_element
56 struct lfds700_btree_au_state
59 struct lfds700_misc_prng_state
65 /* TRD : single-threaded test
66 we create a single hash_a
67 we populate with 1000 elements
68 where key and value is the number of the element (e.g. 0 to 999)
69 we then allocate 1000 counters, init to 0
71 we increment each element as we see it in the iterate
72 if any are missing or seen more than once, problemo!
74 we do this once with a table of 10, to ensure each table has (or almost certainly has) something in
75 and then a second tiem with a table of 10000, to ensure some empty tables exist
78 internal_display_test_name( "Iterate" );
80 lfds700_misc_prng_init( &ps );
82 element_array = util_aligned_malloc( sizeof(struct lfds700_hash_a_element) * 1000, LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES );
84 counter_array = util_malloc_wrapper( sizeof(lfds700_pal_uint_t) * 1000 );
86 // TRD : first time around
87 baus = util_aligned_malloc( sizeof(struct lfds700_btree_au_state) * 10, LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES );
89 lfds700_hash_a_init_valid_on_current_logical_core( &has, baus, 10, key_compare_function, key_hash_function, LFDS700_HASH_A_EXISTING_KEY_FAIL, NULL );
91 for( loop = 0 ; loop < 1000 ; loop++ )
93 LFDS700_HASH_A_SET_KEY_IN_ELEMENT( *(element_array+loop), loop );
94 LFDS700_HASH_A_SET_VALUE_IN_ELEMENT( *(element_array+loop), loop );
95 lfds700_hash_a_insert( &has, element_array+loop, NULL, &ps );
98 for( loop = 0 ; loop < 1000 ; loop++ )
99 *(counter_array+loop) = 0;
101 lfds700_hash_a_iterate_init( &has, &hai );
103 while( dvs == LFDS700_MISC_VALIDITY_VALID and lfds700_hash_a_iterate(&hai, &hae) )
105 value = LFDS700_HASH_A_GET_VALUE_FROM_ELEMENT( *hae );
106 ( *(counter_array + (lfds700_pal_uint_t) value) )++;
109 if( dvs == LFDS700_MISC_VALIDITY_VALID )
110 for( loop = 0 ; loop < 1000 ; loop++ )
112 if( *(counter_array+loop) > 1 )
113 dvs = LFDS700_MISC_VALIDITY_INVALID_ADDITIONAL_ELEMENTS;
115 if( *(counter_array+loop) == 0 )
116 dvs = LFDS700_MISC_VALIDITY_INVALID_MISSING_ELEMENTS;
119 lfds700_hash_a_cleanup( &has, NULL );
121 util_aligned_free( baus );
123 // TRD : second time around
124 if( dvs == LFDS700_MISC_VALIDITY_VALID )
126 baus = util_aligned_malloc( sizeof(struct lfds700_btree_au_state) * 10000, LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES );
128 lfds700_hash_a_init_valid_on_current_logical_core( &has, baus, 10000, key_compare_function, key_hash_function, LFDS700_HASH_A_EXISTING_KEY_FAIL, NULL );
130 for( loop = 0 ; loop < 1000 ; loop++ )
132 LFDS700_HASH_A_SET_KEY_IN_ELEMENT( *(element_array+loop), loop );
133 LFDS700_HASH_A_SET_VALUE_IN_ELEMENT( *(element_array+loop), loop );
134 lfds700_hash_a_insert( &has, element_array+loop, NULL, &ps );
137 for( loop = 0 ; loop < 1000 ; loop++ )
138 *(counter_array+loop) = 0;
140 lfds700_hash_a_iterate_init( &has, &hai );
142 while( dvs == LFDS700_MISC_VALIDITY_VALID and lfds700_hash_a_iterate(&hai, &hae) )
144 value = LFDS700_HASH_A_GET_VALUE_FROM_ELEMENT( *hae );
145 ( *(counter_array + (lfds700_pal_uint_t) value ) )++;
148 if( dvs == LFDS700_MISC_VALIDITY_VALID )
149 for( loop = 0 ; loop < 1000 ; loop++ )
151 if( *(counter_array+loop) > 1 )
152 dvs = LFDS700_MISC_VALIDITY_INVALID_ADDITIONAL_ELEMENTS;
154 if( *(counter_array+loop) == 0 )
155 dvs = LFDS700_MISC_VALIDITY_INVALID_MISSING_ELEMENTS;
158 lfds700_hash_a_cleanup( &has, NULL );
160 util_aligned_free( baus );
164 util_aligned_free( element_array );
165 free( counter_array );
167 // TRD : print the test result
168 internal_display_test_result( 1, "hash_a", dvs );
177 /****************************************************************************/
178 #pragma warning( disable : 4100 )
180 static int key_compare_function( void const *new_key, void const *existing_key )
185 // TRD : new_key can be NULL (i.e. 0)
186 // TRD : existing_key can be NULL (i.e. 0)
188 if( (lfds700_pal_uint_t) new_key < (lfds700_pal_uint_t) existing_key )
191 if( (lfds700_pal_uint_t) new_key > (lfds700_pal_uint_t) existing_key )
197 #pragma warning( default : 4100 )
203 /****************************************************************************/
204 #pragma warning( disable : 4100 )
206 static void key_hash_function( void const *key, lfds700_pal_uint_t *hash )
208 // TRD : key can be NULL
209 assert( hash != NULL );
213 /* TRD : this function iterates over the user data
214 and we are using the void pointer AS user data
215 so here we need to pass in the addy of value
218 LFDS700_HASH_A_32BIT_HASH_FUNCTION( (void *) &key, sizeof(lfds700_pal_uint_t), *hash );
223 #pragma warning( default : 4100 )