Skip to content
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

[RFC 60] Add binary heaps #2950

Merged
merged 1 commit into from
Dec 4, 2018
Merged

[RFC 60] Add binary heaps #2950

merged 1 commit into from
Dec 4, 2018

Conversation

Theodus
Copy link
Contributor

@Theodus Theodus commented Nov 29, 2018

This PR adds binary heaps to the standard collections package. This includes both minimum and maximum priority heaps through the MinHeap and MaxHeap classes.

closes #2948

@Theodus Theodus added the changelog - added Automatically add "Added" CHANGELOG entry on merge label Nov 29, 2018
@jemc jemc merged commit 708a324 into ponylang:master Dec 4, 2018
ponylang-main added a commit that referenced this pull request Dec 4, 2018
@SeanTAllen
Copy link
Member

@Theodus could you write up something for the release notes for this? short overview of them and why they might be useful?

@SeanTAllen SeanTAllen mentioned this pull request Jan 23, 2019
@Theodus
Copy link
Contributor Author

Theodus commented Jan 24, 2019

Release Notes

RFC 60 adds binary heaps to the Pony standard library. Binary heaps are a useful data structure for processing items based on priority, as in priority queues. A min or max heap may be created through the MinHeap or MaxHeap classes, respectively.

Here is an example of a min-heap containing integers:

use "collections"
use "itertools"

actor Main
  new create(env: Env) =>
    let q = MaxHeap[I64](5) .> append([1; 5; 8; 3; 4])

    // prints `8 5 4 3 1`
    env.out.print(" ".join(
      Iter[USize](Range(0, q.size()))
        .map_stateful[I64]({ref(n)? => q.pop()? })))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - added Automatically add "Added" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC 60: Binary Heaps
4 participants