3

Github Add `try_insert_no_grow` method on `RawTable` by cole-miller · Pull Reque...

 3 years ago
source link: https://github.com/rust-lang/hashbrown/pull/229
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Contributor

cole-miller commented 12 days ago

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

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK