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
use std::ops::{Add, Deref, Index, IndexMut};
use structure::vector::VecOps;
pub struct RedoxVector {
pub data: Vec<f64>
}
impl RedoxVector {
pub fn new(n: usize) -> Self {
RedoxVector {
data: vec![f64::default(); n]
}
}
pub fn from_vec(v: Vec<f64>) -> Self {
RedoxVector {
data: v
}
}
}
impl Deref for RedoxVector {
type Target = Vec<f64>;
fn deref(&self) -> &Self::Target {
&self.data
}
}
impl Index<usize> for RedoxVector {
type Output = f64;
fn index(&self, index: usize) -> &Self::Output {
self.data.index(index)
}
}
impl IndexMut<usize> for RedoxVector {
fn index_mut(&mut self, index: usize) -> &mut f64 {
self.data.index_mut(index)
}
}
impl Add<RedoxVector> for RedoxVector {
type Output = RedoxVector;
fn add(self, rhs: Self) -> Self::Output {
RedoxVector::from_vec(self.data.add(&rhs.data))
}
}
impl<'a, 'b> Add<&'b RedoxVector> for &'a RedoxVector {
type Output = RedoxVector;
fn add(self, rhs: &'b RedoxVector) -> Self::Output {
RedoxVector::from_vec(self.data.add(&rhs.data))
}
}