Talk:Algorithm Implementation/Sorting/Schwartzian transform

Transwiki from Wikipedia
This chapter contains text from English Wikipedia article Schwartzian transform.

Edit history

 * 04:15, 23 July 2006 210.6.255.241 (Talk) (→Algorithm description)
 * 21:11, 17 July 2006 Bart Massey (Talk | contribs) (→Algorithm description - clarify efficiency savings)
 * 04:37, 31 May 2006 IlkkaPoutanen (Talk | contribs) m (→Algorithm description - Fixed last line to insert first element of each transformedArray element into sortedArray, not the first element of transformedArray over and over)
 * 17:12, 24 February 2006 Matthew Woodcraft (Talk | contribs) (Current version of the article shows how to do a full transform in Python)
 * 11:49, 23 February 2006 StephenH (Talk | contribs) m (→Implementation in Ruby - there is no ruby 2.4 - somebody's been C+Ping ;-))
 * 16:08, 21 February 2006 BACbKA (Talk | contribs) (Revert: memoized is not a typo.)
 * 15:29, 21 February 2006 164.107.36.35 (Talk) (→"Full Schwartzian Transform" - typo)
 * 16:02, 17 February 2006 TuukkaH (Talk | contribs) (→Implementation in Python - explain the possibilities better)
 * 15:14, 17 February 2006 TuukkaH (Talk | contribs) (add article structure)
 * 15:50, 15 February 2006 RandalSchwartz (Talk | contribs) m (spelling fix (it's not a good day when you spell your own last name incorrectly))
 * 14:30, 15 February 2006 24.182.39.15 (Talk)
 * 12:43, 15 February 2006 RandalSchwartz (Talk | contribs) m (add full-blown ST example (from the horses mouth, so be careful if you edit this, because I do know what I'm talking about))
 * 12:32, 15 February 2006 RandalSchwartz (Talk | contribs) (Ruby's version is an optimized sort, but not an ST, because you can't specify multiple sort keys that evaluate comparisons in a lazy manner.)
 * 20:53, 8 December 2005 R. Koot (Talk | contribs) m (cat)
 * 03:09, 1 December 2005 Marudubshinki (Talk | contribs)
 * 12:16, 22 November 2005 Toniher (Talk | contribs) (+ca)
 * 14:08, 23 October 2005 Fubar Obfusco (Talk | contribs) (comment code)
 * 14:03, 23 October 2005 Fubar Obfusco (Talk | contribs) (alternate name: decorate-sort-undecorate)
 * 16:12, 15 October 2005 TuukkaH (Talk | contribs) (→External links - remove unsuitable link)
 * 00:07, 13 October 2005 P0lyglut (Talk | contribs) (→External links)
 * 09:48, 10 October 2005 TuukkaH (Talk | contribs) (relate the example to memoization)
 * 09:37, 10 October 2005 TuukkaH (Talk | contribs) (relation to memoization)
 * 09:14, 10 October 2005 151.8.1.14 (Talk)
 * 10:47, 29 July 2005 Turnstep (Talk | contribs) (NPOV, specify version)
 * 01:09, 29 July 2005 144.135.3.174 (Talk) (add Ruby comparison)
 * 13:37, 28 July 2005 Matthew Woodcraft (Talk | contribs) (Restore working Python 2.3 code and simpler Python 2.4 code)
 * 19:18, 27 July 2005 Alterego (Talk | contribs) m (rv)
 * 17:58, 27 July 2005 Matthew Woodcraft (Talk | contribs) (fix python 2.4 code)
 * 17:51, 27 July 2005 Matthew Woodcraft (Talk | contribs) (fix Python code)
 * 11:14, 22 July 2005 Boredzo (Talk | contribs) m (Fixed date format. Linkified 2005. Space after *.)
 * 11:00, 22 July 2005 Grendelkhan (Talk | contribs) m (→External links - +1)
 * 03:44, 22 July 2005 195.159.128.110 (Talk) (→External links)
 * 07:16, 18 July 2005 Charles Matthews (Talk | contribs) m
 * 11:13, 11 July 2005 Alterego (Talk | contribs) m (Reverted edits by Neilc to last version by 128.189.203.217)
 * 11:12, 11 July 2005 Neilc (Talk | contribs)
 * 12:19, 28 June 2005 128.189.203.217 (Talk) ((trivial correction))
 * 11:56, 28 June 2005 128.189.203.217 (Talk) (Added some historical background.)
 * 20:24, 22 June 2005 Alterego (Talk | contribs) m
 * 20:23, 22 June 2005 Alterego (Talk | contribs) (add python reference)
 * 20:18, 22 June 2005 Jerub (Talk | contribs)
 * 13:08, 16 June 2005 Deco (Talk | contribs) (-wikicode)
 * 23:19, 17 May 2005 Jonadab (Talk | contribs) (wording change for clarity)
 * 14:18, 15 April 2005 69.78.62.119 (Talk) (Randal L. Schwartz)
 * 04:48, 3 April 2005 Brentdax (Talk | contribs) (Added Perl version back in)
 * 11:46, 24 March 2005 Fredrik (Talk | contribs) m
 * 22:26, 20 January 2005 Nightwatch (Talk | contribs) m (minor wikicode correction)
 * 22:25, 20 January 2005 Nightwatch (Talk | contribs) (converted to wikicode)
 * 19:45, 30 December 2004 MrItty (Talk | contribs) (Initial Entry)

Talk page
Who the heck thought this wikicode was easier to read than the original Perl?

@new = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [$_, foo($_)] } @old;

At least include the Perl for comparison. I've seldom seen a Schwartzian Transform outside of Perl. grendel|khan 17:43, 2005 Mar 7 (UTC)


 * The wikicode is easier to read for people who are not accustomed to the functional programming style and perl punctuation. Luckily, both versions are in the article now. --TuukkaH 08:33:40, 2005-09-09 (UTC)

I prefer the Python version: new = [p[1] for p in sorted([(criterion(e), e) for e in old])] - Fredrik | talk 15:59, 24 Mar 2005 (UTC)


 * This needs Python version 2.4 because  is used. But on Python 2.4 the programmer doesn't need to write the transformation, because   and   accept the keyword argument  . Now a guestion remains whether Python internally uses the transformation or a less efficient sort. It seems it uses the transformation: "-- cmp is called multiple times for each list element while key and reverse touch each element only once." (2.3.6.4 Mutable Sequence Types) --TuukkaH 08:33:40, 2005-09-09 (UTC)

Alterego, can you explain why you reverted my changes? The old version of the Python 2.3 code didn't actually run, and the old version of the 2.4 code was a needlessly long way round. Matthew Woodcraft 17:40, 28 July 2005 (UTC)


 * Perhaps we should explain the Python alternatives to the reader better. --TuukkaH 08:33:40, 2005-09-09 (UTC)

Maybe it should be noted that its not the comparsion that is heavy, but the evalution of the operand expressions? --MattiasW

AFAICS the Ruby example is broken:


 * The mtime of every file is retrieved even though it might not be needed.
 * It seems to incorrectly assume that  evaluates to   like in Perl, but in fact it evaluates to  . Therefore if two files tie on size, their age and name are ignored for the purposes of sorting.

I asked StackOverflow for ideas on how to do this correctly in Ruby and got a helpful answer: https://stackoverflow.com/questions/48240069/idiomatic-lazy-sorting-by-multiple-criteria --AdamSpiers (discuss • contribs) 13:16, 13 April 2019 (UTC)