@@ -281,6 +281,24 @@ impl<T: Idx> DenseBitSet<T> {
281
281
}
282
282
283
283
bit_relations_inherent_impls ! { }
284
+
285
+ /// Sets `self = self | !other`.
286
+ ///
287
+ /// FIXME: Incorporate this into [`BitRelations`] and fill out
288
+ /// implementations for other bitset types, if needed.
289
+ pub fn union_not ( & mut self , other : & DenseBitSet < T > ) {
290
+ assert_eq ! ( self . domain_size, other. domain_size) ;
291
+
292
+ // FIXME(Zalathar): If we were to forcibly _set_ all excess bits before
293
+ // the bitwise update, and then clear them again afterwards, we could
294
+ // quickly and accurately detect whether the update changed anything.
295
+ // But that's only worth doing if there's an actual use-case.
296
+
297
+ bitwise ( & mut self . words , & other. words , |a, b| a | !b) ;
298
+ // The bitwise update `a | !b` can result in the last word containing
299
+ // out-of-domain bits, so we need to clear them.
300
+ self . clear_excess_bits ( ) ;
301
+ }
284
302
}
285
303
286
304
// dense REL dense
@@ -1087,6 +1105,18 @@ impl<T: Idx> fmt::Debug for ChunkedBitSet<T> {
1087
1105
}
1088
1106
}
1089
1107
1108
+ /// Sets `out_vec[i] = op(out_vec[i], in_vec[i])` for each index `i` in both
1109
+ /// slices. The slices must have the same length.
1110
+ ///
1111
+ /// Returns true if at least one bit in `out_vec` was changed.
1112
+ ///
1113
+ /// ## Warning
1114
+ /// Some bitwise operations (e.g. union-not, xor) can set output bits that were
1115
+ /// unset in in both inputs. If this happens in the last word/chunk of a bitset,
1116
+ /// it can cause the bitset to contain out-of-domain values, which need to
1117
+ /// be cleared with `clear_excess_bits_in_final_word`. This also makes the
1118
+ /// "changed" return value unreliable, because the change might have only
1119
+ /// affected excess bits.
1090
1120
#[ inline]
1091
1121
fn bitwise < Op > ( out_vec : & mut [ Word ] , in_vec : & [ Word ] , op : Op ) -> bool
1092
1122
where
0 commit comments