Utility to select top N items from a collection.
Given a collection of M items, the aim is to select top N (as defined by some explicit or implicit Ordering).
Basically same as collection.sorted(ordering).take(N).
The point of this class is to avoid sorting entire collection of M items while producing same results.
Implementation assumes that N is relatively small.
scala> import com.gilt.gfc.collection.TopN
scala> import scala.math.Ordering.Int
scala> val elements = scala.util.Random.shuffle((1 to 10))
scala> val topN = TopN[Int](5, elements)
topN: Seq[Int] = ArraySeq(1, 2, 3, 4, 5)
Utility to select top N items from a collection. Given a collection of M items, the aim is to select top N (as defined by some explicit or implicit Ordering). Basically same as collection.sorted(ordering).take(N). The point of this class is to avoid sorting entire collection of M items while producing same results. Implementation assumes that N is relatively small.