From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,385be4c68a9e4de6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-03 07:54:08 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!paloalto-snf1.gtei.net!chcgil2-snh1.gtei.net!cambridge1-snf1.gtei.net!news.gtei.net!bos-service1.ext.raytheon.com!bos-service2.ext.raytheon.com.POSTED!not-for-mail Message-ID: <3D230974.3B0D0402@despammed.com> From: Wes Groleau Reply-To: wesgroleau@despammed.com X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U) X-Accept-Language: en,es-MX,es,pt,fr-CA,fr MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Smart sorting algorithm ? References: <3D21D581.6EF6CB06@despammed.com> <3D21DC25.AD402F70@easystreet.com> <3D220648.6F3BE45D@despammed.com> <3D2221CD.3F619935@easystreet.com> <3D22278D.D3D34B7D@despammed.com> <3D222FC8.D4F10CF4@easystreet.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Wed, 03 Jul 2002 09:25:56 -0500 NNTP-Posting-Host: 151.168.144.162 X-Complaints-To: news@ext.ray.com X-Trace: bos-service2.ext.raytheon.com 1025706390 151.168.144.162 (Wed, 03 Jul 2002 10:26:30 EDT) NNTP-Posting-Date: Wed, 03 Jul 2002 10:26:30 EDT Organization: Raytheon Company Xref: archiver1.google.com comp.lang.ada:26846 Date: 2002-07-03T09:25:56-05:00 List-Id: > I think that's an optimization of the tight inner loop that is based on > the assumption that one extra item compare is less expensive than > comparing indexes on every iteration of the loop plus keeping track of > where your pivot element is. That comparison of an element with itself > will end the inner loop. In your case, the assumption is maybe not > true, but you get at most one extra compare on the last time through the > loop. I think you can change the loop to save the comparison, but it > makes the algorithm more complicated and it's easy to get it wrong. I > believe I've done that. Actually, once someone gave me the clue-by-four of "insertion with binary search" I re-wrote it that way in less than two hours, under 50 SLOC (including assertions). Far simpler than the quicksort I borrowed, and no compare (X,X). -- Wes Groleau http://freepages.rootsweb.com/~wgroleau