Compute the maximum spread in bytes that a packed integer can cover. This is assuming contiguous packed integer starting with the given bit offset away from a byte boundary. This function is non-monotonic, for instance with zero offset, three bit integers will be split on the first byte boundary (hence having a spread of two bytes) while four bit integer will be well behaved and never spread over
| 61 | /// four bit integer will be well behaved and never spread over byte boundary (hence |
| 62 | /// having a spread of one). |
| 63 | ARROW_FORCE_INLINE constexpr int PackedMaxSpreadBytes(int width, int bit_offset) { |
| 64 | int max = static_cast<int>(bit_util::BytesForBits(width)); |
| 65 | int start = bit_offset; |
| 66 | do { |
| 67 | const int byte_start = start / 8; |
| 68 | const int byte_end = (start + width - 1) / 8; // inclusive end bit |
| 69 | const int spread = byte_end - byte_start + 1; |
| 70 | max = spread > max ? spread : max; |
| 71 | start += width; |
| 72 | } while (start % 8 != bit_offset); |
| 73 | return max; |
| 74 | } |
| 75 | |
| 76 | /// Compute the maximum spread in bytes that a packed integer can cover across all bit |
| 77 | /// offsets. |
no test coverage detected