Skip to content

Commit

Permalink
histogram: remove CompactHistogram
Browse files Browse the repository at this point in the history
  • Loading branch information
mihirn committed Sep 13, 2023
1 parent 25490cf commit 4e76240
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 112 deletions.
5 changes: 0 additions & 5 deletions histogram/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@ homepage = "https://github.com/pelikan-io/rustcommon/histogram"
repository = "https://github.com/pelikan-io/rustcommon"

[dependencies]
serde = { version = "1.0.144", features = ["derive"], optional = true }
thiserror = "1.0.38"

[dev-dependencies]
criterion = "0.4.0"
itertools = "0.11.0"

[features]
default = ["serde-serialize"]
serde-serialize = ["serde"]

[[bench]]
name = "bench"
harness = false
48 changes: 0 additions & 48 deletions histogram/src/compact.rs

This file was deleted.

17 changes: 0 additions & 17 deletions histogram/src/histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,23 +461,6 @@ impl Clone for Histogram {
}
}

#[cfg(feature = "serde-serialize")]
impl TryFrom<&CompactHistogram> for Histogram {
type Error = error::Error;

fn try_from(h: &CompactHistogram) -> Result<Self, Self::Error> {
let histogram = Histogram::new(h.m, h.r, h.n)?;
let nbuckets = histogram.buckets();
for (i, bucket_id) in h.index.iter().enumerate() {
if *bucket_id >= nbuckets {
return Err(Error::OutOfRange);
}
histogram.buckets[*bucket_id].store(h.count[i], Ordering::Relaxed);
}
Ok(histogram)
}
}

/// An iterator that allows walking through the `Bucket`s within a `Histogram`.
pub struct HistogramIter<'a> {
current: usize,
Expand Down
42 changes: 0 additions & 42 deletions histogram/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
// http://www.apache.org/licenses/LICENSE-2.0

mod bucket;
#[cfg(feature = "serde-serialize")]
mod compact;
mod error;
mod histogram;
mod percentile;

pub use self::histogram::{Builder, Histogram};
pub use bucket::Bucket;
#[cfg(feature = "serde-serialize")]
pub use compact::CompactHistogram;
pub use error::Error;
pub use percentile::Percentile;

Expand Down Expand Up @@ -165,42 +161,4 @@ mod tests {
Err(Error::Empty)
);
}

#[cfg(feature = "serde-serialize")]
#[test]
fn compact_histogram() {
let h = CompactHistogram::default();
assert_eq!(h.m, 0);
assert_eq!(h.r, 0);
assert_eq!(h.n, 0);
assert_eq!(&h.index, &[]);
assert_eq!(&h.count, &[]);

assert!(Histogram::try_from(&h).is_err());
}

#[cfg(feature = "serde-serialize")]
#[test]
fn hydrate_and_dehydrate() {
let histogram = Histogram::new(0, 5, 10).unwrap();

for v in (1..1024).step_by(128) {
assert!(histogram.increment(v, 1).is_ok());
}

let h = CompactHistogram::from(&histogram);
assert_eq!(h.m, 0);
assert_eq!(h.r, 5);
assert_eq!(h.n, 10);
assert_eq!(&h.index, &[1, 64, 80, 88, 96, 100, 104, 108]);
assert_eq!(&h.count, &[1, 1, 1, 1, 1, 1, 1, 1]);

let rehydrated = Histogram::try_from(&h).unwrap();
assert_eq!(rehydrated.parameters(), histogram.parameters());
assert_eq!(rehydrated.buckets(), histogram.buckets());
assert!(itertools::equal(
rehydrated.into_iter(),
histogram.into_iter()
));
}
}

0 comments on commit 4e76240

Please sign in to comment.