Skip to content
Tcl Source Code Artifact [ba1ff95299]
Login

Artifact [ba1ff95299]

Artifact ba1ff952999791a8e2861dc011f9fcc67e466d50:

Ticket change [ba1ff95299] - Ticket [1366484fffffffff|1366484fff] <i>patch: speed up lsort (follow on to 1360413)</i> status still Open with 4 other changes by afredd on 2006-01-12 02:10:05.
D 2006-01-12T02:10:05
J icomment Logged\sIn:\sYES\s\nuser_id=1386588\n\nOK\sas\spromised\s:-)\nHere's\sa\szip\sfile\swith\sa\s8.5a3\stclCmdIL.c\swith\sPerl's\nmerge\ssort\sin.\sI've\sincluded\ssome\stiming\sresults\nand\sa\stest\sscript.\sNB.\sthe\ssort\sis\sdocumented\sas\sbeing\nstable.\n\n*WARNING*\sthis\sis\snot\sa\spatch\s(yeah\s-\si\sknow\sthis\sprobably\nisn't\sthe\sbest\splace\sfor\sit\s:-)\sbut\smight\sbe\sof\sinterest\nto\ssomeone.\n\nSo\sis\sit\sfaster?\s....\sWell,\sif\sthe\slist\shas\sany\nexisting\sorder,\sthen\syes.\sFor\srand()om\sdata\susing\sa\squick\ncomparator\s(ie.\snot\s-command!)\sthen\sno.\nIt\scan\sbe\smassively\sfaster;\sit\sis\susually\snot\stoo\sfar\soff.\n\nOverall.\sI'm\sinclined\snot\sto\sgo\sany\sfurther\swith\sthis.\nThe\sperl\ssort\suses\sslightly\smore\smemory,\sand\sis\sslower\nfor\s[lsort\s-integer\s$a_random_list_of_ints].\nNot\smuch\spoint\sswapping\sthe\ssort\salg.\sif\sit\sis\sslower\nin\sa\spotentially\slikely\ssituation.\n\nNB.\swhile\si'm\shere\s(and\sapologies\sfor\sbeing\sOT)...\nlsort\scould\suse\sa\s-numeric\soption\n(or\s-bignum,\sor\s...)\sthat\sis\sequivalent\sto:\n\nproc\snum_cmp\s{a\sb}\s{\n\sif\s{$a\s>\s$b}\s{\sreturn\s1\s}\n\sif\s{$a\s<\s$b}\s{\sreturn\s-1\s}\n\sreturn\s0\n}\nlsort\s-command\snum_cmp\s$num_list\n\nas\scurrently\sthere\sis\sno\sbuiltin\sway\sto\ssort\neither\swides\sor\sthe\snew\sbig\snums\sif\sthey\sare\ntoo\sbig.\sConsider:\n\nset\sl\s[list\s\\\n\s[expr\swide(100000000000000002)]\s\\\n\s[expr\swide(100000000000000001)]\s\\\n\s[expr\swide(100000000000000003)]\s\\\n]\n\nputs\s[lsort\s-real\s$l]\s#\swrong\sresult\nputs\s[lsort\s-integer\s$l]\s#\sinteger\stoo\sbig\n\nI\sfeel\sa\sTIP\scoming\son\s:-)\n\n
J login afredd
J mimetype text/plain
J username afredd
K 1366484fffffffffffffffffffffffffffffffff
U afredd
Z cc7c6cefed535ca62d10848359b18a02