File tree 3 files changed +45
-0
lines changed
3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ use core:: ops:: BitAnd ;
2
+
1
3
use alloc:: vec:: Vec ;
2
4
3
5
use crate :: { bitmap_core:: BitMapCore , traits:: BitMapOps } ;
@@ -108,3 +110,15 @@ impl BitMapOps<usize> for AllocBitmap {
108
110
self . core . set_all ( self . elements , & mut self . data , value) ;
109
111
}
110
112
}
113
+
114
+ impl BitAnd for AllocBitmap {
115
+ type Output = Self ;
116
+
117
+ fn bitand ( self , rhs : Self ) -> Self :: Output {
118
+ let mut result = AllocBitmap :: new ( self . elements ) ;
119
+ for i in 0 ..rhs. data . len ( ) {
120
+ result. data [ i] = self . data [ i] & rhs. data [ i] ;
121
+ }
122
+ result
123
+ }
124
+ }
Original file line number Diff line number Diff line change @@ -643,3 +643,23 @@ fn test_alloc_bitmap_full_128() {
643
643
assert_eq ! ( bitmap. is_full( ) , false ) ;
644
644
assert_eq ! ( bitmap. is_empty( ) , true ) ;
645
645
}
646
+
647
+ #[ test]
648
+ fn test_alloc_bitmap_bitand_128 ( ) {
649
+ let mut bitmap = AllocBitmap :: new ( 128 ) ;
650
+ bitmap. set_all ( true ) ;
651
+
652
+ let mut bitmap2 = AllocBitmap :: new ( 128 ) ;
653
+
654
+ bitmap2. set ( 0 , true ) ;
655
+ bitmap2. set ( 1 , true ) ;
656
+ bitmap2. set ( 67 , true ) ;
657
+
658
+ let bitmap3 = bitmap & bitmap2;
659
+
660
+ assert_eq ! ( bitmap3. len( ) , 128 ) ;
661
+ assert_eq ! ( bitmap3. size( ) , 16 ) ;
662
+ assert_eq ! ( bitmap3. first_index( ) , Some ( 0 ) ) ;
663
+ assert_eq ! ( bitmap3. first_false_index( ) , Some ( 2 ) ) ;
664
+ assert_eq ! ( bitmap3. last_index( ) , Some ( 67 ) ) ;
665
+ }
Original file line number Diff line number Diff line change
1
+ use core:: ops:: BitAnd ;
2
+
1
3
use bitmap:: { traits:: BitMapOps , AllocBitmap } ;
2
4
3
5
use crate :: { mm:: percpu:: PerCpu , smp:: cpu:: ProcessorId } ;
@@ -86,6 +88,15 @@ impl CpuMask {
86
88
}
87
89
}
88
90
91
+ impl BitAnd for CpuMask {
92
+ type Output = Self ;
93
+
94
+ fn bitand ( self , rhs : Self ) -> Self :: Output {
95
+ let bmp = self . bmp & rhs. bmp ;
96
+ Self { bmp }
97
+ }
98
+ }
99
+
89
100
pub struct CpuMaskIter < ' a > {
90
101
mask : & ' a CpuMask ,
91
102
index : Option < ProcessorId > ,
You can’t perform that action at this time.
0 commit comments