pub struct ExecutionProfile {
pub max_number_of_states: usize,
pub start_execution_time: Option<SystemTime>,
pub execution_timeout: u128,
pub max_number_of_terms: usize,
}Expand description
Hold settings about limitations and constraints of operations execution within the engine.
To apply the settings on the current thread you need to call the following function:
use regexsolver::execution_profile::{ExecutionProfile, ThreadLocalParams};
let execution_profile = ExecutionProfile {
max_number_of_states: 1,
start_execution_time: None,
execution_timeout: 1000,
max_number_of_terms: 10,
};
// Store the settings on the current thread.
ThreadLocalParams::init_profile(&execution_profile);§Examples:
§Limiting the number of states
use regexsolver::{Term, execution_profile::{ExecutionProfile, ThreadLocalParams}, error::EngineError};
let term1 = Term::from_regex(".*abc.*").unwrap();
let term2 = Term::from_regex(".*def.*").unwrap();
let execution_profile = ExecutionProfile {
max_number_of_states: 1,
start_execution_time: None,
execution_timeout: 1000,
max_number_of_terms: 10,
};
ThreadLocalParams::init_profile(&execution_profile);
assert_eq!(EngineError::AutomatonHasTooManyStates, term1.intersection(&[term2]).unwrap_err());§Limiting the number of terms
use regexsolver::{Term, execution_profile::{ExecutionProfile, ThreadLocalParams}, error::EngineError};
let term1 = Term::from_regex(".*abc.*").unwrap();
let term2 = Term::from_regex(".*def.*").unwrap();
let term3 = Term::from_regex(".*hij.*").unwrap();
let execution_profile = ExecutionProfile {
max_number_of_states: 8192,
start_execution_time: None,
execution_timeout: 1000,
max_number_of_terms: 2,
};
ThreadLocalParams::init_profile(&execution_profile);
assert_eq!(EngineError::TooMuchTerms(2,3), term1.intersection(&[term2, term3]).unwrap_err());§Limiting the execution time
use regexsolver::{Term, execution_profile::{ExecutionProfile, ThreadLocalParams}, error::EngineError};
use std::time::SystemTime;
let term = Term::from_regex(".*abc.*cdef.*sqdsqf.*").unwrap();
let execution_profile = ExecutionProfile {
max_number_of_states: 8192,
start_execution_time: Some(SystemTime::now()),
execution_timeout: 1,
max_number_of_terms: 50,
};
ThreadLocalParams::init_profile(&execution_profile);
assert_eq!(EngineError::OperationTimeOutError, term.generate_strings(100).unwrap_err());Fields§
§max_number_of_states: usizeThe maximum number of states that a non-determinitic finite automaton can hold, this is checked during the convertion of regular expression to automaton.
start_execution_time: Option<SystemTime>Timestamp of when the execution has started, if this value is not set the operations will never timeout.
execution_timeout: u128The longest time in milliseconds that an operation execution can last, there are no guaranties that the exact time will be respected.
max_number_of_terms: usizeThe maximum number of terms that an operation can have.
Implementations§
source§impl ExecutionProfile
impl ExecutionProfile
sourcepub fn assert_not_timed_out(&self) -> Result<(), EngineError>
pub fn assert_not_timed_out(&self) -> Result<(), EngineError>
Assert that execution_timeout is not exceeded.
Return empty if execution_timeout is not exceeded or if start_execution_time is not set.
Return EngineError::OperationTimeOutError otherwise.