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
use super::traits::{HierarchyBase, HierarchyEdit};
pub trait HierarchyUtil: HierarchyBase {
fn is_top_level_cell(&self, cell: &Self::CellId) -> bool {
self.num_dependent_cells(cell) == 0
}
fn is_leaf_cell(&self, cell: &Self::CellId) -> bool {
self.num_cell_dependencies(cell) == 0
}
fn each_top_level_cell(&self) -> Box<dyn Iterator<Item=Self::CellId> + '_> {
Box::new(self.each_cell()
.filter(move |c| self.is_top_level_cell(c)))
}
fn each_leaf_cell(&self) -> Box<dyn Iterator<Item=Self::CellId> + '_> {
Box::new(self.each_cell()
.filter(move |c| self.is_leaf_cell(c)))
}
}
impl<N: HierarchyBase> HierarchyUtil for N {}
pub trait HierarchyEditUtil: HierarchyEdit {
fn clear_cell_instances(&mut self, cell: &Self::CellId) {
let child_instances = self.each_cell_instance_vec(cell);
for child in &child_instances {
self.remove_cell_instance(child);
}
}
fn prune_cell_instance(&mut self, inst: &Self::CellInstId) {
let template = self.template_cell(inst);
self.remove_cell_instance(inst);
if self.num_cell_references(&template) == 0 {
self.remove_cell(&template)
}
}
fn prune_cell(&mut self, cell: &Self::CellId) {
let child_instances = self.each_cell_instance_vec(cell);
for child in &child_instances {
self.prune_cell_instance(child);
}
self.remove_cell(&cell)
}
}
impl<N: HierarchyEdit> HierarchyEditUtil for N {}