algorithm-archive icon indicating copy to clipboard operation
algorithm-archive copied to clipboard

Kotlin huffman

Open Kroppeb opened this issue 5 years ago • 3 comments

Kroppeb avatar Dec 23 '19 12:12 Kroppeb

This code doesn't work for a string of one unique character multiple times. I don't know Kotlin at all but I have a fix you can look at and improve on.

if (priorityQueue.size == 1) {
    val left = priorityQueue.remove()
    val right = Leaf(0, '\u0000')
    root = Branch(left, right)
} else {
    root = priorityQueue.remove() as? Branch ?: error("No support for string of one unique letter")
}

I'm not sure how to get right to be a null object but this will do.

Gathros avatar Dec 25 '19 15:12 Gathros

I just saw this. Why are these changes on top of https://github.com/algorithm-archivists/algorithm-archive/pull/640?

berquist avatar May 24 '20 02:05 berquist

[lang: kotlin]

ntindle avatar Aug 28 '21 05:08 ntindle