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

added get_or_insert_with function #718

Merged
merged 6 commits into from Jul 22, 2021
Merged

added get_or_insert_with function #718

merged 6 commits into from Jul 22, 2021

Conversation

snow01
Copy link
Contributor

@snow01 snow01 commented Jul 13, 2021

get_or_insert_with function allows lazy creation of default value. Default values may be heavy objects, lazy creation doesn't create un-necessary objects when key is already there in the data structure.

@taiki-e
Copy link
Member

taiki-e commented Jul 13, 2021

Thanks! Could you add a test for the case where the closure panics? (related #717)

@snow01
Copy link
Contributor Author

snow01 commented Jul 19, 2021

I have added two test cases - (a) for valid case (b) where closure panics. Please check if this is what you are looking at.

Thanks

@snow01
Copy link
Contributor Author

snow01 commented Jul 21, 2021

@taiki-e - pls update here.

crossbeam-skiplist/tests/base.rs Outdated Show resolved Hide resolved
crossbeam-skiplist/src/base.rs Outdated Show resolved Hide resolved
@taiki-e
Copy link
Member

taiki-e commented Jul 22, 2021

Also, it would make sense to add the same method to SkipMap and SkipSet. SkipList is a low-level API, and most users use SkipMap and SkipSet.

snow01 and others added 2 commits July 22, 2021 20:34
As suggested by taiki-e

Co-authored-by: Taiki Endo <te316e89@gmail.com>
…n case another thread writes before.

2) Added test case for the same.
@snow01
Copy link
Contributor Author

snow01 commented Jul 22, 2021

Also, it would make sense to add the same method to SkipMap and SkipSet. SkipList is a low-level API, and most users use SkipMap and SkipSet.

Sure, will do.

2) Added corresponding test case for SkipMap
@snow01
Copy link
Contributor Author

snow01 commented Jul 22, 2021

@taiki-e - added corresponding method and test for SkipMap. For SkipSet, as value is always () it may not make sense.

Please review.

Thanks

Copy link
Member

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @snow01!

bors r+

@bors
Copy link
Contributor

bors bot commented Jul 22, 2021

Build succeeded:

@bors bors bot merged commit 800ca61 into crossbeam-rs:master Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

2 participants