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

Entry API #26

Open
glittershark opened this issue Mar 14, 2021 · 2 comments
Open

Entry API #26

glittershark opened this issue Mar 14, 2021 · 2 comments

Comments

@glittershark
Copy link

It'd be really nice to be able to have something akin to the Entry API as it exists on HashMap - something like left_entry and right_entry, for example

@billyrieger
Copy link
Owner

Thank you for the suggestion! It might be possible to partially replicate the Entry API but anything returning a mutable reference to the inserted value would become an immutable reference instead—otherwise it's possible to violate the bijection invariant. Another issue would be to figure out how to handle any overwritten values in the BiMap. I'd rather not drop them in the background but returning them along with the newly inserted value might be clunky. Could you give me an example of how you'd like to use a hypothetical Entry API for a BiMap?

@glittershark
Copy link
Author

glittershark commented Mar 17, 2021

here's the code that's currently not using the Entry API that it'd be nice to be able to use an Entry: https://github.com/glittershark/achilles/blob/master/src/tc/mod.rs#L527-L534 (vars.0 is a bimap there). Essentially I'm just recreating or_insert_with with .get_by_right(...).unwrap_or_else(|| .insert_no_overwrite(...))

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

No branches or pull requests

2 participants