mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 07:06:47 +00:00
feat(bitmap): Add bit and for AllocBitMap (#793)
This commit is contained in:
parent
7401bec5e3
commit
7db6e06354
@ -1,3 +1,5 @@
|
|||||||
|
use core::ops::BitAnd;
|
||||||
|
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
use crate::{bitmap_core::BitMapCore, traits::BitMapOps};
|
use crate::{bitmap_core::BitMapCore, traits::BitMapOps};
|
||||||
@ -108,3 +110,15 @@ impl BitMapOps<usize> for AllocBitmap {
|
|||||||
self.core.set_all(self.elements, &mut self.data, value);
|
self.core.set_all(self.elements, &mut self.data, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl BitAnd for AllocBitmap {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn bitand(self, rhs: Self) -> Self::Output {
|
||||||
|
let mut result = AllocBitmap::new(self.elements);
|
||||||
|
for i in 0..rhs.data.len() {
|
||||||
|
result.data[i] = self.data[i] & rhs.data[i];
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -643,3 +643,23 @@ fn test_alloc_bitmap_full_128() {
|
|||||||
assert_eq!(bitmap.is_full(), false);
|
assert_eq!(bitmap.is_full(), false);
|
||||||
assert_eq!(bitmap.is_empty(), true);
|
assert_eq!(bitmap.is_empty(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_alloc_bitmap_bitand_128() {
|
||||||
|
let mut bitmap = AllocBitmap::new(128);
|
||||||
|
bitmap.set_all(true);
|
||||||
|
|
||||||
|
let mut bitmap2 = AllocBitmap::new(128);
|
||||||
|
|
||||||
|
bitmap2.set(0, true);
|
||||||
|
bitmap2.set(1, true);
|
||||||
|
bitmap2.set(67, true);
|
||||||
|
|
||||||
|
let bitmap3 = bitmap & bitmap2;
|
||||||
|
|
||||||
|
assert_eq!(bitmap3.len(), 128);
|
||||||
|
assert_eq!(bitmap3.size(), 16);
|
||||||
|
assert_eq!(bitmap3.first_index(), Some(0));
|
||||||
|
assert_eq!(bitmap3.first_false_index(), Some(2));
|
||||||
|
assert_eq!(bitmap3.last_index(), Some(67));
|
||||||
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use core::ops::BitAnd;
|
||||||
|
|
||||||
use bitmap::{traits::BitMapOps, AllocBitmap};
|
use bitmap::{traits::BitMapOps, AllocBitmap};
|
||||||
|
|
||||||
use crate::{mm::percpu::PerCpu, smp::cpu::ProcessorId};
|
use crate::{mm::percpu::PerCpu, smp::cpu::ProcessorId};
|
||||||
@ -86,6 +88,15 @@ impl CpuMask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl BitAnd for CpuMask {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn bitand(self, rhs: Self) -> Self::Output {
|
||||||
|
let bmp = self.bmp & rhs.bmp;
|
||||||
|
Self { bmp }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct CpuMaskIter<'a> {
|
pub struct CpuMaskIter<'a> {
|
||||||
mask: &'a CpuMask,
|
mask: &'a CpuMask,
|
||||||
index: Option<ProcessorId>,
|
index: Option<ProcessorId>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user