Skip to main content

ebi_activity_key/
activity_key_translator.rs

1use crate::{Activity, ActivityKey};
2
3pub struct ActivityKeyTranslator {
4    from2to: Vec<Activity>,
5}
6
7impl ActivityKeyTranslator {
8    pub fn new(from: &ActivityKey, to: &mut ActivityKey) -> Self {
9        let mut from2to = vec![];
10
11        for label_from in &from.activity2name {
12            let index_to = to.process_activity(&label_from);
13            from2to.push(index_to);
14        }
15
16        Self { from2to: from2to }
17    }
18
19    pub fn translate_activity(&self, activity: &Activity) -> Activity {
20        self.from2to[activity.id]
21    }
22
23    pub fn translate_trace(&self, trace: &Vec<Activity>) -> Vec<Activity> {
24        let mut result = Vec::with_capacity(trace.len());
25        for from in trace {
26            result.push(self.from2to[from.id]);
27        }
28        result
29    }
30
31    pub fn translate_trace_mut(&self, trace: &mut Vec<Activity>) {
32        trace
33            .iter_mut()
34            .for_each(|event| *event = self.translate_activity(event));
35    }
36}