Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; '"python': 0.16; '-1;': 0.16; 'discussed.': 0.16; 'function"': 0.16; 'kern': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'roy': 0.16; 'underlying': 0.16; 'wrote:': 0.18; 'header:User- Agent:1': 0.23; 'interpret': 0.24; 'java': 0.24; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'robert': 0.30; '3.2': 0.31; 'break;': 0.31; 'struct': 0.31; 'something': 0.35; 'opposed': 0.36; 'url:eu': 0.37; 'to:addr :python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'our': 0.64; 'world': 0.66; 'believe': 0.68; 'smith': 0.68; 'eco': 0.84; 'terrible': 0.84; 'edwards': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robert Kern Subject: Re: Bug in timsort!? Date: Wed, 25 Feb 2015 11:34:29 +0000 References: <1cf84559-3a63-4799-a879-ae8e513d387e@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 213.1.240.226 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424864077 news.xs4all.nl 2847 [2001:888:2000:d::a6]:46175 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86395 On 2015-02-24 22:45, Grant Edwards wrote: > On 2015-02-24, Roy Smith wrote: > >> http://envisage-project.eu/proving-android-java-and-python-sorting-algorithm-is-broken-and-how-to-fix-it/ > > I don't get it. > > 3.2 Corrected Python merge_collapse function > > merge_collapse(MergeState *ms) > { > struct s_slice *p = ms->pending; > > assert(ms); > while (ms->n > 1) { > Py_ssize_t n = ms->n - 2; > if ( n > 0 && p[n-1].len <= p[n].len + p[n+1].len > || (n-1 > 0 && p[n-2].len <= p[n].len + p[n-1].len)) { > if (p[n-1].len < p[n+1].len) > --n; > if (merge_at(ms, n) < 0) > return -1; > } > else if (p[n].len <= p[n+1].len) { > if (merge_at(ms, n) < 0) > return -1; > } > else > break; > } > return 0; > } > > Or does "Python function" mean something else in this context? "Corrected merge_collapse function [from the Python implementation of TimSort]" as opposed to the Java implementation which was also discussed. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco