What is the time complexity of Map.containsKey
and Map.containsValue
in Dart? I'd like to know for the following implementations:
- LinkedHashMap
- HashMap
- SplayTreeMap
I assume for the hash map implementations containsKey
is amortized constant time and containsValue
is probably linear time. For SplayTreeMap
, containsKey
is probably logarithmic time while containsValue
is probably still linear time. However, the documentation seems to be silent on the issue. The best I could find was for LinkedHashMap
, which says:
An insertion-ordered [Map] with expected constant-time lookup.
This doesn't specify if you are looking up the key or the value, but presumably this is referring to the key.
The docs for Set
(if you navigate to the implementations), on the other hand, are not silent. They give the time complexity.
I assume this is an oversight in the documentation, but perhaps they are silent because there is no guaranteed time complexity. (That's would be strange, though, because it goes against developer expectations.)