@@ -160,7 +160,7 @@ impl<T: Idx> BitSet<T> {
160
160
/// Set `self = self & other` and return true if `self` changed.
161
161
/// (i.e., if any bits were removed).
162
162
pub fn intersect ( & mut self , other : & BitSet < T > ) -> bool {
163
- bitwise ( self . words_mut ( ) , other. words ( ) , & Intersect )
163
+ bitwise ( self . words_mut ( ) , other. words ( ) , |a , b| { a & b } )
164
164
}
165
165
166
166
/// Get a slice of the underlying words.
@@ -241,13 +241,13 @@ pub trait SubtractFromBitSet<T: Idx> {
241
241
242
242
impl < T : Idx > UnionIntoBitSet < T > for BitSet < T > {
243
243
fn union_into ( & self , other : & mut BitSet < T > ) -> bool {
244
- bitwise ( other. words_mut ( ) , self . words ( ) , & Union )
244
+ bitwise ( other. words_mut ( ) , self . words ( ) , |a , b| { a | b } )
245
245
}
246
246
}
247
247
248
248
impl < T : Idx > SubtractFromBitSet < T > for BitSet < T > {
249
249
fn subtract_from ( & self , other : & mut BitSet < T > ) -> bool {
250
- bitwise ( other. words_mut ( ) , self . words ( ) , & Subtract )
250
+ bitwise ( other. words_mut ( ) , self . words ( ) , |a , b| { a & !b } )
251
251
}
252
252
}
253
253
@@ -300,43 +300,26 @@ impl<'a, T: Idx> Iterator for BitIter<'a, T> {
300
300
}
301
301
}
302
302
303
- pub trait BitwiseOperator {
304
- /// Applies some bit-operation pointwise to each of the bits in the two inputs .
305
- fn join ( & self , pred1 : Word , pred2 : Word ) -> Word ;
303
+ pub trait BitSetOperator {
304
+ /// Combine one bitset into another .
305
+ fn join < T : Idx > ( & self , inout_set : & mut BitSet < T > , in_set : & BitSet < T > ) -> bool ;
306
306
}
307
307
308
308
#[ inline]
309
- pub fn bitwise < Op : BitwiseOperator > ( out_vec : & mut [ Word ] , in_vec : & [ Word ] , op : & Op ) -> bool
309
+ fn bitwise < Op > ( out_vec : & mut [ Word ] , in_vec : & [ Word ] , op : Op ) -> bool
310
+ where Op : Fn ( Word , Word ) -> Word
310
311
{
311
312
assert_eq ! ( out_vec. len( ) , in_vec. len( ) ) ;
312
313
let mut changed = false ;
313
314
for ( out_elem, in_elem) in out_vec. iter_mut ( ) . zip ( in_vec. iter ( ) ) {
314
315
let old_val = * out_elem;
315
- let new_val = op. join ( old_val, * in_elem) ;
316
+ let new_val = op ( old_val, * in_elem) ;
316
317
* out_elem = new_val;
317
318
changed |= old_val != new_val;
318
319
}
319
320
changed
320
321
}
321
322
322
- pub struct Intersect ;
323
- impl BitwiseOperator for Intersect {
324
- #[ inline]
325
- fn join ( & self , a : Word , b : Word ) -> Word { a & b }
326
- }
327
-
328
- pub struct Union ;
329
- impl BitwiseOperator for Union {
330
- #[ inline]
331
- fn join ( & self , a : Word , b : Word ) -> Word { a | b }
332
- }
333
-
334
- pub struct Subtract ;
335
- impl BitwiseOperator for Subtract {
336
- #[ inline]
337
- fn join ( & self , a : Word , b : Word ) -> Word { a & !b }
338
- }
339
-
340
323
const SPARSE_MAX : usize = 8 ;
341
324
342
325
/// A fixed-size bitset type with a sparse representation and a maximum of
0 commit comments