Compare compares two bit arrays. They can have mixed sizes.
(lhs, rhs BitArray)
| 447 | |
| 448 | // Compare compares two bit arrays. They can have mixed sizes. |
| 449 | func Compare(lhs, rhs BitArray) int { |
| 450 | n := len(lhs.words) |
| 451 | if n > len(rhs.words) { |
| 452 | n = len(rhs.words) |
| 453 | } |
| 454 | i := 0 |
| 455 | for ; i < n; i++ { |
| 456 | lw := lhs.words[i] |
| 457 | rw := rhs.words[i] |
| 458 | if lw < rw { |
| 459 | return -1 |
| 460 | } |
| 461 | if lw > rw { |
| 462 | return 1 |
| 463 | } |
| 464 | } |
| 465 | if i < len(rhs.words) { |
| 466 | // lhs is shorter. |
| 467 | return -1 |
| 468 | } |
| 469 | if i < len(lhs.words) { |
| 470 | // rhs is shorter. |
| 471 | return 1 |
| 472 | } |
| 473 | // Same length. |
| 474 | if lhs.lastBitsUsed < rhs.lastBitsUsed { |
| 475 | return -1 |
| 476 | } |
| 477 | if lhs.lastBitsUsed > rhs.lastBitsUsed { |
| 478 | return 1 |
| 479 | } |
| 480 | return 0 |
| 481 | } |
| 482 | |
| 483 | // EncodingParts retrieves the encoding bits from the bit array. The |
| 484 | // words are presented in big-endian order, with the leftmost bits of |
no outgoing calls
no test coverage detected
searching dependent graphs…