Improve type names

This commit is contained in:
2025-06-30 10:06:29 -05:00
parent 4250028c6a
commit 8825d97858

View File

@@ -1,4 +1,6 @@
use std::collections::HashMap;
use std::collections::HashSet; use std::collections::HashSet;
use std::sync::{Arc, LazyLock, Mutex};
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum Op { pub enum Op {
@@ -19,19 +21,18 @@ impl PermutationCacheKey {
} }
} }
use std::collections::HashMap; type Permutation = Vec<Op>;
use std::sync::{LazyLock, Mutex};
type OperatorCache = HashMap<PermutationCacheKey, HashSet<Vec<Op>>>; type OperatorCache = HashMap<PermutationCacheKey, HashSet<Permutation>>;
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: &PermutationCacheKey) -> Option<HashSet<Vec<Op>>> { fn check_operator_set_cache(cache_key: &PermutationCacheKey) -> Option<HashSet<Permutation>> {
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: PermutationCacheKey, cache_value: HashSet<Vec<Op>>) { fn store_operator_set_in_cache(cache_key: PermutationCacheKey, cache_value: HashSet<Permutation>) {
OPERATOR_SET_CACHE OPERATOR_SET_CACHE
.lock() .lock()
.unwrap() .unwrap()
@@ -41,8 +42,8 @@ fn store_operator_set_in_cache(cache_key: PermutationCacheKey, cache_value: Hash
fn create_permutations_recurse( fn create_permutations_recurse(
values: &[Op], values: &[Op],
len: usize, len: usize,
permutations: &mut HashSet<Vec<Op>>, permutations: &mut HashSet<Permutation>,
curr_permutation: Vec<Op>, curr_permutation: Permutation,
) { ) {
if curr_permutation.len() == len { if curr_permutation.len() == len {
permutations.insert(curr_permutation); permutations.insert(curr_permutation);
@@ -56,7 +57,7 @@ fn create_permutations_recurse(
} }
} }
pub fn create_permutations(set: &[Op], len: usize) -> HashSet<Vec<Op>> { pub fn create_permutations(set: &[Op], len: usize) -> HashSet<Permutation> {
let cache_key = PermutationCacheKey::new(len, set.to_vec()); let cache_key = PermutationCacheKey::new(len, set.to_vec());
if let Some(cached_value) = check_operator_set_cache(&cache_key) { if let Some(cached_value) = check_operator_set_cache(&cache_key) {
return cached_value; return cached_value;