2个稳定版本
1.0.1 | 2024年1月6日 |
---|---|
1.0.0 | 2019年9月21日 |
#94 在 无标准库
14KB
92 行
b2histogram
具有2的幂次间距桶的快速高效的64位整数直方图。
- 固定的内存占用(520字节),没有动态分配
- 记录和检索操作的时间恒定,编译成少量指令
无std
支持- 正在进行中:紧凑的二进制序列化
用法
将此内容添加到您的 Cargo.toml
[dependencies]
b2histogram = "1.0.1"
并将此内容添加到您的crate根目录
extern crate b2histogram;
快速示例
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);
}
}
有关更多信息,请参阅文档。