b2histogram 1.0.1

A compact and efficient integer histogram with fixed memory footprint, constant runtime performance, and (WIP) compact binary serialization.
Documentation
  • Coverage
  • 100%
    14 out of 14 items documented1 out of 11 items with examples
  • Size
  • Source code size: 29.85 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.06 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • int08h/b2histogram
    1 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • int08h

b2histogram

crates.io Build Status Apache License 2

A fast and efficient 64-bit integer histogram with power-of-2 spaced buckets.

  • Fixed memory footprint (520 bytes) with no dynamic allocations
  • Constant time record and retrieve operations that compile down to a few instructions
  • no_std support
  • Work in progress: Compact binary serialization

Usage

Add this to your Cargo.toml:

[dependencies]
b2histogram = "1.0.1"

and this to your crate root:

extern crate b2histogram;

Quick Example

extern crate b2histogram;

use b2histogram::Base2Histogram;

fn main() {
  let mut hist = Base2Histogram::new();

  hist.record(0); // Record a single observation of '0'
  hist.record(11); //
  hist.record(11); // Two observations of '11'
  hist.record_n(300_000, 6); // Six observations of 300,000

  // Retrieve counts directly
  println!("Observations for 300,000: {}", hist.observations(300_000));

  // Retrieve the `Bucket` covering a given value
  println!("Bucket corresponding to '11': {:?}", hist.bucket_for(11));

  // Iterate buckets that have observations
  for bucket in hist.iter().filter(|b| b.count > 0) {
      println!("({:5}, {:5}): {}", bucket.begin, bucket.end, bucket.count);
  }
}

See the documentation for more.