fastbit 0.11.1

A fast, efficient, and pure Rust bitset implementation for high-performance data indexing and analytics.
Documentation
//! # fastbit
//!
//! `fastbit` is a fast, efficient, and pure Rust bitset library for high-performance data indexing and analytics.
//!
//! This crate provides a collection of bitset and bitmap data structures, including growable bit vectors, fixed-size bitsets, bit grids, and efficient bit operations.
//!
//! ## Features
//! - Growable and fixed-size bitsets
//! - Efficient bitwise operations
//! - Bit slices and views for zero-copy access
//! - Iterators and utilities for bit manipulation
//!
//! ## Examples
//! ```rust
//! use fastbit::{BitVec, BitRead, BitWrite};
//!
//! let mut bv: BitVec<u8> = BitVec::new(128);
//! bv.set(5);
//! assert!(bv.test(5));
//! bv.reset(5);
//! assert!(!bv.test(5));
//! ```
//!
//! ## Modules
//! - [`BitVec`]: Growable bit vector
//! - [`BitFixed`]: Fixed-size bitset
//! - [`BitGrid`]: 2D bit grid
//! - [`BitSpan`], [`BitSpanMut`]: Bit slices
//! - [`BitView`], [`BitViewMut`]: Bit views
//! - [`Iter`]: Bit iterator
//!
//! ## Crate-level re-exports
//! The most important types are re-exported at the crate root.

mod bitfixed;
mod bitgrid;
mod bitlist;
mod bitmap;
mod bitop;
mod bitspan;
mod bitvec;
mod bitview;
mod iter;
mod macros;
mod traits;
mod util;

pub use bitfixed::BitFixed;
pub use bitgrid::BitGrid;
pub use bitlist::BitList;
pub use bitop::{BitSetDifference, BitSetIntersection, BitSetSymmetricDifference, BitSetUnion};
pub use bitspan::{BitSpan, BitSpanMut};
pub use bitvec::BitVec;
pub use bitview::{BitView, BitViewMut};
pub use iter::Iter;
pub use traits::{BitRead, BitResize, BitStack, BitWrite};

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_bitset() {}

    #[test]
    fn test_bitvec_basic() {
        let mut bv: BitVec<u8> = BitVec::new(16);
        assert_eq!(bv.len(), 16);
        assert!(!bv.test(3));
        bv.set(3);
        assert!(bv.test(3));
        bv.reset(3);
        assert!(!bv.test(3));
    }

    #[test]
    fn test_bitvec_grow() {
        let mut bv: BitVec<u32> = BitVec::new(11);
        bv.set(10);
        assert!(bv.test(10));
        assert_eq!(bv.len(), 11);
    }

    #[test]
    fn test_bitvec_iter() {
        let mut bv: BitVec<u8> = BitVec::new(10);
        bv.set(2);
        bv.set(5);
        bv.set(7);
        let bits: Vec<usize> = bv.iter().collect();
        assert_eq!(bits, vec![2, 5, 7]);
    }

    #[test]
    fn test_bitfixed_basic() {
        let mut bf: BitFixed<u16> = BitFixed::new(32);
        assert_eq!(bf.len(), 32);
        bf.set(15);
        assert!(bf.test(15));
        bf.reset(15);
        assert!(!bf.test(15));
    }

    #[test]
    fn test_bitfixed_all() {
        let mut bf: BitFixed<u8> = BitFixed::new(8);
        for i in 0..8 {
            bf.set(i);
        }
        for i in 0..8 {
            assert!(bf.test(i));
        }
        bf.reset(3);
        assert!(!bf.test(3));
    }
}