#bitset #bit #flags #bitmask #bitflags #integer

bin+lib rust-dense-bitset

Efficient and compact bitsets for Rust

2 releases

0.1.1 Jan 16, 2019
0.1.0 Jan 14, 2019

#309 in Compression

Download history 23/week @ 2024-03-11 21/week @ 2024-03-18 31/week @ 2024-03-25 52/week @ 2024-04-01 9/week @ 2024-04-08 24/week @ 2024-04-15 24/week @ 2024-04-22 25/week @ 2024-04-29 23/week @ 2024-05-06 27/week @ 2024-05-13 22/week @ 2024-05-20 25/week @ 2024-05-27 18/week @ 2024-06-03 17/week @ 2024-06-10 15/week @ 2024-06-17 23/week @ 2024-06-24

74 downloads per month
Used in 5 crates (3 directly)

MIT license

66KB
1.5K SLoC

rust-dense-bitset

Latest version Documentation Build Status Long time support rustc version License

Efficient and flexible self-contained bitset rust library.

The library is safe rust only, fully documented, and uses the most efficient algorithms whenever possible.

Implementations

  • DenseBitSet is a compact 64-bit bitset supporting in particular
    • Individual bit setting (set_bit) and getting (get_bit)
    • Bitwise operations &, ^, |, !, <<, >> and rotations
    • Hamming weight, bit reversal, find first set
    • Conversion from and to integers and strings
    • Insertion and extraction of bitsets
  • DenseBitSetExtended implements the same functionality, extending the bitset as necessary to accomodate as many bits as needed. Memory can be preallocated and new allocation is only performed if necessary.

Usage

use rust_dense_bitset::{BitSet, DenseBitSetExtended};

let mut bs = DenseBitSetExtended::from_string(
    String::from("f001eddadf411eddec0de5ca1ab1ec0feefeeb1e01dc0b01"),
    16,
);

let bs2 = DenseBitSetExtended::from_string(
    String::from("0J2aG5BaMRS443FEBRGS5DTMV2A"),
    32
);

bs = bs.rotr(17) | (bs2 << 43);
bs.set_bit(123, true);

println!("{}", bs.subset(3, 64).to_string());

Known limits and caveats

  • The data structure does not make use of compression and is therefore not particularly suited to sparse bitsets: in this scenario alternatives such as the hibitset library can be considered instead.

  • clippy incorrectly reports issues with "suspicious operators" in the shift operators. (To avoid errors we deactivated suspicious_op_assign_impl lint)

Running the tests

Each individual function is tested. Run the tests with

cargo test

Running the benchmarks

The Criterion dependency is used to provide precise benchmarkings. Benchmarks can be run with

cargo bench

Documentation

Generate the documentation with

cargo doc

License

This project is licensed under the MIT License - see the LICENSE.md file for details

No runtime deps