Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'assignment': 0.07; 'indexing': 0.07; 'keys,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'storage,': 0.09; '>the': 0.16; 'accepts': 0.16; 'amiga': 0.16; 'class:': 0.16; 'defined,': 0.16; 'deletions': 0.16; 'finite': 0.16; 'hashes': 0.16; 'message- id:@4ax.com': 0.16; 'numbered': 0.16; 'otoh,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'unsigned': 0.16; 'worst': 0.16; 'all,': 0.19; 'example': 0.22; 'byte': 0.24; 'bytes': 0.24; 'url:home': 0.24; 'regardless': 0.24; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; 'needed.': 0.30; 'constant': 0.31; "d'aprano": 0.31; 'keys': 0.31; 'steven': 0.31; 'class': 0.32; 'becomes': 0.33; 'cases': 0.33; 'table': 0.34; "i'd": 0.34; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'useful': 0.36; 'charset:us-ascii': 0.36; 'possible': 0.36; 'list': 0.37; 'list.': 0.37; 'received:76': 0.38; 'to:addr:python- list': 0.38; 'structure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'is.': 0.60; 'full': 0.61; 'back': 0.62; "you've": 0.63; 'real': 0.63; 'world': 0.66; 'mar': 0.68; 'beat': 0.68; 'exceed': 0.68; 'discover': 0.82; '66.': 0.84; 'average': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Balanced trees Date: Mon, 10 Mar 2014 19:57:00 -0400 Organization: IISS Elusive Unicorn 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> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-249-20-148.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1394495825 news.xs4all.nl 2956 [2001:888:2000:d::a6]:47510 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68183 On 10 Mar 2014 03:24:08 GMT, Steven D'Aprano declaimed the following: > >Proof: I create a hash table that accepts unsigned bytes as keys, where >the hash is the value of the byte. So byte 0x42 hashes to 0x42, or >decimal 66. I give the hash table 256 slots, numbered from 0 to 255. >Every hash takes constant time, there are no collisions at all, lookups, >insertions and deletions all take constant time regardless of how full >the table is. The best, worst and average cases are not just O(1) but >also ?(1). > What you've defined, however, can be replaced with straight list indexing No hash function needed. If there is a finite (and small) number of possible keys, the list will likely beat the hash. OTOH, when the keys exceed reasonable list storage, the hash becomes useful -- but one now has to be concerned with collisions. Back in the day, I was somewhat pleased to discover that the Amiga directory structure was a real world example of something I'd only seen as a class assignment in my data structures class: a hashed-head multiple-linked list. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/