use std::time::Duration;
#[derive(Debug, Clone)]
pub struct ParallelConfig {
pub enabled: bool,
pub thread_count: Option<usize>,
pub complexity_threshold: usize,
pub max_parallel_tasks: usize,
}
impl Default for ParallelConfig {
fn default() -> Self {
Self {
enabled: true,
thread_count: None, complexity_threshold: 100,
max_parallel_tasks: 8,
}
}
}
#[derive(Debug, Clone)]
pub struct CacheConfig {
pub enabled: bool,
pub fast_cache_size: usize,
pub exact_cache_size: usize,
pub symbolic_cache_size: usize,
pub cache_ttl: Option<Duration>,
}
impl Default for CacheConfig {
fn default() -> Self {
Self {
enabled: true,
fast_cache_size: 1000,
exact_cache_size: 500,
symbolic_cache_size: 200,
cache_ttl: Some(Duration::from_secs(3600)), }
}
}
#[derive(Debug, Clone)]
pub struct MemoryConfig {
pub max_memory_usage: Option<usize>,
pub cleanup_threshold: f64,
pub auto_gc: bool,
pub gc_interval: Duration,
}
impl Default for MemoryConfig {
fn default() -> Self {
Self {
max_memory_usage: Some(1024 * 1024 * 1024), cleanup_threshold: 0.8, auto_gc: true,
gc_interval: Duration::from_secs(60), }
}
}
#[derive(Debug, Clone)]
pub struct ComputeConfig {
pub enable_progress: bool,
pub progress_interval_ms: u64,
pub max_compute_time: Option<Duration>,
pub allow_cancellation: bool,
pub precision: PrecisionConfig,
pub parallel: ParallelConfig,
pub cache: CacheConfig,
pub memory: MemoryConfig,
}
impl Default for ComputeConfig {
fn default() -> Self {
Self {
enable_progress: true,
progress_interval_ms: 100, max_compute_time: Some(Duration::from_secs(300)), allow_cancellation: true,
precision: PrecisionConfig::default(),
parallel: ParallelConfig::default(),
cache: CacheConfig::default(),
memory: MemoryConfig::default(),
}
}
}
#[derive(Debug, Clone)]
pub struct PrecisionConfig {
pub force_exact: bool,
pub max_precision: Option<usize>,
pub allow_symbolic: bool,
pub approximation_threshold: Option<f64>,
}
impl Default for PrecisionConfig {
fn default() -> Self {
Self {
force_exact: true,
max_precision: None, allow_symbolic: true,
approximation_threshold: None,
}
}
}
impl ComputeConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_progress(mut self, enable: bool) -> Self {
self.enable_progress = enable;
self
}
pub fn with_progress_interval(mut self, interval_ms: u64) -> Self {
self.progress_interval_ms = interval_ms;
self
}
pub fn with_max_compute_time(mut self, duration: Duration) -> Self {
self.max_compute_time = Some(duration);
self
}
pub fn with_cancellation(mut self, allow: bool) -> Self {
self.allow_cancellation = allow;
self
}
pub fn with_precision(mut self, precision: PrecisionConfig) -> Self {
self.precision = precision;
self
}
pub fn with_parallel(mut self, parallel: ParallelConfig) -> Self {
self.parallel = parallel;
self
}
pub fn with_cache(mut self, cache: CacheConfig) -> Self {
self.cache = cache;
self
}
pub fn with_memory(mut self, memory: MemoryConfig) -> Self {
self.memory = memory;
self
}
}
impl PrecisionConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_force_exact(mut self, force: bool) -> Self {
self.force_exact = force;
self
}
pub fn with_max_precision(mut self, max_precision: usize) -> Self {
self.max_precision = Some(max_precision);
self
}
pub fn with_symbolic(mut self, allow: bool) -> Self {
self.allow_symbolic = allow;
self
}
pub fn with_approximation_threshold(mut self, threshold: f64) -> Self {
self.approximation_threshold = Some(threshold);
self
}
}
impl ParallelConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_enabled(mut self, enabled: bool) -> Self {
self.enabled = enabled;
self
}
pub fn with_thread_count(mut self, count: usize) -> Self {
self.thread_count = Some(count);
self
}
pub fn with_complexity_threshold(mut self, threshold: usize) -> Self {
self.complexity_threshold = threshold;
self
}
pub fn with_max_parallel_tasks(mut self, max_tasks: usize) -> Self {
self.max_parallel_tasks = max_tasks;
self
}
}
impl CacheConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_enabled(mut self, enabled: bool) -> Self {
self.enabled = enabled;
self
}
pub fn with_fast_cache_size(mut self, size: usize) -> Self {
self.fast_cache_size = size;
self
}
pub fn with_exact_cache_size(mut self, size: usize) -> Self {
self.exact_cache_size = size;
self
}
pub fn with_symbolic_cache_size(mut self, size: usize) -> Self {
self.symbolic_cache_size = size;
self
}
pub fn with_cache_ttl(mut self, ttl: Duration) -> Self {
self.cache_ttl = Some(ttl);
self
}
pub fn without_cache_ttl(mut self) -> Self {
self.cache_ttl = None;
self
}
}
impl MemoryConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_max_memory_usage(mut self, max_bytes: usize) -> Self {
self.max_memory_usage = Some(max_bytes);
self
}
pub fn without_memory_limit(mut self) -> Self {
self.max_memory_usage = None;
self
}
pub fn with_cleanup_threshold(mut self, threshold: f64) -> Self {
self.cleanup_threshold = threshold.clamp(0.0, 1.0);
self
}
pub fn with_auto_gc(mut self, auto_gc: bool) -> Self {
self.auto_gc = auto_gc;
self
}
pub fn with_gc_interval(mut self, interval: Duration) -> Self {
self.gc_interval = interval;
self
}
}