Yomguithereal / mnemonist

Curated collection of data structures for the JavaScript/TypeScript language.
https://yomguithereal.github.io/mnemonist
MIT License
2.26k stars 92 forks source link

BiMap value lookup? #137

Closed robross0606 closed 4 years ago

robross0606 commented 4 years ago

Typically, a BiMap allows you to look up a value by key, or a key by value. However, I don't see the ability in this API to get a key by value. Am I missing something? That seems like a pretty crucial feature to be missing from a BiMap.

Yomguithereal commented 4 years ago

Hello @robross0606. To get a key by value, you need to use the map's inverse likewise:

bimap.inverse.get(value)

I think this API choice stems from Google's Guava Java library.

robross0606 commented 4 years ago

Yes, sorry, I just came upon that in the documentation. Would be a pretty good thing to call out specifically in the top level docs for a BiMap implementation.

Yomguithereal commented 4 years ago

Indeed. Do you want to open a PR adding an example in the docs (in the gh-pages) if you have some time to spare?