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 get_mut() to maps #52

Merged
merged 1 commit into from
Jan 31, 2021
Merged

Add get_mut() to maps #52

merged 1 commit into from
Jan 31, 2021

Conversation

arthurprs
Copy link
Contributor

@arthurprs arthurprs commented Jan 29, 2021

With it the user can avoid the clunky pattern get() + clone + modify + insert(). Especially useful if you have early returns (eg. with ?) in between.

@arthurprs arthurprs force-pushed the get_mut branch 2 times, most recently from 09da45f to e8bed47 Compare January 29, 2021 12:26
@codecov-io
Copy link

Codecov Report

Merging #52 (e8bed47) into master (60a2f9c) will decrease coverage by 0.40%.
The diff coverage is 75.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #52      +/-   ##
==========================================
- Coverage   93.24%   92.83%   -0.41%     
==========================================
  Files          11       11              
  Lines        1583     1620      +37     
==========================================
+ Hits         1476     1504      +28     
- Misses        107      116       +9     
Impacted Files Coverage Δ
src/map/entry.rs 100.00% <ø> (ø)
src/map/red_black_tree_map/mod.rs 92.81% <55.55%> (-0.67%) ⬇️
src/map/hash_trie_map/mod.rs 91.78% <78.57%> (-0.94%) ⬇️
src/list/mod.rs 91.66% <100.00%> (+0.19%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 60a2f9c...e8bed47. Read the comment docs.

Copy link
Owner

@orium orium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for you contribution. I just have a small comment and it should be good to go.

src/map/hash_trie_map/mod.rs Show resolved Hide resolved
Bucket::Single(_) => None,
Bucket::Collision(entries) => {
let removed =
bucket_utils::list_remove_first(entries, |e| e.matches(key, key_hash));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do this more efficiently, but I don't think we care, given that collisions are extremely rare.

Copy link
Contributor Author

@arthurprs arthurprs Jan 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it shouldn't matter in practice. I thought about doing it the "right way" but it would change a lot more code due to the limited api for the list. Doing this way I got away with just "first_mut".

With it the user can avoid the clunky pattern get() + modify + insert().
@orium
Copy link
Owner

orium commented Jan 31, 2021

Merged. Thanks.

@arthurprs
Copy link
Contributor Author

arthurprs commented Feb 23, 2021

I was hoping you could make a new release? That will include the rand 0.8 update and the get_mut. Thank you 🙏

@orium
Copy link
Owner

orium commented Feb 23, 2021

Sure. Released v0.9.0.

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.

None yet

3 participants