@ @@ 0(__TEXT@@__text__TEXT` `__stubs__TEXT"6"__stub_helper__TEXTP"lP"__cstring__TEXT""__const__TEXT##__unwind_info__TEXT??__DATA@@@@__nl_symbol_ptr__DATA@@ __got__DATA@(@ __la_symbol_ptr__DATA0@H0@__data__DATA@@H__LINKEDIT\"0 hpy8 Pjjk8sK4ޭ'܉$$  * 8d /usr/lib/libSystem.B.dylib& )ЏMUHH=)] f.DUHAVSIHt HH=) H t;IHCuHQ(H8H5N D E1IvH9 t E1L[A^]HSHE1H1uL5 (IfDUHAWAVATSHHt HH= H t&L;IGuH'H8H5 E1mLsIt_IGHHHL1 AH uH Ext1It9IGHIL0L1jt4H uHc IL[A\A^A_]H 'H8H53 gIf.UHHH5]\f.fUHSPHHt HH= HtkH;HGuH&H8H5 CHt+HCHOHHH1t'H u HH=&H8H5g @1HH[]f.UHHH5B]Lf.fUHHH5]lf.fUHHH5r] f.fUHSPHHt HH=HtkH;HGuH%H8H5CHt+HCHOHHH1t'H u HxH-%H8H5W01HH[]f.UHAWAVAUATSHHGHEH9IE1H9HGNt4Iu LQH"H8H50 E1L[A\A^A_]ItHCL L8H1Aօt I $uLM@UHAWAVAUATSHHGuH!H8H5E1 IIH_H HHHELx1f.LIHHwIHMgI9|8LLALeȅuAtILLAօtyLeII9}IH]L9~@HE1LHAH]Ѕu[fDtHLHAօt>H]HL9}L% I$%HE1f.H~HLHAօtLH[A\A]A^A_]fUHAWAVAUATSH(H_H9IIIHuI9H}H]HGL}LE"fDJ JJJ MM9Ol?KL?H9}N$J\HI$HL1AH tI $tAEy*5HI $uLAEHEH]H;XAMH@LEOL9E1L;mHEH@N4f.M}IJHIHL1:H tIt)Ay5fH߉ IuLAxTHUHMH;JuXE1t?HBJ N4N4J ML;}cHH8H5ADH([A\A]A^A_]H\H8H5Wf.UHAVSHH=/ XIH5HH71ۅyIuL7[A^]%%%%%%%%% hRhHh,>hC4h[*hu hh hLMAS%m_heapqheappushheappushpopheappopheapreplaceheapify_heappop_max_heapify_max_heapreplace_maxheap argument must be a listindex out of rangelist changed size during iteration__about__Heap queue algorithm (a.k.a. priority queue). Heaps are arrays for which a[k] <= a[2*k+1] and a[k] <= a[2*k+2] for all k, counting elements from 0. For the sake of comparison, non-existing elements are considered to be infinite. The interesting property of a heap is that a[0] is always its smallest element. Usage: heap = [] # creates an empty heap heappush(heap, item) # pushes a new item on the heap item = heappop(heap) # pops the smallest item from the heap item = heap[0] # smallest item on the heap without popping it heapify(x) # transforms list into a heap, in-place, in linear time item = heapreplace(heap, item) # pops and returns smallest item, and adds # new item; the heap size is unchanged Our API differs from textbook heap algorithms as follows: - We use 0-based indexing. This makes the relationship between the index for a node and the indexes for its children slightly less obvious, but is more suitable since Python uses 0-based indexing. - Our heappop() method returns the smallest item, not the largest. These two make it possible to view the heap as a regular Python list without surprises: heap[0] is the smallest item, and heap.sort() maintains the heap invariant! heappush($module, heap, item, /) -- Push item onto heap, maintaining the heap invariant.heappushpop($module, heap, item, /) -- Push item on the heap, then pop and return the smallest item from the heap. The combined action runs more efficiently than heappush() followed by a separate call to heappop().heappop($module, heap, /) -- Pop the smallest item off the heap, maintaining the heap invariant.heapreplace($module, heap, item, /) -- Pop and return the current smallest value, and add the new item. This is more efficient than heappop() followed by heappush(), and can be more appropriate when using a fixed-size heap. Note that the value returned may be larger than item! That constrains reasonable uses of this routine unless written as part of a conditional replacement: if item > heap[0]: item = heapreplace(heap, item)heapify($module, heap, /) -- Transform list into a heap, in-place, in O(len(heap)) time._heappop_max($module, heap, /) -- Maxheap variant of heappop._heapify_max($module, heap, /) -- Maxheap variant of heapify._heapreplace_max($module, heap, item, /) -- Maxheap variant of heapreplace.Heap queues [explanation by François Pinard] Heaps are arrays for which a[k] <= a[2*k+1] and a[k] <= a[2*k+2] for all k, counting elements from 0. For the sake of comparison, non-existing elements are considered to be infinite. The interesting property of a heap is that a[0] is always its smallest element. The strange invariant above is meant to be an efficient memory representation for a tournament. The numbers below are `k', not a[k]: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 In the tree above, each cell `k' is topping `2*k+1' and `2*k+2'. In a usual binary tournament we see in sports, each cell is the winner over the two cells it tops, and we can trace the winner down the tree to see all opponents s/he had. However, in many computer applications of such tournaments, we do not need to trace the history of a winner. To be more memory efficient, when a winner is promoted, we try to replace it by something else at a lower level, and the rule becomes that a cell and the two cells it tops contain three different items, but the top cell "wins" over the two topped cells. If this heap invariant is protected at all time, index 0 is clearly the overall winner. The simplest algorithmic way to remove it and find the "next" winner is to move some loser (let's say cell 30 in the diagram above) into the 0 position, and then percolate this new 0 down the tree, exchanging values, until the invariant is re-established. This is clearly logarithmic on the total number of items in the tree. By iterating over all items, you get an O(n ln n) sort. A nice feature of this sort is that you can efficiently insert new items while the sort is going on, provided that the inserted items are not "better" than the last 0'th element you extracted. This is especially useful in simulation contexts, where the tree holds all incoming events, and the "win" condition means the smallest scheduled time. When an event schedule other events for execution, they are scheduled into the future, so they can easily go into the heap. So, a heap is a good structure for implementing schedulers (this is what I used for my MIDI sequencer :-). Various structures for implementing schedulers have been extensively studied, and heaps are good for this, as they are reasonably speedy, the speed is almost constant, and the worst case is not much different than the average case. However, there are other representations which are more efficient overall, yet the worst cases might be terrible. Heaps are also very useful in big disk sorts. You most probably all know that a big sort implies producing "runs" (which are pre-sorted sequences, which size is usually related to the amount of CPU memory), followed by a merging passes for these runs, which merging is often very cleverly organised[1]. It is very important that the initial sort produces the longest runs possible. Tournaments are a good way to that. If, using all the memory available to hold a tournament, you replace and percolate items that happen to fit the current run, you'll produce runs which are twice the size of the memory for random input, and much better for input fuzzily ordered. Moreover, if you output the 0'th item on disk and get an input which may not fit in the current tournament (because the value "wins" over the last output value), it cannot fit in the heap, so the size of the heap decreases. The freed memory could be cleverly reused immediately for progressively building a second heap, which grows at exactly the same rate the first heap is melting. When the first heap completely vanishes, you switch heaps and start a new run. Clever and quite effective! In a word, heaps are useful memory structures to know. I use them in a few applications, and I think it is good to keep a `heap' module around. :-) -------------------- [1] The disk balancing algorithms which are current, nowadays, are more annoying than clever, and this is a consequence of the seeking capabilities of the disks. On devices which cannot seek, like big tape drives, the story was quite different, and one had to be very clever to ensure (far in advance) that each tape movement will be the most effective possible (that is, will best participate at "progressing" the merge). Some tapes were even able to read backwards, and this was also used to avoid the rewinding time. Believe me, real good tape sorts were quite spectacular to watch! From all times, sorting has always been a Great Art! :-) 00! X`HH"H 8 0p P"Z"d"n"x""""""#@B"p(" (" )"@ *"+"@,#0,#P,!!0YFRARDRASASASASASASASAp(Q>@_PyExc_IndexErrorQq@_PyExc_RuntimeError@_PyExc_TypeError@__Py_NoneStruct@dyld_stub_binderq0>@_PyErr_SetStringq8>@_PyList_Appendq@>@_PyList_SetSliceqH>@_PyModuleDef_InitqP>@_PyModule_AddObjectqX>@_PyObject_RichCompareBoolq`>@_PyUnicode_FromStringqh>@__PyArg_CheckPositionalqp>@__Py_Dealloc_PyInit__heapq..   & : J@^n0P@P!# p(#(>)U *p+@,,,- @ @ Bd:dIf{`.`$`$ N .$$N. J$ $N. ^$ $ N .@n$@$N.$$ N .$$ N .0$0$ N .P$P$N.$$@N@.@$@$PNP.$$N.P$P$`N`. $$ N .!$!$JNJ#&#/&p(G&(b&)y& *&+&@,&,&,&-& @& @+& Bd`"4HYhykopqrstuv@lmnwxkopqrstuv _PyInit__heapq_PyErr_SetString_PyExc_IndexError_PyExc_RuntimeError_PyExc_TypeError_PyList_Append_PyList_SetSlice_PyModuleDef_Init_PyModule_AddObject_PyObject_RichCompareBool_PyUnicode_FromString__PyArg_CheckPositional__Py_Dealloc__Py_NoneStructdyld_stub_binder__heapq_heappush__heapq_heappushpop__heapq_heappop__heapq_heapreplace__heapq_heapify__heapq__heappop_max__heapq__heapify_max__heapq__heapreplace_max_siftdown_siftup_heappop_internal_heapify_internal_siftup_max_heapq_exec_module_doc__heapq_heappush__doc____heapq_heappushpop__doc____heapq_heappop__doc____heapq_heapreplace__doc____heapq_heapify__doc____heapq__heappop_max__doc____heapq__heapify_max__doc____heapq__heapreplace_max__doc_____about____heapqmodule_heapq_methods_heapq_slots/Users/sysadmin/build/v3.9.6/Modules/_heapqmodule.c/private/tmp/_py/_bld/python/build/temp.macosx-10.9-universal2-3.9/Users/sysadmin/build/v3.9.6/Modules/_heapqmodule.o_PyInit__heapq__heapq_heappush/Users/sysadmin/build/v3.9.6/Modules/clinic/_heapqmodule.c.h/Users/sysadmin/build/v3.9.6/Include/object.h__heapq_heappushpop__heapq_heappop__heapq_heapreplace__heapq_heapify__heapq__heappop_max__heapq__heapify_max__heapq__heapreplace_max_siftdown_siftup_heappop_internal_heapify_internal_siftup_max_heapq_exec_module_doc__heapq_heappush__doc____heapq_heappushpop__doc____heapq_heappop__doc____heapq_heapreplace__doc____heapq_heapify__doc____heapq__heappop_max__doc____heapq__heapify_max__doc____heapq__heapreplace_max__doc_____about____heapqmodule_heapq_methods_heapq_slots )4d `  y@ _heapq.cpython-39-darwinDJ3H93M7VJݔ[g=d=U*J0t谎?XR,>.sZ>AH,9@Ԟ p>9Opl]NiHD&0~*`9&_if]w `_F_!4_ =SkO͕{=SkO͕{=SkO͕{#uZ}Rk#  _heapq.cpython-39-darwin *Hcd *Hcd subject.OU DJ3H93M7VJqq com.apple.security.cs.allow-dyld-environment-variables com.apple.security.cs.disable-library-validation com.apple.security.cs.disable-executable-page-protection com.apple.security.automation.apple-events D$`  y@ _heapq.cpython-39-darwinDJ3H93M7VJjjkEތ;gptpoE"9E\5 bِxk 6qqU@WmOǑwO?A?Z7 =P'Y3mq_`wө$mI֋Nyamt:WKa,Aˤc飫Be00_0],Ψ0$e?wB#SKG6EXJ% XofkOX||zڽH,XofkOX||zڽH,XofkOX||zڽH,ZmG V)甝5 ʹ`)xEii`k_#:"1O4YBx.3E EoZ[: 2m6lp&D{H X#ş9~]2_R@꾬d[jDl>İ&{^j=GX1? v(mNi&NVtKfxLY00UW|-,T0U00U#0+iGv k.@GM^0.U'0%0#!http://crl.apple.com/root.crl0U0 *Hcd0  *H  B9tkƤ7* D,Ya2Կ;P9jDt[pKl#q-_œpe- xXI (3zvOߨJ Vg/>ă:wmt.#Qo`H»ZFE~' "rorPu=%]6H9;ꐀ.`x S>O2VMxଚBzFXV,*E K4aUD'sNp000  *H 0b1 0 UUS10U  Apple Inc.1&0$U Apple Certification Authority10U Apple Root CA0 060425214036Z 350209214036Z0b1 0 UUS10U  Apple Inc.1&0$U Apple Certification Authority10U Apple Root CA0"0  *H 0 䑩 GP^y-6WLUKl"0>P Af$kУ*z G[73Mir]_%UM] d5#KYPXPg ˬ, op?0C=+I(ε^=: !.t< bqGSU/ApLE~LkPAtb A30XZ2hesg^eIv3ew-z0v0U0U00U+iGv k.@GM^0U#0+iGv k.@GM^0U 00 *Hcd00*+https://www.apple.com/appleca/0+0Reliance on this certificate by any party assumes acceptance of the then applicable standard terms and conditions of use, certificate policy and certification practice statements.0  *H \6L-x팛wvw0O=G7@,ԱؾsdyO4آ>xk}9S 8ıO k+Y |@Vtӷ#;Go$ѷpE'mx~"5%kԢ$#s`[ /DH`8=&g 3j /Sj[dc3w:,V!ںsO6U٧2Bq~RB$*M^cKP 7uu!0l0T"^%xV0  *H  0y1-0+U $Developer ID Certification Authority1&0$U Apple Certification Authority10U Apple Inc.1 0 UUS0 190302073001Z 240302073001Z010 &,d DJ3H93M7VJ1907U 0Developer ID Application: Ned Deily (DJ3H93M7VJ)10U DJ3H93M7VJ10U Ned Deily1 0 UUS0"0  *H 0 jm9-jAŧkC-0HvMi;5;754fpmIAq=Cb4ZjLC_ZcH+j[?n2PCrV|K< :^%Sg2 3Wffk%S?z*g| B qT"G-E?gT5Tx7]ɕ$$^m|t(.6Kt>-$ N,phǾ:00 U00U#0W|-,T0>+2000.+0"http://ocsp.apple.com/ocsp-devid010U 00 *Hcd00(+http://www.apple.com/appleca0+0 Reliance on this certificate by any party assumes acceptance of the then applicable standard terms and conditions of use, certificate policy and certification practice statements.0U% 0 +0Uqg&y@gݲ|0U0 *Hcd 0  *H  ,RybM4U${lsMUq8g  q2 b?Wclx*,xx=ujgA L_gMMc$FVM}w{!".A#5qK#o7` I[ ɲxT5&)ʖoZ¤}vvR?l0"{~+9⣃'O Ew(GUݲ)Lj3jH!7,51000y1-0+U $Developer ID Certification Authority1&0$U Apple Certification Authority10U Apple Inc.1 0 UUS"^%xV0  `He%0 *H  1  *H 0 *H  1 210628153649Z0/ *H  1" rn8->eZKkO_[0[ *Hcd 1N0+@0x KfNT/J0- `He oA?ҕH~$ UN&Lǿ 0[ *Hcd 1LH cdhashes w8T2n0AwePsMS2a7TtLaVAAvShQ= b3+3QRc/0pUdSH4kCp5VwdNOJkw= 0  *H  ehΙD?D7`ϊrHns<.ʣ HzD#7,S&HZƕ?mf8y&[$M-\ \QN'IY M0L?wz7F-Rl3:pvNDhJBYwp?(+[G|Moliɠ(V$}V+ H\mmIGyo(j(r!Ve顂0 *H  10 *H 01 0 +0z *H  ki0g*010  `He h- ܵ2[ x&Y9HDPTP 20210628153649Z0.8|O׬ 00N; Z0  *H  0|100.U 'Apple Timestamp Certification Authority1&0$U Apple Certification Authority10U Apple Inc.1 0 UUS0 210623185002Z 210804185001Z0A10U Timestamp Signer MA210U Apple Inc.1 0 UUS0"0  *H 0 _BWA 5ȹoYr#D5! 岇!5&`9OqqKc~^lŢR24 ;Q^D4 ]ڡ񻵹$ bp =/ןaXFZ$=͊B6 TՌaʡ/4{;06sVvN[lV頠:?$@$%Q9:]H! Yʾ_hWL$ZUSہ00 U00U#04%N78X&)0U 00 *Hcd00(+http://www.apple.com/appleca0+0 Reliance on this certificate by any party assumes acceptance of the then applicable standard terms and conditions of use, certificate policy and certification practice statements.0U% 0 +03U,0*0(&$"http://crl.apple.com/timestamp.crl0U?Aa9UZrj0U0  *H  %_[;HͿj-8 _ xzAPvXe> s^q7-I93SfGf ?OV M<࡝0_#"(`Xp2qB } s@/P'4p <No97ڞecIm] 9 :JidF5ea. =o%L x"!{[ѣ~I; r3,JZr 9Pt(ny_~VVlĮ (tM&By^`EXQI^JMs{Rˣ]klt-D>a>E~4u&@u0Kw00U4%N78X&)0U00U#0+iGv k.@GM^0.U'0%0#!http://crl.apple.com/root.crl0U0 *Hcd 0  *H  6qS#xe[#Ǣϴ(p!93rC=BQu]ˌjj:T}k>mzT_Cv\ N<>r4\g e0B4ӧBsu|QC`ܮ'kg3EoɘMiKEN"W""En?厸F\ɰ:m7(FeoUhR>?&:k22H;Kу000  *H 0b1 0 UUS10U  Apple Inc.1&0$U Apple Certification Authority10U Apple Root CA0 060425214036Z 350209214036Z0b1 0 UUS10U  Apple Inc.1&0$U Apple Certification Authority10U Apple Root CA0"0  *H 0 䑩 GP^y-6WLUKl"0>P Af$kУ*z G[73Mir]_%UM] d5#KYPXPg ˬ, op?0C=+I(ε^=: !.t< bqGSU/ApLE~LkPAtb A30XZ2hesg^eIv3ew-z0v0U0U00U+iGv k.@GM^0U#0+iGv k.@GM^0U 00 *Hcd00*+https://www.apple.com/appleca/0+0Reliance on this certificate by any party assumes acceptance of the then applicable standard terms and conditions of use, certificate policy and certification practice statements.0  *H \6L-x팛wvw0O=G7@,ԱؾsdyO4آ>xk}9S 8ıO k+Y |@Vtӷ#;Go$ѷpE'mx~"5%kԢ$#s`[ /DH`8=&g 3j /Sj[dc3w:,V!ںsO6U٧2Bq~RB$*M^cKP 7uu!1?0;00|100.U 'Apple Timestamp Certification Authority1&0$U Apple Certification Authority10U Apple Inc.1 0 UUSN; Z0 +0 *H  1  *H  0 *H  1 210628153649Z0# *H  1.pcdY(y?X0+ *H   1000ٿ [Xd&s]0  *H  Lcrxע)dLH) 03b)X@Wp @Hh@ @3@ @J (ҩ4h@hATn :X@U O{AO¨_ 91 a1 1O{C_TPP BRCRG4`@@B97 h6X@Op @Hh@ @3@ @J (g4h@hAT- 2X@M {AO¨_g_WO{@?-T_mT @yu:Ayz@@R@T@ Tw6 @!T7 @?aTw4@I} ii}iki) i+_LTR H)X@D {DOCWB_AgŨ_ 'X@Bp og_WO{C@? T:A_ T@ } iik} ik i) i+Ti5Ru) ?JTyuyi@@R@T@ Tw6@!T7 @?TR@ X@8 f{EODWC_BgAoƨ_{EODWC_BgAoƨL X@6p WO{@B97 ըX@2p @@yah@h94h@hATD ըX@a0 %{BOAWè_@T@@Ҁ?4@Tg_WO{@B97 hX@*p {DOCWB_AgŨ_@'T AKA)_  Tx!ɚB ѿ T`?`56A`?`4ѿJT-T`?56A`?`4ѿJT Հ X@A T`?`4og_WO{C@TA_T@ R9@)} iik} ik i) i+? Ti9Ry) ?JTyiyy@@R@T@ Tv6P@!T7 @T HX@Ap =T?MT@yy):Ayz@@Rd@T@ Tv6 `@!TZ7 @!TRv4@I} ii+}iki) i+_,T hX@! +{EODWC_BgAoƨ_RO{C@\ ,!P  7R{AO¨_h@hT{AO¨_{AO¨_ pX PX 0X X X X հX ՐX pXPPP,PCP[P uPPP G PX_heapqheappushheappushpopheappopheapreplaceheapify_heappop_max_heapify_max_heapreplace_maxheap argument must be a listindex out of rangelist changed size during iteration__about__Heap queue algorithm (a.k.a. priority queue). Heaps are arrays for which a[k] <= a[2*k+1] and a[k] <= a[2*k+2] for all k, counting elements from 0. For the sake of comparison, non-existing elements are considered to be infinite. The interesting property of a heap is that a[0] is always its smallest element. Usage: heap = [] # creates an empty heap heappush(heap, item) # pushes a new item on the heap item = heappop(heap) # pops the smallest item from the heap item = heap[0] # smallest item on the heap without popping it heapify(x) # transforms list into a heap, in-place, in linear time item = heapreplace(heap, item) # pops and returns smallest item, and adds # new item; the heap size is unchanged Our API differs from textbook heap algorithms as follows: - We use 0-based indexing. This makes the relationship between the index for a node and the indexes for its children slightly less obvious, but is more suitable since Python uses 0-based indexing. - Our heappop() method returns the smallest item, not the largest. These two make it possible to view the heap as a regular Python list without surprises: heap[0] is the smallest item, and heap.sort() maintains the heap invariant! heappush($module, heap, item, /) -- Push item onto heap, maintaining the heap invariant.heappushpop($module, heap, item, /) -- Push item on the heap, then pop and return the smallest item from the heap. The combined action runs more efficiently than heappush() followed by a separate call to heappop().heappop($module, heap, /) -- Pop the smallest item off the heap, maintaining the heap invariant.heapreplace($module, heap, item, /) -- Pop and return the current smallest value, and add the new item. This is more efficient than heappop() followed by heappush(), and can be more appropriate when using a fixed-size heap. Note that the value returned may be larger than item! That constrains reasonable uses of this routine unless written as part of a conditional replacement: if item > heap[0]: item = heapreplace(heap, item)heapify($module, heap, /) -- Transform list into a heap, in-place, in O(len(heap)) time._heappop_max($module, heap, /) -- Maxheap variant of heappop._heapify_max($module, heap, /) -- Maxheap variant of heapify._heapreplace_max($module, heap, item, /) -- Maxheap variant of heapreplace.Heap queues [explanation by François Pinard] Heaps are arrays for which a[k] <= a[2*k+1] and a[k] <= a[2*k+2] for all k, counting elements from 0. For the sake of comparison, non-existing elements are considered to be infinite. The interesting property of a heap is that a[0] is always its smallest element. The strange invariant above is meant to be an efficient memory representation for a tournament. The numbers below are `k', not a[k]: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 In the tree above, each cell `k' is topping `2*k+1' and `2*k+2'. In a usual binary tournament we see in sports, each cell is the winner over the two cells it tops, and we can trace the winner down the tree to see all opponents s/he had. However, in many computer applications of such tournaments, we do not need to trace the history of a winner. To be more memory efficient, when a winner is promoted, we try to replace it by something else at a lower level, and the rule becomes that a cell and the two cells it tops contain three different items, but the top cell "wins" over the two topped cells. If this heap invariant is protected at all time, index 0 is clearly the overall winner. The simplest algorithmic way to remove it and find the "next" winner is to move some loser (let's say cell 30 in the diagram above) into the 0 position, and then percolate this new 0 down the tree, exchanging values, until the invariant is re-established. This is clearly logarithmic on the total number of items in the tree. By iterating over all items, you get an O(n ln n) sort. A nice feature of this sort is that you can efficiently insert new items while the sort is going on, provided that the inserted items are not "better" than the last 0'th element you extracted. This is especially useful in simulation contexts, where the tree holds all incoming events, and the "win" condition means the smallest scheduled time. When an event schedule other events for execution, they are scheduled into the future, so they can easily go into the heap. So, a heap is a good structure for implementing schedulers (this is what I used for my MIDI sequencer :-). Various structures for implementing schedulers have been extensively studied, and heaps are good for this, as they are reasonably speedy, the speed is almost constant, and the worst case is not much different than the average case. However, there are other representations which are more efficient overall, yet the worst cases might be terrible. Heaps are also very useful in big disk sorts. You most probably all know that a big sort implies producing "runs" (which are pre-sorted sequences, which size is usually related to the amount of CPU memory), followed by a merging passes for these runs, which merging is often very cleverly organised[1]. It is very important that the initial sort produces the longest runs possible. Tournaments are a good way to that. If, using all the memory available to hold a tournament, you replace and percolate items that happen to fit the current run, you'll produce runs which are twice the size of the memory for random input, and much better for input fuzzily ordered. Moreover, if you output the 0'th item on disk and get an input which may not fit in the current tournament (because the value "wins" over the last output value), it cannot fit in the heap, so the size of the heap decreases. The freed memory could be cleverly reused immediately for progressively building a second heap, which grows at exactly the same rate the first heap is melting. When the first heap completely vanishes, you switch heaps and start a new run. Clever and quite effective! In a word, heaps are useful memory structures to know. I use them in a few applications, and I think it is good to keep a `heap' module around. :-) -------------------- [1] The disk balancing algorithms which are current, nowadays, are more annoying than clever, and this is a consequence of the seeking capabilities of the disks. On devices which cannot seek, like big tape drives, the story was quite different, and one had to be very clever to ensure (far in advance) that each tape movement will be the most effective possible (that is, will best participate at "progressing" the merge). Some tapes were even able to read backwards, and this was also used to avoid the rewinding time. Believe me, real good tape sorts were quite spectacular to watch! From all times, sorting has always been a Great Art! :-) 00HH!H @  04XT  \"h"t""""""""#؁"("(")#%*#+#=,%#|,2#,p!"YFRARCRASASASASASASASAp(Q>@_PyExc_IndexErrorQq@_PyExc_RuntimeError@_PyExc_TypeError@__Py_NoneStruct@dyld_stub_binderr>@_PyErr_SetStringr>@_PyList_Appendr>@_PyList_SetSlicer>@_PyModuleDef_Initr >@_PyModule_AddObjectr(>@_PyObject_RichCompareBoolr0>@_PyUnicode_FromStringr8>@__PyArg_CheckPositionalr@>@__Py_Dealloc_PyInit__heapq++ &:J^n p!# (#(>)U%*p+=,|,,- H P  ؁#dIdXf{`.$$ N .$$N.$$HNH.$$N.$$N.&$$N.6$$N.K$$N.`$$N.y$$PNP. $ $N.$$N.$$`N`.$$TNT.p!$p!$N&#&(&(&)&%*8&+O&=,k&|,&,&-& P& & ؁d"4HYhyjnopqrstuklmvwjnopqrstu _PyInit__heapq_PyErr_SetString_PyExc_IndexError_PyExc_RuntimeError_PyExc_TypeError_PyList_Append_PyList_SetSlice_PyModuleDef_Init_PyModule_AddObject_PyObject_RichCompareBool_PyUnicode_FromString__PyArg_CheckPositional__Py_Dealloc__Py_NoneStructdyld_stub_binder__heapq_heappush__heapq_heappushpop__heapq_heappop__heapq_heapreplace__heapq_heapify__heapq__heappop_max__heapq__heapify_max__heapq__heapreplace_max_siftdown_siftup_heappop_internal_heapify_internal_siftup_max_heapq_exec_module_doc__heapq_heappush__doc____heapq_heappushpop__doc____heapq_heappop__doc____heapq_heapreplace__doc____heapq_heapify__doc____heapq__heappop_max__doc____heapq__heapify_max__doc____heapq__heapreplace_max__doc_____about____dyld_private__heapqmodule_heapq_methods_heapq_slots/Users/sysadmin/build/v3.9.6/Modules/_heapqmodule.c/private/tmp/_py/_bld/python/build/temp.macosx-10.9-universal2-3.9/Users/sysadmin/build/v3.9.6/Modules/_heapqmodule.o_PyInit__heapq__heapq_heappush__heapq_heappushpop__heapq_heappop__heapq_heapreplace__heapq_heapify__heapq__heappop_max__heapq__heapify_max__heapq__heapreplace_max_siftdown_siftup_heappop_internal_heapify_internal_siftup_max_heapq_exec_module_doc__heapq_heappush__doc____heapq_heappushpop__doc____heapq_heappop__doc____heapq_heapreplace__doc____heapq_heapify__doc____heapq__heappop_max__doc____heapq__heapify_max__doc____heapq__heapreplace_max__doc_____about____heapqmodule_heapq_methods_heapq_slots *4 x ` p y@ _heapq.cpython-39-darwinDJ3H93M7VJݔ[g=d=U*J0t谎?XR,>.eo X4E_Wd^(M`gP^*(K!Eg>9+zf =SkO͕{=SkO͕{=SkO͕{=SkO͕{,P#_O@-=SkO͕{=SkO͕{=SkO͕{50MѮNV>  _heapq.cpython-39-darwin *Hcd *Hcd subject.OU DJ3H93M7VJqq com.apple.security.cs.allow-dyld-environment-variables com.apple.security.cs.disable-library-validation com.apple.security.cs.disable-executable-page-protection com.apple.security.automation.apple-events $` p  y@ _heapq.cpython-39-darwinDJ3H93M7VJjjkEތ;gptpoE"9E\5 bِxk 6qqU@nMAjl~U2q_EX*T9 1q^@rNzzDIc?@K]03 jt1NjT3fzrrx;ל'nKlXofkOX||zڽH,XofkOX||zڽH,XofkOX||zڽH,XofkOX||zڽH, TzK[E4X\Rg*T8tqUXofkOX||zڽH,XofkOX||zڽH,XofkOX||zڽH,$I\0[C$Zt`C #/0 *H 010  `He0 *H 700z–! 0  *H  0b1 0 UUS10U  Apple Inc.1&0$U Apple Certification Authority10U Apple Root CA0 120201221215Z 270201221215Z0y1-0+U $Developer ID Certification Authority1&0$U Apple Certification Authority10U Apple Inc.1 0 UUS0"0  *H 0 vO[A#+_s?5 ?$?O>mG V)甝5 ʹ`)xEii`k_#:"1O4YBx.3E EoZ[: 2m6lp&D{H X#ş9~]2_R@꾬d[jDl>İ&{^j=GX1? v(mNi&NVtKfxLY00UW|-,T0U00U#0+iGv k.@GM^0.U'0%0#!http://crl.apple.com/root.crl0U0 *Hcd0  *H  B9tkƤ7* D,Ya2Կ;P9jDt[pKl#q-_œpe- xXI (3zvOߨJ Vg/>ă:wmt.#Qo`H»ZFE~' "rorPu=%]6H9;ꐀ.`x S>O2VMxଚBzFXV,*E K4aUD'sNp000  *H 0b1 0 UUS10U  Apple Inc.1&0$U Apple Certification Authority10U Apple Root CA0 060425214036Z 350209214036Z0b1 0 UUS10U  Apple Inc.1&0$U Apple Certification Authority10U Apple Root CA0"0  *H 0 䑩 GP^y-6WLUKl"0>P Af$kУ*z G[73Mir]_%UM] d5#KYPXPg ˬ, op?0C=+I(ε^=: !.t< bqGSU/ApLE~LkPAtb A30XZ2hesg^eIv3ew-z0v0U0U00U+iGv k.@GM^0U#0+iGv k.@GM^0U 00 *Hcd00*+https://www.apple.com/appleca/0+0Reliance on this certificate by any party assumes acceptance of the then applicable standard terms and conditions of use, certificate policy and certification practice statements.0  *H \6L-x팛wvw0O=G7@,ԱؾsdyO4آ>xk}9S 8ıO k+Y |@Vtӷ#;Go$ѷpE'mx~"5%kԢ$#s`[ /DH`8=&g 3j /Sj[dc3w:,V!ںsO6U٧2Bq~RB$*M^cKP 7uu!0l0T"^%xV0  *H  0y1-0+U $Developer ID Certification Authority1&0$U Apple Certification Authority10U Apple Inc.1 0 UUS0 190302073001Z 240302073001Z010 &,d DJ3H93M7VJ1907U 0Developer ID Application: Ned Deily (DJ3H93M7VJ)10U DJ3H93M7VJ10U Ned Deily1 0 UUS0"0  *H 0 jm9-jAŧkC-0HvMi;5;754fpmIAq=Cb4ZjLC_ZcH+j[?n2PCrV|K< :^%Sg2 3Wffk%S?z*g| B qT"G-E?gT5Tx7]ɕ$$^m|t(.6Kt>-$ N,phǾ:00 U00U#0W|-,T0>+2000.+0"http://ocsp.apple.com/ocsp-devid010U 00 *Hcd00(+http://www.apple.com/appleca0+0 Reliance on this certificate by any party assumes acceptance of the then applicable standard terms and conditions of use, certificate policy and certification practice statements.0U% 0 +0Uqg&y@gݲ|0U0 *Hcd 0  *H  ,RybM4U${lsMUq8g  q2 b?Wclx*,xx=ujgA L_gMMc$FVM}w{!".A#5qK#o7` I[ ɲxT5&)ʖoZ¤}vvR?l0"{~+9⣃'O Ew(GUݲ)Lj3jH!7,51000y1-0+U $Developer ID Certification Authority1&0$U Apple Certification Authority10U Apple Inc.1 0 UUS"^%xV0  `He%0 *H  1  *H 0 *H  1 210628153649Z0/ *H  1" h;BzD`O"#1ԐPۿS*S0[ *Hcd 1N0+גWLXv@gE0- `He ?Ҭ?$)n>'~j0d0[ *Hcd 1LH cdhashes tteS31edh0xY8u7kdgABQGdFFbc= kZ6MhbMStqw/qanSrD8kAimvbj4= 0  *H  Z2ȴf*=vJU#\1LlgT=4X9~~}!A'C,+Ջׁ.icR. P| : OϿe7)AUw,#lLj!"5sC;Y#W.ņ_jp~<Ѩ/KF_QɊLTȗweH,*w L=t k;HE4D&L*$#} ;0 *H  10 *H 01 0 +0{ *H  lj0h*010  `He ?sEm=/=kg׸L |A 320210628153649Z0 6ؾ 00tb M0  *H  0|100.U 'Apple Timestamp Certification Authority1&0$U Apple Certification Authority10U Apple Inc.1 0 UUS0 210623184502Z 210804184501Z0A10U Timestamp Signer MA110U Apple Inc.1 0 UUS0"0  *H 0 OɪYΜ?ݻFS}[)pPgH.IiQ+₲(p A226Ei6@>\7CtY [ 䗋j|eM0%~Պ9onviIeU;NztDTh(#hK̤ CB$4LyJ\gBzi@ŝsymmY9} )ז`Oc,ZpQ 00 U00U#04%N78X&)0U 00 *Hcd00(+http://www.apple.com/appleca0+0 Reliance on this certificate by any party assumes acceptance of the then applicable standard terms and conditions of use, certificate policy and certification practice statements.0U% 0 +03U,0*0(&$"http://crl.apple.com/timestamp.crl0U,|=ɕDXq'$0U0  *H  /U/ݱ,~bj$wڂt%L>C.u /v&Ț[51FnWy9ԡhZqTt^-[['.0)7xǘ31FH[ -O3ХD~ 'rEB } s@/P'4p <No97ڞecIm] 9 :JidF5ea. =o%L x"!{[ѣ~I; r3,JZr 9Pt(ny_~VVlĮ (tM&By^`EXQI^JMs{Rˣ]klt-D>a>E~4u&@u0Kw00U4%N78X&)0U00U#0+iGv k.@GM^0.U'0%0#!http://crl.apple.com/root.crl0U0 *Hcd 0  *H  6qS#xe[#Ǣϴ(p!93rC=BQu]ˌjj:T}k>mzT_Cv\ N<>r4\g e0B4ӧBsu|QC`ܮ'kg3EoɘMiKEN"W""En?厸F\ɰ:m7(FeoUhR>?&:k22H;Kу000  *H 0b1 0 UUS10U  Apple Inc.1&0$U Apple Certification Authority10U Apple Root CA0 060425214036Z 350209214036Z0b1 0 UUS10U  Apple Inc.1&0$U Apple Certification Authority10U Apple Root CA0"0  *H 0 䑩 GP^y-6WLUKl"0>P Af$kУ*z G[73Mir]_%UM] d5#KYPXPg ˬ, op?0C=+I(ε^=: !.t< bqGSU/ApLE~LkPAtb A30XZ2hesg^eIv3ew-z0v0U0U00U+iGv k.@GM^0U#0+iGv k.@GM^0U 00 *Hcd00*+https://www.apple.com/appleca/0+0Reliance on this certificate by any party assumes acceptance of the then applicable standard terms and conditions of use, certificate policy and certification practice statements.0  *H \6L-x팛wvw0O=G7@,ԱؾsdyO4آ>xk}9S 8ıO k+Y |@Vtӷ#;Go$ѷpE'mx~"5%kԢ$#s`[ /DH`8=&g 3j /Sj[dc3w:,V!ںsO6U٧2Bq~RB$*M^cKP 7uu!1?0;00|100.U 'Apple Timestamp Certification Authority1&0$U Apple Certification Authority10U Apple Inc.1 0 UUStb M0 +0 *H  1  *H  0 *H  1 210628153649Z0# *H  12'uX