Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.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.030 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'tree': 0.05; 'essential.': 0.09; 'mixed': 0.09; 'override': 0.09; 'python': 0.11; '__getitem__,': 0.16; '__len__,': 0.16; 'pythonic': 0.16; 'subclass': 0.16; 'wrote:': 0.18; 'mon,': 0.24; 'header:In-Reply- To:1': 0.27; 'rest': 0.29; 'am,': 0.29; 'especially': 0.30; 'message-id:@mail.gmail.com': 0.30; 'probably': 0.32; 'quite': 0.32; 'cases': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'implement': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'easy': 0.60; 'reviewed': 0.60; 'you.': 0.62; 'mar': 0.68; 'optimized': 0.68; 'default': 0.69; 'faster.': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=WDtiX90f9mH+HL7w/BtbIOSaZmCZAOt2VAs+ZyahPFQ=; b=lKfTQ4lsTqGKHO2xYDi2mLdVTaisuMQde0qEPJfRDLNTIjk6rETX7iguKsQHuYrK72 Iy2Dtv4UkWsCcAhfaF7AilSyjLtJyYJL1y9N7Ojzk/PPhtqdYg5oBystyUTzbpBUStZe /VtzH58KEW6c/r5hxq8nmf3g2uR1jj3zR53fOYN6ng+D1dFxtOkA3S35TfYNmTTqUjKg YS3j7TNC196KIhXrn2TIjOr9HBmLD9FHzEEEto1H0sgX8jiyqjSHl8f+bc6zp0ztaxb3 BHB9M/aTEIO2E7qoTkU+fEL+5WxwIEBwDEon4NSpH/rRRvsentIGv0x3ekrEtPyS5hQc VKew== X-Received: by 10.68.191.39 with SMTP id gv7mr4267650pbc.90.1394736098909; Thu, 13 Mar 2014 11:41:38 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <87zjkyq7nr.fsf@elektro.pacujo.net> References: <87eh2d3x8h.fsf_-_@elektro.pacujo.net> <87eh2ctmht.fsf@elektro.pacujo.net> <87zjkz3eo3.fsf@elektro.pacujo.net> <87a9czrrax.fsf@elektro.pacujo.net> <531d3058$0$29994$c3e8da3$5496439d@news.astraweb.com> <87eh2atw6s.fsf@elektro.pacujo.net> <8761nmrnfk.fsf@elektro.pacujo.net> <87zjkyq7nr.fsf@elektro.pacujo.net> From: Ian Kelly Date: Thu, 13 Mar 2014 12:40:58 -0600 Subject: Re: Balanced trees To: Python Content-Type: text/plain; charset=ISO-8859-1 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: 12 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1394736421 news.xs4all.nl 2901 [2001:888:2000:d::a6]:36284 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68339 On Mon, Mar 10, 2014 at 11:34 AM, Marko Rauhamaa wrote: > The main thing is there are use cases where order is essential. That's > why I have had to implement the AVL tree in Python myself. No biggie, > but a C implementation would probably be much faster. Also, a standard > version would likely be reviewed and tested better and have all Pythonic > accessors in place. That last is actually quite easy to achieve, especially using the built-in ABCs. Just subclass from collections.MutableMapping and implement __len__, __iter__, __getitem__, __setitem__ and __delitem__; and default implementations of the rest will be mixed in for you. Or you can override those with optimized implementations.