/** * Bit Packing - Efficient bit-level compression for boolean and small integers * * Packs boolean values and small integers (0-255) into compact bit representations * to minimize token usage. Particularly effective for flags, status codes, and * categorical data with limited value ranges. * * Features: * - Boolean packing: 8 booleans per byte (87.5% savings) * - Small integer packing: Multiple values per token * - Automatic bit width detection * - Run-length encoding integration * - Efficient encoding/decoding * * Example: * Original: [true, false, true, true, false, false, true, false] * Packed: [0b10110010] = "178" * Savings: ~85% token reduction */ import type { BitPackOptions } from './types.js'; /** * Bit packing analysis result */ export interface BitPackAnalysis { valueCount: number; dataType: 'boolean' | 'small-int' | 'mixed' | 'unsupported'; bitWidth: number; packedSize: number; originalSize: number; compressionRatio: number; recommended: boolean; minValue?: number; maxValue?: number; } /** * Bit packer for boolean and small integer values */ export declare class BitPacker { private options; constructor(options?: Partial); /** * Analyze values for bit packing suitability * * @param values - Array of values * @returns Analysis with recommendations */ analyzeValues(values: any[]): BitPackAnalysis; /** * Pack boolean values into compact bit representation * * @param values - Array of boolean values * @returns Packed values as byte array */ packBooleans(values: boolean[]): number[]; /** * Unpack boolean values from bit representation * * @param packed - Packed byte array * @param count - Number of boolean values * @returns Unpacked boolean array */ unpackBooleans(packed: number[], count: number): boolean[]; /** * Pack small integers into compact bit representation * * @param values - Array of integers (0 to maxIntValue) * @param bitWidth - Bits per value (optional, auto-detected if not provided) * @returns Packed values as byte array */ packIntegers(values: number[], bitWidth?: number): number[]; /** * Unpack small integers from bit representation * * @param packed - Packed byte array * @param count - Number of integer values * @param bitWidth - Bits per value * @returns Unpacked integer array */ unpackIntegers(packed: number[], count: number, bitWidth: number): number[]; /** * Encode packed values to TONL-compatible string format * * Formats: * - Boolean: "b:178,255,..." (b: prefix + comma-separated bytes) * - Integer: "i4:178,255,..." (i{bitWidth}: prefix + comma-separated bytes) * * @param packed - Packed byte array * @param bitWidth - Bits per value (1 for boolean, n for integers) * @returns TONL-compatible string */ encodeToString(packed: number[], bitWidth: number): string; /** * Decode TONL-compatible string to packed values * * @param encoded - Encoded string (e.g., "b:178,255" or "i4:178,255") * @returns Packed byte array and bit width */ decodeFromString(encoded: string): { packed: number[]; bitWidth: number; }; /** * Generate bit packing directive * * Format: @bitpack columnName {bitWidth} {count} * * @param columnName - Column name * @param bitWidth - Bits per value * @param count - Number of values * @returns TONL directive string */ generateDirective(columnName: string, bitWidth: number, count: number): string; /** * Parse bit packing directive * * @param directive - TONL directive like "@bitpack flags 1 100" * @returns Parsed directive info */ parseDirective(directive: string): { columnName: string; bitWidth: number; count: number; }; /** * Check if bit packing would be beneficial * * @param values - Values to analyze * @param minCompressionRatio - Minimum compression ratio (default: 0.3 = 30%) * @returns True if packing is recommended */ shouldPack(values: any[], minCompressionRatio?: number): boolean; /** * Smart pack - automatically analyze and pack if beneficial * * @param values - Array of values * @returns Encoded string or null if packing not beneficial */ smartPack(values: any[]): string | null; /** * Smart unpack - decode from string format * * @param encoded - Encoded string * @param count - Expected number of values * @returns Unpacked values */ smartUnpack(encoded: string, count: number): (boolean | number)[]; /** * Estimate byte savings from bit packing * * @param values - Original values * @returns Estimated bytes saved */ estimateSavings(values: any[]): number; } /** * Bit pack decoder for restoring original values */ export declare class BitPackDecoder { private bitpackColumns; /** * Parse and register bit pack directive * * @param directive - TONL directive like "@bitpack flags 1 100" */ parseDirective(directive: string): void; /** * Check if a column is bit-packed * * @param columnName - Column name * @returns True if column is bit-packed */ isBitPacked(columnName: string): boolean; /** * Decode bit-packed column * * @param columnName - Column name * @param encoded - Encoded string * @returns Decoded values */ decode(columnName: string, encoded: string): (boolean | number)[]; /** * Get all bit-packed column names * * @returns Array of column names */ getBitPackedColumns(): string[]; /** * Clear all directives */ clear(): void; } //# sourceMappingURL=bit-pack.d.ts.map