bitvec
bitvec copied to clipboard
The best way to merge multiple bit vectors?
I am trying to merge multiple BitVecs, such that if a position has a 1 in one of the BitVecs, that position in the final set will store 1; if all the BitVecs have 0 in that position, the result will be 0. I am attempting to accomplish this task in the following way:
for each_class in mask {
for all in mask_all.as_raw_mut_slice() {
for current in each_class.mask.as_raw_slice() {
*all |= *current;
}
}
}
But it doesn't seem to be working properly, how should I change it? This is the current version that works:
for each_class in mask {
for (index, all) in each_class.mask.iter().enumerate() {
if *all {
mask_all.set(index, true);
}
}
}
I know this thread is old, but this should work (or am I missing something?):
for each_class in mask {
mask_all |= each_class;
}