contain-rs / bit-set

A Set of Bits
Apache License 2.0
63 stars 25 forks source link

Optimize Extend / insert many #48

Open pczarn opened 2 months ago

pczarn commented 2 months ago

We really should specialize for extend with iterators that can be cloned. Possibly as an additional fn.

Let's check the speed of Extend w.r.t. growing.

Best to get a maximum of all elements, then grow once if needed.

impl<B: BitBlock> Extend<usize> for BitSet<B> {
    #[inline]
    fn extend<I: IntoIterator<Item = usize>>(&mut self, iter: I) {
        for i in iter {
            self.insert(i);
        }
    }
}