Skip to content

Commit

Permalink
WeightedSample singleton ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
RustedBones committed Nov 4, 2024
1 parent 910a776 commit 34378a8
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ object SampleSCollectionFunctions {

final private case class WeightedSample[T](id: Long, value: T, weight: Long)
private object WeightedSample {
private object WeightedSampleOrdering extends Ordering[WeightedSample[_]] {
override def compare(x: WeightedSample[_], y: WeightedSample[_]): Int =
java.lang.Long.compare(y.id, x.id) // reverse order
}

implicit def ordering[T]: Ordering[WeightedSample[T]] =
Ordering.by[WeightedSample[T], Long](_.id).reverse
WeightedSampleOrdering.asInstanceOf[Ordering[WeightedSample[T]]]
}

final private case class WeightedCombiner[T](
Expand Down

0 comments on commit 34378a8

Please sign in to comment.