mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Add comments
This commit is contained in:
parent
d73a169f93
commit
ce37f0a355
@ -247,6 +247,8 @@ impl<T: Idx> BitRelations<BitSet<T>> for BitSet<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Applies a function to mutate a bitset, and returns true if any
|
||||||
|
// of the applications return true
|
||||||
fn sequential_update<T: Idx>(
|
fn sequential_update<T: Idx>(
|
||||||
mut self_update: impl FnMut(T) -> bool,
|
mut self_update: impl FnMut(T) -> bool,
|
||||||
it: impl Iterator<Item = T>,
|
it: impl Iterator<Item = T>,
|
||||||
@ -258,6 +260,8 @@ fn sequential_update<T: Idx>(
|
|||||||
changed
|
changed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optimization of intersection for SparseBitSet that's generic
|
||||||
|
// over the RHS
|
||||||
fn sparse_intersect<T: Idx>(
|
fn sparse_intersect<T: Idx>(
|
||||||
set: &mut SparseBitSet<T>,
|
set: &mut SparseBitSet<T>,
|
||||||
other_contains: impl Fn(&T) -> bool,
|
other_contains: impl Fn(&T) -> bool,
|
||||||
@ -267,6 +271,10 @@ fn sparse_intersect<T: Idx>(
|
|||||||
set.elems.len() != size
|
set.elems.len() != size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optimization of dense/sparse intersection. The resulting set is
|
||||||
|
// guaranteed to be at most the size of the sparse set, and hence can be
|
||||||
|
// represented as a sparse set. Therefore the sparse set is copied and filtered,
|
||||||
|
// then returned as the new set.
|
||||||
fn dense_sparse_intersect<T: Idx>(
|
fn dense_sparse_intersect<T: Idx>(
|
||||||
dense: &BitSet<T>,
|
dense: &BitSet<T>,
|
||||||
sparse: &SparseBitSet<T>,
|
sparse: &SparseBitSet<T>,
|
||||||
@ -303,6 +311,10 @@ impl<T: Idx> BitRelations<HybridBitSet<T>> for BitSet<T> {
|
|||||||
match other {
|
match other {
|
||||||
HybridBitSet::Sparse(sparse) => {
|
HybridBitSet::Sparse(sparse) => {
|
||||||
let (updated, changed) = dense_sparse_intersect(self, sparse);
|
let (updated, changed) = dense_sparse_intersect(self, sparse);
|
||||||
|
|
||||||
|
// We can't directly assign the BitSet to the SparseBitSet, and
|
||||||
|
// doing `*self = updated.to_dense()` would cause a drop / reallocation. Instead,
|
||||||
|
// the BitSet is cleared and `updated` is copied into `self`.
|
||||||
self.clear();
|
self.clear();
|
||||||
for elem in updated.iter() {
|
for elem in updated.iter() {
|
||||||
self.insert(*elem);
|
self.insert(*elem);
|
||||||
|
Loading…
Reference in New Issue
Block a user