#bitmap #bitvec #vec #heap-allocation

smallbitvec

A bit vector optimized for size and inline storage

20 stable releases

new 2.6.0 Feb 15, 2025
2.5.3 Mar 17, 2024
2.5.1 Aug 5, 2021
2.5.0 May 8, 2020
1.0.7 Sep 27, 2017

#41 in Data structures

Download history 17977/week @ 2024-10-30 18345/week @ 2024-11-06 18020/week @ 2024-11-13 17769/week @ 2024-11-20 12597/week @ 2024-11-27 17053/week @ 2024-12-04 15399/week @ 2024-12-11 12393/week @ 2024-12-18 6615/week @ 2024-12-25 13040/week @ 2025-01-01 20457/week @ 2025-01-08 18911/week @ 2025-01-15 17493/week @ 2025-01-22 14286/week @ 2025-01-29 21640/week @ 2025-02-05 15904/week @ 2025-02-12

72,172 downloads per month
Used in 17 crates (12 directly)

MIT/Apache

43KB
1K SLoC

smallbitvec

A bit vector that is the size of a pointer, and can store data either inline or on the heap. Like the bit-vec crate but optimized for small inline size and reduced allocations.


lib.rs:

SmallBitVec is a bit vector, a vector of single-bit values stored compactly in memory.

SmallBitVec grows dynamically, like the standard Vec<T> type. It can hold up to about one word of bits inline (without a separate heap allocation). If the number of bits exceeds this inline capacity, it will allocate a buffer on the heap.

Example

use smallbitvec::SmallBitVec;

let mut v = SmallBitVec::new();
v.push(true);
v.push(false);

assert_eq!(v[0], true);
assert_eq!(v[1], false);

Dependencies