Debian Codegraph @

src/csi.rs

raw symbols SCIP
1 use std::convert::TryInto;
2
3 /// calculate bin given an alignment covering [beg,end) (zero-based, half-close-half-open)
4 pub fn reg2bin(beg: i64, end: i64, min_shift: u32, depth: u32) -> u32 {
5 let end = end - 1;
6 let mut s = min_shift;
7 let mut t = ((1 << (depth * 3)) - 1) / 7;
8
9 for l2 in 0..depth {
10 //eprintln!("depth: {}", l2);
11 let l = depth - l2;
12 if beg >> s == end >> s {
13 //eprintln!("value: {}", (t + (beg >> s)));
14 return (t + (beg >> s)).try_into().unwrap();
15 };
16 s += 3;
17 //let t2 = t;
18 t -= 1 << ((l - 1) * 3);
19 //eprintln!("t : {} -> {} / {} / {}", t2, t, l, 1 << (l * 3));
20 }
21
22 0
23 }
24
25 /// calculate the list of bins that may overlap with region [beg,end) (zero-based)
26 pub fn reg2bins(beg: i64, end: i64, min_shift: u32, depth: u32) -> Vec<u32> {
27 let mut bins: Vec<u32> = Vec::new();
28 let end = end - 1;
29 let mut s = min_shift + depth * 3;
30 let mut t = 0;
31
32 for l in 0..=depth {
33 let b = t + (beg >> s);
34 let e = t + (end >> s);
35 for i in b..=e {
36 bins.push(i.try_into().unwrap());
37 }
38 s -= 3;
39 t += 1 << (l * 3);
40 }
41
42 bins
43 }