java - One-to-one mapping data structure (A,B) with getKey(B) in O(1)? - Stack Overflow
If you're willing to use third-party libraries, Guava provides a nice API for this as BiMap. Instead of a getKey method, it provides an inverse() view which returns a BiMap<V, K>. (It does, of course, provide constant-time containsValue.)
At the moment, HashBiMap is basically internally two HashMaps kept in sync -- though it's very consistent about how it keeps them matching each other -- but the implementation might get smarter in the future.
Read full article from java - One-to-one mapping data structure (A,B) with getKey(B) in O(1)? - Stack Overflow
No comments:
Post a Comment