Package org.matsim.contrib.util
Class PartialSort<T>
- java.lang.Object
-
- org.matsim.contrib.util.PartialSort<T>
-
- Type Parameters:
T
-
public class PartialSort<T> extends Object
Sorts from smallest to largest. If the opposite should be the case then add elements with their values negated:PartialSort.add(element, -value)
. Works fine for small k (k << n); otherwise, one should consider a partial version of heapsort or quicksort.More info: Partial sorting
-
-
Constructor Summary
Constructors Constructor Description PartialSort(int k)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(T element, double value)
void
addAll(Stream<T> elements, ToDoubleFunction<T> evaluator)
List<T>
kSmallestElements()
Gets k smallest elements (side effect: they are removed from the queue -- the queue gets empty).static <T> List<T>
kSmallestElements(int k, Stream<T> elements, ToDoubleFunction<T> evaluator)
-
-
-
Constructor Detail
-
PartialSort
public PartialSort(int k)
-
-
Method Detail
-
kSmallestElements
public static <T> List<T> kSmallestElements(int k, Stream<T> elements, ToDoubleFunction<T> evaluator)
-
addAll
public void addAll(Stream<T> elements, ToDoubleFunction<T> evaluator)
-
kSmallestElements
public List<T> kSmallestElements()
Gets k smallest elements (side effect: they are removed from the queue -- the queue gets empty).- Returns:
- list containing k smallest elements sorted ascending: from the smallest to the k-th smallest
-
-