https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
l

Loe

03/03/2023, 3:14 PM
Does Kotlin has a
sorted queue
that I can use for KMP project? Java has
PriorityQueue
but I can’t use that for KMP. This message suggests
ArrayQueue
but it doesn’t have a Comparator that I can override
j

jw

03/03/2023, 3:26 PM
If you just want something that works today, use a normal list and do a binary search to find insertion index for new items
l

Loe

03/03/2023, 3:48 PM
got it. tnx
e

ephemient

03/03/2023, 7:32 PM
or write a binary heap, it's not that much code
a

Arjan van Wieringen

03/04/2023, 7:46 AM
I’ve got some MinHeap priority queue lying around that came from this thread: https://codereview.stackexchange.com/questions/175291/minimum-priority-queue-implementation-in-kotlin
l

Loe

03/06/2023, 4:11 PM
Thank you so much @ephemient!
a

Arkadii Ivanov

03/15/2023, 5:51 PM
Just in case, this is PriorityQueue that I've been using so far.
l

Loe

03/15/2023, 8:19 PM
Thank you!
e

ephemient

03/15/2023, 10:37 PM
also, if you have any interest in writing a Fibonacci heap instead of a binary heap,

https://youtu.be/6JxvKfSV9Ns

is a good introduction (but a binary heap is almost always good enough)
93 Views