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

added heappeek, heappushpop!, heapreplace! to collections, + tests #10810

Closed
wants to merge 3 commits into from

Conversation

fabianlischka
Copy link
Contributor

These functions are mostly for convenience, but heappushpop! (push, then pop) and heapreplace! (pop, then push) are a smidgen faster then their equivalents, because the array gets "percolated" only once (and the percolate functions are not exported).

heapreplace! is nice for example if you want to keep a running list of the N "best" elements seen so far.

Plus, systematic tests for heapify!, heappeek, heappop!, heappush!, heappushpop!, heapreplace!, for small heaps, doubling the runtime of the "priorityqueue.jl" test from 1 to 2 seconds on my MacBook Air.

@StefanKarpinski
Copy link
Sponsor Member

This is good but the very large number of heap* functions exported from base makes me feel that this really ought to be moved out of base Julia and into DataStructures.

@tkelman
Copy link
Contributor

tkelman commented Apr 14, 2015

Agreed, it looks like the only place outside of base/collections.jl that heap functions are used is in base/quadgk.jl?

@ViralBShah
Copy link
Member

Would we remove Heaps altogether from Base then?

It seems useful to have a Heap in Base, and perhaps some of these functions could live in a Heap module so that we don't need all the heap* functions.

@fabianlischka
Copy link
Contributor Author

Note that there appears to be a second, totally i dependent heap implementation in Datastructures, which also doesn't have the combined commands (pushpop, replace).
What do you suggest:

  1. Implementing them on the Datastructures heap instead
  2. Trying and unify the heaps?

@tkelman
Copy link
Contributor

tkelman commented Apr 15, 2015

Would we remove Heaps altogether from Base then?

Not for 0.4. Maybe unexport but leave the implementation available in base for 0.4, and if that goes relatively painlessly, then move it out to the package during 0.5-dev?

How widely used is the base heap vs the DataStructures one?

@timholy
Copy link
Sponsor Member

timholy commented Apr 15, 2015

One datapoint: I only use the one in Base.

@fabianlischka
Copy link
Contributor Author

What do you suggest then? Would you accept it if I unexport (then I can still access in my code via qualified name, right)? Or implement on Datastructure heap instead?
Thanks :-)

@tkelman
Copy link
Contributor

tkelman commented Apr 23, 2015

if I unexport (then I can still access in my code via qualified name, right)

Right, functions that are implemented in Base but not exported from Base can be accessed via Base.heappeek etc. Actually I think the way you have it here, it's exported from Base.Collections (which is itself exported, so you can just do Collections.heappeek) but not from Base, the only reason it's usable in test/priorityqueue.jl without qualification is because that file starts with a using Base.Collections. There's no importall .Collections in base/sysimg.jl, so I think this is fine. It adds functionality and exports to the collections module, but doesn't clutter the default namespace with new Base exports.

Or implement on Datastructure heap instead?

If you've got interesting applications built on heap functionality, either the Base.Collections heap or the DataStructures.jl heap, it would be interesting and worthwhile to compare the two I think. Up to you of course.

@StefanKarpinski StefanKarpinski added this to the 0.6.0 milestone Sep 14, 2016
@tkelman
Copy link
Contributor

tkelman commented Dec 22, 2016

Closing as stale. Would be worth revisiting as part of DataStructures.

@tkelman tkelman closed this Dec 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants