From 328c73a9b176e449f0a5d4f35715865710eaa3c9 Mon Sep 17 00:00:00 2001 From: Mora Unie Youer Date: Mon, 28 Apr 2025 10:21:50 +0300 Subject: perf: minimization algorithm now a little faster --- src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index e8c3849..75c796a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,8 @@ impl Cube { let dt = self.t ^ other.t; let df = self.f ^ other.f; + // NOTE: this should be compiled with all optimizations possible + // as `.count_ones()` is bottleneck if dt == df && dt.count_ones() == 1 { Some(Self { t: self.t & other.t, @@ -64,8 +66,9 @@ fn minimize_prime_implicants(n: usize, minterms: &[usize], maxterms: &[usize]) - let mut new_cubes = HashSet::new(); for i in 0..current_cubes.len() { + let a = ¤t_cubes[i]; + for j in i + 1..current_cubes.len() { - let a = ¤t_cubes[i]; let b = ¤t_cubes[j]; if let Some(combined_cube) = a.combine(b) { -- cgit v1.2.3-70-g09d2