Comment out old implementation
This commit is contained in:
@@ -2,9 +2,7 @@ mod operator_set;
|
|||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use operator_set::{Op, create_operator_set};
|
use operator_set::{Op, create_permutations};
|
||||||
|
|
||||||
use crate::equation::operator_set::create_permutations;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Equation {
|
pub struct Equation {
|
||||||
|
|||||||
@@ -8,55 +8,55 @@ pub enum Op {
|
|||||||
Add,
|
Add,
|
||||||
}
|
}
|
||||||
|
|
||||||
type OperatorCache = HashMap<usize, HashSet<Vec<Op>>>;
|
// type OperatorCache = HashMap<usize, HashSet<Vec<Op>>>;
|
||||||
|
|
||||||
static OPERATOR_SET_CACHE: LazyLock<Mutex<OperatorCache>> =
|
// static OPERATOR_SET_CACHE: LazyLock<Mutex<OperatorCache>> =
|
||||||
LazyLock::new(|| Mutex::new(HashMap::new()));
|
// LazyLock::new(|| Mutex::new(HashMap::new()));
|
||||||
|
|
||||||
fn check_operator_set_cache(cache_key: usize) -> Option<HashSet<Vec<Op>>> {
|
// fn check_operator_set_cache(cache_key: usize) -> Option<HashSet<Vec<Op>>> {
|
||||||
OPERATOR_SET_CACHE.lock().unwrap().get(&cache_key).cloned()
|
// OPERATOR_SET_CACHE.lock().unwrap().get(&cache_key).cloned()
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn store_operator_set_in_cache(cache_key: usize, cache_value: HashSet<Vec<Op>>) {
|
// fn store_operator_set_in_cache(cache_key: usize, cache_value: HashSet<Vec<Op>>) {
|
||||||
OPERATOR_SET_CACHE
|
// OPERATOR_SET_CACHE
|
||||||
.lock()
|
// .lock()
|
||||||
.unwrap()
|
// .unwrap()
|
||||||
.insert(cache_key, cache_value);
|
// .insert(cache_key, cache_value);
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn create_operator_set_recurse(
|
// fn create_operator_set_recurse(
|
||||||
operators_permutation_set: &mut HashSet<Vec<Op>>,
|
// operators_permutation_set: &mut HashSet<Vec<Op>>,
|
||||||
operators: Vec<Op>,
|
// operators: Vec<Op>,
|
||||||
) {
|
// ) {
|
||||||
operators_permutation_set.insert(operators.clone());
|
// operators_permutation_set.insert(operators.clone());
|
||||||
if !operators.contains(&Op::Add) {
|
// if !operators.contains(&Op::Add) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
for i in 0..operators.len() {
|
// for i in 0..operators.len() {
|
||||||
if operators[i] == Op::Multiply {
|
// if operators[i] == Op::Multiply {
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
let mut new_operators = operators.clone();
|
// let mut new_operators = operators.clone();
|
||||||
new_operators[i] = Op::Multiply;
|
// new_operators[i] = Op::Multiply;
|
||||||
create_operator_set_recurse(operators_permutation_set, new_operators);
|
// create_operator_set_recurse(operators_permutation_set, new_operators);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn create_operator_set(num_of_operators: usize) -> HashSet<Vec<Op>> {
|
// pub fn create_operator_set(num_of_operators: usize) -> HashSet<Vec<Op>> {
|
||||||
// Check cache
|
// // Check cache
|
||||||
if let Some(cached_value) = check_operator_set_cache(num_of_operators) {
|
// if let Some(cached_value) = check_operator_set_cache(num_of_operators) {
|
||||||
return cached_value.clone();
|
// return cached_value.clone();
|
||||||
}
|
// }
|
||||||
|
|
||||||
let mut operator_sets: HashSet<Vec<Op>> = HashSet::new();
|
// let mut operator_sets: HashSet<Vec<Op>> = HashSet::new();
|
||||||
create_operator_set_recurse(&mut operator_sets, vec![Op::Add; num_of_operators]);
|
// create_operator_set_recurse(&mut operator_sets, vec![Op::Add; num_of_operators]);
|
||||||
|
|
||||||
// Store value in cache
|
// // Store value in cache
|
||||||
store_operator_set_in_cache(num_of_operators, operator_sets.clone());
|
// store_operator_set_in_cache(num_of_operators, operator_sets.clone());
|
||||||
|
|
||||||
operator_sets
|
// operator_sets
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn create_permutations_recurse(
|
fn create_permutations_recurse(
|
||||||
values: &HashSet<Op>,
|
values: &HashSet<Op>,
|
||||||
|
|||||||
Reference in New Issue
Block a user