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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use id::*;
use qdf::*;
#[derive(Debug, Clone)]
pub struct Space<S>
where
S: State,
{
id: ID,
parent: Option<ID>,
state: S,
subspace: Vec<ID>,
}
impl<S> Space<S>
where
S: State,
{
#[inline]
pub(crate) fn new(state: S) -> Self {
Self {
id: ID::new(),
parent: None,
state,
subspace: vec![],
}
}
#[inline]
pub(crate) fn with_id(id: ID, state: S) -> Self {
Self {
id,
parent: None,
state,
subspace: vec![],
}
}
#[inline]
pub(crate) fn with_id_parent_state(id: ID, parent: ID, state: S) -> Self {
Space {
id,
parent: Some(parent),
state,
subspace: vec![],
}
}
#[inline]
pub fn id(&self) -> ID {
self.id
}
#[inline]
pub fn parent(&self) -> Option<ID> {
self.parent
}
#[inline]
pub fn state(&self) -> &S {
&self.state
}
#[inline]
pub fn subspace(&self) -> &[ID] {
&self.subspace
}
#[inline]
pub fn is_platonic(&self) -> bool {
self.subspace.is_empty()
}
#[inline]
pub(crate) fn apply_state(&mut self, state: S) {
self.state = state;
}
#[inline]
pub(crate) fn apply_subspace(&mut self, subspace: Vec<ID>) {
self.subspace = subspace;
}
}
impl<S> Default for Space<S>
where
S: State,
{
#[inline]
fn default() -> Self {
Self::new(S::default())
}
}