|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[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
[2020-06-10 10:31 UTC] nikic@php.net
-Summary: Add a deleteMin() method to SplMaxHeap
+Summary: Add min-max heap to SPL
[2020-06-10 10:31 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 02:00:01 2025 UTC |
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