1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use crate::IntSpan;
use std::collections::BTreeMap;
#[derive(Default, Clone)]
pub struct Coverage {
max: i32,
tiers: BTreeMap<i32, IntSpan>,
}
impl Coverage {
pub fn max(&self) -> &i32 {
&self.max
}
pub fn tiers(&self) -> &BTreeMap<i32, IntSpan> {
&self.tiers
}
pub fn new(max: i32) -> Self {
let mut tiers: BTreeMap<i32, IntSpan> = BTreeMap::new();
tiers.insert(-1, IntSpan::from("1-1000000000"));
tiers.insert(0, IntSpan::from("1-1000000000"));
for i in 1..=max {
tiers.insert(i, IntSpan::new());
}
Self { max, tiers }
}
pub fn bump(&mut self, start: i32, end: i32) {
let mut intspan = IntSpan::new();
intspan.add_pair(start, end);
if self
.tiers
.get(&-1)
.unwrap()
.equals(self.tiers.get(&self.max).unwrap())
{
return;
}
self.tiers.entry(0).and_modify(|e| e.subtract(&intspan));
for i in 1..=self.max {
let intersect = self.tiers.get(&i).unwrap().intersect(&intspan);
self.tiers.entry(i).and_modify(|e| e.merge(&intspan));
if i + 1 > self.max {
break;
}
intspan = intersect.copy();
}
}
pub fn max_tier(&self) -> IntSpan {
self.tiers().get(self.max()).unwrap().copy()
}
}