From 11e408cc17295b558ad4d15134c90d0d115410a8 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Tue, 19 May 2026 00:46:07 +0200 Subject: [PATCH] find mapping --- parser/src/rev_mapper/mod.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/parser/src/rev_mapper/mod.rs b/parser/src/rev_mapper/mod.rs index 90fc01e..f648d87 100644 --- a/parser/src/rev_mapper/mod.rs +++ b/parser/src/rev_mapper/mod.rs @@ -7,10 +7,10 @@ use pest_derive::Parser; #[grammar = "./src/rev_mapper/grammar.pest"] pub struct MistMapperParser; -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct MistMap(pub usize, pub usize); -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct RustMap(pub usize, pub usize); pub fn get_mapping(input: &str) -> HashSet<(RustMap, MistMap)> { @@ -35,3 +35,14 @@ pub fn get_mapping(input: &str) -> HashSet<(RustMap, MistMap)> { mapping } + +pub fn find_mapping( + mapping: &HashSet<(RustMap, MistMap)>, + target: &RustMap, +) -> Option<(RustMap, MistMap)> { + mapping + .iter() + .copied() + .filter(|(rust, _)| rust <= target) + .max_by_key(|(rust, _)| *rust) +}