Expand description
Implementation of a histogram using 32-bit unsigned integers as counters.
This module provides an efficient for creating a histogram which supplies you with the byte occurrences in data. It’s particularly optimized for processing large amounts of data quickly.
§Key Features
- Fast histogram generation from byte slices
- Optimized for different input sizes and hardware capabilities
- Supports x86 and x86_64 specific optimizations (with nightly Rust)
§Main Types
- Histogram32: The primary struct representing a histogram with 32-bit counters.
§Main Functions
histogram32_from_bytes: Efficiently creates a histogram from a byte slice.
§Examples
Basic usage:
use lossless_transform_utils::histogram::histogram32_from_bytes;
use lossless_transform_utils::histogram::Histogram32;
let data = [1, 2, 3, 1, 2, 1];
let mut histogram = Histogram32::default();
histogram32_from_bytes(&data, &mut histogram);
assert_eq!(histogram.inner.counter[1], 3); // Byte value 1 appears 3 times
assert_eq!(histogram.inner.counter[2], 2); // Byte value 2 appears 2 times
assert_eq!(histogram.inner.counter[3], 1); // Byte value 3 appears 1 time§Performance Considerations
The implementations in this module are optimized for different input sizes:
- Small inputs (< 64 bytes) use a simple, efficient implementation.
- Larger inputs use batched processing with loop unrolling for better performance.
- On x86_64 and x86 platforms (with nightly Rust), BMI1 instructions are utilized if available.
Not optimized for non-x86 platforms, as I (Sewer) don’t own any hardware.
§Safety
While some functions in this module use unsafe code internally for performance reasons, all public interfaces are safe to use from safe Rust code.
Structs§
- Histogram32
- Implementation of a histogram using unsigned 32 bit integers as the counter.
Functions§
- histogram32_
from_ bytes - Calculates a new histogram given a byte slice.