good_os_framework/data/
bitmap.rs

1use bit_field::BitField;
2
3/// A simple Bitmap implementation.
4pub struct Bitmap {
5    inner: &'static mut [u8],
6}
7
8impl Bitmap {
9    pub fn new(inner: &'static mut [u8]) -> Self {
10        inner.fill(0);
11        Self { inner }
12    }
13
14    pub fn len(&self) -> usize {
15        self.inner.len()
16    }
17
18    pub fn get(&self, index: usize) -> bool {
19        let byte = self.inner[index / 8];
20        byte.get_bit(index % 8)
21    }
22
23    pub fn set(&mut self, index: usize, value: bool) {
24        let byte = &mut self.inner[index / 8];
25        byte.set_bit(index % 8, value);
26    }
27}