bimap-rs icon indicating copy to clipboard operation
bimap-rs copied to clipboard

Entry API

Open glittershark opened this issue 3 years ago • 2 comments

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

glittershark avatar Mar 14 '21 18:03 glittershark

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?

billyrieger avatar Mar 17 '21 17:03 billyrieger

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(...))

glittershark avatar Mar 17 '21 21:03 glittershark