I have a case class: case class Item(id: Long, rank: Int) and i want to create a heap of Item objects. I try to create an instance of Heap[Item] but i have to override a fold function, i do not know exactly what to do and therefore i am stuck at this point
val heap = new Heap[Item] {
override def fold[B](empty: => B, nonempty: (Int, (Item, Item) => Boolean, Tree[Ranked[Item]]) => B): B = {
}
}
What do i have to do to make this work so i can use the heap collection ; Thanks.
You shouldn't be directly calling
new Heapto begin with.First, define an implicit
Orderfor yourItems. For example to order by rank:And then create
Heaps using helper methods from theHeapcompanion object: