I want to create a priority queue (max heap) for objects of the following class
data class Tuple(val column: Column, var count: Int)
where Column
is
data class Column(val name: String, val dataType: String)
I wrote the following code to instantiate a priority queue for the above class objects with custom comparator like so:
val compareByCount: Comparator<Tuple> = compareByDescending { it.count }
val pq = PriorityQueue<Tuple>(compareByCount)
When I populate the PriorityQueue
and perform pq.peek()
it returns the Tuple
object with the lowest count. Why is it so? Even though I provided a comparator that checks according to descending order.