Lines Matching defs:Bitmap

22 pub struct Bitmap {
26 impl Bitmap {
33 /// * the array must not be freed for the lifetime of this [`Bitmap`]
35 pub unsafe fn from_raw<'a>(ptr: *const usize, nbits: usize) -> &'a Bitmap {
42 // We are casting `*const [()]` to `*const Bitmap`. The `Bitmap`
48 // pointer as `&Bitmap` is safe given the caller's guarantees.
49 unsafe { &*(data as *const Bitmap) }
58 /// * the array must not be freed for the lifetime of this [`Bitmap`]
60 pub unsafe fn from_raw_mut<'a>(ptr: *mut usize, nbits: usize) -> &'a mut Bitmap {
69 // Similar to `from_raw`, casting `*mut [()]` to `*mut Bitmap` is
70 // safe because `Bitmap` is a ZST with a `data: [()]` field,
72 unsafe { &mut *(data as *mut Bitmap) }
75 /// Returns a raw pointer to the backing [`Bitmap`].
77 core::ptr::from_ref::<Bitmap>(self).cast::<usize>()
80 /// Returns a mutable raw pointer to the backing [`Bitmap`].
82 core::ptr::from_mut::<Bitmap>(self).cast::<usize>()
85 /// Returns length of this [`Bitmap`].
121 /// Wraps underlying C bitmap API. See [`Bitmap`] for available
162 type Target = Bitmap;
164 fn deref(&self) -> &Bitmap {
166 // SAFETY: Bitmap is represented inline.
172 // SAFETY: Bitmap is represented as array of `unsigned long`.
176 // SAFETY: We got the right pointer and invariants of [`Bitmap`] hold.
178 unsafe { Bitmap::from_raw(ptr, self.nbits) }
183 fn deref_mut(&mut self) -> &mut Bitmap {
185 // SAFETY: Bitmap is represented inline.
191 // SAFETY: Bitmap is represented as array of `unsigned long`.
197 unsafe { Bitmap::from_raw_mut(ptr, self.nbits) }
208 /// SAFETY: `deref()` will return a reference to a [`Bitmap`]. Its methods
269 /// Returns length of this [`Bitmap`].
276 /// Fills this `Bitmap` with random bits.
292 impl Bitmap {
395 /// Copy `src` into this [`Bitmap`] and set any remaining bits to zero.
416 pub fn copy_and_extend(&mut self, src: &Bitmap) {
513 let b = unsafe { Bitmap::from_raw(fake_bitmap.as_ptr(), fake_bitmap_len) };
522 let b = unsafe { Bitmap::from_raw(core::ptr::addr_of!(fake_bitmap), 8) };