Index: Cargo.toml ================================================================== --- Cargo.toml +++ Cargo.toml @@ -1,8 +1,8 @@ [package] name = "bmap" -version = "0.2.1" +version = "0.2.2" edition = "2021" license = "0BSD" # https://crates.io/category_slugs categories = [ "data-structures" ] keywords = [ "bitmap", "bitvec" ] Index: src/lib.rs ================================================================== --- src/lib.rs +++ src/lib.rs @@ -180,10 +180,33 @@ *v |= bitval; self.remain -= 1; } Ok(()) } + + /// Set a bit, where it is assumed that the caller has validated that the + /// `idx` parameter is valid. + /// + /// ``` + /// use bmap::CountedBitmap; + /// + /// let mut bmap = CountedBitmap::new(4); + /// unsafe { bmap.set_unchecked(2) }; + /// assert_eq!(bmap.is_set(2).unwrap(), true); + /// ``` + /// + /// # Safety + /// The caller must ensure that `idx` is within bounds. + #[inline] + pub unsafe fn set_unchecked(&mut self, idx: usize) { + let (iword, bitval) = self.get_bidx_unchecked(idx); + let v = self.bits.get_unchecked_mut(iword); + if *v & bitval == 0 { + *v |= bitval; + self.remain -= 1; + } + } /// Clear a bit. /// /// ``` /// use bmap::CountedBitmap; Index: www/changelog.md ================================================================== --- www/changelog.md +++ www/changelog.md @@ -2,18 +2,28 @@ ⚠️ indicates a breaking change. ## [Unreleased] -[Details](/vdiff?from=bmap-0.2.1&to=trunk) +[Details](/vdiff?from=bmap-0.2.2&to=trunk) ### Added ### Changed ### Removed +--- + +## [0.2.2] - 2024-03-21 + +[Details](/vdiff?from=bmap-0.2.1&to=bmap-0.2.2) + +### Added + +- Added `unsafe` `CountedBitmap::set_unchecked()`. + --- ## [0.2.1] - 2024-03-21 [Details](/vdiff?from=bmap-0.2.0&to=bmap-0.2.1)