agda / agda-stdlib

The Agda standard library
https://wiki.portal.chalmers.se/agda/Libraries/StandardLibrary
Other
583 stars 236 forks source link

Adding priority queue implementation #1542

Open damhiya opened 3 years ago

damhiya commented 3 years ago

Hi. I implemented leftist heap based priority queue in agda. So I'm going to contribute this code to agda-stdlib if such thing was desired.

However, this code is a bit messy and I didn't care so much about library design while writing it. I would appreciate if someone give a comment about the code.

MatthewDaggitt commented 3 years ago

Hi @damhiya, thanks for opening the issue, yes we'd definitely be interested in a priority queue implementation!

However, the first thing we'd want to do I think is to define an interface (operations + laws) for priority queues. We'd then show that your implementation satisfied that interface. Would you be interested/willing to put together such an interface?

damhiya commented 3 years ago

Hi @damhiya, thanks for opening the issue, yes we'd definitely be interested in a priority queue implementation!

However, the first thing we'd want to do I think is to define an interface (operations + laws) for priority queues. We'd then show that your implementation satisfied that interface. Would you be interested/willing to put together such an interface?

Of course!

MatthewDaggitt commented 3 years ago

Great! If you'd like to open a PR with your proposed interface (probably in Data.PriorityQueue.Interface?) that'd be the best course. Once we've got the interface nailed down and merged in, we can then open a second PR with your implementation :+1:

MatthewDaggitt commented 3 years ago

See feedback in #1552 for a design discussion.

damhiya commented 3 years ago

I'm really sorry for inactivity. I was doing other works. I'll work on this in the future unless someone do it.

MatthewDaggitt commented 2 years ago

Absolutely no worries, not everything has to be added. Our discussion alone has really helped clarify my thoughts on this, so thanks!

andreasabel commented 2 years ago

Btw, I played around with a leftist heap implementation in Agda and ended up with this: https://gist.github.com/andreasabel/352fee52a39c0bebbd5059bff86d9b6e This is 170 loc including comments, imports, and some auxiliary functions about adding a top element to a decidable total order. The actual implementation of heaps and merging is the last third of this gist (rather tiny, I'd say).

gallais commented 2 years ago

We do have a generic min construction: http://agda.github.io/agda-stdlib/Algebra.Construct.NaturalChoice.Min.html And also the extension of an existing total order with a supremum: http://agda.github.io/agda-stdlib/Relation.Binary.Construct.Add.Supremum.NonStrict.html

Taneb commented 2 years ago

Here's a different implementation I made a while back, using pairing heaps: https://gist.github.com/Taneb/7e502c708e2e6eabcea5e7638f42b593