dsi-bitstream 0.9.2

A Rust implementation of read/write bit streams supporting several types of instantaneous codes
Documentation
#![doc(hidden)]
// THIS FILE HAS BEEN GENERATED BY THE SCRIPT gen_code_tables.py
// ~~~~~~~~~~~~~~~~~~~ DO NOT MODIFY ~~~~~~~~~~~~~~~~~~~~~~
// Methods for reading and writing values using precomputed tables for omega codes
use crate::traits::{BE, BitRead, BitWrite, LE};
use num_primitive::PrimitiveNumber;
/// How many bits are needed to read the tables
pub const READ_BITS: usize = 10;
const _: () = assert!(
    READ_BITS >= 2,
    "Read tables for Elias ω must use at least 2 bits"
);
/// Maximum value writable using the table(s)
const _: () = assert!(
    WRITE_MAX >= 62,
    "Write tables for Elias ω must represent 62"
);
pub const WRITE_MAX: u64 = 63;

/// Reads from the decoding table.
///
/// Returns `(len_with_flag, value)` where:
/// - If len_with_flag >= 0: complete code, value is decoded value, len_with_flag is code length
/// - If len_with_flag < 0: partial code, value is partial_n, (len_with_flag & 0x7F) is partial_len
/// - If len_with_flag = 0: no valid decoding (cannot occur with >= 2 bit tables)
///
/// The backend position is always advanced by (len_with_flag & 0x7F) bits.
/// Using signed i8 allows testing with `< 0` instead of masking, which is more efficient.
#[inline(always)]
pub fn read_table_le<B: BitRead<LE>>(backend: &mut B) -> (i8, u64) {
    if let Ok(idx) = backend.peek_bits(READ_BITS) {
        let idx: usize = idx.as_to();
        let len_with_flag = READ_LEN_LE[idx];
        let value = READ_LE[idx] as u64;
        backend.skip_bits_after_peek((len_with_flag & 0x7F) as usize);

        (len_with_flag, value)
    } else {
        // Not enough bits available - return initial state
        (0, 1)
    }
}

/// Reads from the decoding table.
///
/// Returns `(len_with_flag, value)` where:
/// - If len_with_flag >= 0: complete code, value is decoded value, len_with_flag is code length
/// - If len_with_flag < 0: partial code, value is partial_n, (len_with_flag & 0x7F) is partial_len
/// - If len_with_flag = 0: no valid decoding (cannot occur with >= 2 bit tables)
///
/// The backend position is always advanced by (len_with_flag & 0x7F) bits.
/// Using signed i8 allows testing with `< 0` instead of masking, which is more efficient.
#[inline(always)]
pub fn read_table_be<B: BitRead<BE>>(backend: &mut B) -> (i8, u64) {
    if let Ok(idx) = backend.peek_bits(READ_BITS) {
        let idx: usize = idx.as_to();
        let len_with_flag = READ_LEN_BE[idx];
        let value = READ_BE[idx] as u64;
        backend.skip_bits_after_peek((len_with_flag & 0x7F) as usize);

        (len_with_flag, value)
    } else {
        // Not enough bits available - return initial state
        (0, 1)
    }
}

/// Writes a value using an encoding table.
///
/// If the result is `Some` the encoding was successful, and
/// length of the code is returned.
#[inline(always)]
pub fn write_table_le<B: BitWrite<LE>>(
    backend: &mut B,
    mut n: u64,
) -> Result<Option<usize>, B::Error> {
    // We cannot use .get() here because n is a u64
    if n < WRITE_LE.len() as u64 {
        let n = n as usize;
        let len = WRITE_LEN_LE[n] as usize;
        backend.write_bits(WRITE_LE[n] as u64, len)?;
        return Ok(Some(len));
    }
    n += 1;
    let λ = n.ilog2() as usize;
    let bits = WRITE_LE[λ - 1];
    let len = WRITE_LEN_LE[λ - 1] as usize;
    backend.write_bits(bits as u64, len - 1)?;
    #[cfg(feature = "checks")]
    {
        // Clean up after the lowest λ bits in case checks are enabled
        n &= u64::MAX >> (u64::BITS - (λ as u32));
    }
    // Little-endian case: rotate left the lower λ + 1 bits (the bit in
    // position λ is a one) so that the lowest bit can be peeked to find the
    // block.
    backend.write_bits(n << 1 | 1, λ + 1)?;
    backend.write_bits(0, 1)?;
    Ok(Some(λ + len + 1))
}

