2 #include "lfds700_hash_addonly_internal.h"
4 /***** private prototypes *****/
5 static void lfds700_hash_a_internal_validate( struct lfds700_hash_a_state *has, struct lfds700_misc_validation_info *vi, enum lfds700_misc_validity *lfds700_hash_a_validity );
11 /****************************************************************************/
12 void lfds700_hash_a_query( struct lfds700_hash_a_state *has, enum lfds700_hash_a_query query_type, void *query_input, void *query_output )
14 LFDS700_PAL_ASSERT( has != NULL );
15 // TRD : query_type can be any value in its range
17 LFDS700_MISC_BARRIER_LOAD;
21 case LFDS700_HASH_A_QUERY_GET_POTENTIALLY_INACCURATE_COUNT:
23 struct lfds700_hash_a_iterate
26 struct lfds700_hash_a_element
29 LFDS700_PAL_ASSERT( query_input == NULL );
30 LFDS700_PAL_ASSERT( query_output != NULL );
32 *(lfds700_pal_uint_t *) query_output = 0;
34 lfds700_hash_a_iterate_init( has, &ai );
36 while( lfds700_hash_a_iterate(&ai, &hae) )
37 ( *(lfds700_pal_uint_t *) query_output )++;
41 case LFDS700_HASH_A_QUERY_SINGLETHREADED_VALIDATE:
42 // TRD: query_input can be any value in its range
43 LFDS700_PAL_ASSERT( query_output != NULL );
45 lfds700_hash_a_internal_validate( has, (struct lfds700_misc_validation_info *) query_input, (enum lfds700_misc_validity *) query_output );
56 /****************************************************************************/
57 static void lfds700_hash_a_internal_validate( struct lfds700_hash_a_state *has, struct lfds700_misc_validation_info *vi, enum lfds700_misc_validity *lfds700_hash_a_validity )
60 lfds700_hash_a_total_number_elements = 0,
61 lfds700_btree_au_total_number_elements = 0,
67 LFDS700_PAL_ASSERT( has!= NULL );
68 // TRD : vi can be NULL
69 LFDS700_PAL_ASSERT( lfds700_hash_a_validity != NULL );
71 /* TRD : validate every btree_addonly_unbalanced in the addonly_hash
72 sum elements in each btree_addonly_unbalanced
73 check matches expected element counts (if vi is provided)
76 *lfds700_hash_a_validity = LFDS700_MISC_VALIDITY_VALID;
78 for( loop = 0 ; *lfds700_hash_a_validity == LFDS700_MISC_VALIDITY_VALID and loop < has->array_size ; loop++ )
79 lfds700_btree_au_query( has->baus_array+loop, LFDS700_BTREE_AU_QUERY_SINGLETHREADED_VALIDATE, NULL, (void *) lfds700_hash_a_validity );
81 if( *lfds700_hash_a_validity == LFDS700_MISC_VALIDITY_VALID )
83 for( loop = 0 ; loop < has->array_size ; loop++ )
85 lfds700_btree_au_query( has->baus_array+loop, LFDS700_BTREE_AU_QUERY_GET_POTENTIALLY_INACCURATE_COUNT, NULL, (void *) &number_elements );
86 lfds700_btree_au_total_number_elements += number_elements;
89 // TRD : first, check btree_addonly_unbalanced total vs the addonly_hash total
90 lfds700_hash_a_query( has, LFDS700_HASH_A_QUERY_GET_POTENTIALLY_INACCURATE_COUNT, NULL, &lfds700_hash_a_total_number_elements );
92 // TRD : the btree_addonly_unbalanceds are assumed to speak the truth
93 if( lfds700_hash_a_total_number_elements < lfds700_btree_au_total_number_elements )
94 *lfds700_hash_a_validity = LFDS700_MISC_VALIDITY_INVALID_ADDITIONAL_ELEMENTS;
96 if( lfds700_hash_a_total_number_elements > lfds700_btree_au_total_number_elements )
97 *lfds700_hash_a_validity = LFDS700_MISC_VALIDITY_INVALID_MISSING_ELEMENTS;
99 // TRD : second, if we're still valid and vi is provided, check the btree_addonly_unbalanced total against vi
100 if( *lfds700_hash_a_validity == LFDS700_MISC_VALIDITY_VALID and vi != NULL )
102 if( lfds700_btree_au_total_number_elements < vi->min_elements )
103 *lfds700_hash_a_validity = LFDS700_MISC_VALIDITY_INVALID_MISSING_ELEMENTS;
105 if( lfds700_btree_au_total_number_elements > vi->max_elements )
106 *lfds700_hash_a_validity = LFDS700_MISC_VALIDITY_INVALID_ADDITIONAL_ELEMENTS;