Skip to content

Adding priority queue implementation #1542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
damhiya opened this issue Jul 9, 2021 · 9 comments
Open

Adding priority queue implementation #1542

damhiya opened this issue Jul 9, 2021 · 9 comments

Comments

@damhiya
Copy link
Contributor

damhiya commented Jul 9, 2021

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
Copy link
Contributor

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
Copy link
Contributor Author

damhiya commented Jul 11, 2021

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
Copy link
Contributor

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 👍

@MatthewDaggitt
Copy link
Contributor

See feedback in #1552 for a design discussion.

@damhiya
Copy link
Contributor Author

damhiya commented Nov 21, 2021

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

@MatthewDaggitt
Copy link
Contributor

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

@andreasabel
Copy link
Member

andreasabel commented Jan 13, 2022

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
Copy link
Member

gallais commented Jan 13, 2022

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
Copy link
Member

Taneb commented Jan 13, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants