Giter Club home page Giter Club logo

croaring-rs's Introduction

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

A Rust wrapper for CRoaring (a C/C++ implementation at https://github.com/RoaringBitmap/CRoaring)

The original java version can be found at https://github.com/RoaringBitmap/RoaringBitmap

Bitmap usage example

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);

For 64bit Bitmap support, checkout the Treemap. Treemap is not API-compatible with Bitmap, yet most the functionality is overlapping.

Treemap usage example

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);

Building

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

In croaring-rs, just like in CRoaring, some CPU related code optimizations are enabled dynamically at runtime. If you are building binaries for specific CPU architectures you can specify ROARING_ARCH environment variable to control enabled code optimizations, e.g. ROARING_ARCH=ivybridge cargo build --release.

Testing

Running unit tests and doc tests:

cargo test

Running benchmark suite (currently on Rust nightly toolchain only):

cargo bench

Documentation

Current documentation is available at https://docs.rs/croaring/latest/croaring/

croaring-rs's People

Contributors

antiochp avatar besquared avatar dr-emann avatar frostred avatar hashmap avatar kerollmops avatar lemire avatar linxgnu avatar malbarbo avatar malthe avatar nemo157 avatar quentinlesceller avatar roncohen avatar saulius avatar schmidek avatar trevyn avatar vorot93 avatar yihuang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.