Fix clippy warnings

This commit is contained in:
Vinzent Steinberg 2018-03-06 18:48:08 +01:00
parent 86a411143e
commit 3f22412aa3
5 changed files with 14 additions and 13 deletions

View File

@ -33,12 +33,12 @@ macro_rules! define_histogram {
pub fn with_const_width(start: f64, end: f64) -> Self {
let step = (end - start) / (LEN as f64);
let mut range = [0.; LEN + 1];
for i in 0..(LEN + 1) {
range[i] = step * (i as f64);
for (i, r) in range.iter_mut().enumerate() {
*r = step * (i as f64);
}
Self {
range: range,
range,
bin: [0; LEN],
}
}
@ -74,7 +74,7 @@ macro_rules! define_histogram {
return Err(());
}
Ok(Self {
range: range,
range,
bin: [0; LEN],
})
}

View File

@ -33,9 +33,7 @@ impl Min {
/// Create a new minium estimator from a given value.
#[inline]
pub fn from_value(x: f64) -> Min {
Min {
x: x,
}
Min { x }
}
/// Create a new minimum estimator.
@ -115,9 +113,7 @@ impl Max {
/// Create a new maxium estimator from a given value.
#[inline]
pub fn from_value(x: f64) -> Max {
Max {
x: x,
}
Max { x }
}
/// Create a new maximum estimator.

View File

@ -44,6 +44,11 @@ impl Moments {
}
}
#[inline]
pub fn is_empty(&self) -> bool {
self.n == 0
}
#[inline]
pub fn len(&self) -> u64 {
self.n

View File

@ -21,12 +21,12 @@ pub trait Histogram:
/// Return an iterator over the bins normalized by the bin widths.
fn normalized_bins(&self) -> IterNormalized<<&Self as IntoIterator>::IntoIter> {
IterNormalized { histogram_iter: (&self).into_iter() }
IterNormalized { histogram_iter: self.into_iter() }
}
/// Return an iterator over the bin widths.
fn widths(&self) -> IterWidths<<&Self as IntoIterator>::IntoIter> {
IterWidths { histogram_iter: (&self).into_iter() }
IterWidths { histogram_iter: self.into_iter() }
}
}

View File

@ -12,7 +12,7 @@ define_histogram!(Histogram10, 10);
fn with_const_width() {
let mut h = Histogram10::with_const_width(0., 100.);
for i in 0..100 {
h.add(i as f64).unwrap();
h.add(f64::from(i)).unwrap();
}
assert_eq!(h.bins(), &[10, 10, 10, 10, 10, 10, 10, 10, 10, 10]);
}