1 个不稳定版本

使用旧的Rust 2015

0.4.5 2020年3月23日

#4#c-roaring

每月下载量 48
5 个crate中使用(通过croaring-mw

Apache-2.0

485KB
10K SLoC

C 10K SLoC // 0.1% comments Rust 33 SLoC

croaring-rs https://travis-ci.org/saulius/croaring-rs

A Rust 包装器,用于CRoaring(C/C++实现,位于https://github.com/RoaringBitmap/CRoaring

原始的Java版本可以在https://github.com/RoaringBitmap/RoaringBitmap找到

位图使用示例

use croaring::Bitmap;

let mut rb1 = Bitmap::create();
rb1.add(1);
rb1.add(2);
rb1.add(3);
rb1.add(4);
rb1.add(5);
rb1.add(100);
rb1.add(1000);
rb1.run_optimize();

let mut rb2 = Bitmap::create();
rb2.add(3);
rb2.add(4);
rb2.add(1000);
rb2.run_optimize();

let mut rb3 = Bitmap::create();

assert_eq!(rb1.cardinality(), 7);
assert!(rb1.contains(3));

rb1.and_inplace(&rb2);
rb3.add(5);
rb3.or_inplace(&rb1);

let mut rb4 = Bitmap::fast_or(&[&rb1, &rb2, &rb3]);

rb1.and_inplace(&rb2);
println!("{:?}", rb1);

rb3.add(5);
rb3.or_inplace(&rb1);

println!("{:?}", rb1);

rb3.add(5);
rb3.or_inplace(&rb1);

println!("{:?}", rb3.to_vec());
println!("{:?}", rb3);
println!("{:?}", rb4);

rb4 = Bitmap::fast_or(&[&rb1, &rb2, &rb3]);

println!("{:?}", rb4);

对于64位位图支持,请查看TreemapTreemapBitmap 不兼容API,但大多数功能是重叠的。

Treemap使用示例

use std::u64;
use croaring::Treemap;

let mut treemap = Treemap::create();
treemap.add(u64::MAX);
treemap.remove(u64::MAX);

/// Serialization compatible with croaring Treemap version at https://github.com/RoaringBitmap/CRoaring/blob/b88b002407b42fafaea23ea5009a54a24d1c1ed4/cpp/roaring64map.hh

use croaring::treemap::NativeSerializer;

let mut treemap1 = Treemap::create();

for i in 100..1000 {
  treemap1.add(i);
}

treemap1.add(std::u32::MAX as u64);
treemap1.add(std::u64::MAX);

/// Serialization compatible with JVM Treemap version at https://github.com/RoaringBitmap/RoaringBitmap/blob/34654b2d5c3e75e7f9bca1672f4c0b5800d60cf3/roaringbitmap/src/main/java/org/roaringbitmap/longlong/Roaring64NavigableMap.java
use croaring::treemap::JvmSerializer;

let mut treemap2 = Treemap::create();

for i in 100..1000 {
  treemap2.add(i);
}

treemap2.add(std::u32::MAX as u64);
treemap2.add(std::u64::MAX);

本地构建

git clone --recursive https://github.com/saulius/croaring-rs/
cd croaring-rs
cargo build

在Rust stable/beta/nightly 和 LLVM版本 3.8上进行了测试。

测试

运行单元测试和文档测试

cargo test

运行基准测试套件(目前仅在Rust nightly工具链上运行)

cargo bench

文档

当前文档可在https://docs.rs/croaring/latest/croaring/找到

依赖关系

~0–2MB
~39K SLoC