[英]What is the time complexity of this sort? Java Hashmap
I was wondering what is the time complexity of this sorting algorithm that sorts a 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;
}
Thank you. 谢谢。
The only sorting done here is done by the line 这里完成的唯一排序是由线完成的
.sorted(Entry.comparingByValue())
So the real question here is what is the runtime of a stream's .sorted
method. 所以这里真正的问题是流的.sorted
方法的运行时是什么。 This I believe will depend on some internal details, but generally these built-in sort methods are near-optimal, so my guess would be O(n*log(n)). 我相信这将取决于一些内部细节,但通常这些内置的排序方法接近最优,所以我的猜测是O(n * log(n))。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.