/// Writes a value using an encoding table.
///
/// If the result is `Some` the encoding was successful, and
/// length of the code is returned.
#[inline(always)]
pub fn write_table_be<B: BitWrite<BE>>(
    backend: &mut B,
    mut n: u64,
) -> Result<Option<usize>, B::Error> {
    // We cannot use .get() here because n is a u64
    if n < WRITE_BE.len() as u64 {
        let n = n as usize;
        let len = WRITE_LEN_BE[n] as usize;
        backend.write_bits(WRITE_BE[n] as u64, len)?;
        return Ok(Some(len));
    }
    n += 1;
    let λ = n.ilog2() as usize;
    let bits = WRITE_BE[λ - 1];
    let len = WRITE_LEN_BE[λ - 1] as usize;
    backend.write_bits(bits as u64 >> 1, len - 1)?;
    backend.write_bits(n, λ + 1)?;
    backend.write_bits(0, 1)?;
    Ok(Some(λ + len + 1))
}
/// Precomputed table for reading omega codes
/// For complete codes: stores the decoded value
/// For partial codes: stores the partial n state
pub const READ_BE: &[u8] = &[
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12,
    12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
    13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15,
    15, 15, 15,
];
/// Precomputed lengths table for reading omega codes
/// Positive (< 0x80): complete code length
/// Negative (>= 0x80 when viewed as u8): (value & 0x7F) is partial_len (bits consumed by complete blocks)
/// Zero: no valid decoding (cannot occur with >= 2 bit tables)
pub const READ_LEN_BE: &[i8] = &[
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, -118, -118, -118, -118, -118, -118, -118, -118,
    -118, -118, -118, -118, -118, -118, -118, -118, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
    -123, -123, -123, -123, -123, -123, -123, -123, -123, -123, -123, -123, -123, -123, -123, -123,
    6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, -123, -123, -123, -123, -123, -123, -123, -123,
    -123, -123, -123, -123, -123, -123, -123, -123, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
    -123, -123, -123, -123, -123, -123, -123, -123, -123, -123, -123, -123, -123, -123, -123, -123,
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    7, 7, 7, 7, 7, 7, 7, 7, -122, -122, -122, -122, -122, -122, -122, -122, 7, 7, 7, 7, 7, 7, 7, 7,
    -122, -122, -122, -122, -122, -122, -122, -122, 7, 7, 7, 7, 7, 7, 7, 7, -122, -122, -122, -122,
    -122, -122, -122, -122, 7, 7, 7, 7, 7, 7, 7, 7, -122, -122, -122, -122, -122, -122, -122, -122,
    7, 7, 7, 7, 7, 7, 7, 7, -122, -122, -122, -122, -122, -122, -122, -122, 7, 7, 7, 7, 7, 7, 7, 7,
    -122, -122, -122, -122, -122, -122, -122, -122, 7, 7, 7, 7, 7, 7, 7, 7, -122, -122, -122, -122,
    -122, -122, -122, -122, 7, 7, 7, 7, 7, 7, 7, 7, -122, -122, -122, -122, -122, -122, -122, -122,
];
/// Precomputed table for reading omega codes
/// For complete codes: stores the decoded value
/// For partial codes: stores the partial n state
pub const READ_LE: &[u8] = &[
    0, 1, 0, 2, 0, 3, 0, 7, 0, 1, 0, 2, 0, 4, 0, 8, 0, 1, 0, 2, 0, 5, 0, 9, 0, 1, 0, 2, 0, 6, 0,
    10, 0, 1, 0, 2, 0, 16, 0, 11, 0, 1, 0, 2, 0, 5, 0, 12, 0, 1, 0, 2, 0, 6, 0, 13, 0, 1, 0, 2, 0,
    7, 0, 14, 0, 1, 0, 2, 0, 3, 0, 8, 0, 1, 0, 2, 0, 4, 0, 9, 0, 1, 0, 2, 0, 5, 0, 10, 0, 1, 0, 2,
    0, 6, 0, 11, 0, 1, 0, 2, 0, 17, 0, 12, 0, 1, 0, 2, 0, 5, 0, 13, 0, 1, 0, 2, 0, 6, 0, 14, 0, 1,
    0, 2, 0, 7, 0, 15, 0, 1, 0, 2, 0, 3, 0, 7, 0, 1, 0, 2, 0, 4, 0, 8, 0, 1, 0, 2, 0, 5, 0, 9, 0,
    1, 0, 2, 0, 6, 0, 10, 0, 1, 0, 2, 0, 18, 0, 11, 0, 1, 0, 2, 0, 5, 0, 12, 0, 1, 0, 2, 0, 6, 0,
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0, 2, 0, 6, 0, 11, 0, 1, 0, 2, 0, 29, 0, 12, 0, 1, 0, 2, 0, 5, 0, 13, 0, 1, 0, 2, 0, 6,
    0, 14, 0, 1, 0, 2, 0, 7, 0, 15, 0, 1, 0, 2, 0, 3, 0, 7, 0, 1, 0, 2, 0, 4, 0, 8, 0, 1, 0, 2, 0,
    5, 0, 9, 0, 1, 0, 2, 0, 6, 0, 10, 0, 1, 0, 2, 0, 30, 0, 11, 0, 1, 0, 2, 0, 5, 0, 12, 0, 1, 0,
    2, 0, 6, 0, 13, 0, 1, 0, 2, 0, 7, 0, 14, 0, 1, 0, 2, 0, 3, 0, 8, 0, 1, 0, 2, 0, 4, 0, 9, 0, 1,
    0, 2, 0, 5, 0, 10, 0, 1, 0, 2, 0, 6, 0, 11, 0, 1, 0, 2, 0, 31, 0, 12, 0, 1, 0, 2, 0, 5, 0, 13,
    0, 1, 0, 2, 0, 6, 0, 14, 0, 1, 0, 2, 0, 7, 0, 15,
];
/// Precomputed lengths table for reading omega codes
/// Positive (< 0x80): complete code length
/// Negative (>= 0x80 when viewed as u8): (value & 0x7F) is partial_len (bits consumed by complete blocks)
/// Zero: no valid decoding (cannot occur with >= 2 bit tables)
pub const READ_LEN_LE: &[i8] = &[
    1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7,
    1, 3, 1, 3, 1, -118, 1, 7, 1, 3, 1, 3, 1, -123, 1, 7, 1, 3, 1, 3, 1, -123, 1, 7, 1, 3, 1, 3, 1,
    -123, 1, 7, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, 6, 1, -122, 1,
    3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, -118, 1, -122, 1, 3, 1, 3, 1, -123, 1, -122, 1, 3, 1, 3,
    1, -123, 1, -122, 1, 3, 1, 3, 1, -123, 1, -122, 1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7,
    1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, -118, 1, 7, 1, 3, 1, 3, 1, -123,
    1, 7, 1, 3, 1, 3, 1, -123, 1, 7, 1, 3, 1, 3, 1, -123, 1, 7, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1,
    3, 1, 6, 1, -122, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, -118, 1,
    -122, 1, 3, 1, 3, 1, -123, 1, -122, 1, 3, 1, 3, 1, -123, 1, -122, 1, 3, 1, 3, 1, -123, 1, -122,
    1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7,
    1, 3, 1, 3, 1, -118, 1, 7, 1, 3, 1, 3, 1, -123, 1, 7, 1, 3, 1, 3, 1, -123, 1, 7, 1, 3, 1, 3, 1,
    -123, 1, 7, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, 6, 1, -122, 1,
    3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, -118, 1, -122, 1, 3, 1, 3, 1, -123, 1, -122, 1, 3, 1, 3,
    1, -123, 1, -122, 1, 3, 1, 3, 1, -123, 1, -122, 1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7,
    1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, -118, 1, 7, 1, 3, 1, 3, 1, -123,
    1, 7, 1, 3, 1, 3, 1, -123, 1, 7, 1, 3, 1, 3, 1, -123, 1, 7, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1,
    3, 1, 6, 1, -122, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, -118, 1,
    -122, 1, 3, 1, 3, 1, -123, 1, -122, 1, 3, 1, 3, 1, -123, 1, -122, 1, 3, 1, 3, 1, -123, 1, -122,
    1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7,
    1, 3, 1, 3, 1, -118, 1, 7, 1, 3, 1, 3, 1, -123, 1, 7, 1, 3, 1, 3, 1, -123, 1, 7, 1, 3, 1, 3, 1,
    -123, 1, 7, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, 6, 1, -122, 1,
    3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, -118, 1, -122, 1, 3, 1, 3, 1, -123, 1, -122, 1, 3, 1, 3,
    1, -123, 1, -122, 1, 3, 1, 3, 1, -123, 1, -122, 1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7,
    1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, -118, 1, 7, 1, 3, 1, 3, 1, -123,
    1, 7, 1, 3, 1, 3, 1, -123, 1, 7, 1, 3, 1, 3, 1, -123, 1, 7, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1,
    3, 1, 6, 1, -122, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, -118, 1,
    -122, 1, 3, 1, 3, 1, -123, 1, -122, 1, 3, 1, 3, 1, -123, 1, -122, 1, 3, 1, 3, 1, -123, 1, -122,
    1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7,
    1, 3, 1, 3, 1, -118, 1, 7, 1, 3, 1, 3, 1, -123, 1, 7, 1, 3, 1, 3, 1, -123, 1, 7, 1, 3, 1, 3, 1,
    -123, 1, 7, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, 6, 1, -122, 1,
    3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, -118, 1, -122, 1, 3, 1, 3, 1, -123, 1, -122, 1, 3, 1, 3,
    1, -123, 1, -122, 1, 3, 1, 3, 1, -123, 1, -122, 1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7,
    1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, 6, 1, 7, 1, 3, 1, 3, 1, -118, 1, 7, 1, 3, 1, 3, 1, -123,
    1, 7, 1, 3, 1, 3, 1, -123, 1, 7, 1, 3, 1, 3, 1, -123, 1, 7, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1,
    3, 1, 6, 1, -122, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, 6, 1, -122, 1, 3, 1, 3, 1, -118, 1,
    -122, 1, 3, 1, 3, 1, -123, 1, -122, 1, 3, 1, 3, 1, -123, 1, -122, 1, 3, 1, 3, 1, -123, 1, -122,
];
/// Table used to speed up the writing of omega codes
pub const WRITE_BE: &[u16] = &[
    0, 4, 6, 40, 42, 44, 46, 112, 114, 116, 118, 120, 122, 124, 126, 1312, 1314, 1316, 1318, 1320,
    1322, 1324, 1326, 1328, 1330, 1332, 1334, 1336, 1338, 1340, 1342, 2752, 2754, 2756, 2758, 2760,
    2762, 2764, 2766, 2768, 2770, 2772, 2774, 2776, 2778, 2780, 2782, 2784, 2786, 2788, 2790, 2792,
    2794, 2796, 2798, 2800, 2802, 2804, 2806, 2808, 2810, 2812, 2814, 5760,
];
/// Table used to speed up the writing of omega codes
pub const WRITE_LEN_BE: &[u16] = &[
    1, 3, 3, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
    11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
    12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
];
/// Table used to speed up the writing of omega codes
pub const WRITE_LE: &[u16] = &[
    0, 1, 3, 5, 13, 21, 29, 7, 15, 23, 31, 39, 47, 55, 63, 37, 101, 165, 229, 293, 357, 421, 485,
    549, 613, 677, 741, 805, 869, 933, 997, 45, 109, 173, 237, 301, 365, 429, 493, 557, 621, 685,
    749, 813, 877, 941, 1005, 1069, 1133, 1197, 1261, 1325, 1389, 1453, 1517, 1581, 1645, 1709,
    1773, 1837, 1901, 1965, 2029, 53,
];
/// Table used to speed up the writing of omega codes
pub const WRITE_LEN_LE: &[u16] = &[
    1, 3, 3, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
    11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
    12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
];
/// Table used to speed up the skipping of omega codes
pub const LEN: &[u8] = &[
    1, 3, 3, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
    11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
    12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
];
/// Asserts at compile time that `peek_bits` is large enough for these tables.
pub const fn check_read_table(peek_bits: usize) {
    assert!(
        peek_bits >= READ_BITS,
        "BitRead peek word too small for omega code read tables (10 bits required)"
    );
}