You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.5 KiB
Rust
70 lines
1.5 KiB
Rust
/******************************************************************************
|
|
* @file solver.rs
|
|
* @author Joey Pollack
|
|
* @date 2025/11/20 (y/m/d)
|
|
* @modified 2025/11/20 (y/m/d)
|
|
* @copyright Joseph R Pollack (2025)
|
|
* @brief
|
|
******************************************************************************/
|
|
|
|
// pub trait SolutionValue<T: Into<T>>
|
|
// {
|
|
// fn get_solution_value() -> T;
|
|
// // fn into() -> T; // Should be From() instead? https://doc.rust-lang.org/std/convert/trait.Into.html
|
|
// }
|
|
|
|
use std::collections::HashMap;
|
|
|
|
pub trait Solver
|
|
{
|
|
fn init(&mut self, config: SolverState) -> Result<(), String>;
|
|
fn solve(&mut self, input: String) -> Result<u64, String>;
|
|
fn name(&self) -> String;
|
|
}
|
|
|
|
pub enum SolverOption
|
|
{
|
|
Verbose = 0x01,
|
|
Debug = 0x02,
|
|
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct SolverState
|
|
{
|
|
options: u64,
|
|
values: HashMap<String, String>,
|
|
}
|
|
|
|
impl SolverState
|
|
{
|
|
pub fn new() -> Self
|
|
{
|
|
SolverState { options: 0, values: HashMap::new() }
|
|
}
|
|
|
|
pub fn set_option(self: &mut SolverState, opt: SolverOption)
|
|
{
|
|
self.options |= opt as u64;
|
|
}
|
|
|
|
pub fn clear_option(self: &mut SolverState, opt: SolverOption)
|
|
{
|
|
self.options &= !(opt as u64);
|
|
}
|
|
|
|
pub fn check_option(self: &SolverState, opt: SolverOption) -> bool
|
|
{
|
|
self.options & (opt as u64) != 0
|
|
}
|
|
|
|
pub fn set_value(self: &mut SolverState, val: &str, key: &str)
|
|
{
|
|
self.values.insert(key.to_string(), val.to_string());
|
|
}
|
|
|
|
pub fn get_value(self: &SolverState, key: &str) -> String
|
|
{
|
|
self.values[&key.to_string()].clone()
|
|
}
|
|
} |