Skip to content

Commit

Permalink
fix in PairingHeap
Browse files Browse the repository at this point in the history
  • Loading branch information
satorg committed Dec 21, 2022
1 parent 2887270 commit 4e0d647
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions core/src/main/scala/cats/collections/PairingHeap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -308,24 +308,27 @@ object PairingHeap {
}
}

final private case object Leaf extends PairingHeap[Nothing] {
def apply[A](): PairingHeap[A] = this.asInstanceOf[PairingHeap[A]]

def unapply[A](heap: PairingHeap[A]): Boolean = heap.isEmpty

override def subtrees: List[PairingHeap[Nothing]] = Nil
final private case class Leaf[A] private () extends PairingHeap[A] {
override def subtrees: List[PairingHeap[A]] = Nil

override def size: Long = 0L

override def isEmpty: Boolean = true

override def minimumOption: Option[Nothing] = None
override def minimumOption: Option[A] = None

override def exists(fn: A => Boolean): Boolean = false

override def exists(fn: Nothing => Boolean): Boolean = false
override def forall(fn: A => Boolean): Boolean = true

override def combine(that: PairingHeap[A])(implicit order: Order[A]): PairingHeap[A] = that
}

override def forall(fn: Nothing => Boolean): Boolean = true
private object Leaf {
// Cached singleton instance for Leaf.
private val instance = new Leaf

override def combine(that: PairingHeap[Nothing])(implicit order: Order[Nothing]): PairingHeap[Nothing] = that
def apply[A](): Leaf[A] = instance.asInstanceOf[Leaf[A]]
}

implicit def toShowable[A](implicit s: Show[A], order: Order[A]): Show[PairingHeap[A]] = new Show[PairingHeap[A]] {
Expand Down

0 comments on commit 4e0d647

Please sign in to comment.