Skip to content
Tcl Source Code Artifact [0958e1859c]
Login

Artifact [0958e1859c]

Artifact 0958e1859ce2cd89601d0e321943b91a1ed9a7f0:

Ticket change [0958e1859c] - New ticket [2082681fffffffff|2082681fff] <i>Add -group option to lsort</i>. by kieranelby on 2008-08-29 16:10:14.
D 2008-08-29T16:10:14
J assignee dkf
J cmimetype text/plain
J comment This\sis\sa\spatch\sto\sadd\sa\s"-group\sgrpSize"\soption\sto\slsort\sto\scause\nit\sto\streat\sthe\slist\sas\sconsisting\sof\sgroups\sof\sgrpSize\selements,\nand\sto\sthen\sperform\sthe\ssort\sgroup-wise,\skeeping\sthe\selements\swithin\neach\sgroup\stogether.\n\nThis\sis\ssimilar\sto\swhat\swas\srequested\sin\sFeature\sRequest\s747083:\n\nhttps://sourceforge.net/tracker/index.php?func=detail&aid=747083&group_id=10894&atid=360894\n\nA\smore\sdetailed\sexplanation\sfollows\s(not\squite\sa\sTIP\syet\stho!).\n\nAs\swell\sas\sthe\scode\schange,\sthe\spatch\sincludes\sa\schange\sto\sthe\sman\spage,\nbut\sI've\snot\sincluded\sany\stest\ssuite\schanges\s(are\sthere\sany\sexisting\stests\sfor\slsort?).\n\nRationale\n=========\n\n"Flat"\sname-value\spair\slists\sare\subiquitous\sin\sTcl\s-\sconsider\sthe\noutput\sof\s"array\sget",\s"dict\screate"\sor\sthe\sinput\sto\s"foreach".\n\nIt\sis\ssurprising\sthen\sthat\sthere\sis\sno\scommand\sto\sdirectly\ssort\nsuch\sa\slist\sby\seither\sthe\sname\sor\sthe\svalue\selements,\swhile\npreserving\sthe\sname-value\smapping.\n\nDoing\sso\scurrently\srequires\sturning\sa\sname-value\spair\slist\sinto\na\slist\sof\ssublists,\susing\sthe\slsort\s-index\soption\sto\ssort\sthem,\nthen\sflattening\sthe\slist\sagain,\swhich\sis\srather\sfiddly\sand\ninefficient.\n\nWith\sthis\sproposal,\ssorting\sa\sname-value\spair\slist\sby\sthe\snames\sis\nachieved\swith\s"lsort\s-group\s2\s$myList".\n\nSpecification\n=============\n\nA\snew\soption,\s"-group",\staking\sone\sparameter,\s"grpSize"\swill\sbe\nadded\sto\sthe\slsort\scommand.\n\nIf\s-group\sis\ssupplied,\sthe\slist\swill\sbe\streated\sas\sconsisting\sof\ngroups\sof\sgrpSize\selements,\sand\sthe\sgroups\swill\sbe\ssorted\sby\seither\ntheir\sfirst\selement\sor,\sif\sthe\s-index\soption\sis\sused,\sby\sthe\selement\nwithin\seach\sgroup\sgiven\sby\sthe\sfirst\sindex\spassed\sto\s-index\s(which\nis\sthen\signored\sby\s-index).\n\nElements\salways\sremain\sin\sthe\ssame\sposition\swithin\stheir\sgroup.\n\nThe\slist\slength\smust\sbe\sa\smultiple\sof\sgrpSize,\swhich\sin\sturn\smust\sbe\nat\sleast\s2.\n\nExamples\n========\n\n|\slsort\s-group\s2\s{carrot\s10\sapple\s50\sbanana\s25}\nreturns\s{apple\s50\sbanana\s25\scarrot\s10}\n\n|\slsort\s-group\s2\s-index\s1\s-integer\s{carrot\s10\sapple\s50\sbanana\s25}\nreturns\s{carrot\s10\sbanana\s25\sapple\s50}\n\n|\slsort\s-group\s3\s-index\s{0\s1}\s{{Bob\sSmith}\s25\sAudi\s{Jane\sDoe}\s40\sFord}\nreturn\s{{Jane\sDoe}\s40\sFord\s{Bob\sSmith}\s25\sAudi}\n(since\sSmith,\swhich\sis\sat\sindex\s1\sof\selement\s0\sof\sthe\sfirst\sgroup\scomes\nafter\sDoe,\swhich\sis\sat\sthe\ssame\sposition\sin\sthe\snext\sgroup\sof\s3.)\n\nLimitations\n===========\n\nOnly\sone\selement\sin\seach\sgroup\scan\sbe\sused\sfor\scomparison.\n
J foundin None
J is_private 0
J priority 5\sMedium
J resolution None
J status Open
J submitter kieranelby
J subsystem 17.\sCommands\sI-L
J title Add\s-group\soption\sto\slsort
J type Patch
K 2082681fffffffffffffffffffffffffffffffff
U kieranelby
Z 40c46726bd8d5797ea3e104cbe77f079