//! Numeric constants and the base-62 symbol table.
//!
//! Every value here derives from the 62-character table length. The encoder and
//! decoder read these as fixed tag-byte ranges, so the literal values are
//! load-bearing. They are written out as evaluated constants rather than as
//! expressions so the wire format stays pinned.

/// The base-62 symbol table.
///
/// The order is uppercase A-Z, then lowercase a-z, then digits 0-9. This is not
/// the conventional `0-9A-Za-z` order. The table works as a symbol map, not a
/// positional base. Index `i` maps to byte `BASE62TABLE[i]`.
pub const BASE62TABLE: &[u8; 62] =
    b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

/// Number of symbols in the table.
pub const TABLE_LENGTH: usize = 62;

/// Largest value a single distance or length digit can hold.
pub const BUFFER_MAX: usize = 61;

/// Sliding-window prefix length. The encoder prepends this many spaces and the
/// decoder seeds its output with them.
pub const WINDOW_MAX: usize = 1024;

/// Search horizon. A match may reach this many code units behind the cursor.
pub const WINDOW_BUFFER_MAX: usize = 304;

/// Output buffer size for one compress chunk.
pub const COMPRESS_CHUNK_SIZE: usize = 65533;

/// Flush threshold for the compress output buffer.
pub const COMPRESS_CHUNK_MAX: usize = COMPRESS_CHUNK_SIZE - TABLE_LENGTH; // 65471

/// Streaming chunk size for decompress output.
pub const DECOMPRESS_CHUNK_SIZE: usize = COMPRESS_CHUNK_SIZE;

/// Upper bound of the Latin literal range. Code units below this encode as Latin
/// literals.
pub const LATIN_BUFFER_MAX: u32 = 132;

/// Radix for splitting a code unit into base-40 digits.
pub const UNICODE_CHAR_MAX: u32 = 40;

/// Upper bound of the single-digit Unicode literal range.
pub const UNICODE_BUFFER_MAX: u32 = 1640;

/// Base index for Latin start tags.
pub const LATIN_INDEX: u32 = 63;

/// Offset subtracted from a Latin index to form its start tag.
pub const LATIN_INDEX_START: u32 = 20;

/// Base index for Unicode start tags.
pub const UNICODE_INDEX: u32 = 67;

/// Upper bound of a literal payload digit. A first token byte below this is a
/// literal digit.
pub const DECODE_MAX: usize = 43;

/// Upper bound of the Latin start-tag range.
pub const LATIN_DECODE_MAX: usize = 47;

/// Token byte that marks a fresh Unicode literal.
pub const CHAR_START: usize = 48;

/// First token byte of a variable-length match (a length byte follows).
pub const COMPRESS_START: usize = 49;

/// First token byte of a fixed-length-2 match.
pub const COMPRESS_FIXED_START: usize = 54;

/// One past the last match token byte. Indices 59, 60, 61 are unused.
pub const COMPRESS_INDEX: usize = 59;

/// Build the sliding-window prefix: exactly 1024 space code units.
pub fn create_window_internal() -> Vec<u16> {
    vec![0x20; WINDOW_MAX]
}
