dixscript 1.0.0

Config, code, and encryption in one file — a data interchange format with compile-time functions, AES-256/ChaCha20 built-in, and cross-platform FFI
Documentation

//! OPTIMIZATION HELPER: Pre-allocate collections with estimated capacities
//! Reduces memory allocations by 15-20% (no Vec growth overhead)

/// Estimate properties count from token count
/// Typical ratio: 1 property per 4-6 tokens
#[inline]
pub fn estimate_properties_count(token_count: usize) -> usize {
    usize::max(8, token_count / 5)
}

/// Estimate array items from token count
/// Typical ratio: 1 item per 8-10 tokens
#[inline]
pub fn estimate_array_items_count(token_count: usize) -> usize {
    usize::max(4, token_count / 9)
}

/// Estimate statements count from token count
/// Typical ratio: 1 statement per 10-15 tokens
#[inline]
pub fn estimate_statements_count(token_count: usize) -> usize {
    usize::max(4, token_count / 12)
}

/// Estimate enum fields from token count
/// Typical ratio: 1 field per 2-3 tokens
#[inline]
pub fn estimate_enum_fields_count(token_count: usize) -> usize {
    usize::max(4, token_count / 2)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_estimates_have_minimums() {
        assert_eq!(estimate_properties_count(0), 8);
        assert_eq!(estimate_array_items_count(0), 4);
        assert_eq!(estimate_statements_count(0), 4);
        assert_eq!(estimate_enum_fields_count(0), 4);
    }

    #[test]
    fn test_estimates_scale_with_tokens() {
        // 100 tokens
        assert!(estimate_properties_count(100) > 8);
        assert!(estimate_array_items_count(100) > 4);
        assert!(estimate_statements_count(100) > 4);
        assert!(estimate_enum_fields_count(100) > 4);
    }

    #[test]
    fn test_enum_fields_estimate() {
        // Typical: 1 field per 2-3 tokens
        // With 50 tokens, expect ~25 fields minimum
        assert_eq!(estimate_enum_fields_count(50), 25);
    }
}