|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51141 Add min-max heap to SPL
Submitted: 2010-02-25 11:17 UTC Modified: 2020-06-10 10:31 UTC
From: jeroen at jeroen-vandeven dot nl Assigned:
Status: Open Package: SPL related
PHP Version: 5.3.1 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-02-25 11:17 UTC] jeroen at jeroen-vandeven dot nl
Add a deleteMin() method to SplMaxHeap (and/or a deleteMax() to 
SplMinHeap) to limit the size of the heap without taking off the top 

Reproduce code:
$heap = new SplMaxHeap();
for ($i = 0; $i < 10000; $i++) {
if ($heap.count() > 100) {

Expected result:
The example is pretty useless, it will add 100 elements to the heap and 
then add 9900 more, immediately removing each one.

This is useful in other situations where you may only be interested in 
the top 100 sorted elements of 10000 unsorted elements and don't want 
the heap to grow excessively large.

Actual result:
There is no deleteMin() method in SplMaxHeap


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-09 20:51 UTC]
-Package: Feature/Change Request +Package: SPL related
 [2010-04-27 09:37 UTC]
One problem that I see with a deleteMin in a MaxHeap is that there is no easy way 
to find the min in the heap, so it's not a common operation on heaps.
 [2020-06-10 10:31 UTC]
-Summary: Add a deleteMin() method to SplMaxHeap +Summary: Add min-max heap to SPL
 [2020-06-10 10:31 UTC]
This would require a min-max heap, which is a completely different data structure.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 12:01:29 2024 UTC