The kth element of the array.
1 auto foo = [3, 1, 5, 4, 2].dup; 2 auto secondSmallest = partitionK(foo, 1); 3 assert(secondSmallest == 2); 4 foreach(elem; foo[0..1]) { 5 assert(elem <= foo[1]); 6 } 7 foreach(elem; foo[2..$]) { 8 assert(elem >= foo[1]); 9 }
Partitions the input data according to compFun, such that position k contains the kth largest/smallest element according to compFun. For all elements e with indices < k, !compFun(datak, e) is guaranteed to be true. For all elements e with indices > k, !compFun(e, datak) is guaranteed to be true. For example, if compFun is "a < b", all elements with indices < k will be <= datak, and all elements with indices larger than k will be >= k. Reorders any additional input arrays in lockstep.