Edit report at http://bugs.php.net/bug.php?id=51141&edit=1
ID: 51141 Updated by: [email protected] Reported by: jeroen at jeroen-vandeven dot nl Summary: Add a deleteMin() method to SplMaxHeap Status: Open Type: Feature/Change Request Package: SPL related PHP Version: 5.3.1 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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 http://bugs.php.net/bug.php?id=51141&edit=1
