4 /***** private prototypes *****/
5 static int key_compare_function( void const *new_value, void const *value_in_tree );
6 static void key_hash_function( void const *key, lfds700_pal_uint_t *hash );
12 /****************************************************************************/
13 void test_lfds700_hash_a_fail_and_overwrite_on_existing_key()
15 enum lfds700_hash_a_insert_result
18 enum lfds700_misc_validity
19 dvs = LFDS700_MISC_VALIDITY_VALID;
21 struct lfds700_hash_a_element
25 struct lfds700_hash_a_state
28 struct lfds700_btree_au_state
31 struct lfds700_misc_prng_state
34 internal_display_test_name( "Fail and overwrite on existing key" );
36 lfds700_misc_prng_init( &ps );
38 baus = util_aligned_malloc( sizeof(struct lfds700_btree_au_state) * 10, LFDS700_PAL_ATOMIC_ISOLATION_IN_BYTES );
40 // TRD : fail on overwrite
41 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 );
43 LFDS700_HASH_A_SET_KEY_IN_ELEMENT( hae_one, 1 );
44 LFDS700_HASH_A_SET_VALUE_IN_ELEMENT( hae_one, 0 );
45 apr = lfds700_hash_a_insert( &has, &hae_one, NULL, &ps );
47 if( apr != LFDS700_HASH_A_PUT_RESULT_SUCCESS )
48 dvs = LFDS700_MISC_VALIDITY_INVALID_TEST_DATA;
50 LFDS700_HASH_A_SET_KEY_IN_ELEMENT( hae_two, 1 );
51 LFDS700_HASH_A_SET_VALUE_IN_ELEMENT( hae_two, 1 );
52 apr = lfds700_hash_a_insert( &has, &hae_two, NULL, &ps );
54 if( apr != LFDS700_HASH_A_PUT_RESULT_FAILURE_EXISTING_KEY )
55 dvs = LFDS700_MISC_VALIDITY_INVALID_TEST_DATA;
57 lfds700_hash_a_cleanup( &has, NULL );
59 // TRD : success on overwrite
60 lfds700_hash_a_init_valid_on_current_logical_core( &has, baus, 10, key_compare_function, key_hash_function, LFDS700_HASH_A_EXISTING_KEY_OVERWRITE, NULL );
62 LFDS700_HASH_A_SET_KEY_IN_ELEMENT( hae_one, 1 );
63 LFDS700_HASH_A_SET_VALUE_IN_ELEMENT( hae_one, 1 );
64 apr = lfds700_hash_a_insert( &has, &hae_one, NULL, &ps );
66 if( apr != LFDS700_HASH_A_PUT_RESULT_SUCCESS )
67 dvs = LFDS700_MISC_VALIDITY_INVALID_TEST_DATA;
69 LFDS700_HASH_A_SET_KEY_IN_ELEMENT( hae_two, 1 );
70 LFDS700_HASH_A_SET_VALUE_IN_ELEMENT( hae_two, 1 );
71 apr = lfds700_hash_a_insert( &has, &hae_two, NULL, &ps );
73 if( apr != LFDS700_HASH_A_PUT_RESULT_SUCCESS_OVERWRITE )
74 dvs = LFDS700_MISC_VALIDITY_INVALID_TEST_DATA;
76 lfds700_hash_a_cleanup( &has, NULL );
78 util_aligned_free( baus );
80 // TRD : print the test result
81 internal_display_test_result( 1, "hash_a", dvs );
90 /****************************************************************************/
91 #pragma warning( disable : 4100 )
93 static int key_compare_function( void const *new_key, void const *key_in_tree )
98 // TRD : key_new can be any value in its range
99 // TRD : key_in_tree can be any value in its range
101 if( (lfds700_pal_uint_t) new_key < (lfds700_pal_uint_t) key_in_tree )
104 if( (lfds700_pal_uint_t) new_key > (lfds700_pal_uint_t) key_in_tree )
110 #pragma warning( default : 4100 )
116 /****************************************************************************/
117 #pragma warning( disable : 4100 )
119 static void key_hash_function( void const *key, lfds700_pal_uint_t *hash )
121 // TRD : key can be NULL
122 assert( hash != NULL );
126 /* TRD : this function iterates over the user data
127 and we are using the void pointer *as* key data
128 so here we need to pass in the addy of key
131 LFDS700_HASH_A_32BIT_HASH_FUNCTION( (void *) &key, sizeof(lfds700_pal_uint_t), *hash );
136 #pragma warning( default : 4100 )