home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume34 / flogger / part01 next >
SHell self-extracting ARchive  |  1992-12-18  |  52.9 KB

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: SHell self-extracting ARchive (archive/shar).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert SHell self-extracting ARchive (archive/shar) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file Nim source code, ASCII text default (weak)
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/329 Shell Archive Format default
100% detectItEasy Format: plain text[LF] default (weak)



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 4e 65 77 73 67 72 6f 75 | 70 73 3a 20 63 6f 6d 70 |Newsgrou|ps: comp|
|00000010| 2e 73 6f 75 72 63 65 73 | 2e 6d 69 73 63 0a 46 72 |.sources|.misc.Fr|
|00000020| 6f 6d 3a 20 6d 69 6b 65 | 79 40 6f 6e 74 65 6b 2e |om: mike|y@ontek.|
|00000030| 63 6f 6d 20 28 4d 69 6b | 65 20 4c 65 65 29 0a 53 |com (Mik|e Lee).S|
|00000040| 75 62 6a 65 63 74 3a 20 | 20 76 33 34 69 30 37 33 |ubject: | v34i073|
|00000050| 3a 20 20 66 6c 6f 67 67 | 65 72 20 2d 20 53 6f 72 |: flogg|er - Sor|
|00000060| 74 20 46 6c 6f 67 67 65 | 72 20 76 30 2e 30 2c 20 |t Flogge|r v0.0, |
|00000070| 50 61 72 74 30 31 2f 30 | 32 0a 4d 65 73 73 61 67 |Part01/0|2.Messag|
|00000080| 65 2d 49 44 3a 20 3c 63 | 73 6d 2d 76 33 34 69 30 |e-ID: <c|sm-v34i0|
|00000090| 37 33 3d 66 6c 6f 67 67 | 65 72 2e 30 39 31 38 31 |73=flogg|er.09181|
|000000a0| 38 40 73 70 61 72 6b 79 | 2e 49 4d 44 2e 53 74 65 |8@sparky|.IMD.Ste|
|000000b0| 72 6c 69 6e 67 2e 43 4f | 4d 3e 0a 58 2d 4d 64 34 |rling.CO|M>.X-Md4|
|000000c0| 2d 53 69 67 6e 61 74 75 | 72 65 3a 20 66 66 30 61 |-Signatu|re: ff0a|
|000000d0| 64 61 30 34 61 64 37 34 | 34 39 62 36 61 35 61 66 |da04ad74|49b6a5af|
|000000e0| 36 30 39 39 31 65 33 63 | 65 32 61 32 0a 44 61 74 |60991e3c|e2a2.Dat|
|000000f0| 65 3a 20 46 72 69 2c 20 | 31 38 20 44 65 63 20 31 |e: Fri, |18 Dec 1|
|00000100| 39 39 32 20 31 35 3a 32 | 31 3a 34 36 20 47 4d 54 |992 15:2|1:46 GMT|
|00000110| 0a 41 70 70 72 6f 76 65 | 64 3a 20 6b 65 6e 74 40 |.Approve|d: kent@|
|00000120| 73 70 61 72 6b 79 2e 69 | 6d 64 2e 73 74 65 72 6c |sparky.i|md.sterl|
|00000130| 69 6e 67 2e 63 6f 6d 0a | 0a 53 75 62 6d 69 74 74 |ing.com.|.Submitt|
|00000140| 65 64 2d 62 79 3a 20 6d | 69 6b 65 79 40 6f 6e 74 |ed-by: m|ikey@ont|
|00000150| 65 6b 2e 63 6f 6d 20 28 | 4d 69 6b 65 20 4c 65 65 |ek.com (|Mike Lee|
|00000160| 29 0a 50 6f 73 74 69 6e | 67 2d 6e 75 6d 62 65 72 |).Postin|g-number|
|00000170| 3a 20 56 6f 6c 75 6d 65 | 20 33 34 2c 20 49 73 73 |: Volume| 34, Iss|
|00000180| 75 65 20 37 33 0a 41 72 | 63 68 69 76 65 2d 6e 61 |ue 73.Ar|chive-na|
|00000190| 6d 65 3a 20 66 6c 6f 67 | 67 65 72 2f 70 61 72 74 |me: flog|ger/part|
|000001a0| 30 31 0a 45 6e 76 69 72 | 6f 6e 6d 65 6e 74 3a 20 |01.Envir|onment: |
|000001b0| 55 4e 49 58 0a 0a 54 68 | 69 73 20 69 73 20 61 20 |UNIX..Th|is is a |
|000001c0| 73 6d 61 6c 6c 20 63 6f | 6c 6c 65 63 74 69 6f 6e |small co|llection|
|000001d0| 20 6f 66 20 73 6f 6d 65 | 20 6f 66 20 74 68 65 20 | of some| of the |
|000001e0| 6d 6f 72 65 20 70 6f 70 | 75 6c 61 72 20 73 6f 72 |more pop|ular sor|
|000001f0| 74 0a 61 6c 67 6f 72 69 | 74 68 6d 73 2c 20 69 6e |t.algori|thms, in|
|00000200| 63 6c 75 64 69 6e 67 3a | 0a 0a 20 20 20 20 20 20 |cluding:|.. |
|00000210| 62 75 62 62 6c 65 20 73 | 6f 72 74 20 2d 2d 20 61 |bubble s|ort -- a|
|00000220| 6e 79 20 31 73 74 20 73 | 65 6d 65 73 74 65 72 20 |ny 1st s|emester |
|00000230| 63 6f 75 72 73 65 20 69 | 6e 20 43 53 0a 20 20 20 |course i|n CS. |
|00000240| 20 20 20 68 65 61 70 20 | 73 6f 72 74 20 2d 2d 20 | heap |sort -- |
|00000250| 63 6f 6e 74 72 69 62 75 | 74 65 64 20 62 79 20 64 |contribu|ted by d|
|00000260| 65 72 20 4d 6f 75 73 65 | 0a 20 20 20 20 20 20 69 |er Mouse|. i|
|00000270| 6e 73 65 72 74 69 6f 6e | 20 73 6f 72 74 20 2d 2d |nsertion| sort --|
|00000280| 20 61 6e 79 20 31 73 74 | 20 73 65 6d 65 73 74 65 | any 1st| semeste|
|00000290| 72 20 63 6f 75 72 73 65 | 20 69 6e 20 43 53 0a 20 |r course| in CS. |
|000002a0| 20 20 20 20 20 6d 65 72 | 67 65 20 73 6f 72 74 20 | mer|ge sort |
|000002b0| 2d 2d 20 72 6f 75 67 68 | 6c 79 20 70 61 74 74 65 |-- rough|ly patte|
|000002c0| 72 6e 65 64 20 61 66 74 | 65 72 20 4b 6e 75 74 68 |rned aft|er Knuth|
|000002d0| 20 56 6f 6c 2e 20 33 0a | 20 20 20 20 20 20 71 75 | Vol. 3.| qu|
|000002e0| 69 63 6b 20 73 6f 72 74 | 20 2d 2d 20 43 2e 41 2e |ick sort| -- C.A.|
|000002f0| 52 2e 20 48 6f 61 72 65 | 27 73 20 61 73 20 67 69 |R. Hoare|'s as gi|
|00000300| 76 65 6e 20 69 6e 20 4b | 26 52 20 32 20 70 67 20 |ven in K|&R 2 pg |
|00000310| 38 37 0a 20 20 20 20 20 | 20 73 68 65 6c 6c 20 73 |87. | shell s|
|00000320| 6f 72 74 20 2d 2d 20 44 | 2e 4c 2e 20 53 68 65 6c |ort -- D|.L. Shel|
|00000330| 6c 20 61 73 20 67 69 76 | 65 6e 20 69 6e 20 4b 26 |l as giv|en in K&|
|00000340| 52 20 32 20 70 67 20 36 | 32 0a 20 20 20 20 20 20 |R 2 pg 6|2. |
|00000350| 62 6f 67 6f 20 73 6f 72 | 74 20 2d 2d 20 77 6f 72 |bogo sor|t -- wor|
|00000360| 73 74 2d 63 61 73 65 20 | 73 6f 72 74 20 62 79 20 |st-case |sort by |
|00000370| 52 69 63 68 61 72 64 20 | 4b 72 65 68 62 69 65 6c |Richard |Krehbiel|
|00000380| 0a 0a 41 20 73 6c 69 67 | 68 74 6c 79 20 77 65 69 |..A slig|htly wei|
|00000390| 72 64 20 74 65 73 74 20 | 72 6f 75 74 69 6e 65 20 |rd test |routine |
|000003a0| 69 73 20 70 72 6f 76 69 | 64 65 64 20 77 68 69 63 |is provi|ded whic|
|000003b0| 68 20 63 61 6c 63 75 6c | 61 74 65 73 20 73 6f 6d |h calcul|ates som|
|000003c0| 65 0a 70 65 72 66 6f 72 | 6d 61 6e 63 65 20 6d 65 |e.perfor|mance me|
|000003d0| 61 73 75 72 65 6d 65 6e | 74 73 20 6f 6e 20 74 68 |asuremen|ts on th|
|000003e0| 65 20 61 62 6f 76 65 20 | 61 6c 67 6f 72 69 74 68 |e above |algorith|
|000003f0| 6d 73 20 61 6e 64 20 61 | 6c 73 6f 20 6f 6e 20 74 |ms and a|lso on t|
|00000400| 68 65 0a 71 73 6f 72 74 | 28 29 20 66 75 6e 63 74 |he.qsort|() funct|
|00000410| 69 6f 6e 20 70 72 6f 76 | 69 64 65 64 20 77 69 74 |ion prov|ided wit|
|00000420| 68 20 79 6f 75 72 20 73 | 79 73 74 65 6d 2c 20 61 |h your s|ystem, a|
|00000430| 73 20 77 65 6c 6c 20 61 | 73 20 76 65 72 69 66 79 |s well a|s verify|
|00000440| 69 6e 67 20 74 68 61 74 | 0a 74 68 65 20 73 6f 72 |ing that|.the sor|
|00000450| 74 20 61 63 74 75 61 6c | 6c 79 20 77 6f 72 6b 65 |t actual|ly worke|
|00000460| 64 20 61 6e 64 20 74 68 | 61 74 20 69 74 20 64 69 |d and th|at it di|
|00000470| 64 6e 27 74 20 6d 6f 64 | 69 66 79 20 61 6e 79 74 |dn't mod|ify anyt|
|00000480| 68 69 6e 67 20 69 6d 6d | 65 64 69 61 74 65 6c 79 |hing imm|ediately|
|00000490| 0a 61 62 6f 76 65 20 6f | 72 20 62 65 6c 6f 77 20 |.above o|r below |
|000004a0| 74 68 65 20 61 72 72 61 | 79 2c 20 74 68 61 74 20 |the arra|y, that |
|000004b0| 69 74 20 64 6f 65 73 6e | 27 74 20 6c 65 61 6b 20 |it doesn|'t leak |
|000004c0| 6d 65 6d 6f 72 79 2c 20 | 61 6e 64 20 77 68 65 74 |memory, |and whet|
|000004d0| 68 65 72 0a 6f 72 20 6e | 6f 74 20 69 74 27 73 20 |her.or n|ot it's |
|000004e0| 73 74 61 62 6c 65 2e 20 | 20 54 68 65 73 65 20 74 |stable. | These t|
|000004f0| 65 73 74 73 20 61 72 65 | 20 63 61 72 72 69 65 64 |ests are| carried|
|00000500| 20 6f 75 74 20 69 6e 20 | 61 20 76 61 72 69 65 74 | out in |a variet|
|00000510| 79 20 6f 66 0a 73 69 74 | 75 61 74 69 6f 6e 73 20 |y of.sit|uations |
|00000520| 64 65 73 69 67 6e 65 64 | 20 74 6f 20 68 69 67 68 |designed| to high|
|00000530| 6c 69 67 68 74 20 77 6f | 72 73 74 2d 63 61 73 65 |light wo|rst-case|
|00000540| 20 62 65 68 61 76 69 6f | 72 2e 0a 0a 54 68 65 73 | behavio|r...Thes|
|00000550| 65 20 69 6d 70 6c 65 6d | 65 6e 74 61 74 69 6f 6e |e implem|entation|
|00000560| 73 20 6f 66 20 74 68 65 | 20 73 6f 72 74 20 66 75 |s of the| sort fu|
|00000570| 6e 63 74 69 6f 6e 73 20 | 61 72 65 20 61 6c 6c 20 |nctions |are all |
|00000580| 63 6f 6d 70 61 74 69 62 | 6c 65 20 77 69 74 68 0a |compatib|le with.|
|00000590| 71 73 6f 72 74 28 29 27 | 73 20 70 61 72 61 6d 65 |qsort()'|s parame|
|000005a0| 74 65 72 20 6c 69 73 74 | 2c 20 73 6f 20 69 66 20 |ter list|, so if |
|000005b0| 79 6f 75 20 74 68 69 6e | 6b 20 79 6f 75 72 20 61 |you thin|k your a|
|000005c0| 70 70 6c 69 63 61 74 69 | 6f 6e 20 73 70 65 6e 64 |pplicati|on spend|
|000005d0| 73 20 74 6f 6f 0a 6d 75 | 63 68 20 74 69 6d 65 20 |s too.mu|ch time |
|000005e0| 73 6f 72 74 69 6e 67 2c | 20 79 6f 75 20 63 61 6e |sorting,| you can|
|000005f0| 20 6a 75 73 74 20 73 2f | 71 73 6f 72 74 2f 6d 65 | just s/|qsort/me|
|00000600| 72 67 65 5f 73 6f 72 74 | 2f 20 61 6e 64 20 6c 69 |rge_sort|/ and li|
|00000610| 6e 6b 20 69 6e 20 74 68 | 65 0a 73 6f 72 74 20 6c |nk in th|e.sort l|
|00000620| 69 62 72 61 72 79 20 61 | 6e 64 20 67 69 76 65 20 |ibrary a|nd give |
|00000630| 69 74 20 61 20 74 72 79 | 2e 20 20 49 66 20 79 6f |it a try|. If yo|
|00000640| 75 20 74 68 69 6e 6b 20 | 69 74 20 64 6f 65 73 6e |u think |it doesn|
|00000650| 27 74 20 73 70 65 6e 64 | 20 2a 65 6e 6f 75 67 68 |'t spend| *enough|
|00000660| 2a 0a 74 69 6d 65 20 73 | 6f 72 74 69 6e 67 2c 20 |*.time s|orting, |
|00000670| 74 72 79 20 62 75 62 62 | 6c 65 5f 73 6f 72 74 20 |try bubb|le_sort |
|00000680| 69 6e 73 74 65 61 64 2e | 0a 0a 54 68 65 20 68 65 |instead.|..The he|
|00000690| 61 70 73 6f 72 74 20 77 | 61 73 20 63 6f 6e 74 72 |apsort w|as contr|
|000006a0| 69 62 75 74 65 64 20 62 | 79 20 6d 6f 75 73 65 40 |ibuted b|y mouse@|
|000006b0| 6c 61 72 72 79 2e 6d 63 | 72 63 69 6d 2e 6d 63 67 |larry.mc|rcim.mcg|
|000006c0| 69 6c 6c 2e 65 64 75 0a | 61 6b 61 20 22 64 65 72 |ill.edu.|aka "der|
|000006d0| 20 4d 6f 75 73 65 22 2e | 0a 2d 2d 2d 2d 2d 2d 0a | Mouse".|.------.|
|000006e0| 23 21 20 2f 62 69 6e 2f | 73 68 0a 23 20 54 68 69 |#! /bin/|sh.# Thi|
|000006f0| 73 20 69 73 20 61 20 73 | 68 65 6c 6c 20 61 72 63 |s is a s|hell arc|
|00000700| 68 69 76 65 2e 20 20 52 | 65 6d 6f 76 65 20 61 6e |hive. R|emove an|
|00000710| 79 74 68 69 6e 67 20 62 | 65 66 6f 72 65 20 74 68 |ything b|efore th|
|00000720| 69 73 20 6c 69 6e 65 2c | 20 74 68 65 6e 20 66 65 |is line,| then fe|
|00000730| 65 64 20 69 74 0a 23 20 | 69 6e 74 6f 20 61 20 73 |ed it.# |into a s|
|00000740| 68 65 6c 6c 20 76 69 61 | 20 22 73 68 20 66 69 6c |hell via| "sh fil|
|00000750| 65 22 20 6f 72 20 73 69 | 6d 69 6c 61 72 2e 20 20 |e" or si|milar. |
|00000760| 54 6f 20 6f 76 65 72 77 | 72 69 74 65 20 65 78 69 |To overw|rite exi|
|00000770| 73 74 69 6e 67 20 66 69 | 6c 65 73 2c 0a 23 20 74 |sting fi|les,.# t|
|00000780| 79 70 65 20 22 73 68 20 | 66 69 6c 65 20 2d 63 22 |ype "sh |file -c"|
|00000790| 2e 0a 23 20 43 6f 6e 74 | 65 6e 74 73 3a 20 20 52 |..# Cont|ents: R|
|000007a0| 45 41 44 4d 45 20 4f 50 | 54 49 4d 49 5a 49 4e 47 |EADME OP|TIMIZING|
|000007b0| 20 54 4f 44 4f 20 66 6c | 6f 67 67 65 72 2e 63 20 | TODO fl|ogger.c |
|000007c0| 68 65 61 70 5f 73 6f 72 | 74 2e 63 20 6d 65 72 67 |heap_sor|t.c merg|
|000007d0| 65 5f 73 6f 72 74 2e 63 | 0a 23 20 20 20 71 75 69 |e_sort.c|.# qui|
|000007e0| 63 6b 5f 73 6f 72 74 2e | 63 0a 23 20 57 72 61 70 |ck_sort.|c.# Wrap|
|000007f0| 70 65 64 20 62 79 20 6b | 65 6e 74 40 73 70 61 72 |ped by k|ent@spar|
|00000800| 6b 79 20 6f 6e 20 54 68 | 75 20 44 65 63 20 31 37 |ky on Th|u Dec 17|
|00000810| 20 31 33 3a 35 30 3a 33 | 34 20 31 39 39 32 0a 50 | 13:50:3|4 1992.P|
|00000820| 41 54 48 3d 2f 62 69 6e | 3a 2f 75 73 72 2f 62 69 |ATH=/bin|:/usr/bi|
|00000830| 6e 3a 2f 75 73 72 2f 75 | 63 62 3a 2f 75 73 72 2f |n:/usr/u|cb:/usr/|
|00000840| 6c 6f 63 61 6c 2f 62 69 | 6e 3a 2f 75 73 72 2f 6c |local/bi|n:/usr/l|
|00000850| 62 69 6e 20 3b 20 65 78 | 70 6f 72 74 20 50 41 54 |bin ; ex|port PAT|
|00000860| 48 0a 65 63 68 6f 20 49 | 66 20 74 68 69 73 20 61 |H.echo I|f this a|
|00000870| 72 63 68 69 76 65 20 69 | 73 20 63 6f 6d 70 6c 65 |rchive i|s comple|
|00000880| 74 65 2c 20 79 6f 75 20 | 77 69 6c 6c 20 73 65 65 |te, you |will see|
|00000890| 20 74 68 65 20 66 6f 6c | 6c 6f 77 69 6e 67 20 6d | the fol|lowing m|
|000008a0| 65 73 73 61 67 65 3a 0a | 65 63 68 6f 20 27 20 20 |essage:.|echo ' |
|000008b0| 20 20 20 20 20 20 20 20 | 22 73 68 61 72 3a 20 45 | |"shar: E|
|000008c0| 6e 64 20 6f 66 20 61 72 | 63 68 69 76 65 20 31 20 |nd of ar|chive 1 |
|000008d0| 28 6f 66 20 32 29 2e 22 | 27 0a 69 66 20 74 65 73 |(of 2)."|'.if tes|
|000008e0| 74 20 2d 66 20 27 52 45 | 41 44 4d 45 27 20 2d 61 |t -f 'RE|ADME' -a|
|000008f0| 20 22 24 7b 31 7d 22 20 | 21 3d 20 22 2d 63 22 20 | "${1}" |!= "-c" |
|00000900| 3b 20 74 68 65 6e 20 0a | 20 20 65 63 68 6f 20 73 |; then .| echo s|
|00000910| 68 61 72 3a 20 57 69 6c | 6c 20 6e 6f 74 20 63 6c |har: Wil|l not cl|
|00000920| 6f 62 62 65 72 20 65 78 | 69 73 74 69 6e 67 20 66 |obber ex|isting f|
|00000930| 69 6c 65 20 5c 22 27 52 | 45 41 44 4d 45 27 5c 22 |ile \"'R|EADME'\"|
|00000940| 0a 65 6c 73 65 0a 20 20 | 65 63 68 6f 20 73 68 61 |.else. |echo sha|
|00000950| 72 3a 20 45 78 74 72 61 | 63 74 69 6e 67 20 5c 22 |r: Extra|cting \"|
|00000960| 27 52 45 41 44 4d 45 27 | 5c 22 20 5c 28 37 39 39 |'README'|\" \(799|
|00000970| 33 20 63 68 61 72 61 63 | 74 65 72 73 5c 29 0a 20 |3 charac|ters\). |
|00000980| 20 73 65 64 20 22 73 2f | 5e 58 2f 2f 22 20 3e 27 | sed "s/|^X//" >'|
|00000990| 52 45 41 44 4d 45 27 20 | 3c 3c 27 45 4e 44 5f 4f |README' |<<'END_O|
|000009a0| 46 5f 46 49 4c 45 27 0a | 58 0a 58 56 45 52 53 49 |F_FILE'.|X.XVERSI|
|000009b0| 4f 4e 0a 58 0a 58 20 20 | 20 20 54 68 69 73 20 69 |ON.X.X | This i|
|000009c0| 73 20 76 65 72 73 69 6f | 6e 20 30 20 6f 66 20 74 |s versio|n 0 of t|
|000009d0| 68 65 20 74 68 65 20 53 | 6f 72 74 20 46 6c 6f 67 |he the S|ort Flog|
|000009e0| 67 65 72 2e 0a 58 0a 58 | 4f 56 45 52 56 49 45 57 |ger..X.X|OVERVIEW|
|000009f0| 0a 58 0a 58 20 20 20 20 | 54 68 69 73 20 69 73 20 |.X.X |This is |
|00000a00| 61 20 73 6d 61 6c 6c 20 | 63 6f 6c 6c 65 63 74 69 |a small |collecti|
|00000a10| 6f 6e 20 6f 66 20 73 6f | 6d 65 20 6f 66 20 74 68 |on of so|me of th|
|00000a20| 65 20 6d 6f 72 65 20 70 | 6f 70 75 6c 61 72 20 73 |e more p|opular s|
|00000a30| 6f 72 74 0a 58 61 6c 67 | 6f 72 69 74 68 6d 73 2c |ort.Xalg|orithms,|
|00000a40| 20 69 6e 63 6c 75 64 69 | 6e 67 3a 0a 58 0a 58 20 | includi|ng:.X.X |
|00000a50| 20 20 20 20 20 62 75 62 | 62 6c 65 20 73 6f 72 74 | bub|ble sort|
|00000a60| 20 2d 2d 20 61 6e 79 20 | 31 73 74 20 73 65 6d 65 | -- any |1st seme|
|00000a70| 73 74 65 72 20 63 6f 75 | 72 73 65 20 69 6e 20 43 |ster cou|rse in C|
|00000a80| 53 0a 58 20 20 20 20 20 | 20 68 65 61 70 20 73 6f |S.X | heap so|
|00000a90| 72 74 20 2d 2d 20 63 6f | 6e 74 72 69 62 75 74 65 |rt -- co|ntribute|
|00000aa0| 64 20 62 79 20 64 65 72 | 20 4d 6f 75 73 65 0a 58 |d by der| Mouse.X|
|00000ab0| 20 20 20 20 20 20 69 6e | 73 65 72 74 69 6f 6e 20 | in|sertion |
|00000ac0| 73 6f 72 74 20 2d 2d 20 | 61 6e 79 20 31 73 74 20 |sort -- |any 1st |
|00000ad0| 73 65 6d 65 73 74 65 72 | 20 63 6f 75 72 73 65 20 |semester| course |
|00000ae0| 69 6e 20 43 53 0a 58 20 | 20 20 20 20 20 6d 65 72 |in CS.X | mer|
|00000af0| 67 65 20 73 6f 72 74 20 | 2d 2d 20 72 6f 75 67 68 |ge sort |-- rough|
|00000b00| 6c 79 20 70 61 74 74 65 | 72 6e 65 64 20 61 66 74 |ly patte|rned aft|
|00000b10| 65 72 20 4b 6e 75 74 68 | 20 56 6f 6c 2e 20 33 0a |er Knuth| Vol. 3.|
|00000b20| 58 20 20 20 20 20 20 71 | 75 69 63 6b 20 73 6f 72 |X q|uick sor|
|00000b30| 74 20 2d 2d 20 43 2e 41 | 2e 52 2e 20 48 6f 61 72 |t -- C.A|.R. Hoar|
|00000b40| 65 27 73 20 61 73 20 67 | 69 76 65 6e 20 69 6e 20 |e's as g|iven in |
|00000b50| 4b 26 52 20 32 20 70 67 | 20 38 37 0a 58 20 20 20 |K&R 2 pg| 87.X |
|00000b60| 20 20 20 73 68 65 6c 6c | 20 73 6f 72 74 20 2d 2d | shell| sort --|
|00000b70| 20 44 2e 4c 2e 20 53 68 | 65 6c 6c 20 61 73 20 67 | D.L. Sh|ell as g|
|00000b80| 69 76 65 6e 20 69 6e 20 | 4b 26 52 20 32 20 70 67 |iven in |K&R 2 pg|
|00000b90| 20 36 32 0a 58 20 20 20 | 20 20 20 62 6f 67 6f 20 | 62.X | bogo |
|00000ba0| 73 6f 72 74 20 2d 2d 20 | 77 6f 72 73 74 2d 63 61 |sort -- |worst-ca|
|00000bb0| 73 65 20 73 6f 72 74 20 | 62 79 20 52 69 63 68 61 |se sort |by Richa|
|00000bc0| 72 64 20 4b 72 65 68 62 | 69 65 6c 0a 58 0a 58 20 |rd Krehb|iel.X.X |
|00000bd0| 20 20 20 41 20 73 6c 69 | 67 68 74 6c 79 20 77 65 | A sli|ghtly we|
|00000be0| 69 72 64 20 74 65 73 74 | 20 72 6f 75 74 69 6e 65 |ird test| routine|
|00000bf0| 20 69 73 20 70 72 6f 76 | 69 64 65 64 20 77 68 69 | is prov|ided whi|
|00000c00| 63 68 20 63 61 6c 63 75 | 6c 61 74 65 73 20 73 6f |ch calcu|lates so|
|00000c10| 6d 65 0a 58 70 65 72 66 | 6f 72 6d 61 6e 63 65 20 |me.Xperf|ormance |
|00000c20| 6d 65 61 73 75 72 65 6d | 65 6e 74 73 20 6f 6e 20 |measurem|ents on |
|00000c30| 74 68 65 20 61 62 6f 76 | 65 20 61 6c 67 6f 72 69 |the abov|e algori|
|00000c40| 74 68 6d 73 20 61 6e 64 | 20 61 6c 73 6f 20 6f 6e |thms and| also on|
|00000c50| 20 74 68 65 0a 58 71 73 | 6f 72 74 28 29 20 66 75 | the.Xqs|ort() fu|
|00000c60| 6e 63 74 69 6f 6e 20 70 | 72 6f 76 69 64 65 64 20 |nction p|rovided |
|00000c70| 77 69 74 68 20 79 6f 75 | 72 20 73 79 73 74 65 6d |with you|r system|
|00000c80| 2c 20 61 73 20 77 65 6c | 6c 20 61 73 20 76 65 72 |, as wel|l as ver|
|00000c90| 69 66 79 69 6e 67 20 74 | 68 61 74 0a 58 74 68 65 |ifying t|hat.Xthe|
|00000ca0| 20 73 6f 72 74 20 61 63 | 74 75 61 6c 6c 79 20 77 | sort ac|tually w|
|00000cb0| 6f 72 6b 65 64 20 61 6e | 64 20 74 68 61 74 20 69 |orked an|d that i|
|00000cc0| 74 20 64 69 64 6e 27 74 | 20 6d 6f 64 69 66 79 20 |t didn't| modify |
|00000cd0| 61 6e 79 74 68 69 6e 67 | 20 69 6d 6d 65 64 69 61 |anything| immedia|
|00000ce0| 74 65 6c 79 0a 58 61 62 | 6f 76 65 20 6f 72 20 62 |tely.Xab|ove or b|
|00000cf0| 65 6c 6f 77 20 74 68 65 | 20 61 72 72 61 79 2c 20 |elow the| array, |
|00000d00| 74 68 61 74 20 69 74 20 | 64 6f 65 73 6e 27 74 20 |that it |doesn't |
|00000d10| 6c 65 61 6b 20 6d 65 6d | 6f 72 79 2c 20 61 6e 64 |leak mem|ory, and|
|00000d20| 20 77 68 65 74 68 65 72 | 0a 58 6f 72 20 6e 6f 74 | whether|.Xor not|
|00000d30| 20 69 74 27 73 20 73 74 | 61 62 6c 65 2e 20 20 54 | it's st|able. T|
|00000d40| 68 65 73 65 20 74 65 73 | 74 73 20 61 72 65 20 63 |hese tes|ts are c|
|00000d50| 61 72 72 69 65 64 20 6f | 75 74 20 69 6e 20 61 20 |arried o|ut in a |
|00000d60| 76 61 72 69 65 74 79 20 | 6f 66 0a 58 73 69 74 75 |variety |of.Xsitu|
|00000d70| 61 74 69 6f 6e 73 20 64 | 65 73 69 67 6e 65 64 20 |ations d|esigned |
|00000d80| 74 6f 20 68 69 67 68 6c | 69 67 68 74 20 77 6f 72 |to highl|ight wor|
|00000d90| 73 74 2d 63 61 73 65 20 | 62 65 68 61 76 69 6f 72 |st-case |behavior|
|00000da0| 2e 0a 58 0a 58 20 20 20 | 20 54 68 65 73 65 20 69 |..X.X | These i|
|00000db0| 6d 70 6c 65 6d 65 6e 74 | 61 74 69 6f 6e 73 20 6f |mplement|ations o|
|00000dc0| 66 20 74 68 65 20 73 6f | 72 74 20 66 75 6e 63 74 |f the so|rt funct|
|00000dd0| 69 6f 6e 73 20 61 72 65 | 20 61 6c 6c 20 63 6f 6d |ions are| all com|
|00000de0| 70 61 74 69 62 6c 65 20 | 77 69 74 68 0a 58 71 73 |patible |with.Xqs|
|00000df0| 6f 72 74 28 29 27 73 20 | 70 61 72 61 6d 65 74 65 |ort()'s |paramete|
|00000e00| 72 20 6c 69 73 74 2c 20 | 73 6f 20 69 66 20 79 6f |r list, |so if yo|
|00000e10| 75 20 74 68 69 6e 6b 20 | 79 6f 75 72 20 61 70 70 |u think |your app|
|00000e20| 6c 69 63 61 74 69 6f 6e | 20 73 70 65 6e 64 73 20 |lication| spends |
|00000e30| 74 6f 6f 0a 58 6d 75 63 | 68 20 74 69 6d 65 20 73 |too.Xmuc|h time s|
|00000e40| 6f 72 74 69 6e 67 2c 20 | 79 6f 75 20 63 61 6e 20 |orting, |you can |
|00000e50| 6a 75 73 74 20 73 2f 71 | 73 6f 72 74 2f 6d 65 72 |just s/q|sort/mer|
|00000e60| 67 65 5f 73 6f 72 74 2f | 20 61 6e 64 20 6c 69 6e |ge_sort/| and lin|
|00000e70| 6b 20 69 6e 20 74 68 65 | 0a 58 73 6f 72 74 20 6c |k in the|.Xsort l|
|00000e80| 69 62 72 61 72 79 20 61 | 6e 64 20 67 69 76 65 20 |ibrary a|nd give |
|00000e90| 69 74 20 61 20 74 72 79 | 2e 20 20 49 66 20 79 6f |it a try|. If yo|
|00000ea0| 75 20 74 68 69 6e 6b 20 | 69 74 20 64 6f 65 73 6e |u think |it doesn|
|00000eb0| 27 74 20 73 70 65 6e 64 | 20 2a 65 6e 6f 75 67 68 |'t spend| *enough|
|00000ec0| 2a 0a 58 74 69 6d 65 20 | 73 6f 72 74 69 6e 67 2c |*.Xtime |sorting,|
|00000ed0| 20 74 72 79 20 62 75 62 | 62 6c 65 5f 73 6f 72 74 | try bub|ble_sort|
|00000ee0| 20 69 6e 73 74 65 61 64 | 2e 0a 58 0a 58 20 20 20 | instead|..X.X |
|00000ef0| 20 54 68 65 20 6d 65 72 | 67 65 20 73 6f 72 74 20 | The mer|ge sort |
|00000f00| 64 65 63 6c 61 72 65 73 | 20 61 20 67 6c 6f 62 61 |declares| a globa|
|00000f10| 6c 20 69 6e 74 20 63 61 | 6c 6c 65 64 20 5f 6d 61 |l int ca|lled _ma|
|00000f20| 79 62 65 5f 73 6f 72 74 | 65 64 20 77 68 69 63 68 |ybe_sort|ed which|
|00000f30| 0a 58 74 65 6c 6c 73 20 | 6d 65 72 67 65 20 73 6f |.Xtells |merge so|
|00000f40| 72 74 20 74 68 61 74 20 | 74 68 65 20 64 61 74 61 |rt that |the data|
|00000f50| 20 69 6e 20 74 68 65 20 | 61 72 72 61 79 20 6d 61 | in the |array ma|
|00000f60| 79 20 61 6c 72 65 61 64 | 79 20 62 65 20 6d 6f 73 |y alread|y be mos|
|00000f70| 74 6c 79 20 69 6e 0a 58 | 6f 72 64 65 72 2e 20 20 |tly in.X|order. |
|00000f80| 49 74 20 69 73 20 61 64 | 76 69 73 6f 72 79 2d 2d |It is ad|visory--|
|00000f90| 74 68 65 20 61 6c 67 6f | 72 69 74 68 6d 20 77 69 |the algo|rithm wi|
|00000fa0| 6c 6c 20 70 72 6f 64 75 | 63 65 20 74 68 65 20 63 |ll produ|ce the c|
|00000fb0| 6f 72 72 65 63 74 20 72 | 65 73 75 6c 74 73 0a 58 |orrect r|esults.X|
|00000fc0| 72 65 67 61 72 64 6c 65 | 73 73 20 6f 66 20 5f 6d |regardle|ss of _m|
|00000fd0| 61 79 62 65 5f 73 6f 72 | 74 65 64 27 73 20 76 61 |aybe_sor|ted's va|
|00000fe0| 6c 75 65 3b 20 68 6f 77 | 65 76 65 72 20 74 68 65 |lue; how|ever the|
|00000ff0| 20 65 78 65 63 75 74 69 | 6f 6e 20 74 69 6d 65 20 | executi|on time |
|00001000| 66 6f 72 0a 58 6d 65 72 | 67 65 5f 73 6f 72 74 20 |for.Xmer|ge_sort |
|00001010| 77 69 6c 6c 20 62 65 20 | 71 75 69 74 65 20 61 20 |will be |quite a |
|00001020| 62 69 74 20 6c 65 73 73 | 20 69 66 20 74 68 69 73 |bit less| if this|
|00001030| 20 69 73 20 73 65 74 20 | 61 6e 64 20 74 68 65 20 | is set |and the |
|00001040| 61 72 72 61 79 20 69 73 | 0a 58 61 6c 72 65 61 64 |array is|.Xalread|
|00001050| 79 20 6d 6f 73 74 6c 79 | 20 73 6f 72 74 65 64 2e |y mostly| sorted.|
|00001060| 20 20 49 66 20 74 68 65 | 20 61 72 72 61 79 20 69 | If the| array i|
|00001070| 73 6e 27 74 20 73 6f 72 | 74 65 64 20 61 74 20 61 |sn't sor|ted at a|
|00001080| 6c 6c 2c 20 74 68 69 73 | 20 6f 70 74 69 6f 6e 0a |ll, this| option.|
|00001090| 58 65 78 74 72 61 63 74 | 73 20 61 62 6f 75 74 20 |Xextract|s about |
|000010a0| 32 25 20 73 70 65 65 64 | 20 70 65 6e 61 6c 74 79 |2% speed| penalty|
|000010b0| 2e 0a 58 0a 58 20 20 20 | 20 54 68 65 20 68 65 61 |..X.X | The hea|
|000010c0| 70 73 6f 72 74 20 77 61 | 73 20 63 6f 6e 74 72 69 |psort wa|s contri|
|000010d0| 62 75 74 65 64 20 62 79 | 20 6d 6f 75 73 65 40 6c |buted by| mouse@l|
|000010e0| 61 72 72 79 2e 6d 63 72 | 63 69 6d 2e 6d 63 67 69 |arry.mcr|cim.mcgi|
|000010f0| 6c 6c 2e 65 64 75 0a 58 | 61 6b 61 20 22 64 65 72 |ll.edu.X|aka "der|
|00001100| 20 4d 6f 75 73 65 22 2e | 0a 58 0a 58 20 20 20 20 | Mouse".|.X.X |
|00001110| 54 68 65 20 6d 65 72 67 | 65 5f 73 6f 72 74 28 29 |The merg|e_sort()|
|00001120| 20 66 75 6e 63 74 69 6f | 6e 20 69 73 20 74 68 65 | functio|n is the|
|00001130| 20 6f 6e 6c 79 20 6f 6e | 65 20 49 27 76 65 20 74 | only on|e I've t|
|00001140| 61 6b 65 6e 20 61 6e 79 | 20 74 72 6f 75 62 6c 65 |aken any| trouble|
|00001150| 20 74 6f 0a 58 6f 70 74 | 69 6d 69 7a 65 2e 0a 58 | to.Xopt|imize..X|
|00001160| 0a 58 49 4e 53 54 41 4c | 4c 41 54 49 4f 4e 0a 58 |.XINSTAL|LATION.X|
|00001170| 0a 58 20 20 20 20 53 65 | 65 20 74 68 65 20 49 4e |.X Se|e the IN|
|00001180| 53 54 41 4c 4c 41 54 49 | 4f 4e 20 64 6f 63 75 6d |STALLATI|ON docum|
|00001190| 65 6e 74 20 77 68 69 63 | 68 20 73 68 6f 75 6c 64 |ent whic|h should|
|000011a0| 20 62 65 20 6e 65 61 72 | 62 79 2e 0a 58 0a 58 55 | be near|by..X.XU|
|000011b0| 53 41 47 45 0a 58 0a 58 | 20 20 20 20 4a 75 73 74 |SAGE.X.X| Just|
|000011c0| 20 74 79 70 65 20 22 66 | 6c 6f 67 67 65 72 22 20 | type "f|logger" |
|000011d0| 6f 72 20 22 66 6c 6f 67 | 67 65 72 20 3c 6e 75 6d |or "flog|ger <num|
|000011e0| 62 65 72 3e 22 20 61 6e | 64 20 77 61 74 63 68 20 |ber>" an|d watch |
|000011f0| 77 68 61 74 20 68 61 70 | 70 65 6e 73 2e 0a 58 0a |what hap|pens..X.|
|00001200| 58 44 45 53 43 52 49 50 | 54 49 4f 4e 20 4f 46 20 |XDESCRIP|TION OF |
|00001210| 4f 55 54 50 55 54 0a 58 | 0a 58 20 20 20 20 49 74 |OUTPUT.X|.X It|
|00001220| 20 73 65 65 6d 73 20 6c | 69 6b 65 20 69 74 20 64 | seems l|ike it d|
|00001230| 6f 65 73 6e 27 74 20 72 | 65 61 6c 6c 79 20 64 6f |oesn't r|eally do|
|00001240| 20 61 6e 79 74 68 69 6e | 67 20 62 75 74 20 73 70 | anythin|g but sp|
|00001250| 69 74 20 6f 75 74 20 6e | 75 6d 62 65 72 73 2c 0a |it out n|umbers,.|
|00001260| 58 61 6e 64 20 72 61 74 | 68 65 72 20 73 6c 6f 77 |Xand rat|her slow|
|00001270| 6c 79 20 61 74 20 74 68 | 61 74 2e 20 20 54 68 65 |ly at th|at. The|
|00001280| 20 76 65 72 73 69 6f 6e | 20 61 6e 64 20 70 61 74 | version| and pat|
|00001290| 63 68 20 6c 65 76 65 6c | 20 6f 66 20 74 68 65 20 |ch level| of the |
|000012a0| 70 72 6f 67 72 61 6d 0a | 58 69 73 20 70 72 69 6e |program.|Xis prin|
|000012b0| 74 65 64 3b 20 74 68 65 | 20 72 65 73 6f 6c 75 74 |ted; the| resolut|
|000012c0| 69 6f 6e 20 6f 66 20 74 | 68 65 20 63 6c 6f 63 6b |ion of t|he clock|
|000012d0| 20 69 73 20 70 72 69 6e | 74 65 64 3b 20 74 68 65 | is prin|ted; the|
|000012e0| 20 73 69 7a 65 20 6f 66 | 20 74 68 65 0a 58 65 6c | size of| the.Xel|
|000012f0| 65 6d 65 6e 74 73 20 69 | 73 20 72 65 70 6f 72 74 |ements i|s report|
|00001300| 65 64 3b 20 61 6e 64 20 | 74 68 65 20 6e 75 6d 62 |ed; and |the numb|
|00001310| 65 72 20 6f 66 20 65 6c | 65 6d 65 6e 74 73 20 74 |er of el|ements t|
|00001320| 6f 20 62 65 20 73 6f 72 | 74 65 64 20 69 73 0a 58 |o be sor|ted is.X|
|00001330| 72 65 70 6f 72 74 65 64 | 2e 0a 58 0a 58 20 20 20 |reported|..X.X |
|00001340| 20 46 6f 72 20 65 61 63 | 68 20 73 6f 72 74 20 61 | For eac|h sort a|
|00001350| 6c 67 6f 72 69 74 68 6d | 2c 20 61 20 74 61 62 6c |lgorithm|, a tabl|
|00001360| 65 20 6f 66 20 6d 65 61 | 73 75 72 65 6d 65 6e 74 |e of mea|surement|
|00001370| 73 20 69 73 20 72 65 70 | 6f 72 74 65 64 2e 20 20 |s is rep|orted. |
|00001380| 54 68 65 0a 58 72 6f 77 | 73 20 64 65 73 63 72 69 |The.Xrow|s descri|
|00001390| 62 65 20 74 68 65 20 73 | 69 74 75 61 74 69 6f 6e |be the s|ituation|
|000013a0| 20 74 68 65 20 73 6f 72 | 74 20 61 6c 67 6f 72 69 | the sor|t algori|
|000013b0| 74 68 6d 20 77 61 73 20 | 70 72 65 73 65 6e 74 65 |thm was |presente|
|000013c0| 64 20 77 69 74 68 20 66 | 6f 72 0a 58 74 68 6f 73 |d with f|or.Xthos|
|000013d0| 65 20 6d 65 61 73 75 72 | 65 6d 65 6e 74 73 20 61 |e measur|ements a|
|000013e0| 6e 64 20 74 68 65 20 63 | 6f 6c 75 6d 6e 73 20 72 |nd the c|olumns r|
|000013f0| 65 70 72 65 73 65 6e 74 | 20 74 68 65 20 74 79 70 |epresent| the typ|
|00001400| 65 20 6f 66 20 6d 65 61 | 73 75 72 65 6d 65 6e 74 |e of mea|surement|
|00001410| 0a 58 74 61 6b 65 6e 2e | 20 20 54 68 65 20 72 6f |.Xtaken.| The ro|
|00001420| 77 73 20 28 73 69 74 75 | 61 74 69 6f 6e 73 29 20 |ws (situ|ations) |
|00001430| 61 72 65 3a 0a 58 0a 58 | 20 20 20 20 72 61 6e 64 |are:.X.X| rand|
|00001440| 6f 6d 3a 20 20 20 54 68 | 65 20 63 6f 6e 74 65 6e |om: Th|e conten|
|00001450| 74 73 20 6f 66 20 74 68 | 65 20 61 72 72 61 79 20 |ts of th|e array |
|00001460| 74 6f 20 62 65 20 73 6f | 72 74 65 64 20 61 72 65 |to be so|rted are|
|00001470| 20 70 73 65 75 64 6f 20 | 0a 58 20 20 20 20 20 20 | pseudo |.X |
|00001480| 20 20 20 20 20 20 20 20 | 72 61 6e 64 6f 6d 20 6e | |random n|
|00001490| 75 6d 62 65 72 73 20 67 | 65 6e 65 72 61 74 65 64 |umbers g|enerated|
|000014a0| 20 62 79 20 72 61 6e 64 | 28 29 2c 20 77 69 74 68 | by rand|(), with|
|000014b0| 20 74 77 6f 20 73 70 65 | 63 69 61 6c 0a 58 20 20 | two spe|cial.X |
|000014c0| 20 20 20 20 20 20 20 20 | 20 20 20 20 76 61 6c 75 | | valu|
|000014d0| 65 73 20 65 78 63 6c 75 | 64 65 64 20 66 6f 72 20 |es exclu|ded for |
|000014e0| 74 68 65 20 70 75 72 70 | 6f 73 65 20 6f 66 20 64 |the purp|ose of d|
|000014f0| 65 74 65 63 74 69 6e 67 | 20 6f 76 65 72 77 72 69 |etecting| overwri|
|00001500| 74 65 73 0a 58 20 20 20 | 20 20 20 20 20 20 20 20 |tes.X | |
|00001510| 20 20 20 61 74 20 74 68 | 65 20 65 6e 64 73 20 6f | at th|e ends o|
|00001520| 66 20 74 68 65 20 61 72 | 72 61 79 2e 0a 58 20 20 |f the ar|ray..X |
|00001530| 20 20 61 73 63 65 6e 64 | 3a 20 20 20 54 68 65 20 | ascend|: The |
|00001540| 61 72 72 61 79 20 69 73 | 20 61 6c 72 65 61 64 79 |array is| already|
|00001550| 20 63 6f 6d 70 6c 65 74 | 65 6c 79 20 69 6e 20 6f | complet|ely in o|
|00001560| 72 64 65 72 2e 20 20 54 | 6f 20 73 69 6d 70 6c 79 |rder. T|o simply|
|00001570| 0a 58 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |.X | |
|00001580| 76 65 72 69 66 79 20 74 | 68 69 73 20 66 61 63 74 |verify t|his fact|
|00001590| 20 69 73 20 61 6c 6c 20 | 74 68 61 74 27 73 20 72 | is all |that's r|
|000015a0| 65 71 75 69 72 65 64 20 | 6f 66 20 74 68 65 20 73 |equired |of the s|
|000015b0| 6f 72 74 0a 58 20 20 20 | 20 20 20 20 20 20 20 20 |ort.X | |
|000015c0| 20 20 20 61 6c 67 6f 72 | 69 74 68 6d 3b 20 69 72 | algor|ithm; ir|
|000015d0| 6f 6e 69 63 61 6c 6c 79 | 2c 20 62 75 62 62 6c 65 |onically|, bubble|
|000015e0| 20 73 6f 72 74 20 6f 75 | 74 70 65 72 66 6f 72 6d | sort ou|tperform|
|000015f0| 73 20 61 6c 6c 0a 58 20 | 20 20 20 20 20 20 20 20 |s all.X | |
|00001600| 20 20 20 20 20 74 68 65 | 20 72 65 73 74 20 69 6e | the| rest in|
|00001610| 20 74 68 69 73 20 63 61 | 73 65 2e 0a 58 20 20 20 | this ca|se..X |
|00001620| 20 64 65 73 63 65 6e 64 | 3a 20 20 54 68 65 20 61 | descend|: The a|
|00001630| 72 72 61 79 20 69 73 20 | 65 78 61 63 74 6c 79 20 |rray is |exactly |
|00001640| 69 6e 20 72 65 76 65 72 | 73 65 20 6f 72 64 65 72 |in rever|se order|
|00001650| 2e 20 20 54 68 65 6f 72 | 65 74 69 63 61 6c 6c 79 |. Theor|etically|
|00001660| 2c 0a 58 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |,.X | |
|00001670| 20 61 6e 20 73 6f 72 74 | 20 66 75 6e 63 74 69 6f | an sort| functio|
|00001680| 6e 20 63 6f 75 6c 64 20 | 64 65 74 65 63 74 20 74 |n could |detect t|
|00001690| 68 69 73 20 61 6e 64 20 | 73 77 61 70 20 65 6e 64 |his and |swap end|
|000016a0| 73 20 69 6e 0a 58 20 20 | 20 20 20 20 20 20 20 20 |s in.X | |
|000016b0| 20 20 20 20 6c 69 6e 65 | 61 72 20 74 69 6d 65 2c | line|ar time,|
|000016c0| 20 62 75 74 20 69 74 20 | 68 61 72 64 6c 79 20 73 | but it |hardly s|
|000016d0| 65 65 6d 73 20 75 73 65 | 66 75 6c 2e 0a 58 20 20 |eems use|ful..X |
|000016e0| 20 20 66 69 62 20 61 73 | 63 3a 20 20 54 68 65 20 | fib as|c: The |
|000016f0| 63 6f 6e 74 65 6e 74 73 | 20 6f 66 20 74 68 65 20 |contents| of the |
|00001700| 61 72 72 61 79 20 61 72 | 65 20 69 72 72 65 6c 65 |array ar|e irrele|
|00001710| 76 61 6e 74 3b 20 74 68 | 65 20 63 6f 6d 70 61 72 |vant; th|e compar|
|00001720| 69 73 6f 6e 0a 58 20 20 | 20 20 20 20 20 20 20 20 |ison.X | |
|00001730| 20 20 20 20 66 75 6e 63 | 74 69 6f 6e 20 70 61 73 | func|tion pas|
|00001740| 73 65 64 20 74 6f 20 74 | 68 65 20 72 6f 75 74 69 |sed to t|he routi|
|00001750| 6e 65 20 61 6c 77 61 79 | 73 20 73 61 79 73 20 74 |ne alway|s says t|
|00001760| 68 61 74 20 69 74 73 0a | 58 20 20 20 20 20 20 20 |hat its.|X |
|00001770| 20 20 20 20 20 20 20 66 | 69 72 73 74 20 61 72 67 | f|irst arg|
|00001780| 75 6d 65 6e 74 20 69 73 | 20 6c 65 73 73 20 74 68 |ument is| less th|
|00001790| 61 6e 20 69 74 73 20 73 | 65 63 6f 6e 64 2e 0a 58 |an its s|econd..X|
|000017a0| 20 20 20 20 66 69 62 20 | 64 65 73 63 3a 20 53 69 | fib |desc: Si|
|000017b0| 6d 69 6c 61 72 6c 79 2c | 20 74 68 65 20 63 6f 6d |milarly,| the com|
|000017c0| 70 61 72 69 73 6f 6e 20 | 66 75 6e 63 74 69 6f 6e |parison |function|
|000017d0| 20 61 6c 77 61 79 73 20 | 73 61 79 73 20 74 68 61 | always |says tha|
|000017e0| 74 20 69 74 73 0a 58 20 | 20 20 20 20 20 20 20 20 |t its.X | |
|000017f0| 20 20 20 20 20 66 69 72 | 73 74 20 61 72 67 75 6d | fir|st argum|
|00001800| 65 6e 74 20 69 73 20 67 | 72 65 61 74 65 72 20 74 |ent is g|reater t|
|00001810| 68 61 6e 20 69 74 73 20 | 73 65 63 6f 6e 64 2e 0a |han its |second..|
|00001820| 58 20 20 20 20 73 75 72 | 70 72 69 73 65 3a 20 41 |X sur|prise: A|
|00001830| 20 70 73 65 75 64 6f 72 | 61 6e 64 6f 6d 20 72 65 | pseudor|andom re|
|00001840| 73 75 6c 74 20 69 73 20 | 72 65 74 75 72 6e 65 64 |sult is |returned|
|00001850| 20 66 72 6f 6d 20 74 68 | 65 20 63 6f 6d 70 61 72 | from th|e compar|
|00001860| 69 73 6f 6e 20 0a 58 20 | 20 20 20 20 20 20 20 20 |ison .X | |
|00001870| 20 20 20 20 20 66 75 6e | 63 74 69 6f 6e 20 69 6e | fun|ction in|
|00001880| 20 61 6e 20 61 74 74 65 | 6d 70 74 20 74 6f 20 63 | an atte|mpt to c|
|00001890| 6f 6e 66 6f 75 6e 64 20 | 74 68 65 20 61 6c 67 6f |onfound |the algo|
|000018a0| 72 69 74 68 6d 73 27 20 | 65 66 66 6f 72 74 73 0a |rithms' |efforts.|
|000018b0| 58 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 61 |X | a|
|000018c0| 74 20 73 6f 72 74 69 6e | 67 2e 0a 58 20 20 20 20 |t sortin|g..X |
|000018d0| 6d 6f 73 74 6c 79 3a 20 | 20 20 53 69 6d 69 6c 61 |mostly: | Simila|
|000018e0| 72 20 74 6f 20 61 73 63 | 65 6e 64 2c 20 62 75 74 |r to asc|end, but|
|000018f0| 20 74 68 65 20 66 69 72 | 73 74 20 61 6e 64 20 6c | the fir|st and l|
|00001900| 61 73 74 20 65 6c 65 6d | 65 6e 74 73 0a 58 20 20 |ast elem|ents.X |
|00001910| 20 20 20 20 20 20 20 20 | 20 20 20 20 61 72 65 20 | | are |
|00001920| 72 65 76 65 72 73 65 64 | 2e 20 20 54 68 69 73 20 |reversed|. This |
|00001930| 69 73 20 6d 65 61 6e 74 | 20 74 6f 20 73 69 6d 75 |is meant| to simu|
|00001940| 6c 61 74 65 20 61 6e 20 | 69 6e 64 65 78 20 77 68 |late an |index wh|
|00001950| 69 63 68 0a 58 20 20 20 | 20 20 20 20 20 20 20 20 |ich.X | |
|00001960| 20 20 20 69 73 20 70 72 | 65 74 74 79 20 6d 75 63 | is pr|etty muc|
|00001970| 68 20 61 6c 72 65 61 64 | 79 20 73 6f 72 74 65 64 |h alread|y sorted|
|00001980| 20 61 6e 64 20 6f 6e 6c | 79 20 61 20 73 6d 61 6c | and onl|y a smal|
|00001990| 6c 20 6e 75 6d 62 65 72 | 0a 58 20 20 20 20 20 20 |l number|.X |
|000019a0| 20 20 20 20 20 20 20 20 | 6f 66 20 6e 65 77 20 69 | |of new i|
|000019b0| 74 65 6d 73 20 6e 65 65 | 64 20 74 6f 20 62 65 20 |tems nee|d to be |
|000019c0| 69 6e 73 65 72 74 65 64 | 2e 0a 58 20 20 20 20 65 |inserted|..X e|
|000019d0| 71 75 69 76 3a 20 20 20 | 20 54 68 65 20 63 6f 6d |quiv: | The com|
|000019e0| 70 61 72 69 73 6f 6e 20 | 66 75 6e 63 74 69 6f 6e |parison |function|
|000019f0| 20 72 65 70 6f 72 74 73 | 20 74 68 61 74 20 61 6c | reports| that al|
|00001a00| 6c 20 65 6c 65 6d 65 6e | 74 73 20 0a 58 20 20 20 |l elemen|ts .X |
|00001a10| 20 20 20 20 20 20 20 20 | 20 20 20 63 6f 6d 70 61 | | compa|
|00001a20| 72 65 20 65 71 75 61 6c | 2e 20 20 54 68 65 20 64 |re equal|. The d|
|00001a30| 61 74 61 20 69 73 20 61 | 72 72 61 6e 67 65 64 20 |ata is a|rranged |
|00001a40| 73 6f 20 74 68 61 74 20 | 61 0a 58 20 20 20 20 20 |so that |a.X |
|00001a50| 20 20 20 20 20 20 20 20 | 20 63 68 65 63 6b 20 63 | | check c|
|00001a60| 61 6e 20 62 65 20 6d 61 | 64 65 20 66 6f 72 20 77 |an be ma|de for w|
|00001a70| 68 65 74 68 65 72 20 74 | 68 65 20 61 6c 67 6f 72 |hether t|he algor|
|00001a80| 69 74 68 6d 20 69 73 0a | 58 20 20 20 20 20 20 20 |ithm is.|X |
|00001a90| 20 20 20 20 20 20 20 73 | 74 61 62 6c 65 3b 20 74 | s|table; t|
|00001aa0| 68 61 74 20 69 73 20 74 | 68 65 20 70 72 6f 70 65 |hat is t|he prope|
|00001ab0| 72 74 79 20 74 68 61 74 | 20 72 65 63 6f 72 64 73 |rty that| records|
|00001ac0| 20 77 69 74 68 0a 58 20 | 20 20 20 20 20 20 20 20 | with.X | |
|00001ad0| 20 20 20 20 20 65 71 75 | 61 6c 20 6b 65 79 73 20 | equ|al keys |
|00001ae0| 73 74 61 79 20 69 6e 20 | 74 68 65 20 73 61 6d 65 |stay in |the same|
|00001af0| 20 72 65 6c 61 74 69 76 | 65 20 6f 72 64 65 72 20 | relativ|e order |
|00001b00| 69 6e 20 74 68 65 0a 58 | 20 20 20 20 20 20 20 20 |in the.X| |
|00001b10| 20 20 20 20 20 20 61 72 | 72 61 79 20 74 68 61 74 | ar|ray that|
|00001b20| 20 74 68 65 79 20 77 65 | 72 65 20 69 6e 20 62 65 | they we|re in be|
|00001b30| 66 6f 72 65 20 74 68 65 | 20 73 6f 72 74 20 62 65 |fore the| sort be|
|00001b40| 67 61 6e 2e 0a 58 0a 58 | 54 68 65 20 63 6f 6c 75 |gan..X.X|The colu|
|00001b50| 6d 6e 73 20 72 65 66 65 | 72 20 74 6f 20 74 68 65 |mns refe|r to the|
|00001b60| 73 65 20 6d 65 61 73 75 | 72 65 6d 65 6e 74 73 3a |se measu|rements:|
|00001b70| 0a 58 0a 58 20 20 20 20 | 63 6f 6d 70 61 72 65 73 |.X.X |compares|
|00001b80| 3a 20 54 68 65 20 6e 75 | 6d 62 65 72 20 6f 66 20 |: The nu|mber of |
|00001b90| 63 61 6c 6c 73 20 74 6f | 20 74 68 65 20 63 6f 6d |calls to| the com|
|00001ba0| 70 61 72 69 73 6f 6e 20 | 72 6f 75 74 69 6e 65 20 |parison |routine |
|00001bb0| 64 75 72 69 6e 67 0a 58 | 20 20 20 20 20 20 20 20 |during.X| |
|00001bc0| 20 20 20 20 20 20 74 68 | 65 20 73 6f 72 74 2e 20 | th|e sort. |
|00001bd0| 20 49 20 63 6f 6e 73 69 | 64 65 72 20 74 68 69 73 | I consi|der this|
|00001be0| 20 76 65 72 79 20 69 6d | 70 6f 72 74 61 6e 74 2c | very im|portant,|
|00001bf0| 20 61 73 20 6d 6f 73 74 | 0a 58 20 20 20 20 20 20 | as most|.X |
|00001c00| 20 20 20 20 20 20 20 20 | 6f 66 20 74 68 65 20 73 | |of the s|
|00001c10| 6f 72 74 69 6e 67 20 62 | 6f 74 74 6c 65 6e 65 63 |orting b|ottlenec|
|00001c20| 6b 73 20 49 27 76 65 20 | 65 78 70 65 72 69 65 6e |ks I've |experien|
|00001c30| 63 65 20 63 65 6e 74 65 | 72 0a 58 20 20 20 20 20 |ce cente|r.X |
|00001c40| 20 20 20 20 20 20 20 20 | 20 61 72 6f 75 6e 64 20 | | around |
|00001c50| 74 68 65 20 63 6f 6d 70 | 61 72 69 73 6f 6e 20 66 |the comp|arison f|
|00001c60| 75 6e 63 74 69 6f 6e 2e | 0a 58 20 20 20 20 73 74 |unction.|.X st|
|00001c70| 61 63 6b 3a 20 20 20 20 | 28 45 73 74 69 6d 61 74 |ack: |(Estimat|
|00001c80| 65 64 29 20 53 6f 6d 65 | 20 73 65 6d 69 2d 6e 6f |ed) Some| semi-no|
|00001c90| 6e 2d 70 6f 72 74 61 62 | 6c 65 20 61 74 74 65 6d |n-portab|le attem|
|00001ca0| 70 74 73 20 74 6f 20 72 | 65 63 6f 72 64 0a 58 20 |pts to r|ecord.X |
|00001cb0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 74 68 65 | | the|
|00001cc0| 20 67 72 6f 77 74 68 20 | 6f 66 20 74 68 65 20 73 | growth |of the s|
|00001cd0| 74 61 63 6b 20 61 72 65 | 20 6d 61 64 65 20 61 6e |tack are| made an|
|00001ce0| 64 20 61 20 6e 75 6d 62 | 65 72 20 63 6f 6d 65 73 |d a numb|er comes|
|00001cf0| 0a 58 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |.X | |
|00001d00| 6f 75 74 2e 20 20 49 20 | 63 6f 6e 73 69 64 65 72 |out. I |consider|
|00001d10| 20 4f 28 6c 6f 67 20 6e | 29 20 75 73 65 20 6f 66 | O(log n|) use of|
|00001d20| 20 74 68 65 20 73 74 61 | 63 6b 20 61 63 63 65 70 | the sta|ck accep|
|00001d30| 74 61 62 6c 65 0a 58 20 | 20 20 20 20 20 20 20 20 |table.X | |
|00001d40| 20 20 20 20 20 6f 6e 20 | 6d 6f 64 65 72 6e 20 6d | on |modern m|
|00001d50| 61 63 68 69 6e 65 73 20 | 61 6e 64 20 6e 6f 6e 65 |achines |and none|
|00001d60| 20 6f 66 20 74 68 65 73 | 65 20 61 6c 67 6f 72 69 | of thes|e algori|
|00001d70| 74 68 6d 73 20 61 72 65 | 0a 58 20 20 20 20 20 20 |thms are|.X |
|00001d80| 20 20 20 20 20 20 20 20 | 77 6f 72 73 65 20 74 68 | |worse th|
|00001d90| 61 6e 20 74 68 61 74 2e | 20 0a 58 20 20 20 20 68 |an that.| .X h|
|00001da0| 65 61 70 3a 20 20 20 20 | 20 41 6d 6f 75 6e 74 20 |eap: | Amount |
|00001db0| 6f 66 20 6d 61 6c 6c 6f | 63 27 64 20 73 74 6f 72 |of mallo|c'd stor|
|00001dc0| 61 67 65 20 61 73 20 72 | 65 70 6f 72 74 65 64 20 |age as r|eported |
|00001dd0| 62 79 20 6d 61 6c 6c 69 | 6e 66 6f 28 29 2e 0a 58 |by malli|nfo()..X|
|00001de0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 49 66 | | If|
|00001df0| 20 79 6f 75 72 20 43 20 | 6c 69 62 72 61 72 79 20 | your C |library |
|00001e00| 64 6f 65 73 6e 27 74 20 | 73 75 70 70 6f 72 74 20 |doesn't |support |
|00001e10| 6d 61 6c 6c 69 6e 66 6f | 28 29 2c 20 74 68 65 0a |mallinfo|(), the.|
|00001e20| 58 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 63 |X | c|
|00001e30| 6f 6d 70 69 6c 65 72 20 | 77 69 6c 6c 20 70 72 6f |ompiler |will pro|
|00001e40| 62 61 62 6c 79 20 62 61 | 72 66 20 6f 6e 20 66 6c |bably ba|rf on fl|
|00001e50| 6f 67 67 65 72 2e 63 2e | 20 20 54 68 65 20 66 6c |ogger.c.| The fl|
|00001e60| 6f 67 67 65 72 0a 58 20 | 20 20 20 20 20 20 20 20 |ogger.X | |
|00001e70| 20 20 20 20 20 63 68 65 | 63 6b 73 20 66 6f 72 20 | che|cks for |
|00001e80| 6d 65 6d 6f 72 79 20 6c | 65 61 6b 73 2e 0a 58 20 |memory l|eaks..X |
|00001e90| 20 20 20 75 73 65 72 3a | 20 20 20 20 20 41 6d 6f | user:| Amo|
|00001ea0| 75 6e 74 20 6f 66 20 75 | 73 65 72 20 6d 6f 64 65 |unt of u|ser mode|
|00001eb0| 20 43 50 55 20 74 69 6d | 65 20 61 73 20 72 65 70 | CPU tim|e as rep|
|00001ec0| 6f 72 74 65 64 20 62 79 | 20 74 69 6d 65 73 28 29 |orted by| times()|
|00001ed0| 2e 0a 58 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |..X | |
|00001ee0| 20 54 68 69 73 20 69 6e | 63 6c 75 64 65 73 20 74 | This in|cludes t|
|00001ef0| 69 6d 65 20 66 6f 72 20 | 62 6f 74 68 20 74 68 65 |ime for |both the|
|00001f00| 20 6f 70 65 72 61 74 69 | 6f 6e 20 6f 66 20 74 68 | operati|on of th|
|00001f10| 65 0a 58 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |e.X | |
|00001f20| 20 73 6f 72 74 20 66 75 | 6e 63 74 69 6f 6e 20 61 | sort fu|nction a|
|00001f30| 6e 64 20 74 68 65 20 63 | 6f 6d 70 61 72 69 73 6f |nd the c|ompariso|
|00001f40| 6e 20 66 75 6e 63 74 69 | 6f 6e 3b 20 61 73 20 74 |n functi|on; as t|
|00001f50| 68 65 73 65 0a 58 20 20 | 20 20 20 20 20 20 20 20 |hese.X | |
|00001f60| 20 20 20 20 61 72 65 20 | 6f 6e 6c 79 20 6d 61 72 | are |only mar|
|00001f70| 67 69 6e 61 6c 6c 79 20 | 72 65 6c 61 74 65 64 2c |ginally |related,|
|00001f80| 20 74 68 69 73 20 6e 75 | 6d 62 65 72 20 69 73 20 | this nu|mber is |
|00001f90| 6e 6f 74 0a 58 20 20 20 | 20 20 20 20 20 20 20 20 |not.X | |
|00001fa0| 20 20 20 75 73 65 66 75 | 6c 20 66 6f 72 20 65 73 | usefu|l for es|
|00001fb0| 74 69 6d 61 74 69 6e 67 | 20 68 6f 77 20 6c 6f 6e |timating| how lon|
|00001fc0| 67 20 69 74 20 6d 69 67 | 68 74 20 74 61 6b 65 20 |g it mig|ht take |
|00001fd0| 74 6f 20 0a 58 20 20 20 | 20 20 20 20 20 20 20 20 |to .X | |
|00001fe0| 20 20 20 73 6f 72 74 20 | 75 73 65 66 75 6c 20 64 | sort |useful d|
|00001ff0| 61 74 61 20 69 6e 20 73 | 6f 6d 65 20 6f 74 68 65 |ata in s|ome othe|
|00002000| 72 20 70 72 6f 67 72 61 | 6d 2e 0a 58 20 20 20 20 |r progra|m..X |
|00002010| 73 79 73 74 65 6d 3a 20 | 20 20 41 6d 6f 75 6e 74 |system: | Amount|
|00002020| 20 6f 66 20 73 79 73 74 | 65 6d 20 43 50 55 20 74 | of syst|em CPU t|
|00002030| 69 6d 65 20 61 73 20 72 | 65 70 6f 72 74 65 64 20 |ime as r|eported |
|00002040| 62 79 20 74 69 6d 65 73 | 28 29 2e 0a 58 20 20 20 |by times|()..X |
|00002050| 20 20 20 20 20 20 20 20 | 20 20 20 47 65 6e 65 72 | | Gener|
|00002060| 61 6c 6c 79 20 30 2e 30 | 30 20 6f 72 20 76 65 72 |ally 0.0|0 or ver|
|00002070| 79 20 73 6d 61 6c 6c 2e | 20 20 49 66 20 61 20 73 |y small.| If a s|
|00002080| 6f 72 74 20 61 6c 67 6f | 72 69 74 68 6d 0a 58 20 |ort algo|rithm.X |
|00002090| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 75 73 65 | | use|
|000020a0| 73 20 6c 6f 74 73 20 6f | 66 20 73 79 73 74 65 6d |s lots o|f system|
|000020b0| 20 74 69 6d 65 20 69 74 | 27 73 20 70 72 6f 62 61 | time it|'s proba|
|000020c0| 62 6c 79 20 61 20 54 72 | 6f 6a 61 6e 20 68 6f 72 |bly a Tr|ojan hor|
|000020d0| 73 65 0a 58 20 20 20 20 | 20 20 20 20 20 20 20 20 |se.X | |
|000020e0| 20 20 74 72 79 69 6e 67 | 20 74 6f 20 62 72 65 61 | trying| to brea|
|000020f0| 6b 20 69 6e 74 6f 20 74 | 68 65 20 70 61 73 73 77 |k into t|he passw|
|00002100| 64 20 66 69 6c 65 20 6f | 72 20 64 65 6c 65 74 65 |d file o|r delete|
|00002110| 20 79 6f 75 72 0a 58 20 | 20 20 20 20 20 20 20 20 | your.X | |
|00002120| 20 20 20 20 20 68 6f 6d | 65 20 64 69 72 65 63 74 | hom|e direct|
|00002130| 6f 72 79 20 6f 72 20 73 | 6f 6d 65 74 68 69 6e 67 |ory or s|omething|
|00002140| 20 73 6f 20 6d 61 79 62 | 65 20 79 6f 75 20 73 68 | so mayb|e you sh|
|00002150| 6f 75 6c 64 0a 58 20 20 | 20 20 20 20 20 20 20 20 |ould.X | |
|00002160| 20 20 20 20 73 74 61 72 | 74 20 73 68 75 66 66 6c | star|t shuffl|
|00002170| 69 6e 67 20 74 68 72 6f | 75 67 68 20 79 6f 75 72 |ing thro|ugh your|
|00002180| 20 64 65 73 6b 20 6c 6f | 6f 6b 69 6e 67 20 66 6f | desk lo|oking fo|
|00002190| 72 20 61 20 72 65 63 65 | 6e 74 0a 58 20 20 20 20 |r a rece|nt.X |
|000021a0| 20 20 20 20 20 20 20 20 | 20 20 62 61 63 6b 75 70 | | backup|
|000021b0| 20 74 61 70 65 2e 20 20 | 49 20 6d 61 79 20 72 65 | tape. |I may re|
|000021c0| 6d 6f 76 65 20 74 68 69 | 73 20 69 6e 20 61 20 66 |move thi|s in a f|
|000021d0| 75 74 75 72 65 20 76 65 | 72 73 69 6f 6e 0a 58 20 |uture ve|rsion.X |
|000021e0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 28 74 68 | | (th|
|000021f0| 65 20 72 65 70 6f 72 74 | 20 6f 66 20 73 79 73 74 |e report| of syst|
|00002200| 65 6d 20 74 69 6d 65 2c | 20 6e 6f 74 20 74 68 65 |em time,| not the|
|00002210| 20 54 72 6f 6a 61 6e 20 | 68 6f 72 73 65 29 0a 58 | Trojan |horse).X|
|00002220| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 69 6e | | in|
|00002230| 20 66 61 76 6f 72 20 6f | 66 20 61 6e 6f 74 68 65 | favor o|f anothe|
|00002240| 72 20 6d 65 74 72 69 63 | 2c 20 70 65 72 68 61 70 |r metric|, perhap|
|00002250| 73 20 77 61 6c 6c 20 63 | 6c 6f 63 6b 20 74 69 6d |s wall c|lock tim|
|00002260| 65 2e 0a 58 0a 58 20 20 | 20 20 42 75 74 20 69 74 |e..X.X | But it|
|00002270| 20 69 73 6e 27 74 20 65 | 6e 6f 75 67 68 20 73 69 | isn't e|nough si|
|00002280| 6d 70 6c 79 20 74 6f 20 | 62 65 20 66 61 73 74 2c |mply to |be fast,|
|00002290| 20 61 20 73 6f 72 74 20 | 61 6c 67 6f 72 69 74 68 | a sort |algorith|
|000022a0| 6d 20 61 6c 73 6f 20 68 | 61 73 0a 58 74 6f 20 62 |m also h|as.Xto b|
|000022b0| 65 20 63 6f 72 72 65 63 | 74 2e 20 20 54 6f 20 74 |e correc|t. To t|
|000022c0| 68 61 74 20 65 6e 64 2c | 20 74 68 65 20 66 6c 6f |hat end,| the flo|
|000022d0| 67 67 65 72 20 72 6f 75 | 74 69 6e 65 20 76 65 72 |gger rou|tine ver|
|000022e0| 69 66 69 65 73 20 74 68 | 61 74 0a 58 74 68 65 20 |ifies th|at.Xthe |
|000022f0| 61 72 72 61 79 20 77 61 | 73 20 61 63 74 75 61 6c |array wa|s actual|
|00002300| 6c 79 20 73 6f 72 74 65 | 64 2c 20 61 74 20 6c 65 |ly sorte|d, at le|
|00002310| 61 73 74 20 77 68 65 6e | 20 74 68 65 20 63 6f 6d |ast when| the com|
|00002320| 70 61 72 69 73 6f 6e 20 | 72 6f 75 74 69 6e 65 0a |parison |routine.|
|00002330| 58 77 61 73 6e 27 74 20 | 6c 79 69 6e 67 2e 20 20 |Xwasn't |lying. |
|00002340| 49 74 20 61 6c 73 6f 20 | 63 68 65 63 6b 73 20 74 |It also |checks t|
|00002350| 68 61 74 20 6d 61 67 69 | 63 20 76 61 6c 75 65 73 |hat magi|c values|
|00002360| 20 69 6e 20 74 68 65 20 | 6d 65 6d 6f 72 79 20 6c | in the |memory l|
|00002370| 6f 63 61 74 69 6f 6e 73 | 0a 58 69 6d 6d 65 64 69 |ocations|.Ximmedi|
|00002380| 61 74 65 6c 79 20 61 62 | 6f 76 65 20 61 6e 64 20 |ately ab|ove and |
|00002390| 62 65 6c 6f 77 20 74 68 | 65 20 61 72 72 61 79 20 |below th|e array |
|000023a0| 77 65 72 65 20 6e 6f 74 | 20 61 63 63 69 64 65 6e |were not| acciden|
|000023b0| 74 61 6c 6c 79 20 61 63 | 63 65 73 73 65 64 0a 58 |tally ac|cessed.X|
|000023c0| 6f 72 20 6f 76 65 72 77 | 72 69 74 74 65 6e 2e 0a |or overw|ritten..|
|000023d0| 58 0a 58 20 20 20 20 54 | 68 65 20 62 6f 67 6f 20 |X.X T|he bogo |
|000023e0| 73 6f 72 74 20 72 75 6e | 20 69 73 20 73 6b 69 70 |sort run| is skip|
|000023f0| 70 65 64 20 69 66 20 6e | 20 69 73 20 73 75 66 66 |ped if n| is suff|
|00002400| 69 63 69 65 6e 74 6c 79 | 20 6c 61 72 67 65 20 74 |iciently| large t|
|00002410| 68 61 74 0a 58 69 74 27 | 73 20 65 78 65 63 75 74 |hat.Xit'|s execut|
|00002420| 69 6f 6e 20 77 6f 75 6c | 64 20 72 75 6e 20 69 6e |ion woul|d run in|
|00002430| 74 6f 20 74 72 69 6c 6c | 69 6f 6e 73 20 6f 66 20 |to trill|ions of |
|00002440| 63 79 63 6c 65 73 20 28 | 61 70 70 72 6f 78 20 6e |cycles (|approx n|
|00002450| 20 3d 20 31 35 29 2e 0a | 58 0a 58 4d 49 53 43 45 | = 15)..|X.XMISCE|
|00002460| 4c 4c 41 4e 45 4f 55 53 | 0a 58 0a 58 20 20 20 20 |LLANEOUS|.X.X |
|00002470| 57 68 65 6e 20 72 75 6e | 6e 69 6e 67 20 74 68 65 |When run|ning the|
|00002480| 20 74 65 73 74 20 72 6f | 75 74 69 6e 65 2c 20 73 | test ro|utine, s|
|00002490| 6f 6d 65 20 73 6f 72 74 | 73 20 74 61 6b 65 20 73 |ome sort|s take s|
|000024a0| 6f 20 6c 6f 6e 67 20 74 | 68 61 74 20 79 6f 75 0a |o long t|hat you.|
|000024b0| 58 6d 69 67 68 74 20 6c | 6f 73 65 20 70 61 74 69 |Xmight l|ose pati|
|000024c0| 65 6e 63 65 2e 20 20 4b | 65 79 62 6f 61 72 64 20 |ence. K|eyboard |
|000024d0| 69 6e 74 65 72 72 75 70 | 74 20 28 61 6b 61 20 43 |interrup|t (aka C|
|000024e0| 6f 6e 74 72 6f 6c 2d 43 | 29 20 77 69 6c 6c 20 61 |ontrol-C|) will a|
|000024f0| 62 6f 72 74 20 74 68 65 | 0a 58 63 75 72 72 65 6e |bort the|.Xcurren|
|00002500| 74 20 73 6f 72 74 20 74 | 65 73 74 20 61 6e 64 20 |t sort t|est and |
|00002510| 6d 6f 76 65 20 6f 6e 20 | 74 6f 20 74 68 65 20 6e |move on |to the n|
|00002520| 65 78 74 2e 20 20 49 66 | 20 79 6f 75 20 72 65 61 |ext. If| you rea|
|00002530| 6c 6c 79 20 77 61 6e 74 | 20 74 68 65 0a 58 70 72 |lly want| the.Xpr|
|00002540| 6f 67 72 61 6d 20 74 6f | 20 65 6e 64 2c 20 67 69 |ogram to| end, gi|
|00002550| 76 65 20 69 74 20 61 20 | 71 75 69 74 20 73 69 67 |ve it a |quit sig|
|00002560| 6e 61 6c 20 28 43 6f 6e | 74 72 6f 6c 2d 5c 29 20 |nal (Con|trol-\) |
|00002570| 6f 72 20 73 65 6e 64 20 | 69 74 20 61 20 73 69 67 |or send |it a sig|
|00002580| 6e 61 6c 0a 58 77 69 74 | 68 20 74 68 65 20 6b 69 |nal.Xwit|h the ki|
|00002590| 6c 6c 20 63 6f 6d 6d 61 | 6e 64 2e 20 20 20 59 6f |ll comma|nd. Yo|
|000025a0| 75 20 63 61 6e 20 61 6c | 73 6f 20 62 61 63 6b 67 |u can al|so backg|
|000025b0| 72 6f 75 6e 64 20 69 74 | 20 28 43 6f 6e 74 72 6f |round it| (Contro|
|000025c0| 6c 2d 5a 29 20 66 72 6f | 6d 0a 58 74 68 65 20 43 |l-Z) fro|m.Xthe C|
|000025d0| 2d 73 68 65 6c 6c 20 74 | 68 65 6e 20 6b 69 6c 6c |-shell t|hen kill|
|000025e0| 20 69 74 2e 0a 58 0a 58 | 20 20 20 20 54 68 65 20 | it..X.X| The |
|000025f0| 73 69 7a 65 20 6f 66 20 | 74 68 65 20 65 6c 65 6d |size of |the elem|
|00002600| 65 6e 74 73 20 62 65 69 | 6e 67 20 73 6f 72 74 65 |ents bei|ng sorte|
|00002610| 64 20 69 73 20 68 61 72 | 64 2d 63 6f 64 65 64 20 |d is har|d-coded |
|00002620| 61 74 20 74 68 65 20 6d | 6f 6d 65 6e 74 2c 0a 58 |at the m|oment,.X|
|00002630| 62 75 74 20 69 74 20 63 | 61 6e 20 62 65 20 63 68 |but it c|an be ch|
|00002640| 61 6e 67 65 64 20 62 79 | 20 67 6f 69 6e 67 20 69 |anged by| going i|
|00002650| 6e 74 6f 20 66 6c 6f 67 | 67 65 72 2e 63 20 61 6e |nto flog|ger.c an|
|00002660| 64 20 63 68 61 6e 67 69 | 6e 67 20 74 68 65 20 74 |d changi|ng the t|
|00002670| 79 70 65 64 65 66 73 20 | 66 6f 72 0a 58 0a 58 20 |ypedefs |for.X.X |
|00002680| 20 20 20 23 64 65 66 69 | 6e 65 20 54 45 53 54 5f | #defi|ne TEST_|
|00002690| 54 59 50 45 20 64 6f 75 | 62 6c 65 0a 58 20 20 20 |TYPE dou|ble.X |
|000026a0| 20 23 64 65 66 69 6e 65 | 20 54 45 53 54 5f 46 55 | #define| TEST_FU|
|000026b0| 4e 43 20 64 6f 75 62 6c | 65 5f 63 6f 6d 70 61 72 |NC doubl|e_compar|
|000026c0| 65 0a 58 0a 58 69 6e 74 | 6f 0a 58 0a 58 20 20 20 |e.X.Xint|o.X.X |
|000026d0| 20 23 64 65 66 69 6e 65 | 20 54 45 53 54 5f 54 59 | #define| TEST_TY|
|000026e0| 50 45 20 69 6e 74 0a 58 | 20 20 20 20 23 64 65 66 |PE int.X| #def|
|000026f0| 69 6e 65 20 54 45 53 54 | 5f 46 55 4e 43 20 69 6e |ine TEST|_FUNC in|
|00002700| 74 5f 63 6f 6d 70 61 72 | 65 0a 58 0a 58 6f 72 20 |t_compar|e.X.Xor |
|00002710| 62 61 63 6b 20 61 67 61 | 69 6e 2e 20 20 4f 72 20 |back aga|in. Or |
|00002720| 61 64 64 20 61 20 6e 65 | 77 20 74 79 70 65 20 61 |add a ne|w type a|
|00002730| 6e 64 20 61 20 6e 65 77 | 20 63 6f 6d 70 61 72 69 |nd a new| compari|
|00002740| 73 6f 6e 20 66 75 6e 63 | 74 69 6f 6e 2e 0a 58 0a |son func|tion..X.|
|00002750| 58 20 20 20 20 53 65 76 | 65 72 61 6c 20 6f 66 20 |X Sev|eral of |
|00002760| 74 68 65 20 73 6f 72 74 | 20 61 6c 67 6f 72 69 74 |the sort| algorit|
|00002770| 68 6d 73 20 61 72 65 20 | 6e 6f 74 20 72 65 2d 65 |hms are |not re-e|
|00002780| 6e 74 72 61 6e 74 20 77 | 68 69 63 68 20 6d 65 61 |ntrant w|hich mea|
|00002790| 6e 73 0a 58 79 6f 75 20 | 73 68 6f 75 6c 64 6e 27 |ns.Xyou |shouldn'|
|000027a0| 74 20 63 61 6c 6c 20 74 | 68 65 20 73 6f 72 74 20 |t call t|he sort |
|000027b0| 66 72 6f 6d 20 77 69 74 | 68 69 6e 20 74 68 65 20 |from wit|hin the |
|000027c0| 76 65 72 79 20 73 61 6d | 65 20 63 6f 6d 70 61 72 |very sam|e compar|
|000027d0| 69 73 6f 6e 20 0a 58 66 | 75 6e 63 74 69 6f 6e 20 |ison .Xf|unction |
|000027e0| 79 6f 75 20 70 61 73 73 | 65 64 20 69 6e 74 6f 20 |you pass|ed into |
|000027f0| 74 68 61 74 20 73 6f 72 | 74 20 69 6e 20 74 68 65 |that sor|t in the|
|00002800| 20 66 69 72 73 74 20 70 | 6c 61 63 65 2e 0a 58 0a | first p|lace..X.|
|00002810| 58 43 4f 50 59 52 49 47 | 48 54 0a 58 0a 58 20 20 |XCOPYRIG|HT.X.X |
|00002820| 20 20 53 69 6e 63 65 20 | 6e 6f 6e 65 20 6f 66 20 | Since |none of |
|00002830| 74 68 65 20 73 6f 72 74 | 20 61 6c 67 6f 72 69 74 |the sort| algorit|
|00002840| 68 6d 73 20 61 72 65 20 | 6d 69 6e 65 20 61 6e 64 |hms are |mine and|
|00002850| 20 61 6e 79 6f 6e 65 20 | 77 69 74 68 20 61 20 63 | anyone |with a c|
|00002860| 6f 70 79 0a 58 6f 66 20 | 4b 6e 75 74 68 20 56 6f |opy.Xof |Knuth Vo|
|00002870| 6c 20 33 20 61 6e 64 20 | 61 20 6c 69 74 74 6c 65 |l 3 and |a little|
|00002880| 20 6b 6e 6f 77 6c 65 64 | 67 65 20 6f 66 20 43 20 | knowled|ge of C |
|00002890| 63 6f 75 6c 64 20 74 79 | 70 65 20 74 68 65 6d 20 |could ty|pe them |
|000028a0| 69 6e 20 61 73 20 65 61 | 73 69 6c 79 0a 58 61 73 |in as ea|sily.Xas|
|000028b0| 20 49 20 64 69 64 2c 20 | 74 68 65 72 65 20 69 73 | I did, |there is|
|000028c0| 6e 27 74 20 6d 75 63 68 | 20 70 6f 69 6e 74 20 69 |n't much| point i|
|000028d0| 6e 20 63 6c 61 69 6d 69 | 6e 67 20 61 20 63 6f 70 |n claimi|ng a cop|
|000028e0| 79 72 69 67 68 74 2c 20 | 6d 75 63 68 20 6c 65 73 |yright, |much les|
|000028f0| 73 0a 58 61 70 70 6c 79 | 69 6e 67 20 66 6f 72 20 |s.Xapply|ing for |
|00002900| 61 20 70 61 74 65 6e 74 | 2e 20 20 49 20 77 61 6e |a patent|. I wan|
|00002910| 74 65 64 20 74 6f 20 64 | 69 73 63 6c 61 69 6d 20 |ted to d|isclaim |
|00002920| 6c 69 61 62 69 6c 69 74 | 79 20 74 68 6f 75 67 68 |liabilit|y though|
|00002930| 2c 20 73 6f 20 49 20 70 | 75 74 0a 58 61 20 66 65 |, so I p|ut.Xa fe|
|00002940| 77 20 6d 69 6e 6f 72 20 | 72 65 73 74 72 69 63 74 |w minor |restrict|
|00002950| 69 6f 6e 73 20 6f 6e 20 | 74 68 65 20 63 6f 64 65 |ions on |the code|
|00002960| 2c 20 61 73 20 73 65 74 | 20 66 6f 72 74 68 20 69 |, as set| forth i|
|00002970| 6e 20 65 61 63 68 20 6f | 66 20 74 68 65 0a 58 73 |n each o|f the.Xs|
|00002980| 6f 75 72 63 65 20 66 69 | 6c 65 73 2e 0a 45 4e 44 |ource fi|les..END|
|00002990| 5f 4f 46 5f 46 49 4c 45 | 0a 20 20 69 66 20 74 65 |_OF_FILE|. if te|
|000029a0| 73 74 20 37 39 39 33 20 | 2d 6e 65 20 60 77 63 20 |st 7993 |-ne `wc |
|000029b0| 2d 63 20 3c 27 52 45 41 | 44 4d 45 27 60 3b 20 74 |-c <'REA|DME'`; t|
|000029c0| 68 65 6e 0a 20 20 20 20 | 65 63 68 6f 20 73 68 61 |hen. |echo sha|
|000029d0| 72 3a 20 5c 22 27 52 45 | 41 44 4d 45 27 5c 22 20 |r: \"'RE|ADME'\" |
|000029e0| 75 6e 70 61 63 6b 65 64 | 20 77 69 74 68 20 77 72 |unpacked| with wr|
|000029f0| 6f 6e 67 20 73 69 7a 65 | 21 0a 20 20 66 69 0a 20 |ong size|!. fi. |
|00002a00| 20 23 20 65 6e 64 20 6f | 66 20 27 52 45 41 44 4d | # end o|f 'READM|
|00002a10| 45 27 0a 66 69 0a 69 66 | 20 74 65 73 74 20 2d 66 |E'.fi.if| test -f|
|00002a20| 20 27 4f 50 54 49 4d 49 | 5a 49 4e 47 27 20 2d 61 | 'OPTIMI|ZING' -a|
|00002a30| 20 22 24 7b 31 7d 22 20 | 21 3d 20 22 2d 63 22 20 | "${1}" |!= "-c" |
|00002a40| 3b 20 74 68 65 6e 20 0a | 20 20 65 63 68 6f 20 73 |; then .| echo s|
|00002a50| 68 61 72 3a 20 57 69 6c | 6c 20 6e 6f 74 20 63 6c |har: Wil|l not cl|
|00002a60| 6f 62 62 65 72 20 65 78 | 69 73 74 69 6e 67 20 66 |obber ex|isting f|
|00002a70| 69 6c 65 20 5c 22 27 4f | 50 54 49 4d 49 5a 49 4e |ile \"'O|PTIMIZIN|
|00002a80| 47 27 5c 22 0a 65 6c 73 | 65 0a 20 20 65 63 68 6f |G'\".els|e. echo|
|00002a90| 20 73 68 61 72 3a 20 45 | 78 74 72 61 63 74 69 6e | shar: E|xtractin|
|00002aa0| 67 20 5c 22 27 4f 50 54 | 49 4d 49 5a 49 4e 47 27 |g \"'OPT|IMIZING'|
|00002ab0| 5c 22 20 5c 28 34 34 35 | 32 20 63 68 61 72 61 63 |\" \(445|2 charac|
|00002ac0| 74 65 72 73 5c 29 0a 20 | 20 73 65 64 20 22 73 2f |ters\). | sed "s/|
|00002ad0| 5e 58 2f 2f 22 20 3e 27 | 4f 50 54 49 4d 49 5a 49 |^X//" >'|OPTIMIZI|
|00002ae0| 4e 47 27 20 3c 3c 27 45 | 4e 44 5f 4f 46 5f 46 49 |NG' <<'E|ND_OF_FI|
|00002af0| 4c 45 27 0a 58 0a 58 41 | 20 62 72 69 65 66 20 77 |LE'.X.XA| brief w|
|00002b00| 6f 72 64 20 61 62 6f 75 | 74 20 6f 70 74 69 6d 69 |ord abou|t optimi|
|00002b10| 7a 69 6e 67 20 63 6f 64 | 65 2c 20 69 6e 20 70 61 |zing cod|e, in pa|
|00002b20| 72 74 69 63 75 6c 61 72 | 2c 20 63 6f 64 65 20 74 |rticular|, code t|
|00002b30| 68 61 74 0a 58 63 61 6c | 6c 73 20 61 20 73 6f 72 |hat.Xcal|ls a sor|
|00002b40| 74 69 6e 67 20 66 75 6e | 63 74 69 6f 6e 2e 0a 58 |ting fun|ction..X|
|00002b50| 0a 58 54 68 65 20 71 73 | 6f 72 74 28 29 20 74 68 |.XThe qs|ort() th|
|00002b60| 61 74 20 63 6f 6d 65 73 | 20 77 69 74 68 20 6d 6f |at comes| with mo|
|00002b70| 73 74 20 43 20 69 6d 70 | 6c 65 6d 65 6e 74 61 74 |st C imp|lementat|
|00002b80| 69 6f 6e 73 20 69 73 20 | 66 61 73 74 20 65 6e 6f |ions is |fast eno|
|00002b90| 75 67 68 20 66 6f 72 0a | 58 6e 65 61 72 6c 79 20 |ugh for.|Xnearly |
|00002ba0| 61 6c 6c 20 70 75 72 70 | 6f 73 65 73 2e 20 20 54 |all purp|oses. T|
|00002bb0| 68 65 20 73 6f 72 74 20 | 61 6c 67 6f 72 69 74 68 |he sort |algorith|
|00002bc0| 6d 73 20 69 6e 20 74 68 | 69 73 20 70 61 63 6b 61 |ms in th|is packa|
|00002bd0| 67 65 20 61 72 65 20 68 | 65 72 65 0a 58 6d 6f 73 |ge are h|ere.Xmos|
|00002be0| 74 6c 79 20 66 6f 72 20 | 69 6e 74 65 6c 6c 65 63 |tly for |intellec|
|00002bf0| 74 75 61 6c 20 63 75 72 | 69 6f 75 73 69 74 79 2e |tual cur|iousity.|
|00002c00| 20 20 54 68 65 20 6d 65 | 72 67 65 5f 73 6f 72 74 | The me|rge_sort|
|00002c10| 20 61 6c 67 6f 72 69 74 | 68 6d 20 69 73 0a 58 73 | algorit|hm is.Xs|
|00002c20| 75 70 65 72 69 6f 72 20 | 69 6e 20 73 6f 6d 65 20 |uperior |in some |
|00002c30| 77 61 79 73 2c 20 6d 6f | 73 74 6c 79 20 74 68 61 |ways, mo|stly tha|
|00002c40| 74 20 69 74 20 72 65 71 | 75 69 72 65 73 20 66 65 |t it req|uires fe|
|00002c50| 77 65 72 20 63 61 6c 6c | 62 61 63 6b 73 20 74 6f |wer call|backs to|
|00002c60| 20 74 68 65 0a 58 63 6f | 6d 70 61 72 69 73 6f 6e | the.Xco|mparison|
|00002c70| 20 66 75 6e 63 74 69 6f | 6e 2c 20 62 75 74 20 74 | functio|n, but t|
|00002c80| 68 61 74 20 61 6c 6f 6e | 65 20 69 73 20 6e 6f 20 |hat alon|e is no |
|00002c90| 72 65 61 73 6f 6e 20 74 | 6f 20 73 65 64 20 2d 65 |reason t|o sed -e|
|00002ca0| 20 73 2f 71 73 6f 72 74 | 2f 6d 65 72 67 65 5f 73 | s/qsort|/merge_s|
|00002cb0| 6f 72 74 2f 0a 58 6f 76 | 65 72 20 61 6c 6c 20 79 |ort/.Xov|er all y|
|00002cc0| 6f 75 72 20 63 6f 64 65 | 2e 0a 58 0a 58 53 6f 6d |our code|..X.XSom|
|00002cd0| 65 20 67 65 6e 65 72 61 | 6c 20 61 70 70 72 6f 61 |e genera|l approa|
|00002ce0| 63 68 65 73 20 74 6f 20 | 63 6f 6e 73 69 64 65 72 |ches to |consider|
|00002cf0| 20 62 65 66 6f 72 65 20 | 62 6f 72 72 6f 77 69 6e | before |borrowin|
|00002d00| 67 20 6f 6e 65 20 6f 66 | 20 74 68 65 73 65 0a 58 |g one of| these.X|
|00002d10| 73 6f 72 74 20 61 6c 67 | 6f 72 69 74 68 6d 73 20 |sort alg|orithms |
|00002d20| 66 6f 72 20 75 73 65 20 | 69 6e 20 79 6f 75 72 20 |for use |in your |
|00002d30| 63 6f 64 65 2c 20 61 70 | 70 72 6f 78 69 6d 61 74 |code, ap|proximat|
|00002d40| 65 6c 79 20 69 6e 20 64 | 65 63 72 65 61 73 69 6e |ely in d|ecreasin|
|00002d50| 67 0a 58 6f 72 64 65 72 | 20 6f 66 20 65 66 66 65 |g.Xorder| of effe|
|00002d60| 63 74 69 76 65 6e 65 73 | 73 3a 0a 58 0a 58 31 2e |ctivenes|s:.X.X1.|
|00002d70| 20 72 75 6e 20 70 72 6f | 66 20 6f 72 20 67 70 72 | run pro|f or gpr|
|00002d80| 6f 66 20 74 6f 20 6d 61 | 6b 65 20 73 75 72 65 20 |of to ma|ke sure |
|00002d90| 74 68 65 20 73 6f 72 74 | 69 6e 67 20 69 73 20 61 |the sort|ing is a|
|00002da0| 6e 20 61 63 74 75 61 6c | 0a 58 20 20 20 62 6f 74 |n actual|.X bot|
|00002db0| 74 6c 65 6e 65 63 6b 3b | 20 6f 66 74 65 6e 2c 20 |tleneck;| often, |
|00002dc0| 72 65 61 64 69 6e 67 20 | 69 6e 20 74 68 65 20 72 |reading |in the r|
|00002dd0| 65 63 6f 72 64 73 20 74 | 6f 20 62 65 20 73 6f 72 |ecords t|o be sor|
|00002de0| 74 65 64 0a 58 20 20 20 | 74 61 6b 65 73 20 6d 6f |ted.X |takes mo|
|00002df0| 72 65 20 77 61 6c 6c 20 | 63 6c 6f 63 6b 20 74 69 |re wall |clock ti|
|00002e00| 6d 65 20 74 68 61 6e 20 | 74 68 65 20 73 6f 72 74 |me than |the sort|
|00002e10| 20 69 74 73 65 6c 66 20 | 61 6e 64 20 65 66 66 6f | itself |and effo|
|00002e20| 72 74 0a 58 20 20 20 73 | 70 65 6e 74 20 6f 70 74 |rt.X s|pent opt|
|00002e30| 69 6d 69 7a 69 6e 67 20 | 74 68 65 20 73 6f 72 74 |imizing |the sort|
|00002e40| 20 69 73 20 63 6f 6d 70 | 6c 65 74 65 6c 79 20 70 | is comp|letely p|
|00002e50| 6f 69 6e 74 6c 65 73 73 | 2e 0a 58 0a 58 32 2e 20 |ointless|..X.X2. |
|00002e60| 55 73 65 20 79 6f 75 72 | 20 63 6f 6d 70 69 6c 65 |Use your| compile|
|00002e70| 72 27 73 20 6d 61 78 69 | 6d 61 6c 20 6f 70 74 69 |r's maxi|mal opti|
|00002e80| 6d 69 7a 61 74 69 6f 6e | 20 6c 65 76 65 6c 20 77 |mization| level w|
|00002e90| 68 65 6e 20 63 6f 6d 70 | 69 6c 69 6e 67 0a 58 20 |hen comp|iling.X |
|00002ea0| 20 20 74 68 65 20 63 6f | 6d 70 61 72 69 73 6f 6e | the co|mparison|
|00002eb0| 20 66 75 6e 63 74 69 6f | 6e 2e 20 20 54 68 69 73 | functio|n. This|
|00002ec0| 20 63 61 6e 20 72 65 73 | 75 6c 74 20 69 6e 20 61 | can res|ult in a|
|00002ed0| 20 73 75 72 70 72 69 73 | 69 6e 67 20 0a 58 20 20 | surpris|ing .X |
|00002ee0| 20 69 6d 70 72 6f 76 65 | 6d 65 6e 74 20 69 6e 20 | improve|ment in |
|00002ef0| 70 65 72 66 6f 72 6d 61 | 6e 63 65 2e 0a 58 0a 58 |performa|nce..X.X|
|00002f00| 33 2e 20 48 61 6e 64 20 | 6f 70 74 69 6d 69 7a 65 |3. Hand |optimize|
|00002f10| 20 74 68 65 20 63 6f 6d | 70 61 72 69 73 6f 6e 20 | the com|parison |
|00002f20| 66 75 6e 63 74 69 6f 6e | 2e 20 20 43 6f 6e 73 69 |function|. Consi|
|00002f30| 64 65 72 20 73 6f 72 74 | 69 6e 67 20 6f 6e 0a 58 |der sort|ing on.X|
|00002f40| 20 20 20 61 20 22 70 72 | 65 64 69 67 65 73 74 65 | a "pr|edigeste|
|00002f50| 64 22 20 6b 65 79 20 74 | 68 61 74 20 72 65 71 75 |d" key t|hat requ|
|00002f60| 69 72 65 73 20 6c 65 73 | 73 20 77 6f 72 6b 20 74 |ires les|s work t|
|00002f70| 6f 20 63 6f 6d 70 61 72 | 65 20 74 68 61 6e 20 0a |o compar|e than .|
|00002f80| 58 20 20 20 74 68 65 20 | 72 65 63 6f 72 64 73 20 |X the |records |
|00002f90| 74 68 65 6d 73 65 6c 76 | 65 73 2e 20 20 4d 61 6b |themselv|es. Mak|
|00002fa0| 65 20 61 73 20 66 65 77 | 20 63 61 6c 6c 73 20 74 |e as few| calls t|
|00002fb0| 6f 20 6f 74 68 65 72 20 | 66 75 6e 63 74 69 6f 6e |o other |function|
|00002fc0| 73 20 0a 58 20 20 20 61 | 73 20 6e 65 63 65 73 73 |s .X a|s necess|
|00002fd0| 61 72 79 20 66 72 6f 6d | 20 77 69 74 68 69 6e 20 |ary from| within |
|00002fe0| 74 68 65 20 63 6f 6d 70 | 61 72 69 73 6f 6e 20 66 |the comp|arison f|
|00002ff0| 75 6e 63 74 69 6f 6e 2e | 0a 58 0a 58 34 2e 20 52 |unction.|.X.X4. R|
|00003000| 65 64 75 63 65 20 74 68 | 65 20 73 69 7a 65 20 6f |educe th|e size o|
|00003010| 66 20 74 68 65 20 69 74 | 65 6d 73 20 62 65 69 6e |f the it|ems bein|
|00003020| 67 20 73 6f 72 74 65 64 | 2e 20 20 43 72 65 61 74 |g sorted|. Creat|
|00003030| 65 20 61 6e 0a 58 20 20 | 20 61 72 72 61 79 20 6f |e an.X | array o|
|00003040| 66 20 70 6f 69 6e 74 65 | 72 73 20 74 6f 20 72 65 |f pointe|rs to re|
|00003050| 63 6f 72 64 73 20 61 6c | 72 65 61 64 79 20 65 78 |cords al|ready ex|
|00003060| 69 73 74 69 6e 67 20 65 | 6c 73 65 77 68 65 72 65 |isting e|lsewhere|
|00003070| 0a 58 20 20 20 69 6e 20 | 6d 65 6d 6f 72 79 3b 20 |.X in |memory; |
|00003080| 74 68 65 20 73 6f 72 74 | 20 77 69 6c 6c 20 74 68 |the sort| will th|
|00003090| 65 6e 20 6f 6e 6c 79 20 | 68 61 76 65 20 74 6f 20 |en only |have to |
|000030a0| 73 68 75 66 66 6c 65 20 | 74 68 65 0a 58 20 20 20 |shuffle |the.X |
|000030b0| 70 6f 69 6e 74 65 72 73 | 20 61 72 6f 75 6e 64 20 |pointers| around |
|000030c0| 72 61 74 68 65 72 20 74 | 68 61 6e 20 63 6f 70 79 |rather t|han copy|
|000030d0| 20 65 6e 74 69 72 65 20 | 72 65 63 6f 72 64 73 2e | entire |records.|
|000030e0| 20 20 57 6f 72 6b 73 0a | 58 20 20 20 77 65 6c 6c | Works.|X well|
|000030f0| 20 69 6e 20 63 6f 6d 62 | 69 6e 61 74 69 6f 6e 20 | in comb|ination |
|00003100| 77 69 74 68 20 23 33 2e | 0a 58 0a 58 35 2e 20 43 |with #3.|.X.X5. C|
|00003110| 6f 6e 73 69 64 65 72 20 | 6d 61 69 6e 74 61 69 6e |onsider |maintain|
|00003120| 69 6e 67 20 61 20 62 2d | 74 72 65 65 20 6f 72 20 |ing a b-|tree or |
|00003130| 6f 74 68 65 72 20 69 6e | 64 65 78 20 77 68 69 63 |other in|dex whic|
|00003140| 68 0a 58 20 20 20 6c 61 | 73 74 73 20 62 65 79 6f |h.X la|sts beyo|
|00003150| 6e 64 20 70 72 6f 67 72 | 61 6d 20 74 65 72 6d 69 |nd progr|am termi|
|00003160| 6e 61 74 69 6f 6e 2e 20 | 20 49 66 20 74 68 65 20 |nation. | If the |
|00003170| 69 6e 64 65 78 20 69 73 | 20 75 70 64 61 74 65 64 |index is| updated|
|00003180| 0a 58 20 20 20 69 6e 66 | 72 65 71 75 65 6e 74 6c |.X inf|requentl|
|00003190| 79 20 61 6e 64 20 6f 6e | 6c 79 20 6f 6e 65 20 6f |y and on|ly one o|
|000031a0| 72 20 74 77 6f 20 65 6c | 65 6d 65 6e 74 73 20 61 |r two el|ements a|
|000031b0| 72 65 20 61 64 64 65 64 | 0a 58 20 20 20 74 6f 20 |re added|.X to |
|000031c0| 69 74 20 61 74 20 61 20 | 74 69 6d 65 2c 20 74 68 |it at a |time, th|
|000031d0| 65 20 6d 75 63 68 2d 6d | 61 6c 69 67 6e 65 64 20 |e much-m|aligned |
|000031e0| 62 75 62 62 6c 65 20 73 | 6f 72 74 20 6d 69 67 68 |bubble s|ort migh|
|000031f0| 74 0a 58 20 20 20 61 63 | 74 75 61 6c 6c 79 20 62 |t.X ac|tually b|
|00003200| 65 20 6f 66 20 75 73 65 | 2e 0a 58 0a 58 36 2e 20 |e of use|..X.X6. |
|00003210| 50 6c 75 67 20 69 6e 20 | 6d 65 72 67 65 5f 73 6f |Plug in |merge_so|
|00003220| 72 74 20 66 72 6f 6d 20 | 74 68 69 73 20 70 61 63 |rt from |this pac|
|00003230| 6b 61 67 65 2e 20 20 45 | 78 70 65 63 74 20 6f 6e |kage. E|xpect on|
|00003240| 6c 79 20 61 20 73 6c 69 | 67 68 74 0a 58 20 20 20 |ly a sli|ght.X |
|00003250| 69 6d 70 72 6f 76 65 6d | 65 6e 74 2e 20 20 42 75 |improvem|ent. Bu|
|00003260| 74 20 61 20 64 65 67 72 | 61 64 61 74 69 6f 6e 20 |t a degr|adation |
|00003270| 69 73 20 70 6f 73 73 69 | 62 6c 65 20 61 73 20 77 |is possi|ble as w|
|00003280| 65 6c 6c 3a 20 74 68 69 | 73 20 6d 65 72 67 65 0a |ell: thi|s merge.|
|00003290| 58 20 20 20 73 6f 72 74 | 20 61 6c 6c 6f 63 61 74 |X sort| allocat|
|000032a0| 65 73 20 61 20 62 69 67 | 20 63 68 75 6e 6b 20 6f |es a big| chunk o|
|000032b0| 66 20 6d 65 6d 6f 72 79 | 2c 20 77 68 69 63 68 20 |f memory|, which |
|000032c0| 63 61 6e 20 65 61 74 20 | 75 70 20 73 77 61 70 20 |can eat |up swap |
|000032d0| 0a 58 20 20 20 73 70 61 | 63 65 20 61 6e 64 20 73 |.X spa|ce and s|
|000032e0| 6c 6f 77 20 74 68 69 6e | 67 73 20 64 6f 77 6e 2e |low thin|gs down.|
|000032f0| 0a 58 0a 58 37 2e 20 4d | 61 6b 65 20 61 20 63 6f |.X.X7. M|ake a co|
|00003300| 70 79 20 6f 66 20 74 68 | 65 20 6d 65 72 67 65 5f |py of th|e merge_|
|00003310| 73 6f 72 74 20 63 6f 64 | 65 20 61 6e 64 20 72 65 |sort cod|e and re|
|00003320| 70 6c 61 63 65 20 74 68 | 65 20 63 61 6c 6c 73 0a |place th|e calls.|
|00003330| 58 20 20 20 74 6f 20 74 | 68 65 20 63 6d 70 72 5f |X to t|he cmpr_|
|00003340| 66 75 6e 63 20 77 69 74 | 68 20 74 68 65 20 61 63 |func wit|h the ac|
|00003350| 74 75 61 6c 20 63 6f 64 | 65 20 6f 66 20 74 68 65 |tual cod|e of the|
|00003360| 20 63 6f 6d 70 61 72 65 | 2e 0a 58 20 20 20 4f 72 | compare|..X Or|
|00003370| 20 69 66 20 79 6f 75 20 | 68 61 76 65 20 67 63 63 | if you |have gcc|
|00003380| 2c 20 74 61 6b 65 20 61 | 64 76 61 6e 74 61 67 65 |, take a|dvantage|
|00003390| 20 6f 66 20 69 6e 6c 69 | 6e 69 6e 67 20 74 6f 20 | of inli|ning to |
|000033a0| 61 63 68 69 65 76 65 0a | 58 20 20 20 74 68 65 20 |achieve.|X the |
|000033b0| 73 61 6d 65 20 74 68 69 | 6e 67 2e 20 20 45 78 70 |same thi|ng. Exp|
|000033c0| 65 63 74 20 61 6e 20 65 | 76 65 6e 20 6c 65 73 73 |ect an e|ven less|
|000033d0| 20 6e 6f 74 69 63 65 61 | 62 6c 65 20 69 6d 70 72 | noticea|ble impr|
|000033e0| 6f 76 65 6d 65 6e 74 2e | 0a 58 0a 58 38 2e 20 49 |ovement.|.X.X8. I|
|000033f0| 66 20 69 74 27 73 20 2a | 73 74 69 6c 6c 20 74 6f |f it's *|still to|
|00003400| 6f 20 73 6c 6f 77 2a 2c | 20 77 72 69 74 65 20 61 |o slow*,| write a|
|00003410| 20 73 6f 72 74 20 74 68 | 61 74 20 74 61 6b 65 73 | sort th|at takes|
|00003420| 20 61 64 76 61 6e 74 61 | 67 65 0a 58 20 20 20 6f | advanta|ge.X o|
|00003430| 66 20 74 68 65 20 64 69 | 73 74 72 69 62 75 74 69 |f the di|stributi|
|00003440| 6f 6e 20 6f 66 20 6b 65 | 79 73 20 74 6f 20 63 61 |on of ke|ys to ca|
|00003450| 6c 63 75 6c 61 74 65 20 | 74 68 65 20 70 6f 73 69 |lculate |the posi|
|00003460| 74 69 6f 6e 20 6f 66 20 | 61 0a 58 20 20 20 72 65 |tion of |a.X re|
|00003470| 63 6f 72 64 20 64 69 72 | 65 63 74 6c 79 20 77 69 |cord dir|ectly wi|
|00003480| 74 68 6f 75 74 20 68 61 | 76 69 6e 67 20 74 6f 20 |thout ha|ving to |
|00003490| 63 6f 6d 70 61 72 65 20 | 69 74 20 74 6f 20 6f 74 |compare |it to ot|
|000034a0| 68 65 72 20 72 65 63 6f | 72 64 73 2e 0a 58 0a 58 |her reco|rds..X.X|
|000034b0| 0a 58 54 68 65 20 63 6f | 6d 70 2e 6c 61 6e 67 2e |.XThe co|mp.lang.|
|000034c0| 63 20 46 41 51 20 6c 69 | 73 74 20 68 61 73 20 74 |c FAQ li|st has t|
|000034d0| 68 69 73 20 74 6f 20 73 | 61 79 20 61 62 6f 75 74 |his to s|ay about|
|000034e0| 20 74 68 65 20 73 75 62 | 6a 65 63 74 20 6f 66 0a | the sub|ject of.|
|000034f0| 58 65 66 66 69 63 69 65 | 6e 63 79 20 69 6e 20 67 |Xefficie|ncy in g|
|00003500| 65 6e 65 72 61 6c 2e 20 | 20 22 52 65 61 64 20 69 |eneral. | "Read i|
|00003510| 74 2e 20 20 4c 65 61 72 | 6e 20 69 74 2e 20 20 4c |t. Lear|n it. L|
|00003520| 69 76 65 20 69 74 2e 22 | 0a 58 0a 58 2d 2d 2d 2d |ive it."|.X.X----|
|00003530| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00003540| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00003550| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00003560| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00003570| 2d 2d 2d 2d 2d 2d 2d 0a | 58 31 37 2e 31 33 3a 20 |-------.|X17.13: |
|00003580| 20 48 6f 77 20 63 61 6e | 20 49 20 6d 61 6b 65 20 | How can| I make |
|00003590| 74 68 69 73 20 63 6f 64 | 65 20 6d 6f 72 65 20 65 |this cod|e more e|
|000035a0| 66 66 69 63 69 65 6e 74 | 3f 0a 58 0a 58 41 3a 20 |fficient|?.X.XA: |
|000035b0| 20 20 20 20 20 45 66 66 | 69 63 69 65 6e 63 79 2c | Eff|iciency,|
|000035c0| 20 74 68 6f 75 67 68 20 | 61 20 66 61 76 6f 72 69 | though |a favori|
|000035d0| 74 65 20 63 6f 6d 70 2e | 6c 61 6e 67 2e 63 20 74 |te comp.|lang.c t|
|000035e0| 6f 70 69 63 2c 20 69 73 | 20 6e 6f 74 0a 58 20 20 |opic, is| not.X |
|000035f0| 20 20 20 20 20 20 69 6d | 70 6f 72 74 61 6e 74 20 | im|portant |
|00003600| 6e 65 61 72 6c 79 20 61 | 73 20 6f 66 74 65 6e 20 |nearly a|s often |
|00003610| 61 73 20 70 65 6f 70 6c | 65 20 74 65 6e 64 20 74 |as peopl|e tend t|
|00003620| 6f 20 74 68 69 6e 6b 20 | 69 74 20 69 73 2e 20 20 |o think |it is. |
|00003630| 4d 6f 73 74 0a 58 20 20 | 20 20 20 20 20 20 6f 66 |Most.X | of|
|00003640| 20 74 68 65 20 63 6f 64 | 65 20 69 6e 20 6d 6f 73 | the cod|e in mos|
|00003650| 74 20 70 72 6f 67 72 61 | 6d 73 20 69 73 20 6e 6f |t progra|ms is no|
|00003660| 74 20 74 69 6d 65 2d 63 | 72 69 74 69 63 61 6c 2e |t time-c|ritical.|
|00003670| 20 20 57 68 65 6e 20 63 | 6f 64 65 20 69 73 0a 58 | When c|ode is.X|
|00003680| 20 20 20 20 20 20 20 20 | 6e 6f 74 20 74 69 6d 65 | |not time|
|00003690| 2d 63 72 69 74 69 63 61 | 6c 2c 20 69 74 20 69 73 |-critica|l, it is|
|000036a0| 20 66 61 72 20 6d 6f 72 | 65 20 69 6d 70 6f 72 74 | far mor|e import|
|000036b0| 61 6e 74 20 74 68 61 74 | 20 69 74 20 62 65 20 77 |ant that| it be w|
|000036c0| 72 69 74 74 65 6e 0a 58 | 20 20 20 20 20 20 20 20 |ritten.X| |
|000036d0| 63 6c 65 61 72 6c 79 20 | 61 6e 64 20 70 6f 72 74 |clearly |and port|
|000036e0| 61 62 6c 79 20 74 68 61 | 6e 20 74 68 61 74 20 69 |ably tha|n that i|
|000036f0| 74 20 62 65 20 77 72 69 | 74 74 65 6e 20 6d 61 78 |t be wri|tten max|
|00003700| 69 6d 61 6c 6c 79 0a 58 | 20 20 20 20 20 20 20 20 |imally.X| |
|00003710| 65 66 66 69 63 69 65 6e | 74 6c 79 2e 20 20 28 52 |efficien|tly. (R|
|00003720| 65 6d 65 6d 62 65 72 20 | 74 68 61 74 20 63 6f 6d |emember |that com|
|00003730| 70 75 74 65 72 73 20 61 | 72 65 20 76 65 72 79 2c |puters a|re very,|
|00003740| 20 76 65 72 79 20 66 61 | 73 74 2c 20 61 6e 64 0a | very fa|st, and.|
|00003750| 58 20 20 20 20 20 20 20 | 20 74 68 61 74 20 65 76 |X | that ev|
|00003760| 65 6e 20 22 69 6e 65 66 | 66 69 63 69 65 6e 74 22 |en "inef|ficient"|
|00003770| 20 63 6f 64 65 20 63 61 | 6e 20 72 75 6e 20 77 69 | code ca|n run wi|
|00003780| 74 68 6f 75 74 20 61 70 | 70 61 72 65 6e 74 20 64 |thout ap|parent d|
|00003790| 65 6c 61 79 2e 29 0a 58 | 0a 58 20 20 20 20 20 20 |elay.).X|.X |
|000037a0| 20 20 49 74 20 69 73 20 | 6e 6f 74 6f 72 69 6f 75 | It is |notoriou|
|000037b0| 73 6c 79 20 64 69 66 66 | 69 63 75 6c 74 20 74 6f |sly diff|icult to|
|000037c0| 20 70 72 65 64 69 63 74 | 20 77 68 61 74 20 74 68 | predict| what th|
|000037d0| 65 20 22 68 6f 74 20 73 | 70 6f 74 73 22 20 69 6e |e "hot s|pots" in|
|000037e0| 20 61 0a 58 20 20 20 20 | 20 20 20 20 70 72 6f 67 | a.X | prog|
|000037f0| 72 61 6d 20 77 69 6c 6c | 20 62 65 2e 20 20 57 68 |ram will| be. Wh|
|00003800| 65 6e 20 65 66 66 69 63 | 69 65 6e 63 79 20 69 73 |en effic|iency is|
|00003810| 20 61 20 63 6f 6e 63 65 | 72 6e 2c 20 69 74 20 69 | a conce|rn, it i|
|00003820| 73 20 69 6d 70 6f 72 74 | 61 6e 74 0a 58 20 20 20 |s import|ant.X |
|00003830| 20 20 20 20 20 74 6f 20 | 75 73 65 20 70 72 6f 66 | to |use prof|
|00003840| 69 6c 69 6e 67 20 73 6f | 66 74 77 61 72 65 20 74 |iling so|ftware t|
|00003850| 6f 20 64 65 74 65 72 6d | 69 6e 65 20 77 68 69 63 |o determ|ine whic|
|00003860| 68 20 70 61 72 74 73 20 | 6f 66 20 74 68 65 0a 58 |h parts |of the.X|
|00003870| 20 20 20 20 20 20 20 20 | 70 72 6f 67 72 61 6d 20 | |program |
|00003880| 64 65 73 65 72 76 65 20 | 61 74 74 65 6e 74 69 6f |deserve |attentio|
|00003890| 6e 2e 20 20 4f 66 74 65 | 6e 2c 20 61 63 74 75 61 |n. Ofte|n, actua|
|000038a0| 6c 20 63 6f 6d 70 75 74 | 61 74 69 6f 6e 20 74 69 |l comput|ation ti|
|000038b0| 6d 65 20 69 73 0a 58 20 | 20 20 20 20 20 20 20 73 |me is.X | s|
|000038c0| 77 61 6d 70 65 64 20 62 | 79 20 70 65 72 69 70 68 |wamped b|y periph|
|000038d0| 65 72 61 6c 20 74 61 73 | 6b 73 20 73 75 63 68 20 |eral tas|ks such |
|000038e0| 61 73 20 49 2f 4f 20 61 | 6e 64 20 6d 65 6d 6f 72 |as I/O a|nd memor|
|000038f0| 79 20 61 6c 6c 6f 63 61 | 74 69 6f 6e 2c 0a 58 20 |y alloca|tion,.X |
|00003900| 20 20 20 20 20 20 20 77 | 68 69 63 68 20 63 61 6e | w|hich can|
|00003910| 20 62 65 20 73 70 65 64 | 20 75 70 20 62 79 20 75 | be sped| up by u|
|00003920| 73 69 6e 67 20 62 75 66 | 66 65 72 69 6e 67 20 61 |sing buf|fering a|
|00003930| 6e 64 20 63 61 63 68 65 | 69 6e 67 20 74 65 63 68 |nd cache|ing tech|
|00003940| 6e 69 71 75 65 73 2e 0a | 58 0a 58 20 20 20 20 20 |niques..|X.X |
|00003950| 20 20 20 46 6f 72 20 74 | 68 65 20 73 6d 61 6c 6c | For t|he small|
|00003960| 20 66 72 61 63 74 69 6f | 6e 20 6f 66 20 63 6f 64 | fractio|n of cod|
|00003970| 65 20 74 68 61 74 20 69 | 73 20 74 69 6d 65 2d 63 |e that i|s time-c|
|00003980| 72 69 74 69 63 61 6c 2c | 20 69 74 20 69 73 0a 58 |ritical,| it is.X|
|00003990| 20 20 20 20 20 20 20 20 | 76 69 74 61 6c 20 74 6f | |vital to|
|000039a0| 20 70 69 63 6b 20 61 20 | 67 6f 6f 64 20 61 6c 67 | pick a |good alg|
|000039b0| 6f 72 69 74 68 6d 3b 20 | 69 74 20 69 73 20 6c 65 |orithm; |it is le|
|000039c0| 73 73 20 69 6d 70 6f 72 | 74 61 6e 74 20 74 6f 0a |ss impor|tant to.|
|000039d0| 58 20 20 20 20 20 20 20 | 20 22 6d 69 63 72 6f 6f |X | "microo|
|000039e0| 70 74 69 6d 69 7a 65 22 | 20 74 68 65 20 63 6f 64 |ptimize"| the cod|
|000039f0| 69 6e 67 20 64 65 74 61 | 69 6c 73 2e 20 20 4d 61 |ing deta|ils. Ma|
|00003a00| 6e 79 20 6f 66 20 74 68 | 65 20 22 65 66 66 69 63 |ny of th|e "effic|
|00003a10| 69 65 6e 74 0a 58 20 20 | 20 20 20 20 20 20 63 6f |ient.X | co|
|00003a20| 64 69 6e 67 20 74 72 69 | 63 6b 73 22 20 77 68 69 |ding tri|cks" whi|
|00003a30| 63 68 20 61 72 65 20 66 | 72 65 71 75 65 6e 74 6c |ch are f|requentl|
|00003a40| 79 20 73 75 67 67 65 73 | 74 65 64 20 28 65 2e 67 |y sugges|ted (e.g|
|00003a50| 2e 20 73 75 62 73 74 69 | 74 75 74 69 6e 67 0a 58 |. substi|tuting.X|
|00003a60| 20 20 20 20 20 20 20 20 | 73 68 69 66 74 20 6f 70 | |shift op|
|00003a70| 65 72 61 74 6f 72 73 20 | 66 6f 72 20 6d 75 6c 74 |erators |for mult|
|00003a80| 69 70 6c 69 63 61 74 69 | 6f 6e 20 62 79 20 70 6f |iplicati|on by po|
|00003a90| 77 65 72 73 20 6f 66 20 | 74 77 6f 29 20 61 72 65 |wers of |two) are|
|00003aa0| 0a 58 20 20 20 20 20 20 | 20 20 70 65 72 66 6f 72 |.X | perfor|
|00003ab0| 6d 65 64 20 61 75 74 6f | 6d 61 74 69 63 61 6c 6c |med auto|maticall|
|00003ac0| 79 20 62 79 20 65 76 65 | 6e 20 73 69 6d 70 6c 65 |y by eve|n simple|
|00003ad0| 6d 69 6e 64 65 64 20 63 | 6f 6d 70 69 6c 65 72 73 |minded c|ompilers|
|00003ae0| 2e 0a 58 20 20 20 20 20 | 20 20 20 48 65 61 76 79 |..X | Heavy|
|00003af0| 68 61 6e 64 65 64 20 22 | 6f 70 74 69 6d 69 7a 61 |handed "|optimiza|
|00003b00| 74 69 6f 6e 22 20 61 74 | 74 65 6d 70 74 73 20 63 |tion" at|tempts c|
|00003b10| 61 6e 20 6d 61 6b 65 20 | 63 6f 64 65 20 73 6f 20 |an make |code so |
|00003b20| 62 75 6c 6b 79 20 74 68 | 61 74 0a 58 20 20 20 20 |bulky th|at.X |
|00003b30| 20 20 20 20 70 65 72 66 | 6f 72 6d 61 6e 63 65 20 | perf|ormance |
|00003b40| 69 73 20 64 65 67 72 61 | 64 65 64 2e 0a 58 0a 58 |is degra|ded..X.X|
|00003b50| 20 20 20 20 20 20 20 20 | 46 6f 72 20 6d 6f 72 65 | |For more|
|00003b60| 20 64 69 73 63 75 73 73 | 69 6f 6e 20 6f 66 20 65 | discuss|ion of e|
|00003b70| 66 66 69 63 69 65 6e 63 | 79 20 74 72 61 64 65 6f |fficienc|y tradeo|
|00003b80| 66 66 73 2c 20 61 73 20 | 77 65 6c 6c 20 61 73 20 |ffs, as |well as |
|00003b90| 67 6f 6f 64 0a 58 20 20 | 20 20 20 20 20 20 61 64 |good.X | ad|
|00003ba0| 76 69 63 65 20 6f 6e 20 | 68 6f 77 20 74 6f 20 69 |vice on |how to i|
|00003bb0| 6e 63 72 65 61 73 65 20 | 65 66 66 69 63 69 65 6e |ncrease |efficien|
|00003bc0| 63 79 20 77 68 65 6e 20 | 69 74 20 69 73 20 69 6d |cy when |it is im|
|00003bd0| 70 6f 72 74 61 6e 74 2c | 20 73 65 65 0a 58 20 20 |portant,| see.X |
|00003be0| 20 20 20 20 20 20 63 68 | 61 70 74 65 72 20 37 20 | ch|apter 7 |
|00003bf0| 6f 66 20 4b 65 72 6e 69 | 67 68 61 6e 20 61 6e 64 |of Kerni|ghan and|
|00003c00| 20 50 6c 61 75 67 65 72 | 27 73 20 54 68 65 20 45 | Plauger|'s The E|
|00003c10| 6c 65 6d 65 6e 74 73 20 | 6f 66 20 50 72 6f 67 72 |lements |of Progr|
|00003c20| 61 6d 6d 69 6e 67 0a 58 | 20 20 20 20 20 20 20 20 |amming.X| |
|00003c30| 53 74 79 6c 65 2c 20 61 | 6e 64 20 4a 6f 6e 20 42 |Style, a|nd Jon B|
|00003c40| 65 6e 74 6c 65 79 27 73 | 20 57 72 69 74 69 6e 67 |entley's| Writing|
|00003c50| 20 45 66 66 69 63 69 65 | 6e 74 20 50 72 6f 67 72 | Efficie|nt Progr|
|00003c60| 61 6d 73 2e 0a 58 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |ams..X--|--------|
|00003c70| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00003c80| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00003c90| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00003ca0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00003cb0| 2d 0a 58 0a 45 4e 44 5f | 4f 46 5f 46 49 4c 45 0a |-.X.END_|OF_FILE.|
|00003cc0| 20 20 69 66 20 74 65 73 | 74 20 34 34 35 32 20 2d | if tes|t 4452 -|
|00003cd0| 6e 65 20 60 77 63 20 2d | 63 20 3c 27 4f 50 54 49 |ne `wc -|c <'OPTI|
|00003ce0| 4d 49 5a 49 4e 47 27 60 | 3b 20 74 68 65 6e 0a 20 |MIZING'`|; then. |
|00003cf0| 20 20 20 65 63 68 6f 20 | 73 68 61 72 3a 20 5c 22 | echo |shar: \"|
|00003d00| 27 4f 50 54 49 4d 49 5a | 49 4e 47 27 5c 22 20 75 |'OPTIMIZ|ING'\" u|
|00003d10| 6e 70 61 63 6b 65 64 20 | 77 69 74 68 20 77 72 6f |npacked |with wro|
|00003d20| 6e 67 20 73 69 7a 65 21 | 0a 20 20 66 69 0a 20 20 |ng size!|. fi. |
|00003d30| 23 20 65 6e 64 20 6f 66 | 20 27 4f 50 54 49 4d 49 |# end of| 'OPTIMI|
|00003d40| 5a 49 4e 47 27 0a 66 69 | 0a 69 66 20 74 65 73 74 |ZING'.fi|.if test|
|00003d50| 20 2d 66 20 27 54 4f 44 | 4f 27 20 2d 61 20 22 24 | -f 'TOD|O' -a "$|
|00003d60| 7b 31 7d 22 20 21 3d 20 | 22 2d 63 22 20 3b 20 74 |{1}" != |"-c" ; t|
|00003d70| 68 65 6e 20 0a 20 20 65 | 63 68 6f 20 73 68 61 72 |hen . e|cho shar|
|00003d80| 3a 20 57 69 6c 6c 20 6e | 6f 74 20 63 6c 6f 62 62 |: Will n|ot clobb|
|00003d90| 65 72 20 65 78 69 73 74 | 69 6e 67 20 66 69 6c 65 |er exist|ing file|
|00003da0| 20 5c 22 27 54 4f 44 4f | 27 5c 22 0a 65 6c 73 65 | \"'TODO|'\".else|
|00003db0| 0a 20 20 65 63 68 6f 20 | 73 68 61 72 3a 20 45 78 |. echo |shar: Ex|
|00003dc0| 74 72 61 63 74 69 6e 67 | 20 5c 22 27 54 4f 44 4f |tracting| \"'TODO|
|00003dd0| 27 5c 22 20 5c 28 39 33 | 35 20 63 68 61 72 61 63 |'\" \(93|5 charac|
|00003de0| 74 65 72 73 5c 29 0a 20 | 20 73 65 64 20 22 73 2f |ters\). | sed "s/|
|00003df0| 5e 58 2f 2f 22 20 3e 27 | 54 4f 44 4f 27 20 3c 3c |^X//" >'|TODO' <<|
|00003e00| 27 45 4e 44 5f 4f 46 5f | 46 49 4c 45 27 0a 58 0a |'END_OF_|FILE'.X.|
|00003e10| 58 72 65 74 75 72 6e 20 | 2d 31 20 6f 72 20 73 6f |Xreturn |-1 or so|
|00003e20| 6d 65 74 68 69 6e 67 20 | 72 61 74 68 65 72 20 74 |mething |rather t|
|00003e30| 68 61 6e 20 63 61 6c 6c | 69 6e 67 20 61 73 73 65 |han call|ing asse|
|00003e40| 72 74 28 29 20 69 6e 20 | 6d 61 6e 79 20 70 6c 61 |rt() in |many pla|
|00003e50| 63 65 73 0a 58 0a 58 75 | 73 65 20 22 74 61 67 22 |ces.X.Xu|se "tag"|
|00003e60| 20 73 6f 72 74 20 77 68 | 65 6e 20 73 69 7a 65 20 | sort wh|en size |
|00003e70| 6f 66 20 72 65 63 6f 72 | 64 73 20 69 73 20 73 6f |of recor|ds is so|
|00003e80| 20 6c 61 72 67 65 20 0a | 58 20 20 74 68 61 74 20 | large .|X that |
|00003e90| 6d 65 6d 63 70 79 20 74 | 61 6b 65 73 20 61 20 73 |memcpy t|akes a s|
|00003ea0| 69 67 6e 69 66 69 63 61 | 6e 74 20 61 6d 6f 75 6e |ignifica|nt amoun|
|00003eb0| 74 20 6f 66 20 74 69 6d | 65 2e 0a 58 0a 58 62 65 |t of tim|e..X.Xbe|
|00003ec0| 74 74 65 72 20 66 6c 6f | 77 20 63 6f 6e 74 72 6f |tter flo|w contro|
|00003ed0| 6c 20 69 6e 20 66 6c 6f | 67 67 65 72 3b 20 61 64 |l in flo|gger; ad|
|00003ee0| 64 20 73 6f 6d 65 20 63 | 6f 6d 6d 61 6e 64 20 6c |d some c|ommand l|
|00003ef0| 69 6e 65 20 6f 70 74 69 | 6f 6e 73 0a 58 20 20 66 |ine opti|ons.X f|
|00003f00| 6f 72 20 73 65 6c 65 63 | 74 69 6e 67 20 77 68 69 |or selec|ting whi|
|00003f10| 63 68 20 61 6c 67 6f 72 | 69 74 68 6d 73 20 74 6f |ch algor|ithms to|
|00003f20| 20 74 65 73 74 20 61 6e | 64 20 77 68 69 63 68 20 | test an|d which |
|00003f30| 73 69 74 75 61 74 69 6f | 6e 73 0a 58 20 20 74 6f |situatio|ns.X to|
|00003f40| 20 70 72 65 73 65 6e 74 | 20 74 68 65 6d 20 77 69 | present| them wi|
|00003f50| 74 68 2e 0a 58 0a 58 74 | 68 65 20 63 68 65 63 6b |th..X.Xt|he check|
|00003f60| 20 66 6f 72 20 73 74 61 | 62 6c 65 20 73 6f 72 74 | for sta|ble sort|
|00003f70| 69 6e 67 20 69 73 6e 27 | 74 20 64 65 63 69 73 69 |ing isn'|t decisi|
|00003f80| 76 65 2e 0a 58 0a 58 73 | 6f 6d 65 20 6f 66 20 74 |ve..X.Xs|ome of t|
|00003f90| 68 65 20 66 69 6c 65 20 | 6e 61 6d 65 73 20 65 78 |he file |names ex|
|00003fa0| 63 65 65 64 20 31 34 20 | 63 68 61 72 61 63 74 65 |ceed 14 |characte|
|00003fb0| 72 73 0a 58 0a 58 6d 61 | 6b 65 20 74 68 65 20 61 |rs.X.Xma|ke the a|
|00003fc0| 6c 69 67 6e 6d 65 6e 74 | 20 63 68 65 63 6b 69 6e |lignment| checkin|
|00003fd0| 67 20 65 61 73 69 65 72 | 20 74 6f 20 63 6f 6e 66 |g easier| to conf|
|00003fe0| 69 67 75 72 65 20 28 6d | 65 72 67 65 20 61 6e 64 |igure (m|erge and|
|00003ff0| 20 71 75 69 63 6b 20 73 | 6f 72 74 73 29 0a 58 0a | quick s|orts).X.|
|00004000| 58 6d 61 79 62 65 20 61 | 6e 61 6c 79 7a 65 20 69 |Xmaybe a|nalyze i|
|00004010| 6e 63 72 65 61 73 65 20 | 69 6e 20 73 70 61 63 65 |ncrease |in space|
|00004020| 2f 74 69 6d 65 20 63 6f | 6d 70 6c 65 78 69 74 79 |/time co|mplexity|
|00004030| 20 61 73 20 61 72 72 61 | 79 20 73 69 7a 65 20 67 | as arra|y size g|
|00004040| 72 6f 77 73 0a 58 20 20 | 61 6e 64 20 66 69 67 75 |rows.X |and figu|
|00004050| 72 65 20 6f 75 74 20 4f | 28 29 20 65 6d 70 69 72 |re out O|() empir|
|00004060| 69 63 61 6c 6c 79 2e 0a | 58 0a 58 69 6e 63 6c 75 |ically..|X.Xinclu|
|00004070| 64 65 20 66 69 6c 65 20 | 22 73 6f 72 74 69 6e 67 |de file |"sorting|
|00004080| 2e 68 22 20 69 73 20 6f | 66 20 71 75 65 73 74 69 |.h" is o|f questi|
|00004090| 6f 6e 61 62 6c 65 20 75 | 74 69 6c 69 74 79 2e 0a |onable u|tility..|
|000040a0| 58 0a 58 2f 75 73 72 2f | 6c 69 62 2f 6c 69 6e 74 |X.X/usr/|lib/lint|
|000040b0| 2f 6c 6c 69 62 2d 6c 73 | 6f 72 74 20 6d 69 67 68 |/llib-ls|ort migh|
|000040c0| 74 20 62 65 20 61 20 6e | 69 63 65 20 74 6f 75 63 |t be a n|ice touc|
|000040d0| 68 20 66 6f 72 20 22 6d | 61 6b 65 20 69 6e 73 74 |h for "m|ake inst|
|000040e0| 61 6c 6c 22 0a 58 0a 58 | 73 68 6f 75 6c 64 20 62 |all".X.X|should b|
|000040f0| 65 20 6d 6f 72 65 20 66 | 6c 65 78 69 62 6c 65 20 |e more f|lexible |
|00004100| 61 62 6f 75 74 20 77 68 | 61 74 20 73 69 7a 65 20 |about wh|at size |
|00004110| 61 6e 64 20 63 6f 6d 70 | 6c 65 78 69 74 79 20 6f |and comp|lexity o|
|00004120| 66 20 74 68 69 6e 67 20 | 74 6f 20 73 6f 72 74 0a |f thing |to sort.|
|00004130| 58 0a 58 6d 61 79 62 65 | 20 61 64 64 20 61 20 70 |X.Xmaybe| add a p|
|00004140| 61 72 61 6c 6c 65 6c 69 | 7a 69 6e 67 20 73 6f 72 |aralleli|zing sor|
|00004150| 74 0a 58 0a 58 6d 61 6b | 65 66 69 6c 65 20 61 6e |t.X.Xmak|efile an|
|00004160| 64 20 66 6c 6f 67 67 65 | 72 20 61 72 65 6e 74 27 |d flogge|r arent'|
|00004170| 74 20 76 65 72 79 20 70 | 6f 72 74 61 62 6c 65 0a |t very p|ortable.|
|00004180| 58 0a 58 63 63 20 2d 70 | 69 63 20 69 73 20 75 6e |X.Xcc -p|ic is un|
|00004190| 6e 65 63 65 73 73 61 72 | 79 20 77 68 65 6e 20 6d |necessar|y when m|
|000041a0| 61 6b 69 6e 67 20 6c 69 | 62 73 6f 72 74 2e 61 0a |aking li|bsort.a.|
|000041b0| 58 0a 58 61 64 64 20 74 | 65 73 74 20 66 6f 72 20 |X.Xadd t|est for |
|000041c0| 72 65 2d 65 6e 74 72 61 | 6e 63 79 20 6f 66 20 73 |re-entra|ncy of s|
|000041d0| 6f 72 74 0a 58 0a 45 4e | 44 5f 4f 46 5f 46 49 4c |ort.X.EN|D_OF_FIL|
|000041e0| 45 0a 20 20 69 66 20 74 | 65 73 74 20 39 33 35 20 |E. if t|est 935 |
|000041f0| 2d 6e 65 20 60 77 63 20 | 2d 63 20 3c 27 54 4f 44 |-ne `wc |-c <'TOD|
|00004200| 4f 27 60 3b 20 74 68 65 | 6e 0a 20 20 20 20 65 63 |O'`; the|n. ec|
|00004210| 68 6f 20 73 68 61 72 3a | 20 5c 22 27 54 4f 44 4f |ho shar:| \"'TODO|
|00004220| 27 5c 22 20 75 6e 70 61 | 63 6b 65 64 20 77 69 74 |'\" unpa|cked wit|
|00004230| 68 20 77 72 6f 6e 67 20 | 73 69 7a 65 21 0a 20 20 |h wrong |size!. |
|00004240| 66 69 0a 20 20 23 20 65 | 6e 64 20 6f 66 20 27 54 |fi. # e|nd of 'T|
|00004250| 4f 44 4f 27 0a 66 69 0a | 69 66 20 74 65 73 74 20 |ODO'.fi.|if test |
|00004260| 2d 66 20 27 66 6c 6f 67 | 67 65 72 2e 63 27 20 2d |-f 'flog|ger.c' -|
|00004270| 61 20 22 24 7b 31 7d 22 | 20 21 3d 20 22 2d 63 22 |a "${1}"| != "-c"|
|00004280| 20 3b 20 74 68 65 6e 20 | 0a 20 20 65 63 68 6f 20 | ; then |. echo |
|00004290| 73 68 61 72 3a 20 57 69 | 6c 6c 20 6e 6f 74 20 63 |shar: Wi|ll not c|
|000042a0| 6c 6f 62 62 65 72 20 65 | 78 69 73 74 69 6e 67 20 |lobber e|xisting |
|000042b0| 66 69 6c 65 20 5c 22 27 | 66 6c 6f 67 67 65 72 2e |file \"'|flogger.|
|000042c0| 63 27 5c 22 0a 65 6c 73 | 65 0a 20 20 65 63 68 6f |c'\".els|e. echo|
|000042d0| 20 73 68 61 72 3a 20 45 | 78 74 72 61 63 74 69 6e | shar: E|xtractin|
|000042e0| 67 20 5c 22 27 66 6c 6f | 67 67 65 72 2e 63 27 5c |g \"'flo|gger.c'\|
|000042f0| 22 20 5c 28 31 36 30 37 | 35 20 63 68 61 72 61 63 |" \(1607|5 charac|
|00004300| 74 65 72 73 5c 29 0a 20 | 20 73 65 64 20 22 73 2f |ters\). | sed "s/|
|00004310| 5e 58 2f 2f 22 20 3e 27 | 66 6c 6f 67 67 65 72 2e |^X//" >'|flogger.|
|00004320| 63 27 20 3c 3c 27 45 4e | 44 5f 4f 46 5f 46 49 4c |c' <<'EN|D_OF_FIL|
|00004330| 45 27 0a 58 0a 58 2f 2a | 20 0a 58 0a 58 4e 41 4d |E'.X.X/*| .X.XNAM|
|00004340| 45 0a 58 20 20 66 6c 6f | 67 67 65 72 0a 58 0a 58 |E.X flo|gger.X.X|
|00004350| 44 45 53 43 52 49 50 54 | 49 4f 4e 0a 58 0a 58 20 |DESCRIPT|ION.X.X |
|00004360| 20 50 75 74 20 74 68 65 | 20 73 6f 72 74 20 72 6f | Put the| sort ro|
|00004370| 75 74 69 6e 65 73 20 74 | 68 72 6f 75 67 68 20 74 |utines t|hrough t|
|00004380| 68 65 20 70 61 63 65 73 | 2e 20 20 56 65 72 69 66 |he paces|. Verif|
|00004390| 79 20 74 68 61 74 20 74 | 68 65 79 20 61 63 74 75 |y that t|hey actu|
|000043a0| 61 6c 6c 79 0a 58 20 20 | 6f 72 64 65 72 20 64 61 |ally.X |order da|
|000043b0| 74 61 20 70 72 6f 70 65 | 72 6c 79 20 61 6e 64 20 |ta prope|rly and |
|000043c0| 74 68 61 74 20 74 68 65 | 79 20 64 6f 6e 27 74 20 |that the|y don't |
|000043d0| 6d 6f 6c 65 73 74 20 74 | 68 65 20 6d 65 6d 6f 72 |molest t|he memor|
|000043e0| 79 20 6c 6f 63 61 74 69 | 6f 6e 73 0a 58 20 20 69 |y locati|ons.X i|
|000043f0| 6d 6d 65 64 69 61 74 65 | 6c 79 20 61 62 6f 76 65 |mmediate|ly above|
|00004400| 20 6f 72 20 62 65 6c 6f | 77 20 74 68 65 20 61 72 | or belo|w the ar|
|00004410| 72 61 79 2e 20 20 54 72 | 69 65 73 20 73 6f 6d 65 |ray. Tr|ies some|
|00004420| 20 63 6f 6d 6d 6f 6e 20 | 77 6f 72 73 74 2d 63 61 | common |worst-ca|
|00004430| 73 65 0a 58 20 20 73 69 | 74 75 61 74 69 6f 6e 73 |se.X si|tuations|
|00004440| 20 6c 69 6b 65 20 61 6c | 72 65 61 64 79 2d 6f 72 | like al|ready-or|
|00004450| 64 65 72 65 64 20 64 61 | 74 61 20 61 6e 64 20 63 |dered da|ta and c|
|00004460| 6f 6d 70 61 72 69 73 6f | 6e 20 66 75 6e 63 74 69 |ompariso|n functi|
|00004470| 6f 6e 73 20 77 68 69 63 | 68 0a 58 20 20 61 72 65 |ons whic|h.X are|
|00004480| 20 64 65 66 65 63 74 69 | 76 65 2e 0a 58 0a 58 20 | defecti|ve..X.X |
|00004490| 20 50 72 69 6e 74 73 20 | 6f 75 74 20 65 73 74 69 | Prints |out esti|
|000044a0| 6d 61 74 65 73 20 66 6f | 72 20 65 61 63 68 20 73 |mates fo|r each s|
|000044b0| 6f 72 74 20 61 6c 67 6f | 72 69 74 68 6d 20 66 6f |ort algo|rithm fo|
|000044c0| 72 20 75 73 61 67 65 20 | 6f 66 20 68 65 61 70 20 |r usage |of heap |
|000044d0| 73 70 61 63 65 2c 0a 58 | 20 20 73 74 61 63 6b 20 |space,.X| stack |
|000044e0| 73 70 61 63 65 2c 20 61 | 6e 64 20 72 75 6e 20 74 |space, a|nd run t|
|000044f0| 69 6d 65 20 61 6e 64 20 | 61 6c 73 6f 20 66 6f 72 |ime and |also for|
|00004500| 20 74 68 65 20 6e 75 6d | 62 65 72 20 6f 66 20 63 | the num|ber of c|
|00004510| 61 6c 6c 73 20 74 6f 20 | 74 68 65 0a 58 20 20 63 |alls to |the.X c|
|00004520| 6f 6d 70 61 72 69 73 6f | 6e 20 66 75 6e 63 74 69 |ompariso|n functi|
|00004530| 6f 6e 2e 0a 58 0a 58 20 | 20 54 61 6b 65 73 20 6f |on..X.X | Takes o|
|00004540| 6e 65 20 63 6f 6d 6d 61 | 6e 64 20 6c 69 6e 65 20 |ne comma|nd line |
|00004550| 61 72 67 75 6d 65 6e 74 | 20 77 68 69 63 68 20 73 |argument| which s|
|00004560| 70 65 63 69 66 69 65 73 | 20 74 68 65 20 6e 75 6d |pecifies| the num|
|00004570| 62 65 72 20 6f 66 20 69 | 74 65 6d 73 0a 58 20 20 |ber of i|tems.X |
|00004580| 74 6f 20 70 75 74 20 69 | 6e 20 74 68 65 20 61 72 |to put i|n the ar|
|00004590| 72 61 79 2e 20 20 4c 61 | 72 67 65 72 20 76 61 6c |ray. La|rger val|
|000045a0| 75 65 73 20 74 61 6b 65 | 20 6c 6f 6e 67 65 72 20 |ues take| longer |
|000045b0| 74 6f 20 72 75 6e 2e 0a | 58 0a 58 41 55 54 48 4f |to run..|X.XAUTHO|
|000045c0| 52 53 48 49 50 0a 58 0a | 58 20 20 4d 69 6b 65 20 |RSHIP.X.|X Mike |
|000045d0| 4c 65 65 2c 20 63 75 72 | 72 65 6e 74 6c 79 20 6d |Lee, cur|rently m|
|000045e0| 69 6b 65 79 40 6f 6e 74 | 65 6b 2e 63 6f 6d 0a 58 |ikey@ont|ek.com.X|
|000045f0| 0a 58 52 45 46 45 52 45 | 4e 43 45 53 0a 58 0a 58 |.XREFERE|NCES.X.X|
|00004600| 20 20 4b 6e 75 74 68 2c | 20 41 72 74 20 6f 66 20 | Knuth,| Art of |
|00004610| 43 6f 6d 70 75 74 65 72 | 20 50 72 6f 67 72 61 6d |Computer| Program|
|00004620| 6d 69 6e 67 20 56 6f 6c | 20 33 3a 20 53 65 61 72 |ming Vol| 3: Sear|
|00004630| 63 68 69 6e 67 20 61 6e | 64 20 53 6f 72 74 69 6e |ching an|d Sortin|
|00004640| 67 0a 58 20 20 4b 65 72 | 6e 69 67 68 61 6e 20 26 |g.X Ker|nighan &|
|00004650| 20 52 69 63 68 74 69 65 | 2c 20 54 68 65 20 43 20 | Richtie|, The C |
|00004660| 50 72 6f 67 72 61 6d 6d | 69 6e 67 20 4c 61 6e 67 |Programm|ing Lang|
|00004670| 75 61 67 65 2c 20 53 65 | 63 6f 6e 64 20 45 64 69 |uage, Se|cond Edi|
|00004680| 74 69 6f 6e 0a 58 0a 58 | 57 4f 52 4b 20 52 45 4d |tion.X.X|WORK REM|
|00004690| 41 49 4e 49 4e 47 0a 58 | 0a 58 20 20 54 68 65 20 |AINING.X|.X The |
|000046a0| 6d 61 69 6e 20 6c 6f 6f | 70 20 69 73 20 68 6f 70 |main loo|p is hop|
|000046b0| 65 6c 65 73 73 2e 0a 58 | 20 20 53 65 65 20 74 68 |eless..X| See th|
|000046c0| 65 20 54 4f 44 4f 20 64 | 6f 63 75 6d 65 6e 74 20 |e TODO d|ocument |
|000046d0| 28 77 68 69 63 68 20 73 | 68 6f 75 6c 64 20 61 63 |(which s|hould ac|
|000046e0| 63 6f 6d 70 61 6e 79 20 | 74 68 69 73 20 70 72 6f |company |this pro|
|000046f0| 67 72 61 6d 2e 29 0a 58 | 0a 58 43 4f 50 59 52 49 |gram.).X|.XCOPYRI|
|00004700| 47 48 54 0a 58 0a 58 20 | 20 43 6f 70 79 72 69 67 |GHT.X.X | Copyrig|
|00004710| 68 74 20 31 39 39 32 20 | 4d 69 63 68 61 65 6c 20 |ht 1992 |Michael |
|00004720| 4c 65 65 2e 0a 58 0a 58 | 20 20 28 31 29 20 50 65 |Lee..X.X| (1) Pe|
|00004730| 72 6d 69 73 73 69 6f 6e | 20 74 6f 20 75 73 65 2c |rmission| to use,|
|00004740| 20 63 6f 70 79 2c 20 64 | 69 73 74 72 69 62 75 74 | copy, d|istribut|
|00004750| 65 2c 20 61 6e 64 20 6d | 61 6b 65 20 63 68 61 6e |e, and m|ake chan|
|00004760| 67 65 73 20 69 73 20 67 | 72 61 6e 74 65 64 0a 58 |ges is g|ranted.X|
|00004770| 20 20 70 72 6f 76 69 64 | 69 6e 67 20 74 68 61 74 | provid|ing that|
|00004780| 20 28 61 29 20 74 68 61 | 74 20 79 6f 75 20 64 6f | (a) tha|t you do|
|00004790| 20 73 6f 20 77 69 74 68 | 6f 75 74 20 63 68 61 72 | so with|out char|
|000047a0| 67 69 6e 67 20 61 6e 79 | 6f 6e 65 20 61 20 66 65 |ging any|one a fe|
|000047b0| 65 20 61 6e 64 0a 58 20 | 20 28 62 29 20 74 68 69 |e and.X | (b) thi|
|000047c0| 73 20 63 6f 70 79 72 69 | 67 68 74 20 6e 6f 74 69 |s copyri|ght noti|
|000047d0| 63 65 20 6d 75 73 74 20 | 62 65 20 69 6e 63 6c 75 |ce must |be inclu|
|000047e0| 64 65 64 20 76 65 72 62 | 61 74 69 6d 20 69 6e 20 |ded verb|atim in |
|000047f0| 61 6c 6c 20 63 6f 70 69 | 65 73 20 61 6e 64 20 0a |all copi|es and .|
|00004800| 58 20 20 64 69 73 74 72 | 69 62 75 74 69 6f 6e 73 |X distr|ibutions|
|00004810| 2e 20 20 0a 58 0a 58 20 | 20 28 32 29 20 54 68 65 |. .X.X | (2) The|
|00004820| 72 65 20 69 73 20 6e 6f | 20 77 61 72 72 61 6e 74 |re is no| warrant|
|00004830| 79 20 66 6f 72 20 74 68 | 69 73 20 70 72 6f 67 72 |y for th|is progr|
|00004840| 61 6d 2c 20 74 6f 20 74 | 68 65 20 65 78 74 65 6e |am, to t|he exten|
|00004850| 74 20 70 65 72 6d 69 74 | 74 65 64 20 62 79 0a 58 |t permit|ted by.X|
|00004860| 20 20 61 70 70 6c 69 63 | 61 62 6c 65 20 6c 61 77 | applic|able law|
|00004870| 2e 20 20 54 68 69 73 20 | 70 72 6f 67 72 61 6d 20 |. This |program |
|00004880| 69 73 20 70 72 6f 76 69 | 64 65 64 20 22 41 53 20 |is provi|ded "AS |
|00004890| 49 53 22 20 77 69 74 68 | 6f 75 74 20 77 61 72 72 |IS" with|out warr|
|000048a0| 61 6e 74 79 20 6f 66 0a | 58 20 20 61 6e 79 20 6b |anty of.|X any k|
|000048b0| 69 6e 64 2c 20 65 69 74 | 68 65 72 20 65 78 70 72 |ind, eit|her expr|
|000048c0| 65 73 73 65 64 20 6f 72 | 20 69 6d 70 6c 69 65 64 |essed or| implied|
|000048d0| 2c 20 69 6e 63 6c 75 64 | 69 6e 67 2c 20 62 75 74 |, includ|ing, but|
|000048e0| 20 6e 6f 74 20 6c 69 6d | 69 74 65 64 20 74 6f 2c | not lim|ited to,|
|000048f0| 0a 58 20 20 74 68 65 20 | 69 6d 70 6c 69 65 64 20 |.X the |implied |
|00004900| 77 61 72 72 61 6e 74 69 | 65 73 20 6f 66 20 6d 65 |warranti|es of me|
|00004910| 72 63 68 61 6e 74 61 62 | 69 6c 69 74 79 20 61 6e |rchantab|ility an|
|00004920| 64 20 66 69 74 6e 65 73 | 73 20 66 6f 72 20 61 20 |d fitnes|s for a |
|00004930| 70 61 72 74 69 63 75 6c | 61 72 20 0a 58 20 20 70 |particul|ar .X p|
|00004940| 75 72 70 6f 73 65 2e 20 | 20 54 68 65 20 65 6e 74 |urpose. | The ent|
|00004950| 69 72 65 20 72 69 73 6b | 20 61 73 20 74 6f 20 74 |ire risk| as to t|
|00004960| 68 65 20 71 75 61 6c 69 | 74 79 20 61 6e 64 20 70 |he quali|ty and p|
|00004970| 65 72 66 6f 72 6d 61 6e | 63 65 20 6f 66 20 74 68 |erforman|ce of th|
|00004980| 69 73 20 0a 58 20 20 70 | 72 6f 67 72 61 6d 20 69 |is .X p|rogram i|
|00004990| 73 20 77 69 74 68 20 74 | 68 65 20 75 73 65 72 2e |s with t|he user.|
|000049a0| 20 20 53 68 6f 75 6c 64 | 20 74 68 69 73 20 70 72 | Should| this pr|
|000049b0| 6f 67 72 61 6d 20 70 72 | 6f 76 65 20 64 65 66 65 |ogram pr|ove defe|
|000049c0| 63 74 69 76 65 2c 20 74 | 68 65 20 0a 58 20 20 75 |ctive, t|he .X u|
|000049d0| 73 65 72 20 61 73 73 75 | 6d 65 73 20 74 68 65 20 |ser assu|mes the |
|000049e0| 63 6f 73 74 20 6f 66 20 | 61 6c 6c 20 6e 65 63 65 |cost of |all nece|
|000049f0| 73 73 61 72 79 20 73 65 | 72 76 69 63 69 6e 67 2c |ssary se|rvicing,|
|00004a00| 20 72 65 70 61 69 72 20 | 6f 72 20 63 6f 72 72 65 | repair |or corre|
|00004a10| 63 74 69 6f 6e 2e 0a 58 | 0a 58 20 20 28 33 29 20 |ction..X|.X (3) |
|00004a20| 49 6e 20 6e 6f 20 65 76 | 65 6e 74 20 75 6e 6c 65 |In no ev|ent unle|
|00004a30| 73 73 20 72 65 71 75 69 | 72 65 64 20 62 79 20 61 |ss requi|red by a|
|00004a40| 70 70 6c 69 63 61 62 6c | 65 20 6c 61 77 20 77 69 |pplicabl|e law wi|
|00004a50| 6c 6c 20 74 68 65 20 63 | 6f 70 79 72 69 67 68 74 |ll the c|opyright|
|00004a60| 0a 58 20 20 68 6f 6c 64 | 65 72 20 62 65 20 6c 69 |.X hold|er be li|
|00004a70| 61 62 6c 65 20 74 6f 20 | 74 68 65 20 75 73 65 72 |able to |the user|
|00004a80| 20 66 6f 72 20 64 61 6d | 61 67 65 73 2c 20 69 6e | for dam|ages, in|
|00004a90| 63 6c 75 64 69 6e 67 20 | 61 6e 79 20 67 65 6e 65 |cluding |any gene|
|00004aa0| 72 61 6c 2c 0a 58 20 20 | 73 70 65 63 69 61 6c 2c |ral,.X |special,|
|00004ab0| 20 69 6e 63 69 64 65 6e | 74 61 6c 20 6f 72 20 63 | inciden|tal or c|
|00004ac0| 6f 6e 73 65 71 75 65 6e | 74 69 61 6c 20 64 61 6d |onsequen|tial dam|
|00004ad0| 61 67 65 73 20 61 72 69 | 73 69 6e 67 20 6f 75 74 |ages ari|sing out|
|00004ae0| 20 6f 66 20 74 68 65 20 | 75 73 65 0a 58 20 20 6f | of the |use.X o|
|00004af0| 72 20 69 6e 61 62 69 6c | 69 74 79 20 74 6f 20 75 |r inabil|ity to u|
|00004b00| 73 65 20 74 68 69 73 20 | 70 72 6f 67 72 61 6d 20 |se this |program |
|00004b10| 28 69 6e 63 6c 75 64 69 | 6e 67 20 62 75 74 20 6e |(includi|ng but n|
|00004b20| 6f 74 20 6c 69 6d 69 74 | 65 64 20 74 6f 20 6c 6f |ot limit|ed to lo|
|00004b30| 73 73 20 6f 66 0a 58 20 | 20 64 61 74 61 20 6f 72 |ss of.X | data or|
|00004b40| 20 64 61 74 61 20 62 65 | 69 6e 67 20 72 65 6e 64 | data be|ing rend|
|00004b50| 65 72 65 64 20 69 6e 61 | 63 63 75 72 61 74 65 20 |ered ina|ccurate |
|00004b60| 6f 72 20 6c 6f 73 73 65 | 73 20 73 75 73 74 61 69 |or losse|s sustai|
|00004b70| 6e 65 64 20 62 79 20 74 | 68 65 0a 58 20 20 75 73 |ned by t|he.X us|
|00004b80| 65 72 20 6f 72 20 74 68 | 69 72 64 20 70 61 72 74 |er or th|ird part|
|00004b90| 69 65 73 20 6f 72 20 61 | 20 66 61 69 6c 75 72 65 |ies or a| failure|
|00004ba0| 20 6f 66 20 74 68 69 73 | 20 70 72 6f 67 72 61 6d | of this| program|
|00004bb0| 20 74 6f 20 6f 70 65 72 | 61 74 65 20 77 69 74 68 | to oper|ate with|
|00004bc0| 20 61 6e 79 0a 58 20 20 | 6f 74 68 65 72 20 70 72 | any.X |other pr|
|00004bd0| 6f 67 72 61 6d 73 29 2c | 20 65 76 65 6e 20 69 66 |ograms),| even if|
|00004be0| 20 73 75 63 68 20 68 6f | 6c 64 65 72 20 6f 72 20 | such ho|lder or |
|00004bf0| 74 68 69 72 64 20 70 61 | 72 74 79 20 68 61 73 20 |third pa|rty has |
|00004c00| 62 65 65 6e 20 61 64 76 | 69 73 65 64 0a 58 20 20 |been adv|ised.X |
|00004c10| 6f 66 20 74 68 65 20 70 | 6f 73 73 69 62 69 6c 69 |of the p|ossibili|
|00004c20| 74 79 20 6f 66 20 73 75 | 63 68 20 64 61 6d 61 67 |ty of su|ch damag|
|00004c30| 65 73 2e 0a 58 0a 58 20 | 20 28 34 29 20 4f 62 6a |es..X.X | (4) Obj|
|00004c40| 65 63 74 20 63 6f 64 65 | 20 70 72 6f 64 75 63 65 |ect code| produce|
|00004c50| 64 20 62 79 20 61 20 63 | 6f 6d 70 69 6c 65 72 20 |d by a c|ompiler |
|00004c60| 66 72 6f 6d 20 74 68 69 | 73 20 63 6f 64 65 20 6d |from thi|s code m|
|00004c70| 61 79 20 62 65 20 0a 58 | 20 20 69 6e 63 6f 72 70 |ay be .X| incorp|
|00004c80| 6f 72 61 74 65 64 20 69 | 6e 74 6f 20 63 6f 6d 6d |orated i|nto comm|
|00004c90| 65 72 63 69 61 6c 20 70 | 72 6f 64 75 63 74 73 20 |ercial p|roducts |
|00004ca0| 77 69 74 68 6f 75 74 20 | 62 65 69 6e 67 20 73 75 |without |being su|
|00004cb0| 62 6a 65 63 74 20 74 6f | 20 0a 58 20 20 72 65 73 |bject to| .X res|
|00004cc0| 74 72 69 63 74 69 6f 6e | 73 20 28 31 29 28 61 29 |triction|s (1)(a)|
|00004cd0| 20 6f 72 20 28 31 29 28 | 62 29 2e 0a 58 0a 58 2a | or (1)(|b)..X.X*|
|00004ce0| 2f 0a 58 0a 58 23 69 6e | 63 6c 75 64 65 20 3c 73 |/.X.X#in|clude <s|
|00004cf0| 74 64 69 6f 2e 68 3e 0a | 58 23 69 6e 63 6c 75 64 |tdio.h>.|X#includ|
|00004d00| 65 20 3c 6d 61 6c 6c 6f | 63 2e 68 3e 0a 58 23 69 |e <mallo|c.h>.X#i|
|00004d10| 6e 63 6c 75 64 65 20 3c | 6d 65 6d 6f 72 79 2e 68 |nclude <|memory.h|
|00004d20| 3e 0a 58 23 69 6e 63 6c | 75 64 65 20 3c 73 74 72 |>.X#incl|ude <str|
|00004d30| 69 6e 67 2e 68 3e 0a 58 | 23 69 6e 63 6c 75 64 65 |ing.h>.X|#include|
|00004d40| 20 3c 73 69 67 6e 61 6c | 2e 68 3e 0a 58 23 69 6e | <signal|.h>.X#in|
|00004d50| 63 6c 75 64 65 20 3c 73 | 65 74 6a 6d 70 2e 68 3e |clude <s|etjmp.h>|
|00004d60| 0a 58 0a 58 23 69 6e 63 | 6c 75 64 65 20 3c 73 79 |.X.X#inc|lude <sy|
|00004d70| 73 2f 74 79 70 65 73 2e | 68 3e 0a 58 23 69 6e 63 |s/types.|h>.X#inc|
|00004d80| 6c 75 64 65 20 3c 73 79 | 73 2f 74 69 6d 65 73 2e |lude <sy|s/times.|
|00004d90| 68 3e 0a 58 23 69 6e 63 | 6c 75 64 65 20 3c 73 79 |h>.X#inc|lude <sy|
|00004da0| 73 2f 70 61 72 61 6d 2e | 68 3e 0a 58 0a 58 23 69 |s/param.|h>.X.X#i|
|00004db0| 6e 63 6c 75 64 65 20 22 | 73 6f 72 74 69 6e 67 2e |nclude "|sorting.|
|00004dc0| 68 22 0a 58 0a 58 23 64 | 65 66 69 6e 65 20 54 45 |h".X.X#d|efine TE|
|00004dd0| 53 54 5f 54 59 50 45 20 | 64 6f 75 62 6c 65 0a 58 |ST_TYPE |double.X|
|00004de0| 23 64 65 66 69 6e 65 20 | 54 45 53 54 5f 46 55 4e |#define |TEST_FUN|
|00004df0| 43 20 64 6f 75 62 6c 65 | 5f 63 6f 6d 70 61 72 65 |C double|_compare|
|00004e00| 0a 58 23 64 65 66 69 6e | 65 20 44 45 46 41 55 4c |.X#defin|e DEFAUL|
|00004e10| 54 5f 43 4f 55 4e 54 20 | 32 32 32 30 20 2f 2a 20 |T_COUNT |2220 /* |
|00004e20| 70 72 6f 64 75 63 74 20 | 6f 66 20 34 20 61 6e 64 |product |of 4 and|
|00004e30| 20 73 65 76 65 72 61 6c | 20 70 72 69 6d 65 73 20 | several| primes |
|00004e40| 2a 2f 0a 58 0a 58 23 64 | 65 66 69 6e 65 20 43 41 |*/.X.X#d|efine CA|
|00004e50| 4e 41 52 59 5f 4c 4f 57 | 20 2d 37 37 2e 30 0a 58 |NARY_LOW| -77.0.X|
|00004e60| 23 64 65 66 69 6e 65 20 | 43 41 4e 41 52 59 5f 48 |#define |CANARY_H|
|00004e70| 49 47 48 20 2d 38 38 2e | 30 0a 58 0a 58 23 64 65 |IGH -88.|0.X.X#de|
|00004e80| 66 69 6e 65 20 54 45 53 | 54 5f 52 41 4e 44 4f 4d |fine TES|T_RANDOM|
|00004e90| 20 31 0a 58 23 64 65 66 | 69 6e 65 20 54 45 53 54 | 1.X#def|ine TEST|
|00004ea0| 5f 41 53 43 45 4e 44 20 | 32 0a 58 23 64 65 66 69 |_ASCEND |2.X#defi|
|00004eb0| 6e 65 20 54 45 53 54 5f | 44 45 53 43 45 4e 44 20 |ne TEST_|DESCEND |
|00004ec0| 33 0a 58 23 64 65 66 69 | 6e 65 20 54 45 53 54 5f |3.X#defi|ne TEST_|
|00004ed0| 46 49 42 5f 41 53 43 20 | 34 0a 58 23 64 65 66 69 |FIB_ASC |4.X#defi|
|00004ee0| 6e 65 20 54 45 53 54 5f | 46 49 42 5f 44 45 53 43 |ne TEST_|FIB_DESC|
|00004ef0| 20 35 0a 58 23 64 65 66 | 69 6e 65 20 54 45 53 54 | 5.X#def|ine TEST|
|00004f00| 5f 53 55 52 50 52 49 53 | 45 20 36 0a 58 23 64 65 |_SURPRIS|E 6.X#de|
|00004f10| 66 69 6e 65 20 54 45 53 | 54 5f 4d 4f 53 54 4c 59 |fine TES|T_MOSTLY|
|00004f20| 20 37 0a 58 23 64 65 66 | 69 6e 65 20 54 45 53 54 | 7.X#def|ine TEST|
|00004f30| 5f 45 51 55 49 56 20 38 | 0a 58 0a 58 73 74 61 74 |_EQUIV 8|.X.Xstat|
|00004f40| 69 63 20 69 6e 74 20 63 | 6f 6d 70 61 72 65 5f 63 |ic int c|ompare_c|
|00004f50| 6f 75 6e 74 3b 0a 58 73 | 74 61 74 69 63 20 69 6e |ount;.Xs|tatic in|
|00004f60| 74 20 73 5f 68 65 61 70 | 3b 0a 58 73 74 61 74 69 |t s_heap|;.Xstati|
|00004f70| 63 20 63 68 61 72 20 2a | 20 73 5f 6c 6f 77 2c 20 |c char *| s_low, |
|00004f80| 2a 20 73 5f 68 69 67 68 | 3b 0a 58 0a 58 23 64 65 |* s_high|;.X.X#de|
|00004f90| 66 69 6e 65 20 43 48 45 | 43 4b 5f 43 41 4e 41 52 |fine CHE|CK_CANAR|
|00004fa0| 49 45 53 20 5c 0a 58 20 | 20 7b 20 5c 0a 58 20 20 |IES \.X | { \.X |
|00004fb0| 20 20 69 66 20 28 2a 28 | 54 45 53 54 5f 54 59 50 | if (*(|TEST_TYP|
|00004fc0| 45 20 2a 29 20 61 20 3d | 3d 20 43 41 4e 41 52 59 |E *) a =|= CANARY|
|00004fd0| 5f 4c 4f 57 20 7c 7c 20 | 2a 28 54 45 53 54 5f 54 |_LOW || |*(TEST_T|
|00004fe0| 59 50 45 20 2a 29 20 62 | 20 3d 3d 20 43 41 4e 41 |YPE *) b| == CANA|
|00004ff0| 52 59 5f 4c 4f 57 29 5c | 0a 58 20 20 20 20 7b 20 |RY_LOW)\|.X { |
|00005000| 5c 0a 58 20 20 20 20 20 | 20 70 72 69 6e 74 66 28 |\.X | printf(|
|00005010| 22 72 61 6e 20 6f 66 66 | 20 74 68 65 20 62 6f 74 |"ran off| the bot|
|00005020| 74 6f 6d 20 6f 66 20 74 | 68 65 20 61 72 72 61 79 |tom of t|he array|
|00005030| 21 5c 6e 22 29 3b 20 5c | 0a 58 20 20 20 20 20 20 |!\n"); \|.X |
|00005040| 66 66 6c 75 73 68 28 73 | 74 64 6f 75 74 29 3b 20 |fflush(s|tdout); |
|00005050| 5c 0a 58 20 20 20 20 20 | 20 6c 6f 6e 67 6a 6d 70 |\.X | longjmp|
|00005060| 28 6e 65 78 74 2c 20 31 | 29 3b 20 5c 0a 58 20 20 |(next, 1|); \.X |
|00005070| 20 20 7d 20 5c 0a 58 20 | 20 20 20 69 66 20 28 2a | } \.X | if (*|
|00005080| 28 54 45 53 54 5f 54 59 | 50 45 20 2a 29 20 61 20 |(TEST_TY|PE *) a |
|00005090| 3d 3d 20 43 41 4e 41 52 | 59 5f 48 49 47 48 20 7c |== CANAR|Y_HIGH ||
|000050a0| 7c 20 2a 28 54 45 53 54 | 5f 54 59 50 45 20 2a 29 || *(TEST|_TYPE *)|
|000050b0| 20 62 20 3d 3d 20 43 41 | 4e 41 52 59 5f 48 49 47 | b == CA|NARY_HIG|
|000050c0| 48 29 5c 0a 58 20 20 20 | 20 7b 20 5c 0a 58 20 20 |H)\.X | { \.X |
|000050d0| 20 20 20 20 70 72 69 6e | 74 66 28 22 72 61 6e 20 | prin|tf("ran |
|000050e0| 6f 66 66 20 74 68 65 20 | 74 6f 70 20 6f 66 20 74 |off the |top of t|
|000050f0| 68 65 20 61 72 72 61 79 | 21 5c 6e 22 29 3b 20 5c |he array|!\n"); \|
|00005100| 0a 58 20 20 20 20 20 20 | 66 66 6c 75 73 68 28 73 |.X |fflush(s|
|00005110| 74 64 6f 75 74 29 3b 20 | 5c 0a 58 20 20 20 20 20 |tdout); |\.X |
|00005120| 20 6c 6f 6e 67 6a 6d 70 | 28 6e 65 78 74 2c 20 31 | longjmp|(next, 1|
|00005130| 29 3b 20 5c 0a 58 20 20 | 20 20 7d 20 5c 0a 58 20 |); \.X | } \.X |
|00005140| 20 7d 0a 58 0a 58 23 64 | 65 66 69 6e 65 20 55 50 | }.X.X#d|efine UP|
|00005150| 44 41 54 45 5f 53 5f 48 | 45 41 50 20 5c 0a 58 20 |DATE_S_H|EAP \.X |
|00005160| 20 7b 20 73 74 72 75 63 | 74 20 6d 61 6c 6c 69 6e | { struc|t mallin|
|00005170| 66 6f 20 6d 69 3b 20 5c | 0a 58 20 20 20 20 6d 69 |fo mi; \|.X mi|
|00005180| 20 3d 20 6d 61 6c 6c 69 | 6e 66 6f 28 29 3b 20 20 | = malli|nfo(); |
|00005190| 5c 0a 58 20 20 20 20 69 | 66 20 28 73 5f 68 65 61 |\.X i|f (s_hea|
|000051a0| 70 20 3c 20 6d 69 2e 75 | 6f 72 64 62 6c 6b 73 29 |p < mi.u|ordblks)|
|000051b0| 20 73 5f 68 65 61 70 20 | 3d 20 6d 69 2e 75 6f 72 | s_heap |= mi.uor|
|000051c0| 64 62 6c 6b 73 3b 20 20 | 5c 0a 58 20 20 20 20 69 |dblks; |\.X i|
|000051d0| 66 20 28 73 5f 6c 6f 77 | 20 3d 3d 20 4e 55 4c 4c |f (s_low| == NULL|
|000051e0| 20 7c 7c 20 77 68 65 72 | 65 20 3c 20 73 5f 6c 6f | || wher|e < s_lo|
|000051f0| 77 29 20 73 5f 6c 6f 77 | 20 3d 20 77 68 65 72 65 |w) s_low| = where|
|00005200| 3b 20 5c 0a 58 20 20 20 | 20 69 66 20 28 73 5f 68 |; \.X | if (s_h|
|00005210| 69 67 68 20 3d 3d 20 4e | 55 4c 4c 20 7c 7c 20 77 |igh == N|ULL || w|
|00005220| 68 65 72 65 20 3e 20 73 | 5f 68 69 67 68 29 20 73 |here > s|_high) s|
|00005230| 5f 68 69 67 68 20 3d 20 | 77 68 65 72 65 3b 20 5c |_high = |where; \|
|00005240| 0a 58 20 20 20 20 63 6f | 6d 70 61 72 65 5f 63 6f |.X co|mpare_co|
|00005250| 75 6e 74 20 2b 2b 3b 20 | 7d 0a 58 0a 58 73 74 61 |unt ++; |}.X.Xsta|
|00005260| 74 69 63 20 6a 6d 70 5f | 62 75 66 20 6e 65 78 74 |tic jmp_|buf next|
|00005270| 3b 0a 58 0a 58 76 6f 69 | 64 20 63 61 74 63 68 5f |;.X.Xvoi|d catch_|
|00005280| 71 75 69 74 28 29 0a 58 | 7b 0a 58 20 20 70 72 69 |quit().X|{.X pri|
|00005290| 6e 74 66 28 22 5c 6e 22 | 29 3b 0a 58 20 20 66 66 |ntf("\n"|);.X ff|
|000052a0| 6c 75 73 68 28 73 74 64 | 6f 75 74 29 3b 0a 58 20 |lush(std|out);.X |
|000052b0| 20 6c 6f 6e 67 6a 6d 70 | 28 6e 65 78 74 2c 20 31 | longjmp|(next, 1|
|000052c0| 29 3b 0a 58 7d 0a 58 0a | 58 76 6f 69 64 20 74 65 |);.X}.X.|Xvoid te|
|000052d0| 73 74 5f 73 6f 72 74 5f | 66 75 6e 63 28 29 3b 0a |st_sort_|func();.|
|000052e0| 58 0a 58 69 6e 74 20 69 | 6e 74 5f 63 6f 6d 70 61 |X.Xint i|nt_compa|
|000052f0| 72 65 28 61 2c 20 62 29 | 20 69 6e 74 20 2a 20 61 |re(a, b)| int * a|
|00005300| 2c 20 2a 62 3b 20 0a 58 | 7b 20 0a 58 20 20 63 68 |, *b; .X|{ .X ch|
|00005310| 61 72 20 66 6f 6f 3b 0a | 58 20 20 63 68 61 72 20 |ar foo;.|X char |
|00005320| 2a 20 77 68 65 72 65 20 | 3d 20 26 66 6f 6f 3b 0a |* where |= &foo;.|
|00005330| 58 0a 58 20 20 43 48 45 | 43 4b 5f 43 41 4e 41 52 |X.X CHE|CK_CANAR|
|00005340| 49 45 53 3b 0a 58 20 20 | 55 50 44 41 54 45 5f 53 |IES;.X |UPDATE_S|
|00005350| 5f 48 45 41 50 3b 0a 58 | 0a 58 20 20 69 66 20 28 |_HEAP;.X|.X if (|
|00005360| 2a 61 20 3e 20 2a 62 29 | 20 72 65 74 75 72 6e 20 |*a > *b)| return |
|00005370| 31 3b 0a 58 20 20 69 66 | 20 28 2a 61 20 3c 20 2a |1;.X if| (*a < *|
|00005380| 62 29 20 72 65 74 75 72 | 6e 20 2d 31 3b 0a 58 20 |b) retur|n -1;.X |
|00005390| 20 72 65 74 75 72 6e 20 | 30 3b 0a 58 7d 0a 58 0a | return |0;.X}.X.|
|000053a0| 58 69 6e 74 20 64 6f 75 | 62 6c 65 5f 63 6f 6d 70 |Xint dou|ble_comp|
|000053b0| 61 72 65 28 61 2c 20 62 | 29 20 64 6f 75 62 6c 65 |are(a, b|) double|
|000053c0| 20 2a 20 61 2c 20 2a 62 | 3b 20 0a 58 7b 20 0a 58 | * a, *b|; .X{ .X|
|000053d0| 20 20 63 68 61 72 20 66 | 6f 6f 3b 0a 58 20 20 63 | char f|oo;.X c|
|000053e0| 68 61 72 20 2a 20 77 68 | 65 72 65 20 3d 20 26 66 |har * wh|ere = &f|
|000053f0| 6f 6f 3b 0a 58 0a 58 20 | 20 43 48 45 43 4b 5f 43 |oo;.X.X | CHECK_C|
|00005400| 41 4e 41 52 49 45 53 3b | 0a 58 20 20 55 50 44 41 |ANARIES;|.X UPDA|
|00005410| 54 45 5f 53 5f 48 45 41 | 50 3b 0a 58 0a 58 20 20 |TE_S_HEA|P;.X.X |
|00005420| 69 66 20 28 2a 61 20 3e | 20 2a 62 29 20 72 65 74 |if (*a >| *b) ret|
|00005430| 75 72 6e 20 31 3b 0a 58 | 20 20 69 66 20 28 2a 61 |urn 1;.X| if (*a|
|00005440| 20 3c 20 2a 62 29 20 72 | 65 74 75 72 6e 20 2d 31 | < *b) r|eturn -1|
|00005450| 3b 0a 58 20 20 72 65 74 | 75 72 6e 20 30 3b 0a 58 |;.X ret|urn 0;.X|
|00005460| 7d 0a 58 0a 58 2f 2a 41 | 52 47 53 55 53 45 44 2a |}.X.X/*A|RGSUSED*|
|00005470| 2f 0a 58 69 6e 74 20 6c | 69 65 5f 61 73 63 65 6e |/.Xint l|ie_ascen|
|00005480| 64 69 6e 67 28 61 2c 20 | 62 29 20 63 68 61 72 20 |ding(a, |b) char |
|00005490| 2a 20 61 2c 20 2a 62 3b | 20 0a 58 7b 20 0a 58 20 |* a, *b;| .X{ .X |
|000054a0| 20 63 68 61 72 20 66 6f | 6f 3b 0a 58 20 20 63 68 | char fo|o;.X ch|
|000054b0| 61 72 20 2a 20 77 68 65 | 72 65 20 3d 20 26 66 6f |ar * whe|re = &fo|
|000054c0| 6f 3b 0a 58 0a 58 20 20 | 43 48 45 43 4b 5f 43 41 |o;.X.X |CHECK_CA|
|000054d0| 4e 41 52 49 45 53 3b 0a | 58 20 20 55 50 44 41 54 |NARIES;.|X UPDAT|
|000054e0| 45 5f 53 5f 48 45 41 50 | 3b 0a 58 0a 58 20 20 72 |E_S_HEAP|;.X.X r|
|000054f0| 65 74 75 72 6e 20 2d 31 | 3b 0a 58 7d 0a 58 0a 58 |eturn -1|;.X}.X.X|
|00005500| 2f 2a 41 52 47 53 55 53 | 45 44 2a 2f 0a 58 69 6e |/*ARGSUS|ED*/.Xin|
|00005510| 74 20 6c 69 65 5f 64 65 | 73 63 65 6e 64 69 6e 67 |t lie_de|scending|
|00005520| 28 61 2c 20 62 29 20 63 | 68 61 72 20 2a 20 61 2c |(a, b) c|har * a,|
|00005530| 20 2a 62 3b 20 0a 58 7b | 20 0a 58 20 20 63 68 61 | *b; .X{| .X cha|
|00005540| 72 20 66 6f 6f 3b 0a 58 | 20 20 63 68 61 72 20 2a |r foo;.X| char *|
|00005550| 20 77 68 65 72 65 20 3d | 20 26 66 6f 6f 3b 0a 58 | where =| &foo;.X|
|00005560| 0a 58 20 20 43 48 45 43 | 4b 5f 43 41 4e 41 52 49 |.X CHEC|K_CANARI|
|00005570| 45 53 3b 0a 58 20 20 55 | 50 44 41 54 45 5f 53 5f |ES;.X U|PDATE_S_|
|00005580| 48 45 41 50 3b 0a 58 0a | 58 20 20 72 65 74 75 72 |HEAP;.X.|X retur|
|00005590| 6e 20 31 3b 0a 58 7d 0a | 58 0a 58 2f 2a 41 52 47 |n 1;.X}.|X.X/*ARG|
|000055a0| 53 55 53 45 44 2a 2f 0a | 58 69 6e 74 20 6c 69 65 |SUSED*/.|Xint lie|
|000055b0| 5f 65 71 75 61 6c 28 61 | 2c 20 62 29 20 63 68 61 |_equal(a|, b) cha|
|000055c0| 72 20 2a 20 61 2c 20 2a | 62 3b 20 0a 58 7b 20 0a |r * a, *|b; .X{ .|
|000055d0| 58 20 20 63 68 61 72 20 | 66 6f 6f 3b 0a 58 20 20 |X char |foo;.X |
|000055e0| 63 68 61 72 20 2a 20 77 | 68 65 72 65 20 3d 20 26 |char * w|here = &|
|000055f0| 66 6f 6f 3b 0a 58 0a 58 | 20 20 43 48 45 43 4b 5f |foo;.X.X| CHECK_|
|00005600| 43 41 4e 41 52 49 45 53 | 3b 0a 58 20 20 55 50 44 |CANARIES|;.X UPD|
|00005610| 41 54 45 5f 53 5f 48 45 | 41 50 3b 0a 58 0a 58 20 |ATE_S_HE|AP;.X.X |
|00005620| 20 72 65 74 75 72 6e 20 | 30 3b 0a 58 7d 0a 58 0a | return |0;.X}.X.|
|00005630| 58 2f 2a 41 52 47 53 55 | 53 45 44 2a 2f 0a 58 69 |X/*ARGSU|SED*/.Xi|
|00005640| 6e 74 20 73 75 72 70 72 | 69 73 65 28 61 2c 20 62 |nt surpr|ise(a, b|
|00005650| 29 20 63 68 61 72 20 2a | 20 61 2c 20 2a 62 3b 20 |) char *| a, *b; |
|00005660| 0a 58 7b 20 0a 58 20 20 | 63 68 61 72 20 66 6f 6f |.X{ .X |char foo|
|00005670| 3b 0a 58 20 20 63 68 61 | 72 20 2a 20 77 68 65 72 |;.X cha|r * wher|
|00005680| 65 20 3d 20 26 66 6f 6f | 3b 0a 58 0a 58 20 20 43 |e = &foo|;.X.X C|
|00005690| 48 45 43 4b 5f 43 41 4e | 41 52 49 45 53 3b 0a 58 |HECK_CAN|ARIES;.X|
|000056a0| 20 20 55 50 44 41 54 45 | 5f 53 5f 48 45 41 50 3b | UPDATE|_S_HEAP;|
|000056b0| 0a 58 0a 58 20 20 66 6f | 6f 20 3d 20 72 61 6e 64 |.X.X fo|o = rand|
|000056c0| 28 29 20 3e 3e 20 32 33 | 3b 0a 58 20 20 69 66 20 |() >> 23|;.X if |
|000056d0| 28 28 75 6e 73 69 67 6e | 65 64 20 63 68 61 72 29 |((unsign|ed char)|
|000056e0| 20 66 6f 6f 20 3c 20 38 | 35 29 20 72 65 74 75 72 | foo < 8|5) retur|
|000056f0| 6e 20 2d 31 3b 0a 58 20 | 20 69 66 20 28 28 75 6e |n -1;.X | if ((un|
|00005700| 73 69 67 6e 65 64 20 63 | 68 61 72 29 20 66 6f 6f |signed c|har) foo|
|00005710| 20 3c 20 31 37 31 29 20 | 72 65 74 75 72 6e 20 30 | < 171) |return 0|
|00005720| 3b 0a 58 20 20 72 65 74 | 75 72 6e 20 31 3b 0a 58 |;.X ret|urn 1;.X|
|00005730| 7d 0a 58 0a 58 69 6e 74 | 20 6d 61 69 6e 28 61 72 |}.X.Xint| main(ar|
|00005740| 67 63 2c 20 61 72 67 76 | 29 20 69 6e 74 20 61 72 |gc, argv|) int ar|
|00005750| 67 63 3b 20 63 68 61 72 | 20 2a 20 61 72 67 76 5b |gc; char| * argv[|
|00005760| 5d 3b 0a 58 7b 0a 58 20 | 20 69 6e 74 20 6e 3b 0a |];.X{.X | int n;.|
|00005770| 58 20 20 69 6e 74 20 73 | 74 61 67 65 20 3d 20 30 |X int s|tage = 0|
|00005780| 3b 0a 58 20 20 69 6e 74 | 20 64 6f 6e 65 20 3d 20 |;.X int| done = |
|00005790| 30 3b 0a 58 0a 58 20 20 | 70 72 69 6e 74 66 28 22 |0;.X.X |printf("|
|000057a0| 73 6f 72 74 20 66 6c 6f | 67 67 65 72 20 76 65 72 |sort flo|gger ver|
|000057b0| 73 69 6f 6e 20 25 64 20 | 70 61 74 63 68 20 6c 65 |sion %d |patch le|
|000057c0| 76 65 6c 20 25 64 2e 5c | 6e 22 2c 0a 58 20 20 20 |vel %d.\|n",.X |
|000057d0| 20 46 4c 4f 47 47 45 52 | 5f 56 45 52 53 49 4f 4e | FLOGGER|_VERSION|
|000057e0| 2c 20 46 4c 4f 47 47 45 | 52 5f 50 41 54 43 48 4c |, FLOGGE|R_PATCHL|
|000057f0| 45 56 45 4c 29 3b 0a 58 | 20 20 69 66 20 28 61 72 |EVEL);.X| if (ar|
|00005800| 67 63 20 3e 20 31 29 20 | 0a 58 20 20 20 20 6e 20 |gc > 1) |.X n |
|00005810| 3d 20 61 74 6f 69 28 61 | 72 67 76 5b 31 5d 29 3b |= atoi(a|rgv[1]);|
|00005820| 0a 58 20 20 65 6c 73 65 | 0a 58 20 20 20 20 6e 20 |.X else|.X n |
|00005830| 3d 20 44 45 46 41 55 4c | 54 5f 43 4f 55 4e 54 3b |= DEFAUL|T_COUNT;|
|00005840| 0a 58 20 20 69 66 20 28 | 6e 20 3c 20 30 29 20 6e |.X if (|n < 0) n|
|00005850| 20 3d 20 2d 6e 3b 0a 58 | 0a 58 20 20 70 72 69 6e | = -n;.X|.X prin|
|00005860| 74 66 28 22 74 69 6d 65 | 72 20 72 65 73 6f 6c 75 |tf("time|r resolu|
|00005870| 74 69 6f 6e 20 3d 20 25 | 31 2e 36 66 5c 6e 22 2c |tion = %|1.6f\n",|
|00005880| 20 31 2e 30 2f 28 64 6f | 75 62 6c 65 29 48 5a 29 | 1.0/(do|uble)HZ)|
|00005890| 3b 0a 58 20 20 70 72 69 | 6e 74 66 28 22 65 6c 65 |;.X pri|ntf("ele|
|000058a0| 6d 65 6e 74 20 73 69 7a | 65 20 3d 20 25 64 5c 6e |ment siz|e = %d\n|
|000058b0| 22 2c 20 73 69 7a 65 6f | 66 28 54 45 53 54 5f 54 |", sizeo|f(TEST_T|
|000058c0| 59 50 45 29 29 3b 0a 58 | 20 20 70 72 69 6e 74 66 |YPE));.X| printf|
|000058d0| 28 22 6e 75 6d 62 65 72 | 20 6f 66 20 65 6c 65 6d |("number| of elem|
|000058e0| 65 6e 74 73 20 3d 20 25 | 64 22 2c 20 6e 29 3b 0a |ents = %|d", n);.|
|000058f0| 58 20 20 66 66 6c 75 73 | 68 28 73 74 64 6f 75 74 |X fflus|h(stdout|
|00005900| 29 3b 0a 58 0a 58 20 20 | 73 65 74 6a 6d 70 28 6e |);.X.X |setjmp(n|
|00005910| 65 78 74 29 3b 0a 58 20 | 20 73 69 67 6e 61 6c 28 |ext);.X | signal(|
|00005920| 53 49 47 49 4e 54 2c 20 | 63 61 74 63 68 5f 71 75 |SIGINT, |catch_qu|
|00005930| 69 74 29 3b 0a 58 0a 58 | 20 20 2f 2a 20 61 70 6f |it);.X.X| /* apo|
|00005940| 6c 6f 67 69 65 73 20 66 | 6f 72 20 74 68 65 20 62 |logies f|or the b|
|00005950| 69 7a 61 72 72 65 20 63 | 6f 64 65 20 6c 61 79 6f |izarre c|ode layo|
|00005960| 75 74 20 2a 2f 0a 58 0a | 58 20 20 77 68 69 6c 65 |ut */.X.|X while|
|00005970| 20 28 21 20 64 6f 6e 65 | 29 20 73 77 69 74 63 68 | (! done|) switch|
|00005980| 20 28 73 74 61 67 65 29 | 0a 58 20 20 7b 0a 58 20 | (stage)|.X {.X |
|00005990| 20 20 20 63 61 73 65 20 | 30 3a 20 70 72 69 6e 74 | case |0: print|
|000059a0| 66 28 22 5c 6e 2a 2a 2a | 20 71 73 6f 72 74 20 2a |f("\n***| qsort *|
|000059b0| 2a 2a 5c 6e 22 29 3b 0a | 58 20 20 20 20 20 20 20 |**\n");.|X |
|000059c0| 20 20 20 20 20 70 72 69 | 6e 74 66 28 22 64 61 74 | pri|ntf("dat|
|000059d0| 61 20 20 20 20 20 20 20 | 20 20 63 6f 6d 70 61 72 |a | compar|
|000059e0| 65 73 20 20 20 20 20 20 | 73 74 61 63 6b 20 20 20 |es |stack |
|000059f0| 20 20 20 20 22 29 3b 0a | 58 20 20 20 20 20 20 20 | ");.|X |
|00005a00| 20 20 20 20 20 70 72 69 | 6e 74 66 28 22 68 65 61 | pri|ntf("hea|
|00005a10| 70 20 20 20 20 20 20 20 | 75 73 65 72 20 20 20 20 |p |user |
|00005a20| 20 20 20 73 79 73 74 65 | 6d 5c 6e 22 29 3b 0a 58 | syste|m\n");.X|
|00005a30| 20 20 20 20 20 20 20 20 | 20 20 20 20 66 66 6c 75 | | fflu|
|00005a40| 73 68 28 73 74 64 6f 75 | 74 29 3b 0a 58 20 20 20 |sh(stdou|t);.X |
|00005a50| 20 20 20 20 20 20 20 20 | 20 73 74 61 67 65 20 2b | | stage +|
|00005a60| 2b 3b 20 74 65 73 74 5f | 73 6f 72 74 5f 66 75 6e |+; test_|sort_fun|
|00005a70| 63 28 71 73 6f 72 74 2c | 20 6e 2c 20 31 29 3b 20 |c(qsort,| n, 1); |
|00005a80| 62 72 65 61 6b 3b 0a 58 | 20 20 20 20 63 61 73 65 |break;.X| case|
|00005a90| 20 31 3a 20 73 74 61 67 | 65 20 2b 2b 3b 20 74 65 | 1: stag|e ++; te|
|00005aa0| 73 74 5f 73 6f 72 74 5f | 66 75 6e 63 28 71 73 6f |st_sort_|func(qso|
|00005ab0| 72 74 2c 20 6e 2c 20 32 | 29 3b 20 62 72 65 61 6b |rt, n, 2|); break|
|00005ac0| 3b 0a 58 20 20 20 20 63 | 61 73 65 20 32 3a 20 73 |;.X c|ase 2: s|
|00005ad0| 74 61 67 65 20 2b 2b 3b | 20 74 65 73 74 5f 73 6f |tage ++;| test_so|
|00005ae0| 72 74 5f 66 75 6e 63 28 | 71 73 6f 72 74 2c 20 6e |rt_func(|qsort, n|
|00005af0| 2c 20 33 29 3b 20 62 72 | 65 61 6b 3b 0a 58 20 20 |, 3); br|eak;.X |
|00005b00| 20 20 63 61 73 65 20 33 | 3a 20 73 74 61 67 65 20 | case 3|: stage |
|00005b10| 2b 2b 3b 20 74 65 73 74 | 5f 73 6f 72 74 5f 66 75 |++; test|_sort_fu|
|00005b20| 6e 63 28 71 73 6f 72 74 | 2c 20 6e 2c 20 34 29 3b |nc(qsort|, n, 4);|
|00005b30| 20 62 72 65 61 6b 3b 0a | 58 20 20 20 20 63 61 73 | break;.|X cas|
|00005b40| 65 20 34 3a 20 73 74 61 | 67 65 20 2b 2b 3b 20 74 |e 4: sta|ge ++; t|
|00005b50| 65 73 74 5f 73 6f 72 74 | 5f 66 75 6e 63 28 71 73 |est_sort|_func(qs|
|00005b60| 6f 72 74 2c 20 6e 2c 20 | 35 29 3b 20 62 72 65 61 |ort, n, |5); brea|
|00005b70| 6b 3b 0a 58 20 20 20 20 | 63 61 73 65 20 35 3a 20 |k;.X |case 5: |
|00005b80| 73 74 61 67 65 20 2b 2b | 3b 20 74 65 73 74 5f 73 |stage ++|; test_s|
|00005b90| 6f 72 74 5f 66 75 6e 63 | 28 71 73 6f 72 74 2c 20 |ort_func|(qsort, |
|00005ba0| 6e 2c 20 36 29 3b 20 62 | 72 65 61 6b 3b 0a 58 20 |n, 6); b|reak;.X |
|00005bb0| 20 20 20 63 61 73 65 20 | 36 3a 20 73 74 61 67 65 | case |6: stage|
|00005bc0| 20 2b 2b 3b 20 74 65 73 | 74 5f 73 6f 72 74 5f 66 | ++; tes|t_sort_f|
|00005bd0| 75 6e 63 28 71 73 6f 72 | 74 2c 20 6e 2c 20 37 29 |unc(qsor|t, n, 7)|
|00005be0| 3b 20 62 72 65 61 6b 3b | 0a 58 20 20 20 20 63 61 |; break;|.X ca|
|00005bf0| 73 65 20 37 3a 20 73 74 | 61 67 65 20 2b 2b 3b 20 |se 7: st|age ++; |
|00005c00| 74 65 73 74 5f 73 6f 72 | 74 5f 66 75 6e 63 28 71 |test_sor|t_func(q|
|00005c10| 73 6f 72 74 2c 20 6e 2c | 20 38 29 3b 20 62 72 65 |sort, n,| 8); bre|
|00005c20| 61 6b 3b 0a 58 0a 58 20 | 20 20 20 63 61 73 65 20 |ak;.X.X | case |
|00005c30| 31 30 3a 20 5f 6d 61 79 | 62 65 5f 73 6f 72 74 65 |10: _may|be_sorte|
|00005c40| 64 20 3d 20 30 3b 0a 58 | 20 20 20 20 20 20 20 20 |d = 0;.X| |
|00005c50| 20 20 20 20 20 70 72 69 | 6e 74 66 28 22 5c 6e 2a | pri|ntf("\n*|
|00005c60| 2a 2a 20 6d 65 72 67 65 | 5f 73 6f 72 74 20 2a 2a |** merge|_sort **|
|00005c70| 2a 5c 6e 22 29 3b 0a 58 | 20 20 20 20 20 20 20 20 |*\n");.X| |
|00005c80| 20 20 20 20 20 70 72 69 | 6e 74 66 28 22 64 61 74 | pri|ntf("dat|
|00005c90| 61 20 20 20 20 20 20 20 | 20 20 63 6f 6d 70 61 72 |a | compar|
|00005ca0| 65 73 20 20 20 20 20 20 | 73 74 61 63 6b 20 20 20 |es |stack |
|00005cb0| 20 20 20 20 22 29 3b 0a | 58 20 20 20 20 20 20 20 | ");.|X |
|00005cc0| 20 20 20 20 20 20 70 72 | 69 6e 74 66 28 22 68 65 | pr|intf("he|
|00005cd0| 61 70 20 20 20 20 20 20 | 20 75 73 65 72 20 20 20 |ap | user |
|00005ce0| 20 20 20 20 73 79 73 74 | 65 6d 5c 6e 22 29 3b 0a | syst|em\n");.|
|00005cf0| 58 20 20 20 20 20 20 20 | 20 20 20 20 20 20 66 66 |X | ff|
|00005d00| 6c 75 73 68 28 73 74 64 | 6f 75 74 29 3b 0a 58 20 |lush(std|out);.X |
|00005d10| 20 20 20 20 20 20 20 20 | 20 20 20 20 73 74 61 67 | | stag|
|00005d20| 65 20 2b 2b 3b 20 74 65 | 73 74 5f 73 6f 72 74 5f |e ++; te|st_sort_|
|00005d30| 66 75 6e 63 28 6d 65 72 | 67 65 5f 73 6f 72 74 2c |func(mer|ge_sort,|
|00005d40| 20 6e 2c 20 31 29 3b 20 | 62 72 65 61 6b 3b 0a 58 | n, 1); |break;.X|
|00005d50| 20 20 20 20 63 61 73 65 | 20 31 31 3a 20 73 74 61 | case| 11: sta|
|00005d60| 67 65 20 2b 2b 3b 20 74 | 65 73 74 5f 73 6f 72 74 |ge ++; t|est_sort|
|00005d70| 5f 66 75 6e 63 28 6d 65 | 72 67 65 5f 73 6f 72 74 |_func(me|rge_sort|
|00005d80| 2c 20 6e 2c 20 32 29 3b | 20 62 72 65 61 6b 3b 0a |, n, 2);| break;.|
|00005d90| 58 20 20 20 20 63 61 73 | 65 20 31 32 3a 20 73 74 |X cas|e 12: st|
|00005da0| 61 67 65 20 2b 2b 3b 20 | 74 65 73 74 5f 73 6f 72 |age ++; |test_sor|
|00005db0| 74 5f 66 75 6e 63 28 6d | 65 72 67 65 5f 73 6f 72 |t_func(m|erge_sor|
|00005dc0| 74 2c 20 6e 2c 20 33 29 | 3b 20 62 72 65 61 6b 3b |t, n, 3)|; break;|
|00005dd0| 0a 58 20 20 20 20 63 61 | 73 65 20 31 33 3a 20 73 |.X ca|se 13: s|
|00005de0| 74 61 67 65 20 2b 2b 3b | 20 74 65 73 74 5f 73 6f |tage ++;| test_so|
|00005df0| 72 74 5f 66 75 6e 63 28 | 6d 65 72 67 65 5f 73 6f |rt_func(|merge_so|
|00005e00| 72 74 2c 20 6e 2c 20 34 | 29 3b 20 62 72 65 61 6b |rt, n, 4|); break|
|00005e10| 3b 0a 58 20 20 20 20 63 | 61 73 65 20 31 34 3a 20 |;.X c|ase 14: |
|00005e20| 73 74 61 67 65 20 2b 2b | 3b 20 74 65 73 74 5f 73 |stage ++|; test_s|
|00005e30| 6f 72 74 5f 66 75 6e 63 | 28 6d 65 72 67 65 5f 73 |ort_func|(merge_s|
|00005e40| 6f 72 74 2c 20 6e 2c 20 | 35 29 3b 20 62 72 65 61 |ort, n, |5); brea|
|00005e50| 6b 3b 0a 58 20 20 20 20 | 63 61 73 65 20 31 35 3a |k;.X |case 15:|
|00005e60| 20 73 74 61 67 65 20 2b | 2b 3b 20 74 65 73 74 5f | stage +|+; test_|
|00005e70| 73 6f 72 74 5f 66 75 6e | 63 28 6d 65 72 67 65 5f |sort_fun|c(merge_|
|00005e80| 73 6f 72 74 2c 20 6e 2c | 20 36 29 3b 20 62 72 65 |sort, n,| 6); bre|
|00005e90| 61 6b 3b 0a 58 20 20 20 | 20 63 61 73 65 20 31 36 |ak;.X | case 16|
|00005ea0| 3a 20 73 74 61 67 65 20 | 2b 2b 3b 20 74 65 73 74 |: stage |++; test|
|00005eb0| 5f 73 6f 72 74 5f 66 75 | 6e 63 28 6d 65 72 67 65 |_sort_fu|nc(merge|
|00005ec0| 5f 73 6f 72 74 2c 20 6e | 2c 20 37 29 3b 20 62 72 |_sort, n|, 7); br|
|00005ed0| 65 61 6b 3b 0a 58 20 20 | 20 20 63 61 73 65 20 31 |eak;.X | case 1|
|00005ee0| 37 3a 20 73 74 61 67 65 | 20 2b 2b 3b 20 74 65 73 |7: stage| ++; tes|
|00005ef0| 74 5f 73 6f 72 74 5f 66 | 75 6e 63 28 6d 65 72 67 |t_sort_f|unc(merg|
|00005f00| 65 5f 73 6f 72 74 2c 20 | 6e 2c 20 38 29 3b 20 62 |e_sort, |n, 8); b|
|00005f10| 72 65 61 6b 3b 0a 58 0a | 58 20 20 20 20 63 61 73 |reak;.X.|X cas|
|00005f20| 65 20 32 30 3a 20 5f 6d | 61 79 62 65 5f 73 6f 72 |e 20: _m|aybe_sor|
|00005f30| 74 65 64 20 3d 20 31 3b | 0a 58 20 20 20 20 20 20 |ted = 1;|.X |
|00005f40| 20 20 20 20 20 20 20 70 | 72 69 6e 74 66 28 22 5c | p|rintf("\|
|00005f50| 6e 2a 2a 2a 20 6d 65 72 | 67 65 5f 73 6f 72 74 28 |n*** mer|ge_sort(|
|00005f60| 5f 6d 61 79 62 65 5f 73 | 6f 72 74 65 64 29 20 2a |_maybe_s|orted) *|
|00005f70| 2a 2a 5c 6e 22 29 3b 0a | 58 20 20 20 20 20 20 20 |**\n");.|X |
|00005f80| 20 20 20 20 20 20 70 72 | 69 6e 74 66 28 22 64 61 | pr|intf("da|
|00005f90| 74 61 20 20 20 20 20 20 | 20 20 20 63 6f 6d 70 61 |ta | compa|
|00005fa0| 72 65 73 20 20 20 20 20 | 20 73 74 61 63 6b 20 20 |res | stack |
|00005fb0| 20 20 20 20 20 22 29 3b | 0a 58 20 20 20 20 20 20 | ");|.X |
|00005fc0| 20 20 20 20 20 20 20 70 | 72 69 6e 74 66 28 22 68 | p|rintf("h|
|00005fd0| 65 61 70 20 20 20 20 20 | 20 20 75 73 65 72 20 20 |eap | user |
|00005fe0| 20 20 20 20 20 73 79 73 | 74 65 6d 5c 6e 22 29 3b | sys|tem\n");|
|00005ff0| 0a 58 20 20 20 20 20 20 | 20 20 20 20 20 20 20 66 |.X | f|
|00006000| 66 6c 75 73 68 28 73 74 | 64 6f 75 74 29 3b 0a 58 |flush(st|dout);.X|
|00006010| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 73 74 61 | | sta|
|00006020| 67 65 20 2b 2b 3b 20 74 | 65 73 74 5f 73 6f 72 74 |ge ++; t|est_sort|
|00006030| 5f 66 75 6e 63 28 6d 65 | 72 67 65 5f 73 6f 72 74 |_func(me|rge_sort|
|00006040| 2c 20 6e 2c 20 31 29 3b | 20 62 72 65 61 6b 3b 0a |, n, 1);| break;.|
|00006050| 58 20 20 20 20 63 61 73 | 65 20 32 31 3a 20 73 74 |X cas|e 21: st|
|00006060| 61 67 65 20 2b 2b 3b 20 | 74 65 73 74 5f 73 6f 72 |age ++; |test_sor|
|00006070| 74 5f 66 75 6e 63 28 6d | 65 72 67 65 5f 73 6f 72 |t_func(m|erge_sor|
|00006080| 74 2c 20 6e 2c 20 32 29 | 3b 20 62 72 65 61 6b 3b |t, n, 2)|; break;|
|00006090| 0a 58 20 20 20 20 63 61 | 73 65 20 32 32 3a 20 73 |.X ca|se 22: s|
|000060a0| 74 61 67 65 20 2b 2b 3b | 20 74 65 73 74 5f 73 6f |tage ++;| test_so|
|000060b0| 72 74 5f 66 75 6e 63 28 | 6d 65 72 67 65 5f 73 6f |rt_func(|merge_so|
|000060c0| 72 74 2c 20 6e 2c 20 33 | 29 3b 20 62 72 65 61 6b |rt, n, 3|); break|
|000060d0| 3b 0a 58 20 20 20 20 63 | 61 73 65 20 32 33 3a 20 |;.X c|ase 23: |
|000060e0| 73 74 61 67 65 20 2b 2b | 3b 20 74 65 73 74 5f 73 |stage ++|; test_s|
|000060f0| 6f 72 74 5f 66 75 6e 63 | 28 6d 65 72 67 65 5f 73 |ort_func|(merge_s|
|00006100| 6f 72 74 2c 20 6e 2c 20 | 34 29 3b 20 62 72 65 61 |ort, n, |4); brea|
|00006110| 6b 3b 0a 58 20 20 20 20 | 63 61 73 65 20 32 34 3a |k;.X |case 24:|
|00006120| 20 73 74 61 67 65 20 2b | 2b 3b 20 74 65 73 74 5f | stage +|+; test_|
|00006130| 73 6f 72 74 5f 66 75 6e | 63 28 6d 65 72 67 65 5f |sort_fun|c(merge_|
|00006140| 73 6f 72 74 2c 20 6e 2c | 20 35 29 3b 20 62 72 65 |sort, n,| 5); bre|
|00006150| 61 6b 3b 0a 58 20 20 20 | 20 63 61 73 65 20 32 35 |ak;.X | case 25|
|00006160| 3a 20 73 74 61 67 65 20 | 2b 2b 3b 20 74 65 73 74 |: stage |++; test|
|00006170| 5f 73 6f 72 74 5f 66 75 | 6e 63 28 6d 65 72 67 65 |_sort_fu|nc(merge|
|00006180| 5f 73 6f 72 74 2c 20 6e | 2c 20 36 29 3b 20 62 72 |_sort, n|, 6); br|
|00006190| 65 61 6b 3b 0a 58 20 20 | 20 20 63 61 73 65 20 32 |eak;.X | case 2|
|000061a0| 36 3a 20 73 74 61 67 65 | 20 2b 2b 3b 20 74 65 73 |6: stage| ++; tes|
|000061b0| 74 5f 73 6f 72 74 5f 66 | 75 6e 63 28 6d 65 72 67 |t_sort_f|unc(merg|
|000061c0| 65 5f 73 6f 72 74 2c 20 | 6e 2c 20 37 29 3b 20 62 |e_sort, |n, 7); b|
|000061d0| 72 65 61 6b 3b 0a 58 20 | 20 20 20 63 61 73 65 20 |reak;.X | case |
|000061e0| 32 37 3a 20 73 74 61 67 | 65 20 2b 2b 3b 20 74 65 |27: stag|e ++; te|
|000061f0| 73 74 5f 73 6f 72 74 5f | 66 75 6e 63 28 6d 65 72 |st_sort_|func(mer|
|00006200| 67 65 5f 73 6f 72 74 2c | 20 6e 2c 20 38 29 3b 20 |ge_sort,| n, 8); |
|00006210| 62 72 65 61 6b 3b 0a 58 | 0a 58 20 20 20 20 63 61 |break;.X|.X ca|
|00006220| 73 65 20 33 30 3a 20 70 | 72 69 6e 74 66 28 22 5c |se 30: p|rintf("\|
|00006230| 6e 2a 2a 2a 20 68 65 61 | 70 5f 73 6f 72 74 20 2a |n*** hea|p_sort *|
|00006240| 2a 2a 5c 6e 22 29 3b 0a | 58 20 20 20 20 20 20 20 |**\n");.|X |
|00006250| 20 20 20 20 20 20 70 72 | 69 6e 74 66 28 22 64 61 | pr|intf("da|
|00006260| 74 61 20 20 20 20 20 20 | 20 20 20 63 6f 6d 70 61 |ta | compa|
|00006270| 72 65 73 20 20 20 20 20 | 20 73 74 61 63 6b 20 20 |res | stack |
|00006280| 20 20 20 20 20 22 29 3b | 0a 58 20 20 20 20 20 20 | ");|.X |
|00006290| 20 20 20 20 20 20 20 70 | 72 69 6e 74 66 28 22 68 | p|rintf("h|
|000062a0| 65 61 70 20 20 20 20 20 | 20 20 75 73 65 72 20 20 |eap | user |
|000062b0| 20 20 20 20 20 73 79 73 | 74 65 6d 5c 6e 22 29 3b | sys|tem\n");|
|000062c0| 0a 58 20 20 20 20 20 20 | 20 20 20 20 20 20 20 66 |.X | f|
|000062d0| 66 6c 75 73 68 28 73 74 | 64 6f 75 74 29 3b 0a 58 |flush(st|dout);.X|
|000062e0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 73 74 61 | | sta|
|000062f0| 67 65 20 2b 2b 3b 20 74 | 65 73 74 5f 73 6f 72 74 |ge ++; t|est_sort|
|00006300| 5f 66 75 6e 63 28 68 65 | 61 70 5f 73 6f 72 74 2c |_func(he|ap_sort,|
|00006310| 20 6e 2c 20 31 29 3b 20 | 62 72 65 61 6b 3b 0a 58 | n, 1); |break;.X|
|00006320| 20 20 20 20 63 61 73 65 | 20 33 31 3a 20 73 74 61 | case| 31: sta|
|00006330| 67 65 20 2b 2b 3b 20 74 | 65 73 74 5f 73 6f 72 74 |ge ++; t|est_sort|
|00006340| 5f 66 75 6e 63 28 68 65 | 61 70 5f 73 6f 72 74 2c |_func(he|ap_sort,|
|00006350| 20 6e 2c 20 32 29 3b 20 | 62 72 65 61 6b 3b 0a 58 | n, 2); |break;.X|
|00006360| 20 20 20 20 63 61 73 65 | 20 33 32 3a 20 73 74 61 | case| 32: sta|
|00006370| 67 65 20 2b 2b 3b 20 74 | 65 73 74 5f 73 6f 72 74 |ge ++; t|est_sort|
|00006380| 5f 66 75 6e 63 28 68 65 | 61 70 5f 73 6f 72 74 2c |_func(he|ap_sort,|
|00006390| 20 6e 2c 20 33 29 3b 20 | 62 72 65 61 6b 3b 0a 58 | n, 3); |break;.X|
|000063a0| 20 20 20 20 63 61 73 65 | 20 33 33 3a 20 73 74 61 | case| 33: sta|
|000063b0| 67 65 20 2b 2b 3b 20 74 | 65 73 74 5f 73 6f 72 74 |ge ++; t|est_sort|
|000063c0| 5f 66 75 6e 63 28 68 65 | 61 70 5f 73 6f 72 74 2c |_func(he|ap_sort,|
|000063d0| 20 6e 2c 20 34 29 3b 20 | 62 72 65 61 6b 3b 0a 58 | n, 4); |break;.X|
|000063e0| 20 20 20 20 63 61 73 65 | 20 33 34 3a 20 73 74 61 | case| 34: sta|
|000063f0| 67 65 20 2b 2b 3b 20 74 | 65 73 74 5f 73 6f 72 74 |ge ++; t|est_sort|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.