Skip to content

Commit

Permalink
Auto merge of #86 - edre:rehash, r=Amanieu
Browse files Browse the repository at this point in the history
Resize with a more conservative amount of space after deletions

Otherwise we can force a rehash for each insert and removal if we're right under the size limit.

Benchmark with SIZE=895, just under a rehash limit.
    name                     oops ns/iter  okthen ns/iter  diff ns/iter   diff %   speedup
    insert_erase_std_serial  9,875,585     60,696            -9,814,889  -99.39%  x 162.71

Fixes #85
  • Loading branch information
bors committed Jun 6, 2019
2 parents 119f429 + afc20d7 commit b240ee0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,13 +652,20 @@ impl<T> RawTable<T> {
.checked_add(additional)
.ok_or_else(|| fallability.capacity_overflow())?;

// Rehash in-place without re-allocating if we have plenty of spare
// capacity that is locked up due to DELETED entries.
if new_items < bucket_mask_to_capacity(self.bucket_mask) / 2 {
let full_capacity = bucket_mask_to_capacity(self.bucket_mask);
if new_items <= full_capacity / 2 {
// Rehash in-place without re-allocating if we have plenty of spare
// capacity that is locked up due to DELETED entries.
self.rehash_in_place(hasher);
Ok(())
} else {
self.resize(new_items, hasher, fallability)
// Otherwise, conservatively resize to at least the next size up
// to avoid churning deletes into frequent rehashes.
self.resize(
usize::max(new_items, full_capacity + 1),
hasher,
fallability,
)
}
}

Expand Down

0 comments on commit b240ee0

Please sign in to comment.