Req #51141 [Opn]: Add min-max heap to SPL
| From: | nikic@php.net | Date: | Wed, 10 Jun 2020 10:31:04 +0000 |
| Subject: | Req #51141 [Opn]: Add min-max heap to SPL | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227400@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=51141&edit=1
ID: 51141
Updated by: nikic@php.net
Reported by: jeroen at jeroen-vandeven dot nl
-Summary: Add a deleteMin() method to SplMaxHeap
+Summary: Add min-max heap to SPL
Status: Open
Type: Feature/Change Request
Package: SPL related
PHP Version: 5.3.1
Block user comment: N
Private report: N
New Comment:
This would require a min-max heap, which is a completely different data structure.
Previous Comments:
------------------------------------------------------------------------
[2010-04-27 09:37:23] 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.
------------------------------------------------------------------------
[2010-02-25 11:17:12] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=51141&edit=1