A bit vector with the Rust standard library's portable SIMD API

Overview

Usage

Add bitsvec to Cargo.toml:

bitsvec = "x.y.z"

Write some code like this:

let mut bitvec = BitVec::ones(1000); // create a bitvec contains 0 ..= 999
bitvec.set(900, false); // delete 900 from bitvec
bitvec.set(1200, true); // add 1200 to bitvec (and expand bitvec to length 1201)
let bitvec2 = BitVec::ones(1000);

let new_bitvec = bitvec.and_cloned(&bitvec2); // and operation, without consume
let new_bitvec2 = bitvec & bitvec2; // and operation, consume both bitvec

// Operation Supported:
// and, or, xor, not, eq, eq_left

assert_eq!(new_bitvec, new_bitvec2);

Performance

Compared on AMD Ryzen 9 5900hs, aginst:

$ cargo bench

bitsvec(this crate)     time:   [330.34 ns 330.75 ns 331.18 ns]
Found 6 outliers among 100 measurements (6.00%)
  4 (4.00%) high mild
  2 (2.00%) high severe

bitsvec_u16x8(this crate)
                        time:   [332.23 ns 333.90 ns 335.98 ns]
Found 16 outliers among 100 measurements (16.00%)
  6 (6.00%) high mild
  10 (10.00%) high severe

bitvec_simd 0.15.0      time:   [371.96 ns 372.23 ns 372.53 ns]
Found 6 outliers among 100 measurements (6.00%)
  4 (4.00%) high mild
  2 (2.00%) high severe

bitvec_simd 0.15.0 u16x8
                        time:   [578.38 ns 578.68 ns 579.01 ns]
Found 7 outliers among 100 measurements (7.00%)
  6 (6.00%) high mild
  1 (1.00%) high severe

bitvector_simd 0.2.2    time:   [288.55 ns 289.11 ns 289.64 ns]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild

bit-vec 0.6             time:   [1.5177 us 1.5200 us 1.5224 us]

bitvec 1.0              time:   [32.119 us 32.254 us 32.390 us]

bitsvec(this crate) with creation
                        time:   [888.59 ns 889.45 ns 890.39 ns]
Found 10 outliers among 100 measurements (10.00%)
  9 (9.00%) high mild
  1 (1.00%) high severe
                                                                                                              bitsvec_u16x8(this crate) with creation
                        time:   [1.1006 us 1.1031 us 1.1059 us]
Found 11 outliers among 100 measurements (11.00%)
  8 (8.00%) high mild
  3 (3.00%) high severe

bitvec_simd 0.15.0 with creation
                        time:   [970.09 ns 970.82 ns 971.67 ns]
Found 12 outliers among 100 measurements (12.00%)
  10 (10.00%) high mild
  2 (2.00%) high severe
                                                                                                              bitvec_simd 0.15.0 u16x8 with creation
                        time:   [1.1158 us 1.1185 us 1.1215 us]
Found 8 outliers among 100 measurements (8.00%)
  6 (6.00%) low mild
  2 (2.00%) high mild

bitvector_simd 0.2.2 with creation
                        time:   [736.46 ns 737.95 ns 739.49 ns]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe

bit-vec 0.6 with creation
                        time:   [1.6515 us 1.6527 us 1.6539 us]
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high mild

bitvec 1.0 with creation
                        time:   [28.484 us 28.501 us 28.518 us]
Found 20 outliers among 100 measurements (20.00%)
  15 (15.00%) low severe
  3 (3.00%) high mild
  2 (2.00%) high severe

bitsvec(this crate) resize false
                        time:   [676.30 ns 677.13 ns 677.93 ns]
                                                                                                              bitsvec_u16x8(this crate) resize false
                        time:   [618.70 ns 619.73 ns 620.98 ns]
Found 2 outliers among 100 measurements (2.00%)
  1 (1.00%) high mild
  1 (1.00%) high severe

bitvec_simd 0.15.0 resize false
                        time:   [676.27 ns 677.96 ns 679.66 ns]
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) high mild
  1 (1.00%) high severe

bitvec_simd 0.15.0 u16x8 resize false
                        time:   [472.84 ns 473.76 ns 474.71 ns]
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high mild

bitvec 1.0 resize false time:   [108.23 us 108.29 us 108.36 us]
Found 9 outliers among 100 measurements (9.00%)
  6 (6.00%) high mild
  3 (3.00%) high severe

bitsvec(this crate) resize true
                        time:   [679.71 ns 680.66 ns 681.75 ns]
Found 9 outliers among 100 measurements (9.00%)
  7 (7.00%) high mild
  2 (2.00%) high severe

bitsvec_u16x8(this crate) resize true
                        time:   [876.21 ns 876.89 ns 877.71 ns]
Found 8 outliers among 100 measurements (8.00%)
  6 (6.00%) high mild
  2 (2.00%) high severe

bitvec_simd 0.15.0 resize true
                        time:   [672.44 ns 672.82 ns 673.24 ns]
Found 9 outliers among 100 measurements (9.00%)
  6 (6.00%) high mild
  3 (3.00%) high severe

bitvec_simd 0.15.0 u16x8 resize true
                        time:   [748.77 ns 751.48 ns 754.59 ns]

bitvec 1.0 resize true  time:   [100.50 us 100.63 us 100.75 us]

Credits

Most code of this crate is from (https://github.com/GCCFeli/bitvec_simd). On top of that, some changes were made.

License

This library is licensed under either of:

at your option.

You might also like...
sparse linear algebra library for rust

sprs, sparse matrices for Rust sprs implements some sparse matrix data structures and linear algebra algorithms in pure Rust. The API is a work in pro

DataFrame / Series data processing in Rust

black-jack While PRs are welcome, the approach taken only allows for concrete types (String, f64, i64, ...) I'm not sure this is the way to go. I want

A Modern Real-Time Data Processing & Analytics DBMS with Cloud-Native Architecture, written in Rust

Datafuse Modern Real-Time Data Processing & Analytics DBMS with Cloud-Native Architecture Datafuse is a Real-Time Data Processing & Analytics DBMS wit

(MERGED) Rust bindings for TVM runtime
(MERGED) Rust bindings for TVM runtime

DEPRECATED The RFC is closed and this has been merge into TVM. TVM Runtime Frontend Support This crate provides an idiomatic Rust API for TVM runtime

ConnectorX - Fastest library to load data from DB to DataFrames in Rust and Python
ConnectorX - Fastest library to load data from DB to DataFrames in Rust and Python

ConnectorX enables you to load data from databases into Python in the fastest and most memory efficient way.

Fill Apache Arrow record batches from an ODBC data source in Rust.

arrow-odbc Fill Apache Arrow arrays from ODBC data sources. This crate is build on top of the arrow and odbc-api crate and enables you to read the dat

A new arguably faster implementation of Apache Spark from scratch in Rust

vega Previously known as native_spark. Documentation A new, arguably faster, implementation of Apache Spark from scratch in Rust. WIP Framework tested

Work out how to read Parquet files in a browser using web assembly (via the Rust toolchain)

wasm-pack-template A template for kick starting a Rust and WebAssembly project using wasm-pack. Tutorial | Chat Built with 🦀 🕸 by The Rust and WebAs

bspipe A Rust implementation of Bidirectional Secure Pipe

bspipe A Rust implementation of Bidirectional Secure Pipe

Releases(v0.1.1)
Owner
Chojan Shang
During the day with @datafuselabs . A @DataSlime at night.
Chojan Shang
📊 Cube.js — Open-Source Analytics API for Building Data Apps

?? Cube.js — Open-Source Analytics API for Building Data Apps

Cube.js 14.4k Jan 8, 2023
Yet Another Technical Analysis library [for Rust]

YATA Yet Another Technical Analysis library YaTa implements most common technical analysis methods and indicators. It also provides you an interface t

Dmitry 197 Dec 29, 2022
Dataframe structure and operations in Rust

Utah Utah is a Rust crate backed by ndarray for type-conscious, tabular data manipulation with an expressive, functional interface. Note: This crate w

Suchin 139 Sep 26, 2022
Rust DataFrame library

Polars Blazingly fast DataFrames in Rust & Python Polars is a blazingly fast DataFrames library implemented in Rust. Its memory model uses Apache Arro

Ritchie Vink 11.9k Jan 8, 2023
A Rust DataFrame implementation, built on Apache Arrow

Rust DataFrame A dataframe implementation in Rust, powered by Apache Arrow. What is a dataframe? A dataframe is a 2-dimensional tabular data structure

Wakahisa 287 Nov 11, 2022
Rayon: A data parallelism library for Rust

Rayon Rayon is a data-parallelism library for Rust. It is extremely lightweight and makes it easy to convert a sequential computation into a parallel

null 7.8k Jan 8, 2023
A Rust crate that reads and writes tfrecord files

tfrecord-rust The crate provides the functionality to serialize and deserialize TFRecord data format from TensorFlow. Features Provide both high level

null 22 Nov 3, 2022
Official Rust implementation of Apache Arrow

Native Rust implementation of Apache Arrow Welcome to the implementation of Arrow, the popular in-memory columnar format, in Rust. This part of the Ar

The Apache Software Foundation 1.3k Jan 9, 2023
Fastest and safest Rust implementation of parquet. `unsafe` free. Integration-tested against pyarrow

Parquet2 This is a re-write of the official parquet crate with performance, parallelism and safety in mind. The five main differentiators in compariso

Jorge Leitao 237 Jan 1, 2023
Apache TinkerPop from Rust via Rucaja (JNI)

Apache TinkerPop from Rust An example showing how to call Apache TinkerPop from Rust via Rucaja (JNI). This repository contains two directories: java

null 8 Sep 27, 2022