Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize with a more conservative amount of space after deletions #86

Merged
merged 1 commit into from Jun 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/raw/mod.rs
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