Skip to content
Snippets Groups Projects
Commit 109f7106 authored by Marc-Antoine Manningham's avatar Marc-Antoine Manningham
Browse files

refactor: simple fix

parent 49ccd0ba
No related branches found
No related tags found
1 merge request!12Feat update leptos
......@@ -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)
}
......
......@@ -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);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment