From 109f7106f44fa3073cebffaaafdf1cfde59d98f0 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Manningham <marc-antoine.m@outlook.com> Date: Sat, 14 Sep 2024 21:25:31 -0400 Subject: [PATCH] refactor: simple fix --- combinatoric-solver/src/collection.rs | 13 +++++++------ combinatoric-solver/src/solver.rs | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/combinatoric-solver/src/collection.rs b/combinatoric-solver/src/collection.rs index a7c1dd9..d21d0f6 100644 --- a/combinatoric-solver/src/collection.rs +++ b/combinatoric-solver/src/collection.rs @@ -7,39 +7,39 @@ where V: ItemVariant, { pub score: S, - pub item_quantity: usize, pub item_variant: [V; MAX_ITEMS], } impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> Collection<MAX_ITEMS, S, V> { - pub fn push(&self, item_variant: V) -> Self { + #[inline] + pub fn push(&self, iteration: usize, item_variant: V) -> Self { let mut new = self.clone(); - new.item_variant[self.item_quantity] = item_variant; - new.item_quantity += 1; + new.item_variant[iteration] = item_variant; new } } impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> Default for Collection<MAX_ITEMS, S, V> { + #[inline] fn default() -> Self { let score = S::default(); - let item_quantity = 0; let item_variant = [V::default(); MAX_ITEMS]; Self { score, - item_quantity, item_variant, } } } impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> PartialEq for Collection<MAX_ITEMS, S, V> { + #[inline] fn eq(&self, other: &Self) -> bool { self.item_variant == other.item_variant } } impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> PartialOrd for Collection<MAX_ITEMS, S, V> { + #[inline] fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { self.score.partial_cmp(&other.score) } @@ -48,6 +48,7 @@ impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> PartialOrd for Collection impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> Eq for Collection<MAX_ITEMS, S, V> {} impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> Ord for Collection<MAX_ITEMS, S, V> { + #[inline] fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.score.cmp(&other.score) } diff --git a/combinatoric-solver/src/solver.rs b/combinatoric-solver/src/solver.rs index 863a287..eb27c47 100644 --- a/combinatoric-solver/src/solver.rs +++ b/combinatoric-solver/src/solver.rs @@ -49,7 +49,7 @@ where } for variant in items[i].variants() { - let collections = collection.push(variant); + let collections = collection.push(i, variant); Self::rec_iter(i + 1, collections, items, top_items); } } -- GitLab