Simplified a notch TinySet::pop_lowest()

This commit is contained in:
Paul Masurel
2018-02-22 10:43:06 +09:00
parent 4ee2db25a0
commit c3fbc4c8fa
2 changed files with 6 additions and 16 deletions

View File

@@ -84,23 +84,12 @@ impl TinySet {
/// and removes it.
#[inline(always)]
pub fn pop_lowest(&mut self) -> Option<u32> {
if let Some(lowest) = self.lowest() {
self.0 ^= TinySet::singleton(lowest).0;
Some(lowest)
} else {
None
}
}
/// Returns the lowest element in the `TinySet`
/// (or None if the set is empty).
#[inline(always)]
pub fn lowest(&mut self) -> Option<u32> {
if self.is_empty() {
None
} else {
let least_significant_bit = self.0.trailing_zeros() as u32;
Some(least_significant_bit)
let lowest = self.0.trailing_zeros() as u32;
self.0 ^= TinySet::singleton(lowest).0;
Some(lowest)
}
}
@@ -366,7 +355,7 @@ mod tests {
#[bench]
fn bench_tinyset_pop(b: &mut test::Bencher) {
b.iter(|| test::black_box(TinySet::singleton(31u32)).pop_lowest());
b.iter(|| test::black_box(TinySet(321u64)).pop_lowest());
}
#[bench]
@@ -387,4 +376,5 @@ mod tests {
fn bench_bitset_initialize(b: &mut test::Bencher) {
b.iter(|| BitSet::with_max_value(1_000_000));
}
}

View File

@@ -244,7 +244,7 @@ mod tests {
#[bench]
fn bench_bitset_1pct_clone_iterate(b: &mut test::Bencher) {
let els = tests::generate_nonunique_unsorted(1_000_000u32, 10_000);
let els = tests::sample(1_000_000u32, 0.01);
let mut bitset = BitSet::with_max_value(1_000_000);
for el in els {
bitset.insert(el);