Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^5: Using filepath method to identify an .html page

by blue_cowdawg (Monsignor)
on Jan 22, 2013 at 19:34 UTC ( #1014774=note: print w/replies, xml ) Need Help??

in reply to Re^4: Using filepath method to identify an .html page
in thread Using filepath method to identify an .html page

      The perl code will produce the same hash for "abc.html" as for "bca.html"

Which underscores the point I made earlier about adding collision detection and rehashing logic to whatever algorithm you use. One workround I've seen:

| handwaving here... my @i = split(//,$url); # put each letter in it's own bin my $j=0; # Initailize our my $k=1; # hashing increment values my @m=(); # workspace foreach my $n(@i){ my $q=ord($n); # ASCII for character $k += $j; # Increment our hash offset $q += $k; # add our "old" value $j = $k; # store that. push @m,$q; # save the offsetted value } my $hashval=0; #initialize our hash value # Generate that map { $hashval = ($hashval + $_) % 10000} @m;
Using that method ABC.html and CBA.html now have different values because each letter position's value gets bumped up increasingly from left to right.

Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1014774]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2023-05-30 20:57 GMT
Find Nodes?
    Voting Booth?

    No recent polls found