Detailed description |
|
da_is_included has a return value of DC_TRUE "if a is included in b", else DC_FALSE. If you assume that this means every value of set A has to be present in set B, then the current implementation of da_is_included does not work. A workaround for da_is_included that adheres to the above statement could look as follows:
DC_BOOL da_is_included(dyn_array_t *a, dyn_array_t *b, da_cmp_cbk compare)
{
int i, j;
if (a == NULL || a->nb == 0)
return DC_TRUE;
if (b == NULL || b->nb == 0)
return DC_FALSE;
for (i = 0; i < a->nb; i++)
{
int present = 0;
for (j = 0; j < b->nb ; j++ ) {
if ( 0 == compare(GET_ENTRY(a, i), GET_ENTRY(b, j)) ) {
present = 1;
break;
}
}
if (0 == present)
return DC_FALSE;
}
return DC_TRUE;
}
Is my understanding of "is included" correct?
-Remo- |
|