@@ -162,7 +162,7 @@ impl<T: Idx> BitSet<T> {
162162 /// Set `self = self & other` and return true if `self` changed.
163163 /// (i.e., if any bits were removed).
164164 pub fn intersect ( & mut self , other : & BitSet < T > ) -> bool {
165- bitwise ( self . words_mut ( ) , other. words ( ) , & Intersect )
165+ bitwise ( self . words_mut ( ) , other. words ( ) , |a , b| { a & b } )
166166 }
167167
168168 /// Get a slice of the underlying words.
@@ -243,13 +243,13 @@ pub trait SubtractFromBitSet<T: Idx> {
243243
244244impl < T : Idx > UnionIntoBitSet < T > for BitSet < T > {
245245 fn union_into ( & self , other : & mut BitSet < T > ) -> bool {
246- bitwise ( other. words_mut ( ) , self . words ( ) , & Union )
246+ bitwise ( other. words_mut ( ) , self . words ( ) , |a , b| { a | b } )
247247 }
248248}
249249
250250impl < T : Idx > SubtractFromBitSet < T > for BitSet < T > {
251251 fn subtract_from ( & self , other : & mut BitSet < T > ) -> bool {
252- bitwise ( other. words_mut ( ) , self . words ( ) , & Subtract )
252+ bitwise ( other. words_mut ( ) , self . words ( ) , |a , b| { a & !b } )
253253 }
254254}
255255
@@ -302,43 +302,26 @@ impl<'a, T: Idx> Iterator for BitIter<'a, T> {
302302 }
303303}
304304
305- pub trait BitwiseOperator {
306- /// Applies some bit-operation pointwise to each of the bits in the two inputs .
307- fn join ( & self , pred1 : Word , pred2 : Word ) -> Word ;
305+ pub trait BitSetOperator {
306+ /// Combine one bitset into another .
307+ fn join < T : Idx > ( & self , inout_set : & mut BitSet < T > , in_set : & BitSet < T > ) -> bool ;
308308}
309309
310310#[ inline]
311- pub fn bitwise < Op : BitwiseOperator > ( out_vec : & mut [ Word ] , in_vec : & [ Word ] , op : & Op ) -> bool
311+ fn bitwise < Op > ( out_vec : & mut [ Word ] , in_vec : & [ Word ] , op : Op ) -> bool
312+ where Op : Fn ( Word , Word ) -> Word
312313{
313314 assert_eq ! ( out_vec. len( ) , in_vec. len( ) ) ;
314315 let mut changed = false ;
315316 for ( out_elem, in_elem) in out_vec. iter_mut ( ) . zip ( in_vec. iter ( ) ) {
316317 let old_val = * out_elem;
317- let new_val = op. join ( old_val, * in_elem) ;
318+ let new_val = op ( old_val, * in_elem) ;
318319 * out_elem = new_val;
319320 changed |= old_val != new_val;
320321 }
321322 changed
322323}
323324
324- pub struct Intersect ;
325- impl BitwiseOperator for Intersect {
326- #[ inline]
327- fn join ( & self , a : Word , b : Word ) -> Word { a & b }
328- }
329-
330- pub struct Union ;
331- impl BitwiseOperator for Union {
332- #[ inline]
333- fn join ( & self , a : Word , b : Word ) -> Word { a | b }
334- }
335-
336- pub struct Subtract ;
337- impl BitwiseOperator for Subtract {
338- #[ inline]
339- fn join ( & self , a : Word , b : Word ) -> Word { a & !b }
340- }
341-
342325const SPARSE_MAX : usize = 8 ;
343326
344327/// A fixed-size bitset type with a sparse representation and a maximum of
0 commit comments