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
100
101
102
103
use std::mem;
use std::ptr;
use std::ops::*;
pub trait Array1<Element: Copy>: Index<usize, Output=Element> + IndexMut<usize, Output=Element> {
fn ptr<'a>(&'a self) -> &'a Element {
&(*self)[0]
}
fn mut_ptr<'a>(&'a mut self) -> &'a mut Element {
&mut (*self)[0]
}
#[inline]
fn swap_elems(&mut self, i: usize, j: usize) {
unsafe { ptr::swap(&mut (*self)[i], &mut (*self)[j]) };
}
#[inline]
fn replace_elem(&mut self, i: usize, src: Element) -> Element {
mem::replace(&mut (*self)[i], src)
}
fn map<F>(&mut self, op: F) -> Self
where F: FnMut(Element) -> Element;
}
pub trait Array2<Column: Array1<Element>+'static, Row: Array1<Element>, Element: Copy>:
Index<usize, Output=Column> + IndexMut<usize, Output=Column> {
fn ptr<'a>(&'a self) -> &'a Element {
&(*self)[0][0]
}
fn mut_ptr<'a>(&'a mut self) -> &'a mut Element {
&mut (*self)[0][0]
}
#[inline]
fn swap_cols(&mut self, a: usize, b: usize) {
unsafe { ptr::swap(&mut (*self)[a], &mut (*self)[b]) };
}
#[inline]
fn replace_col(&mut self, c: usize, src: Column) -> Column {
mem::replace(&mut (*self)[c], src)
}
fn row(&self, r: usize) -> Row;
fn swap_rows(&mut self, a: usize, b: usize);
#[inline]
fn swap_elems(&mut self, a: (usize, usize), b: (usize, usize)) {
let (ac, ar) = a;
let (bc, br) = b;
unsafe { ptr::swap(&mut (*self)[ac][ar], &mut (*self)[bc][br]) };
}
fn map<F>(&mut self, op: F) -> Self
where F: FnMut(&Column) -> Column;
}
pub trait FixedArray<V> {
fn into_fixed(self) -> V;
fn as_fixed<'a>(&'a self) -> &'a V;
fn as_mut_fixed<'a>(&'a mut self) -> &'a mut V;
fn from_fixed(v: V) -> Self;
fn from_fixed_ref<'a>(v: &'a V) -> &'a Self;
fn from_fixed_mut<'a>(v: &'a mut V) -> &'a mut Self;
}