#bitset #bitarray #bitmap #bitmask #bitslice

no-std bitset-core

Straightforward, no-std compatible, simd optimized, BitSet API

2 releases

0.1.1 Sep 19, 2020
0.1.0 Jul 9, 2020

#742 in Data structures

Download history 520/week @ 2023-08-14 545/week @ 2023-08-21 471/week @ 2023-08-28 415/week @ 2023-09-04 418/week @ 2023-09-11 421/week @ 2023-09-18 448/week @ 2023-09-25 436/week @ 2023-10-02 513/week @ 2023-10-09 489/week @ 2023-10-16 454/week @ 2023-10-23 479/week @ 2023-10-30 559/week @ 2023-11-06 535/week @ 2023-11-13 524/week @ 2023-11-20 355/week @ 2023-11-27

2,021 downloads per month
Used in 9 crates (2 directly)

MIT license

796 lines


MIT License crates.io docs.rs

Straightforward, no-std compatible, simd optimized, BitSet API.


This crate provides its functionality through the BitSet trait.

use bitset_core::BitSet;

The containers for the bitset provided by this crate are unsigned integers, slices of unsigned integers and simd-like types, and Vec<_>, Box<[_]> if the std feature is enabled (enabled by default).

use bitset_core::BitSet;

let mut bits = [0u32; 4];
assert_eq!(bits.bit_len(), 4 * 32);

bits.bit_init(true); // Set all bits to true
assert!(bits.bit_all()); // All bits are set

bits.bit_reset(13); // Reset the 13th bit
assert!(bits.bit_any()); // At least some bits are set

bits.bit_flip(42); // Flip the 42nd bit twice (no change)

bits.bit_cond(1, false); // Set the bit to runtime value

assert_eq!(bits.bit_test(42), true);
assert_eq!(bits.bit_test(13), false);
assert_eq!(bits.bit_test(1), false);

assert_eq!(bits.bit_count(), 4 * 32 - 2);

Simd optimization is provided by using underlying primitives such as [u32; 4] which match the hardware's 128-bit simd registers. The compiler is heavily encouraged to vectorize these primitives.

use bitset_core::BitSet;

let mut a = [[0x21212121u32; 4]; 16];
let b = [[0x55555555u32; 4]; 16];


assert_eq!(a, [[0xffffffffu32; 4]; 16]);

For non fixed-size containers using the std feature BitSet is also implemented for Vec<T> and Box<[T]> (where [T]: BitSet).

Future work includes making everything const fn to enable all of this at compiletime, blocked on support for traits in const fn.


Licensed under MIT License, see license.txt.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions.

No runtime deps