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
use std::{
collections::HashMap,
sync::atomic::{AtomicUsize, Ordering},
};
#[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)]
pub struct DependencyId(usize);
static ID_VALUE: AtomicUsize = AtomicUsize::new(0);
impl DependencyId {
pub(crate) fn new() -> Self {
Self(ID_VALUE.fetch_add(1, Ordering::Relaxed))
}
}
#[derive(Clone)]
pub enum Evaluation {
IsEmpty,
Equals(String),
}
#[derive(Clone, Copy, Eq, PartialEq)]
pub enum Action {
Hide,
Show,
}
pub struct DependencyState {
evaluation_states: HashMap<DependencyId, bool>,
evaluation_sources: HashMap<DependencyId, (usize, usize)>,
}
impl DependencyState {
pub(crate) fn new() -> Self {
Self {
evaluation_states: HashMap::new(),
evaluation_sources: HashMap::new(),
}
}
pub(crate) fn register_evaluation(&mut self, id: &DependencyId, step: usize, control: usize) {
self.evaluation_sources.insert(*id, (step, control));
}
pub(crate) fn get_source(&self, id: &DependencyId) -> (usize, usize) {
*self.evaluation_sources.get(id).unwrap()
}
pub(crate) fn update_evaluation(&mut self, id: &DependencyId, value: bool) {
self.evaluation_states.insert(*id, value);
}
pub(crate) fn get_evaluation(&self, id: &DependencyId) -> bool {
*self.evaluation_states.get(id).unwrap_or(&false)
}
}