From 8825d978582d46a46f7e0596fd3ce6fe5aecbb71 Mon Sep 17 00:00:00 2001 From: Bearmine Date: Mon, 30 Jun 2025 10:06:29 -0500 Subject: [PATCH] Improve type names --- day_07/src/equation/operator_set.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/day_07/src/equation/operator_set.rs b/day_07/src/equation/operator_set.rs index c69c96d..3759286 100644 --- a/day_07/src/equation/operator_set.rs +++ b/day_07/src/equation/operator_set.rs @@ -1,4 +1,6 @@ +use std::collections::HashMap; use std::collections::HashSet; +use std::sync::{Arc, LazyLock, Mutex}; #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] pub enum Op { @@ -19,19 +21,18 @@ impl PermutationCacheKey { } } -use std::collections::HashMap; -use std::sync::{LazyLock, Mutex}; +type Permutation = Vec; -type OperatorCache = HashMap>>; +type OperatorCache = HashMap>; static OPERATOR_SET_CACHE: LazyLock> = LazyLock::new(|| Mutex::new(HashMap::new())); -fn check_operator_set_cache(cache_key: &PermutationCacheKey) -> Option>> { +fn check_operator_set_cache(cache_key: &PermutationCacheKey) -> Option> { OPERATOR_SET_CACHE.lock().unwrap().get(cache_key).cloned() } -fn store_operator_set_in_cache(cache_key: PermutationCacheKey, cache_value: HashSet>) { +fn store_operator_set_in_cache(cache_key: PermutationCacheKey, cache_value: HashSet) { OPERATOR_SET_CACHE .lock() .unwrap() @@ -41,8 +42,8 @@ fn store_operator_set_in_cache(cache_key: PermutationCacheKey, cache_value: Hash fn create_permutations_recurse( values: &[Op], len: usize, - permutations: &mut HashSet>, - curr_permutation: Vec, + permutations: &mut HashSet, + curr_permutation: Permutation, ) { if curr_permutation.len() == len { permutations.insert(curr_permutation); @@ -56,7 +57,7 @@ fn create_permutations_recurse( } } -pub fn create_permutations(set: &[Op], len: usize) -> HashSet> { +pub fn create_permutations(set: &[Op], len: usize) -> HashSet { let cache_key = PermutationCacheKey::new(len, set.to_vec()); if let Some(cached_value) = check_operator_set_cache(&cache_key) { return cached_value;