Created
December 28, 2020 18:20
-
-
Save florianpircher/08871bb90af69e1ef404001166787276 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Segment { | |
start: u16, | |
end: u16, | |
id_delta: i16, | |
} | |
fn format4_segments_fast(map: &BTreeMap<char, u32>) -> Vec<Segment> { | |
let mut segments = Vec::<Segment>::new(); | |
if map.is_empty() { | |
return segments; | |
} | |
let mut previous_cid: u32 = 0; | |
let mut previous_gid: u32 = 0; | |
let mut start_cid: u32 = 0; | |
let mut id_delta: i64 = 0; | |
for (c, gid) in map { | |
let cid = *c as u32; | |
if cid > 0xFFFF { | |
break; | |
} | |
let gid = *gid; | |
id_delta = (gid as i64) - (cid as i64); | |
if start_cid == 0 { | |
start_cid = cid; | |
} else if previous_cid + 1 != cid || previous_gid + 1 != gid { | |
let segment = Segment { | |
start: start_cid as u16, | |
end: previous_cid as u16, | |
id_delta: id_delta as i16, | |
}; | |
segments.push(segment); | |
start_cid = cid; | |
} | |
previous_cid = cid; | |
previous_gid = gid; | |
} | |
let segment = Segment { | |
start: start_cid as u16, | |
end: previous_cid as u16, | |
id_delta: id_delta as i16, | |
}; | |
segments.push(segment); | |
segments | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment