lossless_transform_utils/histogram/mod.rs
1//! This module contains the implementation of a 'histogram'.
2//!
3//! A histogram is simply a counter of how many times an individual item has appeared
4//! in a given dataset.
5//!
6//! For example, given the bytes `[0, 1, 2, 0, 1]`, the histogram would be `[2, 2, 1]`,
7//! as bytes `0` and `1` appear two times, but the byte `2` appears once.
8//!
9//! The histogram code in this module is built around calculating occurrences of bytes, the amount
10//! of times a byte has been met is stored.
11
12pub mod histogram32;
13pub use histogram32::*;
14
15/// The implementation of a generic histogram, storing the for each byte using type `T`.
16/// `T` should be a type that can be incremented.
17#[repr(C)]
18#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
19pub struct Histogram<T> {
20 pub counter: [T; 256],
21}
22
23#[cfg(any(test, feature = "bench"))]
24pub mod histogram32_private;
25#[cfg(any(test, feature = "bench"))]
26pub use histogram32_private::*;
27
28/// Benchmark only re-exports.
29#[cfg(feature = "bench")]
30pub mod bench {
31 use super::Histogram32;
32
33 pub fn histogram32_generic_batched_unroll_4_u32(bytes: &[u8], histogram: &mut Histogram32) {
34 super::histogram32_generic_batched_unroll_4_u32(bytes, histogram)
35 }
36
37 pub fn histogram32_reference(bytes: &[u8], histogram: &mut Histogram32) {
38 super::histogram32_reference(bytes, histogram)
39 }
40}