in algebird-core/src/main/scala/com/twitter/algebird/TopKMonoid.scala [25:40]
private[algebird] def mergeSortR[T](acc: List[T], list1: List[T], list2: List[T], cnt: Int)(implicit
ord: Ordering[T]
): List[T] =
(list1, list2, cnt) match {
case (_, _, 0) => acc
case (x1 :: t1, x2 :: t2, _) => {
if (ord.lt(x1, x2)) {
mergeSortR(x1 :: acc, t1, list2, cnt - 1)
} else {
mergeSortR(x2 :: acc, list1, t2, cnt - 1)
}
}
case (x1 :: t1, Nil, _) => mergeSortR(x1 :: acc, t1, Nil, cnt - 1)
case (Nil, x2 :: t2, _) => mergeSortR(x2 :: acc, Nil, t2, cnt - 1)
case (Nil, Nil, _) => acc
}