diff --git a/combinatoric-solver/src/collection.rs b/combinatoric-solver/src/collection.rs index f16919cc65443c9c68774e4d9a82a70ab019517e..a7c1dd9303322c8545e2403fdfa2c626e3acafc4 100644 --- a/combinatoric-solver/src/collection.rs +++ b/combinatoric-solver/src/collection.rs @@ -1,20 +1,18 @@ -use crate::score::Score; +use crate::{item::ItemVariant, score::Score}; #[derive(Clone)] -pub struct Collection<const MAX_ITEMS: usize, S, ItemVariant> +pub struct Collection<const MAX_ITEMS: usize, S, V> where S: Score, - ItemVariant: Eq, + V: ItemVariant, { pub score: S, pub item_quantity: usize, - pub item_variant: [ItemVariant; MAX_ITEMS], + pub item_variant: [V; MAX_ITEMS], } -impl<const MAX_ITEMS: usize, S: Score, ItemVariant: Eq + Default + Copy> - Collection<MAX_ITEMS, S, ItemVariant> -{ - pub fn push(&self, item_variant: ItemVariant) -> Self { +impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> Collection<MAX_ITEMS, S, V> { + pub fn push(&self, item_variant: V) -> Self { let mut new = self.clone(); new.item_variant[self.item_quantity] = item_variant; new.item_quantity += 1; @@ -22,13 +20,11 @@ impl<const MAX_ITEMS: usize, S: Score, ItemVariant: Eq + Default + Copy> } } -impl<const MAX_ITEMS: usize, S: Score, ItemVariant: Eq + Default + Copy> Default - for Collection<MAX_ITEMS, S, ItemVariant> -{ +impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> Default for Collection<MAX_ITEMS, S, V> { fn default() -> Self { let score = S::default(); let item_quantity = 0; - let item_variant = [ItemVariant::default(); MAX_ITEMS]; + let item_variant = [V::default(); MAX_ITEMS]; Self { score, item_quantity, @@ -37,30 +33,21 @@ impl<const MAX_ITEMS: usize, S: Score, ItemVariant: Eq + Default + Copy> Default } } -impl<const MAX_ITEMS: usize, S: Score, ItemVariant: Eq> PartialEq - for Collection<MAX_ITEMS, S, ItemVariant> -{ +impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> PartialEq for Collection<MAX_ITEMS, S, V> { fn eq(&self, other: &Self) -> bool { self.item_variant == other.item_variant } } -impl<const MAX_ITEMS: usize, S: Score, ItemVariant: Eq> PartialOrd - for Collection<MAX_ITEMS, S, ItemVariant> -{ +impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> PartialOrd for Collection<MAX_ITEMS, S, V> { fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { self.score.partial_cmp(&other.score) } } -impl<const MAX_ITEMS: usize, S: Score, ItemVariant: Eq> Eq - for Collection<MAX_ITEMS, S, ItemVariant> -{ -} +impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> Eq for Collection<MAX_ITEMS, S, V> {} -impl<const MAX_ITEMS: usize, S: Score, ItemVariant: Eq> Ord - for Collection<MAX_ITEMS, S, ItemVariant> -{ +impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> Ord for Collection<MAX_ITEMS, S, V> { fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.score.cmp(&other.score) }