Cryptography Reference
In-Depth Information
// only have to compare “hi-int”, since the lower ints
// can't change the comparison.
i = j = 0;
// Otherwise, keep searching through the representational integers
// until one is bigger than another - once we've found one, it's
// safe to stop, since the “lower order bytes” can't affect the
// comparison
while ( i < h1->size && j < h2->size )
{
if ( h1->rep[ i ] < h2->rep[ j ] )
{
return -1;
}
else if ( h1->rep[ i ] > h2->rep[ j ] )
{
return 1;
}
i++;
j++;
}
// If we got all the way to the end without a comparison, the
// two are equal
return 0;
}
If the sizes of the huge s to be compared are different, you don't have to do
any real comparison. A fi ve- char huge always has a larger value than a three-
char huge, assuming you've been diligent in compressing representations to
remove leading 0's:
if ( h1->size > h2->size )
{
return 1;
}
if ( h1->size < h2->size )
{
return -1;
}
Otherwise, you need to do a char-by-char comparison. You can safely stop
at the fi rst non-equal char, though. If the fi rst char of h1 is larger than the fi rst
char of h2 , the lower-order integers can't change the comparison.
while ( i < h1->size && j < h2->size )
{
if ( h1->rep[ i ] < h2->rep[ j ] )
{
return -1;
}
Search WWH ::




Custom Search