Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2a.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'root': 0.05; 'tree': 0.05; 'binary': 0.07; 'cache': 0.07; 'happen.': 0.09; 'insertion': 0.09; 'python:': 0.09; 'trees': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'random': 0.14; 'cc:name:python list': 0.16; 'keys.': 0.16; 'thread,': 0.16; 'which,': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'python?': 0.22; 'cc:addr:python.org': 0.22; 'balancing': 0.24; 'earlier': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'tried': 0.27; 'idea': 0.28; 'wondering': 0.29; 'am,': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'bunch': 0.31; 'comparison': 0.31; 'node': 0.31; 'probably': 0.32; 'quite': 0.32; 'subject: (': 0.35; 'plans': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'library.': 0.36; "didn't": 0.36; 'url:org': 0.36; 'performance': 0.37; 'implement': 0.38; 'ian': 0.60; 'mentioned': 0.61; 'more': 0.64; 'different': 0.65; 'mar': 0.68; 'balanced': 0.84; "it'd": 0.84; 'aging': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=mPXuxGEL0LEuATHap0+xvUXuuhhRpRN2mqy56WrBNWA=; b=W0UH8cMtsC052jKLC5dBmau/qOZXZcAHNH0YNL0fG9NCA3TzryjUTZuuyciMOhxeBz 6eJ504/qCMNnUCFFSrGmgK8WqQD/5BBI1Wn018uaEXGzsQ94VNJA4F+cGgA6V9MDFUv/ r8OMyaSdpQny80l+llzv+UYRWEUQ4UxWo9cCwA+nGksnEX/5GBuDXgt3kM096JnuZ9AH u0zW6kes3pc7+/9vKKFkh4TN1SszAnqy6Agxk3zQrG/3xL0cZkQxXmCFm5C49QBNK7uW llXs4/JQTLhvojXuOUyUVNYBdzOek7OHnF8PGZb1VOkiHEa0O0P2ChDuYp2uupKOMm0B eB8Q== MIME-Version: 1.0 X-Received: by 10.236.124.104 with SMTP id w68mr32723220yhh.2.1394308705184; Sat, 08 Mar 2014 11:58:25 -0800 (PST) In-Reply-To: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> Date: Sat, 8 Mar 2014 11:58:25 -0800 Subject: Re: Balanced trees (was: Re: Tuples and immutability) From: Dan Stromberg To: Marko Rauhamaa Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List 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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1394308707 news.xs4all.nl 2901 [2001:888:2000:d::a6]:49875 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68050 On Sat, Mar 8, 2014 at 12:34 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> I already mentioned this earlier in the thread, but a balanced binary >> tree might implement += as node insertion and then return a different >> object if the balancing causes the root node to change. > > True. > > Speaking of which, are there plans to add a balanced tree to the > "batteries" of Python? Timers, cache aging and the like need it. I'm > using my own AVL tree implementation, but I'm wondering why Python > still doesn't have one. I think it'd probably be a good idea to add one or more balanced binary trees to the standard library. But I suspect it's been tried before, and didn't happen. It might be good to add an _un_balanced tree too, since they do quite well with random keys. Here's a performance comparison I did of a bunch of tree types in Python: http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-01/