Skip to content
Tcl Source Code Artifact [be3634ed64]
Login

Artifact [be3634ed64]

Artifact be3634ed6458cc8b753c68262a49ea0e20cfef86:

Ticket change [be3634ed64] - New ticket [1993441fffffffff|1993441fff] <i>Lightweight pair type &#39;cons&#39;</i>. by ferrieux on 2008-06-13 22:53:00.
D 2008-06-13T22:53:00
J assignee nobody
J cmimetype text/plain
J comment The\sfollowing\stype\sintroduces\sa\snew\sobjtype\s'cons',\swhich\sis\ssimply\sa\stwo-element\slist\s(named\sby\sanalogy\swith\sLisp's\sfundamental\sdata\sstructures).\sThe\sadvantage\sover\splain\slists\sis\sthe\sabsence\sof\sheap-allocated\sspace\sfor\sthe\sinternal\srep,\ssince\stwoPtrValue\sis\senough\sto\shold\sthe\stwo\spointers.\n\nThe\sscript-visible\spart\sis\sas\sfollows:\n\n\s-\s[cons\s$a\s$b]\screates\sa\sCons\sof\selements\s$a\sand\s$b\n\s-\sthe\sstring\srepr\sof\s[cons\s$a\s$b]\sis\sthe\ssame\sas\s[list\s$a\s$b]'s\n\nImportant\sdetails\sbehind\sthe\sscenes:\n\n\s-\s[lindex]\sand\s[lsort\s-index]\saccess\sConses\stransparently\s*without\sshimmering*\n\n\s-\sall\sother\slist\sops\sdo\sshimmer\sas\sthey\sshould,\sgiving\sthem\sthe\sintuitively\sexpected\ssemantics\s(By\sgoing\sthrough\sthe\sstring\srep\sfor\snow.\sA\sshortcut\sis\simagineable).\n\nTiming\sresults\sbelow.\n\nSummary:\s\n\n-\sCons\sis\snearly\s2x\sfaster\sand\s1.7x\ssmaller-memory\sthan\sList\sfor\sbuilding\sa\slarge\s(10\smillion)\slist\sof\spairs.\n\n-\sThis\slist\sis\stypical\sof\san\s[lsort\s-index]\stask\n\n-\sThe\s[lsort\s-index]\sspeed\sis\sthen\sexactly\sthe\ssame\n\nPerspective:\n\nThe\scons\scan\sbe\sa\suseful\sreplacement\sfor\slists\severywhere\sa\ssmall\sstructure\sis\sneeded.\sThat\sis\snotably\sthe\scase\sof\sthe\sMaybe\smonad\sproposed\sby\sNeil\sMadden\sto\ssolve\sthe\sNULL\sissue:\n\n\s\s\s\s[cons\s0\s""]\s->\sNothing\n\s\s\s\s[cons\s1\s$x]\s->\sSome\s$x\n\n\n\n***CONS***\n\nAlex@DELLALEX\s/src/cvs/tcl/win\n$\s./tclsh86.exe\n%\sproc\sg\sn\s{set\sl\s{};for\s{set\si\s0}\s{$i<$n}\s{incr\si}\s{lappend\sl\s[cons\s$i\s$i]};return\s$l}\n%\stime\s{set\sbig\s[g\s10000000];set\sx\s1}\n4288955\smicroseconds\sper\siteration\n%\stime\s{set\sbig\s[g\s10000000];set\sx\s1}\n3746134\smicroseconds\sper\siteration\n%\stime\s{set\sbig\s[g\s10000000];set\sx\s1}\n3697388\smicroseconds\sper\siteration\n\n%\stime\s{set\ssrt\s[lsort\s-index\s0\s-integer\s-decreasing\s$big];set\sx\s1}\n2301849\smicroseconds\sper\siteration\n%\stime\s{set\ssrt\s[lsort\s-index\s0\s-integer\s-decreasing\s$big];set\sx\s1}\n2683979\smicroseconds\sper\siteration\n%\sexit\n(process\sVM\s~474M)\n\n\n***LIST***\n\nAlex@DELLALEX\s/src/cvs/tcl/win\n$\s./tclsh86.exe\n%\sproc\sf\sn\s{set\sl\s{};for\s{set\si\s0}\s{$i<$n}\s{incr\si}\s{lappend\sl\s[list\s$i\s$i]};return\s$l}\n%\stime\s{set\sbig\s[f\s10000000];set\sx\s1}\n7609976\smicroseconds\sper\siteration\n%\stime\s{set\sbig\s[f\s10000000];set\sx\s1}\n6912197\smicroseconds\sper\siteration\n%\stime\s{set\sbig\s[f\s10000000];set\sx\s1}\n7021424\smicroseconds\sper\siteration\n\n%\stime\s{set\ssrt\s[lsort\s-index\s0\s-integer\s-decreasing\s$big];set\sx\s1}\n2304322\smicroseconds\sper\siteration\n%\stime\s{set\ssrt\s[lsort\s-index\s0\s-integer\s-decreasing\s$big];set\sx\s1}\n2703814\smicroseconds\sper\siteration\n%\sexit\n(process\sVM\s~796M)\n\n
J foundin None
J is_private 0
J priority 5\sMedium
J resolution None
J status Open
J submitter ferrieux
J subsystem None
J title Lightweight\spair\stype\s'cons'
J type Patch
K 1993441fffffffffffffffffffffffffffffffff
U ferrieux
Z f005e998e2386018ee9f1e231e218170