find mapping

This commit is contained in:
2026-05-19 00:46:07 +02:00
parent 5e8946a126
commit 11e408cc17
+13 -2
View File
@@ -7,10 +7,10 @@ use pest_derive::Parser;
#[grammar = "./src/rev_mapper/grammar.pest"] #[grammar = "./src/rev_mapper/grammar.pest"]
pub struct MistMapperParser; 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); 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 struct RustMap(pub usize, pub usize);
pub fn get_mapping(input: &str) -> HashSet<(RustMap, MistMap)> { pub fn get_mapping(input: &str) -> HashSet<(RustMap, MistMap)> {
@@ -35,3 +35,14 @@ pub fn get_mapping(input: &str) -> HashSet<(RustMap, MistMap)> {
mapping 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)
}