php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51141 Add a deleteMin() method to SplMaxHeap
Submitted: 2010-02-25 11:17 UTC Modified: 2010-04-27 09:37 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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jeroen at jeroen-vandeven dot nl
New email:
PHP Version: OS:

 

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

Reproduce code:
---------------
$heap = new SplMaxHeap();
for ($i = 0; $i < 10000; $i++) {
$heap.insert($arr[$i])
if ($heap.count() > 100) {
$heap.deleteMin();
}
}

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-09 20:51 UTC] jani@php.net
-Package: Feature/Change Request +Package: SPL related
 [2010-04-27 09:37 UTC] colder@php.net
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.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC