简体   繁体   中英

Why the javadoc of LinkedList does not guarantee constant time performance in pop and push?

In Java Collection Framework, a lot of implmentations mention about their performance in the Javadoc. For example, HashSet's says:

This class offers constant time performance for the basic operations (add, remove, contains and size), assuming the hash function disperses the elements properly among the buckets. Iterating over this set requires time proportional to the sum of the HashSet instance's size (the number of elements) plus the "capacity" of the backing HashMap instance (the number of buckets).

And ArrayList's says:

The size, isEmpty, get, set, iterator, and listIterator operations run in constant time.

But LinkedList's says nothing about its performance.

I believe pop and push method of LinkedList runs in constant time as linked list in computer science does. But I'm worry that It is okay to suppose that when I implement a method which has a LinkedList parameter.

Does LinkedList has any reason not to say its performance?

The javadoc for HashMap.get(Object) doesn't guarantee O(1) performance either, yet it is well known for being so.

Javadoc is about the contract , not the implementation . API contracts typically concern themselves with behaviour, not performance SLAs.

Specific implementation choices that impact the contract may be documented in javadoc, but that still falls under the subject of "contract".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM