This is static - there is no 'this' argument.
| 515 | |
| 516 | // This is static - there is no 'this' argument. |
| 517 | int ByteVector::compare(const ByteVector &bv1, const ByteVector &bv2) |
| 518 | { |
| 519 | unsigned bv1size = bv1.sizeBits(), bv2size = bv2.sizeBits(); |
| 520 | unsigned minsize = MIN(bv1size,bv2size); |
| 521 | unsigned bytes = minsize/8; |
| 522 | int result; |
| 523 | // Compare the full bytes. |
| 524 | if (bytes) { |
| 525 | if ((result = memcmp(bv1.begin(),bv2.begin(),bytes))) {return result;} |
| 526 | } |
| 527 | // Compare the partial byte, if any. |
| 528 | unsigned rem = minsize%8; |
| 529 | if (rem) { |
| 530 | if ((result = (int) bv1.getField2(bytes,0,rem) - (int) bv2.getField2(bytes,0,rem))) {return result;} |
| 531 | } |
| 532 | // All bits the same. The longer guy wins. |
| 533 | return (int)bv1size - (int)bv2size; |
| 534 | } |
| 535 | |
| 536 | // We assume that if the last byte is a partial byte (ie bitsize % 8 != 0) |
| 537 | // then the remaining unused bits are all equal, should be 0. |