Skip to content

Three std::cmp's is probably enough. Other cleanup. #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,9 @@

extern crate num;

use std::ops::Index;
use std::ops::IndexMut;
use std::ops::AddAssign;
use std::ops::SubAssign;
use std::borrow::Borrow;
use std::cmp;
use std::ops::{Index, IndexMut, AddAssign, SubAssign};

use iterators::HistogramIterator;

Expand Down Expand Up @@ -696,8 +694,7 @@ impl<T: Counter> Histogram<T> {

/// Allocate a counts array of the given size.
fn alloc(&mut self, len: usize) {
use std::iter;
self.counts = iter::repeat(T::zero()).take(len).collect();
self.counts = std::iter::repeat(T::zero()).take(len).collect();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my eyes this is no less readable, and saves a line.

}

// ********************************************************************************************
Expand Down Expand Up @@ -1078,8 +1075,6 @@ impl<T: Counter> Histogram<T> {
///
/// Two values are considered "equivalent" if `self.equivalent` would return true.
pub fn percentile_below(&self, value: u64) -> f64 {
use std::cmp;

if self.total_count == 0 {
return 100.0;
}
Expand All @@ -1101,7 +1096,6 @@ impl<T: Counter> Histogram<T> {
///
/// May fail if the given values are out of bounds.
pub fn count_between(&self, low: u64, high: u64) -> Result<T, ()> {
use std::cmp;
let low_index = self.index_for(low);
let high_index = cmp::min(self.index_for(high), self.last());
Ok((low_index..(high_index + 1)).map(|i| self[i]).fold(T::zero(), |t, v| t + v))
Expand All @@ -1115,7 +1109,6 @@ impl<T: Counter> Histogram<T> {
///
/// May fail if the given value is out of bounds.
pub fn count_at(&self, value: u64) -> Result<T, ()> {
use std::cmp;
Ok(self[cmp::min(self.index_for(value), self.last())])
}

Expand Down