2 #include "libtest_tests_internal.h"
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, lfds710_pal_uint_t *hash );
12 /****************************************************************************/
13 #pragma warning( disable : 4100 )
15 void libtest_tests_hash_a_fail_and_overwrite_on_existing_key( struct lfds710_list_asu_state *list_of_logical_processors, struct libshared_memory_state *ms, enum lfds710_misc_validity *dvs )
17 enum lfds710_hash_a_insert_result
20 struct lfds710_hash_a_element
24 struct lfds710_hash_a_state
27 struct lfds710_btree_au_state
30 LFDS710_PAL_ASSERT( list_of_logical_processors != NULL );
31 LFDS710_PAL_ASSERT( ms != NULL );
32 LFDS710_PAL_ASSERT( dvs != NULL );
34 *dvs = LFDS710_MISC_VALIDITY_VALID;
36 baus = libshared_memory_alloc_from_unknown_node( ms, sizeof(struct lfds710_btree_au_state) * 10, LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
38 // TRD : fail on overwrite
39 lfds710_hash_a_init_valid_on_current_logical_core( &has, baus, 10, key_compare_function, key_hash_function, LFDS710_HASH_A_EXISTING_KEY_FAIL, NULL );
41 LFDS710_HASH_A_SET_KEY_IN_ELEMENT( hae_one, 1 );
42 LFDS710_HASH_A_SET_VALUE_IN_ELEMENT( hae_one, 0 );
43 apr = lfds710_hash_a_insert( &has, &hae_one, NULL );
45 if( apr != LFDS710_HASH_A_PUT_RESULT_SUCCESS )
46 *dvs = LFDS710_MISC_VALIDITY_INVALID_TEST_DATA;
48 LFDS710_HASH_A_SET_KEY_IN_ELEMENT( hae_two, 1 );
49 LFDS710_HASH_A_SET_VALUE_IN_ELEMENT( hae_two, 1 );
50 apr = lfds710_hash_a_insert( &has, &hae_two, NULL );
52 if( apr != LFDS710_HASH_A_PUT_RESULT_FAILURE_EXISTING_KEY )
53 *dvs = LFDS710_MISC_VALIDITY_INVALID_TEST_DATA;
55 lfds710_hash_a_cleanup( &has, NULL );
57 // TRD : success on overwrite
58 lfds710_hash_a_init_valid_on_current_logical_core( &has, baus, 10, key_compare_function, key_hash_function, LFDS710_HASH_A_EXISTING_KEY_OVERWRITE, NULL );
60 LFDS710_HASH_A_SET_KEY_IN_ELEMENT( hae_one, 1 );
61 LFDS710_HASH_A_SET_VALUE_IN_ELEMENT( hae_one, 1 );
62 apr = lfds710_hash_a_insert( &has, &hae_one, NULL );
64 if( apr != LFDS710_HASH_A_PUT_RESULT_SUCCESS )
65 *dvs = LFDS710_MISC_VALIDITY_INVALID_TEST_DATA;
67 LFDS710_HASH_A_SET_KEY_IN_ELEMENT( hae_two, 1 );
68 LFDS710_HASH_A_SET_VALUE_IN_ELEMENT( hae_two, 1 );
69 apr = lfds710_hash_a_insert( &has, &hae_two, NULL );
71 if( apr != LFDS710_HASH_A_PUT_RESULT_SUCCESS_OVERWRITE )
72 *dvs = LFDS710_MISC_VALIDITY_INVALID_TEST_DATA;
74 lfds710_hash_a_cleanup( &has, NULL );
79 #pragma warning( default : 4100 )
85 /****************************************************************************/
86 static int key_compare_function( void const *new_key, void const *key_in_tree )
91 // TRD : key_new can be any value in its range
92 // TRD : key_in_tree can be any value in its range
94 if( (lfds710_pal_uint_t) new_key < (lfds710_pal_uint_t) key_in_tree )
97 if( (lfds710_pal_uint_t) new_key > (lfds710_pal_uint_t) key_in_tree )
107 /****************************************************************************/
108 static void key_hash_function( void const *key, lfds710_pal_uint_t *hash )
110 // TRD : key can be NULL
111 LFDS710_PAL_ASSERT( hash != NULL );
115 /* TRD : this function iterates over the user data
116 and we are using the void pointer *as* key data
117 so here we need to pass in the addy of key
120 LFDS710_HASH_A_HASH_FUNCTION( (void *) &key, sizeof(lfds710_pal_uint_t), *hash );