[DGD] Comparison of mappings

Colin Ross c.ross at cantab.net
Thu Feb 19 15:17:31 CET 2004


Is there an eas (or easier) way of comparing two mappings for
"equivalence"?  Ie, I want to test that two given mappings
have the same keys and that the values for those keys are 
the same.

For arrays, I can do:

int equal;
equal = (sizeof(array1)==sizeof(array2)) &&
        !sizeof( array1 - array2 )

which will give 1 if they are equal, and 0 otherwise.

For mappings though, I think I have to (for example) check
the sizes are the same, and then loop through the keys
of one, checking that the value of that key in the other
mapping agrees, and if they all agree, then the mappings
are equivalent:

array indices;
int i, equal;
equal = 0;
if ( sizeof(mapping1)==sizeof(mapping2) )
{
    equal = 1;
    indices = map_indices(mapping1);
    for (i=0; i<sizeof(indices); i++)
    {
        if ( mapping1[ indices[i] ] !=
             mapping2[ indices[i] ] )
        {
            equal = 0;
            break;
        }
    }
}

I was just wondering if there was an easier way that was
eluding me? 

Thanks,

Colin

(PS the code may well not actually work since I don't
have DGD available but I hope the intention is clear.)
_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list