Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.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.048 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'algorithm': 0.03; 'skip:/ 10': 0.07; 'okay': 0.09; 'sub': 0.09; 'subject:method': 0.09; 'files.': 0.13; 'algorithm.': 0.16; 'md5': 0.16; 'printf': 0.16; 'skip:@ 20': 0.16; 'wrote:': 0.17; 'integer': 0.17; 'subject:page': 0.17; 'skip:% 10': 0.22; 'tried': 0.25; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'perl': 0.29; 'subject: .': 0.33; 'to:addr:python-list': 0.33; 'pm,': 0.35; 'really': 0.36; 'but': 0.36; 'enough': 0.36; 'quite': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'help': 0.40; "you've": 0.61; 'first': 0.61; 'chance': 0.61; 'different': 0.63; 'cut': 0.71; 'received:74.208': 0.71; '100%': 0.76; '100': 0.78; 'collision': 0.84; 'received:74.208.4.194': 0.84; 'subject:Using': 0.84; '40%': 0.91 Date: Tue, 22 Jan 2013 14:00:16 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> In-Reply-To: <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:zdmOOIiYt+dor6tFseRLRhHy4bmlpJgaJ5w1pEdALl+ tPHmWIRY2f0bCvuH1w8I9XKq99K7/x5/hQ2diI1hfJnC2Y4+/I SP6Yn+SiwccBfSm6/6zN8Ev7T003vZqNKGmswHacbTiw478R5n 7Ow3XKzsmLBCLgAXsBWg/6F8/pGlSBD713DyNAKQ4AvTYq8UPN x+bb7dWEoRaexT8MsQGRr9EBH45Z2mvPctNlB52FQqcaK5XfcK 9/164GpMj3Q2rSJlS8uI4wlXVEvaq3smHKhY/fHIrCDlPHfMbs H+ljvohQhMzeK0u+mROPqgVYU/jDz00evBQo6cEszGjmavj4g= = 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358881241 news.xs4all.nl 6959 [2001:888:2000:d::a6]:40910 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37334 On 01/22/2013 01:26 PM, Ferrous Cranus wrote: > >> > > sub hashit { > my $url=shift; > my @ltrs=split(//,$url); > my $hash = 0; > > foreach my $ltr(@ltrs){ > $hash = ( $hash + ord($ltr)) %10000; > } > printf "%s: %0.4d\n",$url,$hash > > } > > > which yields: > $ perl testMD5.pl > /index.html: 1066 > /about/time.html: 1547 > If you use that algorithm to get a 4 digit number, it'll look good for the first few files. But if you try 100 files, you've got almost 40% chance of a collision, and if you try 10001, you've got a 100% chance. So is it really okay to reuse the same integer for different files? I tried to help you when you were using the md5 algorithm. By using enough digits/characters, you can cut the likelihood of a collision quite small. But 4 digits, don't be ridiculous. -- DaveA