static void matcher_match_column( p_mcol col, const VSchema *schema, const KConfig *cfg ) { uint32_t pair_count = VectorLength( &(col->pairs) ); col->type_cast = NULL; if ( col->excluded ) return; /* call VTypedeclCommonAncestor for every type-pair */ VectorForEach ( &(col->pairs), false, matcher_measure_dist_cb, (void*)schema ); /* if we have more than one pair left... */ if ( pair_count > 1 ) { /* enter the lossy-ness into the src-types... */ VectorForEach ( &(col->src_types), false, matcher_enter_type_score_cb, (void*)cfg ); /* reorder the remaining pair's by: compatibility, lossy-ness, distance, default, order */ VectorReorder ( &(col->pairs), matcher_match_cb, NULL ); } /* pick the winner = first item in the vector */ if ( pair_count > 0 ) { col->type_cast = (p_mpair)VectorFirst ( &(col->pairs) ); /* if the winner is not a compatible pair, we have no cast ! */ if ( col->type_cast->compatible != 0 ) col->type_cast = NULL; } }
void ManipulateNumerics() { /* We should initialize the container before any operations. */ Vector* vector = VectorInit(DEFAULT_CAPACITY); /* Push the integer elements. */ VectorPushBack(vector, (void*)(intptr_t)3); VectorPushBack(vector, (void*)(intptr_t)4); /* Insert the elements at the specified indexes. */ VectorInsert(vector, 0, (void*)(intptr_t)1); VectorInsert(vector, 1, (void*)(intptr_t)2); /*---------------------------------------------------------------* * Now the vector should be: [1] | [2] | [3] | [4] * *---------------------------------------------------------------*/ /* Iterate through the vector. */ int num = 1; void* elem; VectorFirst(vector, false); while (VectorNext(vector, &elem)) { assert((intptr_t)(void*)elem == num); ++num; } /* Reversely iterate through the vector. */ num = 4; VectorFirst(vector, true); while (VectorReverseNext(vector, &elem)) { assert((intptr_t)(void*)elem == num); --num; } /* Get the elements from the specified indexes. */ VectorGet(vector, 0, &elem); assert((intptr_t)(void*)elem == 1); VectorGet(vector, 3, &elem); assert((intptr_t)(void*)elem == 4); /* Replace the elements at the specified indexes. */ VectorSet(vector, 0, (void*)(intptr_t)10); VectorSet(vector, 3, (void*)(intptr_t)40); /*---------------------------------------------------------------* * Now the vector should be: [10] | [2] | [3] | [40] * *---------------------------------------------------------------*/ /* Get the number of stored elements. */ unsigned size = VectorSize(vector); assert(size == 4); /* Sort the integer elements. */ VectorSort(vector, CompareNumber); /*---------------------------------------------------------------* * Now the vector should be: [2] | [3] | [10] | [40] * *---------------------------------------------------------------*/ /* Remove the elements at the specified indexes. */ VectorRemove(vector, 3); VectorRemove(vector, 0); /*---------------------------------------------------------------* * Now the vector should be: [3] | [10] * *---------------------------------------------------------------*/ VectorGet(vector, 0, &elem); assert((int)(intptr_t)elem == 3); VectorGet(vector, 1, &elem); assert((int)(intptr_t)elem == 10); /* Pop the elements. */ VectorPopBack(vector); VectorPopBack(vector); assert(VectorSize(vector) == 0); VectorDeinit(vector); }
void ManipulateObjects() { /* We should initialize the container before any operations. */ Vector* vector = VectorInit(DEFAULT_CAPACITY); VectorSetClean(vector, CleanObject); /* Push the object elements. */ Tuple* tuple = (Tuple*)malloc(sizeof(Tuple)); tuple->first = 3; tuple->second = -3; VectorPushBack(vector, tuple); tuple = (Tuple*)malloc(sizeof(Tuple)); tuple->first = 4; tuple->second = -4; VectorPushBack(vector, tuple); /* Insert the elements at the specified indexes. */ tuple = (Tuple*)malloc(sizeof(Tuple)); tuple->first = 1; tuple->second = -1; VectorInsert(vector, 0, tuple); tuple = (Tuple*)malloc(sizeof(Tuple)); tuple->first = 2; tuple->second = -2; VectorInsert(vector, 1, tuple); /*---------------------------------------------------------------* * Now the vector should be: [1] | [2] | [3] | [4] * *---------------------------------------------------------------*/ /* Iterate through the vector. */ int num = 1; void* elem; VectorFirst(vector, false); while (VectorNext(vector, &elem)) { assert(((Tuple*)elem)->first == num); ++num; } /* Reversely iterate through the vector. */ num = 4; VectorFirst(vector, true); while (VectorReverseNext(vector, &elem)) { assert(((Tuple*)elem)->first == num); --num; } /* Get the elements from the specified indexes. */ VectorGet(vector, 0, &elem); assert(((Tuple*)elem)->first == 1); VectorGet(vector, 3, &elem); assert(((Tuple*)elem)->first == 4); /* Replace the elements at the specified indexes. */ tuple = (Tuple*)malloc(sizeof(Tuple)); tuple->first = 10; tuple->second = -10; VectorSet(vector, 0, tuple); tuple = (Tuple*)malloc(sizeof(Tuple)); tuple->first = 40; tuple->second = -40; VectorSet(vector, 3, tuple); /*---------------------------------------------------------------* * Now the vector should be: [10] | [2] | [3] | [40] * *---------------------------------------------------------------*/ /* Get the number of stored elements. */ unsigned size = VectorSize(vector); assert(size == 4); /* Sort the integer elements. */ VectorSort(vector, CompareObject); /*---------------------------------------------------------------* * Now the vector should be: [2] | [3] | [10] | [40] * *---------------------------------------------------------------*/ /* Remove the elements at the specified indexes. */ VectorRemove(vector, 3); VectorRemove(vector, 0); /*---------------------------------------------------------------* * Now the vector should be: [3] | [10] * *---------------------------------------------------------------*/ VectorGet(vector, 0, &elem); assert(((Tuple*)elem)->first == 3); VectorGet(vector, 1, &elem); assert(((Tuple*)elem)->first == 10); /* Pop the elements. */ VectorPopBack(vector); VectorPopBack(vector); assert(VectorSize(vector) == 0); VectorDeinit(vector); }