[英]What is the time complexity of HashMap.containsValue() in java?
[英]What is the time complexity of this sort? Java Hashmap
我想知道这种排序算法的时间复杂度是什么,它可以对hashmap进行排序。
private HashMap<Pair<T,T>,Double> sortMapOfEdges(HashMap<Pair<T,T>,Double> mapOfEdges){
HashMap<Pair<T,T>, Double> sortedMapOfEdges =
mapOfEdges.entrySet().stream()
.sorted(Entry.comparingByValue())
.collect(Collectors.toMap(Entry::getKey, Entry::getValue,
(e1, e2) -> e1, LinkedHashMap::new));
return sortedMapOfEdges;
}
谢谢。
这里完成的唯一排序是由线完成的
.sorted(Entry.comparingByValue())
所以这里真正的问题是流的.sorted
方法的运行时是什么。 我相信这将取决于一些内部细节,但通常这些内置的排序方法接近最优,所以我的猜测是O(n * log(n))。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.