Edit: /opt/imh-python/lib/python3.9/lib-dynload/_heapq.cpython-39-x86_64-linux-gnu.so (25248B)
ELF > @ [ @ 8 @ ; ; @= @= @= X= X= X= 8 8 8 $ $ ; ; ; Std ; ; ; Ptd \6 \6 \6 Qtd Rtd @= @= @= GNU
1jQe @ BE|qXl 8 }
U j , F " c A v A j A * __gmon_start__ _ITM_deregisterTMCloneTable _ITM_registerTMCloneTable __cxa_finalize PyUnicode_FromString PyModule_AddObject _Py_Dealloc PyObject_RichCompareBool PyExc_RuntimeError PyErr_SetString PyExc_IndexError PyList_SetSlice PyExc_TypeError _PyArg_CheckPositional _Py_NoneStruct PyList_Append PyInit__heapq PyModuleDef_Init libpthread.so.0 libc.so.6 _edata __bss_start _end GLIBC_2.2.5 /opt/imh-python/lib Y ui { @= `
H=
P= P= (@ 0@ , @@ @ H@ @ @ p
@ @ @ 6 @ @ @ @ 2 @ @ P @ 5 A A P A 3 A (A 8A 2 @A HA 0 XA @2 `A hA xA 1 A z A A 1 ? ? ? ?
? ?
? ? p? x? ? ? ? ? ? ? ? ? HH4 HtH 53 %3 h h h h h h h h qh ah Q%U3 D %M3 D %E3 D %=3 D %53 D %-3 D %%3 D %3 D %3 D %
3 D H= 5 H5 H9tH2 Ht H=4 H54 H)HHH?HHtH2 HtfD =4 u+UH=2 HtH=0 Ydm4 ] w UHH= SHH5 HHHx 1H[]HHPHHuH߉D$eD$ff. @ AWAVAUATUSH(LoHt$I9 MHD$HHWIL9 I@ JIH8H9L0L9 K?HXHH4 H2L1L9}HL1HHIHL$HL$H)t6I.tFxVHUHL9m0 H4 H2L1l@ HωD$dI.D$uLD$ND$yH([]A\A]A^A_fHEHD$H9 L<2H;\$U fD I/ xH|$H;} HUHILIL8M>HL9l$ LCLIN$1MN4 I$LII,$uLD$I/D$sLD$eD$^@ H/ H5 H8RH([]A\A]A^A_fD H(1[]A\A]A^A_H/ H5# H8ff. AWAVAUATUSH(HGHt$HD$H9% HGIIHH;T$R H+ H|$I9} IEJIMI4$HI$H2L9t$}|IO1HHH,HIL$ HE HXHm uHD$%H+D$qH߉D$D$aH([]A\A]A^A_ 1H([]A\A]A^A_ Ha. H5r H8H([]A\A]A^A_HW. H5 H8f AWAVAUATUSH(LoH|$Ht$I99 HD$LL|$HHHI9|' f JIH0H2L0H9 K?HXHHL2L9}L$I1LI$LI.t/I,$t?xOHHD$HHL9huwHL2fD LD$I,$D$uLD$D$yH([]A\A]A^A_H\$Ht$H|$H(H[]A\A]A^A_\@ H, H5 H8BH([]A\A]A^A_H, H5* H8끐AVAUATUSHG HoHHtkHGI1HuHLdI$upMHtHC1HL(L Aօu[L]A\A]A^D Im tqE1[]LA\A]A^fH!, E1H5y H8g[L]A\A]A^ I,$uLE16@ H+ H5O E1H8'yfL HH5ff. fHH5Rff. fSHG t2H tKHGHHH01҅uH[H+tJ1fD H+ H5 1H8xfD H+ H5l 1H8XfD H16@ SHHtHֹ H=X ItHsH;H[11[ SHHtHֹ H= tHsH;H'[1[ AWAVAUATUSHHG ! LwHILHI XHy5HHt+HHAԅt1H[]A\A]A^A_HI9 H) H H[]A\A]A^A_ÐLk1f. IIuIIM}M9?IFHD$MfD AtILHAԅtlD IL;|$uIHI9iI AFILHAԅt f H( H5o H8J1 HH5ff. fHH5mff. fAUATUSHHHt!Hֹ H=, H+H[HE H} uHHH[]A\A] HE1HL I$LI,$AtUEx;tH} twHE1HL HHLtI,$uLH1H[]A\A]D L fD H' H5 1H8F H' H5 1H8&ff. UHSHHtHֹ H= tfH] HuHC t;HuEHC1HHP]u/H& H H[] H& H5O H8*H1[]ÐH=& HH __about__ index out of range heap argument must be a list _heapreplace_max heapreplace heappushpop heappush _heapq heappop heapify _heappop_max _heapify_max list changed size during iteration 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! :-)
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!
_heapify_max($module, heap, /)
--
Maxheap variant of heapify. _heapreplace_max($module, heap, item, /)
--
Maxheap variant of heapreplace. _heappop_max($module, heap, /)
--
Maxheap variant of heappop. heapify($module, heap, /)
--
Transform list into a heap, in-place, in O(len(heap)) time. 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(). 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) heappop($module, heap, /)
--
Pop the smallest item off the heap, maintaining the heap invariant. heappush($module, heap, item, /)
--
Push item onto heap, maintaining the heap invariant. ; T < \ D| $X zR x $ H FJw ?:*3$" D ( \ a EKD0d
AAA x \T FBB B(A0A8D`
8F0A(B BBBC
8F0A(B BBBGD
8C0A(B BBBAx @g BBB B(A0A8D`
8F0A(B BBBDF
8A0A(B BBBHZ
8F0A(B BBBA x 4 FBB B(A0A8D`
8A0A(B BBBAS
8D0A(B BBBIZ
8F0A(B BBBA ` 8 BBB A(A0`
(D BBBFK
(A EBBCZ
(D BBBD ` t An
A `H Eu
FG H Eu
FG ` ] BBB B(A0A8DPO
8A0A(B BBBA\
8A0A(B BBBB H \ L p 5 FBA A(G0N
(D ABBHg
(F ABBF 0 EDD m
AADZCA 0 GNU `
P= I Y @
0 @= H= o `
X? P
o o p o o D o X= p , @ @ p
6 @ 2 P 5 P 3 2 0 @2 1 z 1 GCC: (GNU) 8.5.0 20210514 (Red Hat 8.5.0-26) GA$3a1 @ = GA$3p1113 p
0 GA* GA$annobin gcc 8.5.0 20210514 GA$plugin name: gcc-annobin GA$running gcc 8.5.0 20210514 GA* GA* GA!
GA*FORTIFY GA+GLIBCXX_ASSERTIONS GA*GOW * GA*cf_protection GA+omit_frame_pointer GA+stack_clash GA!stack_realign
GA*FORTIFY p
GA+GLIBCXX_ASSERTIONS p
0 5 Q q 9 p
S
k p
a v p
4
T 4 @ g
/ % / E - c 0 t - C 0 C c P c 9 [ p p H H H P H ) I g ] x 3
3 ; u [ @ 5 n u 0 @ h ,
@ @ $ 6 Z ; 2 U 5 b k 3 2 Z @2 ? 1 ? 1 M
A * H= Q `
] @= | :
0 P= X= \6 A X? @ 8 ` D p P
@
`
0 @ \6 6 ; @= H= P= X= X? @ A A` A % 1 D T d } 0 A A - " .annobin__heapqmodule.c .annobin__heapqmodule.c_end .annobin__heapqmodule.c.hot .annobin__heapqmodule.c_end.hot .annobin__heapqmodule.c.unlikely .annobin__heapqmodule.c_end.unlikely .annobin__heapqmodule.c.startup .annobin__heapqmodule.c_end.startup .annobin__heapqmodule.c.exit .annobin__heapqmodule.c_end.exit .annobin_heapq_exec.start .annobin_heapq_exec.end heapq_exec __about__ .annobin_siftup_max.start .annobin_siftup_max.end siftup_max .annobin_siftdown.start .annobin_siftdown.end siftdown .annobin_siftup.start .annobin_siftup.end siftup .annobin_heappop_internal.start .annobin_heappop_internal.end heappop_internal .annobin__heapq__heappop_max.start .annobin__heapq__heappop_max.end _heapq__heappop_max .annobin__heapq_heappop.start .annobin__heapq_heappop.end _heapq_heappop .annobin_heapreplace_internal.start .annobin_heapreplace_internal.end heapreplace_internal .annobin__heapq__heapreplace_max.start .annobin__heapq__heapreplace_max.end _heapq__heapreplace_max .annobin__heapq_heapreplace.start .annobin__heapq_heapreplace.end _heapq_heapreplace .annobin_heapify_internal.start .annobin_heapify_internal.end heapify_internal .annobin__heapq__heapify_max.start .annobin__heapq__heapify_max.end _heapq__heapify_max .annobin__heapq_heapify.start .annobin__heapq_heapify.end _heapq_heapify .annobin__heapq_heappushpop.start .annobin__heapq_heappushpop.end _heapq_heappushpop .annobin__heapq_heappush.start .annobin__heapq_heappush.end _heapq_heappush .annobin_PyInit__heapq.start .annobin_PyInit__heapq.end _heapqmodule module_doc heapq_methods heapq_slots _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__ deregister_tm_clones __do_global_dtors_aux completed.7303 __do_global_dtors_aux_fini_array_entry frame_dummy __frame_dummy_init_array_entry __FRAME_END__ _fini __dso_handle _DYNAMIC __GNU_EH_FRAME_HDR __TMC_END__ _GLOBAL_OFFSET_TABLE_ _init _ITM_deregisterTMCloneTable PyModuleDef_Init PyList_SetSlice _edata _Py_Dealloc PyExc_RuntimeError PyErr_SetString PyExc_TypeError PyObject_RichCompareBool PyList_Append __gmon_start__ PyInit__heapq _PyArg_CheckPositional _Py_NoneStruct __bss_start PyExc_IndexError PyUnicode_FromString PyModule_AddObject _ITM_registerTMCloneTable __cxa_finalize@@GLIBC_2.2.5 .symtab .strtab .shstrtab .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt.sec .text .fini .rodata .eh_frame_hdr .eh_frame .note.gnu.property .init_array .fini_array .data.rel.ro .dynamic .got .data .bss .comment .gnu.build.attributes 8 8 $ . o ` ` 4 8 @ H o D D , U o p p d n B P
P
x @ @ s ` ` ~ 0 0
@ @ \6 \6 6 6 ; ; @= @= H= H= P= P= X= X= X? X? @ @ A A 0 A -
A` A H 8D x p P I Y #