Guava ListMultimap中put()和get()操作的时间复杂度是多少?

What is the time complexity of put() and get() operation in Guava ListMultimap?

put()time complexityGuava ListMultimap or Guava ArrayListMultimap中的get()是什么?

我已经阅读了下面的Guava文档,但是没有提到这些操作的时间复杂度。

ListMultimap

ArrayListMultimap

时间复杂度和Hashmap一样吗(O(1) for both put() and get())?

这在 guava 的一般 documentation for multimap 上有描述,虽然有点间接。具体来说,在 "Implementations" 部分,它表示对于 ArrayListMultimap,键的行为类似于 HashMap,值的行为类似于 ArrayList。

因此,get 和 put 都是 O(1)(关于伴随 HashMap 的声明的 usual caveats)。对于get,获取ArrayList只是一个O(1)的操作;对于 put,它是相同的 O(1) get,然后是另一个 O(1) put(摊销,因为 ArrayList 添加总是如此)。