fastbit 0.11.1

A fast, efficient, and pure Rust bitset implementation for high-performance data indexing and analytics.
Documentation
/// Macro to implement common trait impls for BitSet types.
macro_rules! impl_bitset_traits {
    ($bitset:ident) => {
        // impl std::fmt::Debug for $bitset {
        //     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        //         f.debug_struct(stringify!($bitset))
        //             .field("bits", &self.bits)
        //             .finish()
        //     }
        // }

        // impl Clone for $bitset {
        //     fn clone(&self) -> Self {
        //         Self {
        //             bits: self.bits.clone(),
        //         }
        //     }
        // }

        // impl PartialEq for $bitset {
        //     fn eq(&self, other: &Self) -> bool {
        //         self.bits == other.bits
        //     }
        // }
        impl<W: BitWord> BitRead for $bitset<W> {
            type Iter<'b>
                = Iter<'b, W>
            where
                Self: 'b;

            #[inline(always)]
            fn len(&self) -> usize {
                self.len
            }

            #[inline]
            fn is_empty(&self) -> bool {
                unsafe { bitset_is_empty(self.ptr, self.len) }
            }

            #[inline]
            fn test(&self, idx: usize) -> bool {
                unsafe { bitset_test(self.ptr, self.len, idx) }
            }

            #[inline]
            fn count_ones(&self) -> usize {
                unsafe { bitset_count_ones(self.ptr, self.len) }
            }

            #[inline]
            fn all(&self) -> bool {
                unsafe { bitset_all(self.ptr, self.len) }
            }

            #[inline]
            fn any(&self) -> bool {
                unsafe { bitset_any(self.ptr, self.len) }
            }

            #[inline]
            fn iter(&self) -> Self::Iter<'_> {
                Iter::new(self.ptr, self.len)
            }
        }
    };
}

pub(crate) use impl_bitset_traits;

macro_rules! impl_bitsetmut_traits {
    ($bitset:ident) => {
        // impl std::fmt::Debug for $bitset {
        //     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        //         f.debug_struct(stringify!($bitset))
        //             .field("bits", &self.bits)
        //             .finish()
        //     }
        // }

        // impl Clone for $bitset {
        //     fn clone(&self) -> Self {
        //         Self {
        //             bits: self.bits.clone(),
        //         }
        //     }
        // }

        // impl PartialEq for $bitset {
        //     fn eq(&self, other: &Self) -> bool {
        //         self.bits == other.bits
        //     }
        // }
        impl<W: BitWord> BitWrite for $bitset<W> {
            #[inline]
            fn set(&mut self, idx: usize) {
                unsafe { bitset_set(self.ptr, self.len, idx) };
            }

            #[inline]
            fn reset(&mut self, idx: usize) {
                unsafe { bitset_reset(self.ptr, self.len, idx) };
            }

            #[inline]
            fn flip(&mut self, idx: usize) {
                unsafe { bitset_flip(self.ptr, self.len, idx) };
            }

            #[inline]
            fn test_and_set(&mut self, idx: usize) -> bool {
                unsafe { bitset_test_and_set(self.ptr, self.len, idx) }
            }

            #[inline]
            fn fill(&mut self) {
                unsafe { bitset_fill(self.ptr, self.len) };
            }

            #[inline]
            fn clear(&mut self) {
                unsafe { bitset_clear(self.ptr, self.len) };
            }
        }
    };
}

pub(crate) use impl_bitsetmut_traits;