Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'wiki': 0.02; 'subject:Python': 0.04; 'bits': 0.07; 'bug.': 0.07; 'hettinger': 0.07; 'terry': 0.07; '32)': 0.09; 'hash': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'pm,': 0.11; 'output': 0.12; 'wrote:': 0.14; '...,': 0.16; '2:17': 0.16; 'correlation': 0.16; 'reedy': 0.16; 'slicing': 0.16; 'value;': 0.16; 'algorithm': 0.16; 'yield': 0.19; 'appear': 0.19; 'seems': 0.21; '(or': 0.22; 'jan': 0.22; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'raymond': 0.22; 'values': 0.23; 'url:wiki': 0.24; 'says': 0.25; 'times.': 0.26; 'pass': 0.27; 'function': 0.27; 'beauty': 0.31; 'key.': 0.31; 'to:addr:python-list': 0.32; 'initial': 0.32; 'bit': 0.33; 'array': 0.33; 'lines': 0.34; 'header:X-Complaints-To:1': 0.34; 'there': 0.35; 'url:en': 0.35; 'header:User-Agent:1': 0.35; 'doing': 0.36; 'should': 0.37; 'either': 0.37; 'less': 0.38; 'but': 0.38; 'url:org': 0.38; 'used': 0.38; 'received:org': 0.38; 'set': 0.39; 'to:addr:python.org': 0.39; 'header:Mime-Version:1': 0.39; 'add': 0.39; 'takes': 0.40; 'tested': 0.40; 'header:Received:5': 0.40; 'url:ly': 0.60; 'wide': 0.63; '"for': 0.68; 'amazing': 0.71; 'article': 0.75; 'article,': 0.84; 'subject:Today': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Today's fun and educational Python recipe Date: Wed, 04 May 2011 15:42:33 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Gmane-NNTP-Posting-Host: rain.gmane.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 36 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1304538174 news.xs4all.nl 41117 [::ffff:82.94.164.166]:55564 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4653 On 5/4/2011 2:17 PM, Raymond Hettinger wrote: > Here's a 22-line beauty for a classic and amazing algorithm: > http://bit.ly/bloom_filter > > The wiki article on the algorithm is brief and well-written: > http://en.wikipedia.org/wiki/Bloom_filter As I understand the article, the array of num_bits should have=20 num_probes (more or less independent) bits set for each key. But as I=20 understand the code for i in range(self.num_probes): h, array_index =3D divmod(h, num_words) h, bit_index =3D divmod(h, 32) yield array_index, 1 << bit_index the same bit is being set or tested num_probes times. The last three=20 lines have no dependence on i that I can see, so they appear to do the=20 same thing each time. This seems like a bug. The article says "For a good hash function with a wide output, there=20 should be little if any correlation between different bit-fields of such = a hash, so this type of hash can be used to generate multiple=20 "different" hash functions by slicing its output into multiple bit=20 fields. Alternatively, one can pass k different initial values (such as=20 0, 1, ..., k =E2=88=92 1) to a hash function that takes an initial value;= or add=20 (or append) these values to the key." I do not see the code doing either = of these. --=20 Terry Jan Reedy