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
104
105
106
107
108
109
110
use crate::{axes::Axes, axis::Axis, FillWith};
use super::fill::{Fill, FillWithWeighted};
pub(crate) type Values<'a, V> = Box<dyn Iterator<Item = &'a V> + 'a>;
pub(crate) type Iter<'a, A, V> =
Box<dyn Iterator<Item = Item<<A as Axis>::BinInterval, &'a V>> + 'a>;
pub(crate) type ValuesMut<'a, V> = Box<dyn Iterator<Item = &'a mut V> + 'a>;
pub(crate) type IterMut<'a, A, V> =
Box<dyn Iterator<Item = Item<<A as Axis>::BinInterval, &'a mut V>> + 'a>;
pub trait Histogram<A: Axes, V> {
fn axes(&self) -> &A;
fn value_at_index(&self, index: usize) -> Option<&V>;
fn value(&self, coordinate: &A::Coordinate) -> Option<&V> {
let index = self.axes().index(coordinate)?;
self.value_at_index(index)
}
fn values(&self) -> Values<'_, V>;
fn iter(&self) -> Iter<'_, A, V>;
fn value_at_index_mut(&mut self, index: usize) -> Option<&mut V>;
fn value_mut(&mut self, coordinate: &A::Coordinate) -> Option<&mut V> {
let index = self.axes().index(coordinate)?;
self.value_at_index_mut(index)
}
fn values_mut(&mut self) -> ValuesMut<'_, V>;
fn iter_mut(&mut self) -> IterMut<'_, A, V>;
fn fill(&mut self, coordinate: &A::Coordinate)
where
V: Fill,
{
if let Some(value) = self.value_mut(coordinate) {
value.fill()
}
}
fn fill_with<D>(&mut self, coordinate: &A::Coordinate, data: D)
where
V: FillWith<D>,
{
if let Some(value) = self.value_mut(coordinate) {
value.fill_with(data)
}
}
fn fill_with_weighted<D, W>(&mut self, coordinate: &A::Coordinate, data: D, weight: W)
where
V: FillWithWeighted<D, W>,
{
if let Some(value) = self.value_mut(coordinate) {
value.fill_with_weighted(data, weight)
}
}
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Item<T, V> {
pub index: usize,
pub bin: T,
pub value: V,
}
impl<T, V> Item<T, V> {
pub fn new(index: usize, bin: T, value: V) -> Item<T, V> {
Item { index, bin, value }
}
}