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
use prelude::*;
use std::ops::{Index, IndexMut};
pub struct IgnoreWriteProp<T> {
read: T,
write: T,
}
impl<I, T: Clone> Index<I> for IgnoreWriteProp<T> {
type Output = T;
#[inline]
fn index(&self, _: I) -> &Self::Output {
&self.read
}
}
impl<I, T: Clone> IndexMut<I> for IgnoreWriteProp<T> {
#[inline]
fn index_mut(&mut self, _: I) -> &mut Self::Output {
self.write.clone_from(&self.read);
&mut self.write
}
}
impl<G, T> VertexPropMutNew<G, T> for IgnoreWriteProp<T>
where
G: WithVertex,
T: Clone,
{
fn new_vertex_prop(_: &G, value: T) -> Self {
IgnoreWriteProp {
read: value.clone(),
write: value,
}
}
}
impl<G, T> EdgePropMutNew<G, T> for IgnoreWriteProp<T>
where
G: WithEdge,
T: Clone,
{
fn new_edge_prop(_: &G, value: T) -> Self {
IgnoreWriteProp {
read: value.clone(),
write: value,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn basic() {
let n = 3;
let val = 7;
let g = CompleteGraph::new(n);
let mut p: IgnoreWriteProp<u32> = g.vertex_prop(val);
for i in 0..n {
assert_eq!(val, p[i]);
p[i] = 20;
for j in 0..n {
assert_eq!(val, p[j]);
}
}
}
}