New function to extend from another bitset.

This commit is contained in:
2018-01-04 10:31:18 +01:00
parent 74f5cfcbb4
commit cffad465c5

View File

@@ -34,7 +34,7 @@ impl Hasher for BitHasher {
type BitBuildHasher = BuildHasherDefault<BitHasher>;
type BitHashMap<K, V> = HashMap<K, V, BitBuildHasher>;
type BitHashSet<T> = HashSet<T, BitBuildHasher>;
// type BitHashSet<T> = HashSet<T, BitBuildHasher>;
type Block = u64;
type Storage = BitHashMap<u64, Block>;
@@ -128,6 +128,18 @@ impl BitSet {
Some(block) => (block & (1 << bit)) != 0,
}
}
#[inline]
pub fn extend_from_bitset(&mut self, other: &Self) {
for (key, value) in &other.blocks {
*self.blocks.entry(*key).or_insert(0) |= value;
}
self.nbits = self.blocks
.values()
.map(|block| block.count_ones() as usize)
.sum();
}
}
impl Default for BitSet {