Skip to content

Commit 3f28811

Browse files
committed
Add documentation on the reasoning
Explains the thought process behind adding the union algorithm and discusses the alternative and heuristic behind.
1 parent 8877f4c commit 3f28811

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/librustc_data_structures/bit_set.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,20 @@ impl<T: Idx> HybridBitSet<T> {
557557
changed
558558
}
559559
HybridBitSet::Dense(other_dense) => {
560-
// `self` is sparse and `other` is dense. Clone the
561-
// other set and do the bitwise union with sparse
562-
// `self`. This avoids traversing the dense
563-
// representation twice.
560+
// `self` is sparse and `other` is dense. To
561+
// merge them, we have two available strategies:
562+
// * Densify `self` then merge other
563+
// * Clone other then integrate bits from `self`
564+
// The second strategy requires dedicated method
565+
// since the usual `union` returns the wrong
566+
// result. In the dedicated case the computation
567+
// is slightly faster if the bits of the sparse
568+
// bitset map to only few words of the dense
569+
// representation, i.e. indices are near each
570+
// other.
571+
//
572+
// Benchmarking seems to suggest that the second
573+
// option is worth it.
564574
let mut new_dense = other_dense.clone();
565575
let changed = new_dense.reverse_union_sparse(self_sparse);
566576
*self = HybridBitSet::Dense(new_dense);

0 commit comments

Comments
 (0)