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
use ndarray::Array1;
pub struct Register {
names: Array1<String>,
}
impl Register {
#[inline]
#[must_use]
pub fn new(mut names: Vec<String>) -> Self {
debug_assert!(!names.is_empty());
names.sort();
names.dedup();
Self {
names: Array1::from(names),
}
}
#[inline]
#[must_use]
pub fn index(&self, name: &str) -> usize {
self.names.iter().position(|n| n == name).unwrap()
}
#[inline]
#[must_use]
pub fn name(&self, index: usize) -> &str {
&self.names[index]
}
#[inline]
#[must_use]
pub fn total(&self) -> usize {
self.names.len()
}
}