Giter VIP home page Giter VIP logo

bitvector's Introduction

bitvector, a simple bitvector implementation in Rust-lang

This crate is a modification of librustc_data_structures/bitvec.rs for set operator support.

Documentation

Visit the online documentation or run

cargo doc

to generate a local copy.

How to use

Add the following line to [dependencies] in your Cargo.toml file:

bitvector = 0.1

Then you can use the BitVector:

extern crate bitvector;
use bitvector::*;

fn main() {
    let mut test_vec = BitVector::new(50);
    for i in vec![0,1,3,5,7,11,13,17,19,23] { test_vec.insert(i); }

    let mut test_vec2 = BitVector::new(50);
    for i in vec![3,5,9,13,19,40,45] { test_vec2.insert(i); }

    // union of test_vec and test_vec2
    // other possible operators: intersection, difference
    let union = test_vec.union(&test_vec2);


    assert!(union.contains(3));
    assert!(union.contains(5));
    assert!(union.contains(13));
    assert!(union.contains(19));
    assert!(union.contains(9));
    assert!(union.contains(40));

    // all the operators also have `*_inplace` variants
    // which directly modify `self` to avoid extra memory operations.
    test_vec.union_inplace(&test_vec2);

    assert!(test_vec.contains(3));
    assert!(test_vec.contains(5));
    assert!(test_vec.contains(13));
    assert!(test_vec.contains(19));
    assert!(test_vec.contains(0));
    assert!(test_vec.contains(9));
    assert!(test_vec.contains(40));
}

Performance Comparison against std::collections::{HashSet,BTreeSet}

test bench::bench_bitset_operator         ... bench:         610 ns/iter (+/- 114)
test bench::bench_bitset_operator_inplace ... bench:         377 ns/iter (+/- 21)
test bench::bench_btreeset_operator       ... bench:       2,782 ns/iter (+/- 169)
test bench::bench_hashset_operator        ... bench:       3,490 ns/iter (+/- 395)

LICENSE

MIT

bitvector's People

Contributors

horasal avatar hongjiezhai avatar

Watchers

James Cloos 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.