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

Add try_insert_no_grow method on RawTable #229

Merged
merged 2 commits into from
Jan 21, 2021

Conversation

cole-miller
Copy link

This is my attempt to answer the need described in #224 by adding a method on RawTable:

impl<T> RawTable<T, Global> {
    pub fn try_insert_no_grow(&mut self, hash: u64, value: T) -> Result<Bucket<T>, T>;
}

This method follows the logic of RawTable::insert, but if the table would need to grow to accomodate the new element it "signals" by returning Err(value) instead of performing the reallocation and insertion.

Marked as draft for now because

  • I'm not sure whether there's a better way to achieve this (advice welcome)
  • some tests are probably needed
  • there's an unused warning (despite the pub) that I haven't figured out how to get rid of

@cole-miller cole-miller force-pushed the try-insert-no-grow branch 2 times, most recently from 0917017 to 1316b35 Compare January 19, 2021 14:33
@cole-miller
Copy link
Author

Fixed the unused warning by adding #[cfg(feature = "raw")] -- not sure if that's the best solution.

The latest CI failure seems to be due to a (new?) Clippy lint ptr_as_ptr triggering on other parts of the code.

@cole-miller cole-miller marked this pull request as ready for review January 19, 2021 15:08
@Amanieu
Copy link
Member

Amanieu commented Jan 20, 2021

Fixed the unused warning by adding #[cfg(feature = "raw")] -- not sure if that's the best solution.

That's the correct solution.

Code LGTM, just need to wait for #230 to land first.

bors added a commit that referenced this pull request Jan 21, 2021
Apply suggestions from `clippy::ptr_as_ptr`

This is a new pedantic lint that triggers on pointer casts with `as` that don't change mutability. It was preventing #229 from passing CI.
@Amanieu
Copy link
Member

Amanieu commented Jan 21, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Jan 21, 2021

📌 Commit 92677e0 has been approved by Amanieu

@bors
Copy link
Contributor

bors commented Jan 21, 2021

⌛ Testing commit 92677e0 with merge 4c3ba70...

@bors
Copy link
Contributor

bors commented Jan 21, 2021

☀️ Test successful - checks-travis
Approved by: Amanieu
Pushing 4c3ba70 to master...

@bors bors merged commit 4c3ba70 into rust-lang:master Jan 21, 2021
@cole-miller cole-miller deleted the try-insert-no-grow branch January 21, 2021 02:40
@cole-miller
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants