1

I am interested in using a Map that will contain unique keys and values. I also would like to have O(1) complexity for .containsKey() and .containsValue(). To me, it seems like a HashBiMap should be able to support this complexity because of the uniqueness of both the keys and values in the map and hashing. Is this a correct assumption?

terminex9
  • 671
  • 5
  • 10

1 Answers1

4

A PROPERLY IMPLEMENTED two-way HashMap (In this case, a HashBiMap) indeed has a runtime complexity of O(1) for containsKey and containsValue.

christopher
  • 26,815
  • 5
  • 55
  • 89
  • 1
    Very true! Looking at the source code for the `HashBiMap` seems to confirm the O(1) complexity for both methods. https://code.google.com/p/guava-libraries/source/browse/guava/src/com/google/common/collect/HashBiMap.java – terminex9 Nov 18 '14 at 19:05
  • Okay then.. well glad we could close that book. – christopher Nov 18 '14 at 19:09