fixedbitset
A simple, fast fixed-size bitset container for Rust with rich set operations
Repository Health
Technical Analysis
fixedbitset is a simple fixed-size bitset container for Rust. It stores a compact array of bits and exposes fast operations for setting, clearing, and testing individual bits, along with whole-set operations like union, intersection, difference, and symmetric difference.
Maintained under the petgraph organization (where it backs graph node/edge sets), it is heavily optimized: its stack size matches a plain Vec, it supports #![no_std], works on wasm32, and offers utility methods for range queries, counting, and finding minimum/maximum set bits. Optional serde support lets you serialize and deserialize bitsets directly.
What You Get
- A
FixedBitSetcontainer with O(1) set, clear, and contains operations - Whole-set algebra: union, intersection, difference, and symmetric difference
- Counting helpers such as
count_ones,union_count, andintersection_count - Range utilities like
insert_range,remove_range,contains_all_in_range,minimum, andmaximum - no_std and wasm32 support, plus optional serde serialization
Common Use Cases
- Tracking visited nodes or edges in graph algorithms
- Representing dense sets of small integer indices compactly
- Performing fast bitwise set operations between collections
- Bit-flag bookkeeping in performance-sensitive code
Under The Hood
Architecture - The crate is organized around src/lib.rs, which defines FixedBitSet as a length plus a heap block of machine words. The block/ module abstracts the underlying word representation (including SIMD-friendly block types), range.rs implements range insertion/removal and range predicates, and serde_impl.rs provides optional serialization. Set operations iterate word-by-word rather than bit-by-bit for speed.
Tech Stack - Pure Rust, dual-licensed Apache-2.0 OR MIT, with #![no_std] support. Dependencies are minimal, with serde gated behind a feature. The repository includes Criterion-style benchmarks under benches/ and an integration test suite under tests/.
Code Quality - fixedbitset is a mature, widely depended-on crate (hundreds of millions of downloads) with steady optimization work: recent releases shrank its stack footprint to match a Vec, fixed Send/Sync, and repaired wasm32 builds. It is well tested and benchmarked, with a clear changelog documenting each behavioral change.
API Design - The API reads like the standard-library set types, with insert, contains, remove, and iterator support, extended by bitset-specific methods for ranges and counts. Operations return counts or new sets predictably, and the fixed-capacity model keeps the mental model simple and allocations bounded.