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

Re^3: Converting a number back to it's original string (that was hashed to generate that number)

by Anonymous Monk
on Jan 23, 2013 at 20:06 UTC ( #1015013=note: print w/replies, xml ) Need Help??


in reply to Re^2: Converting a number back to it's original string (that was hashed to generate that number)
in thread Reaped: Converting a number back to it's original string (that was hashed to generate that number)

HOW to map both ways, in a one to one relation, (5-digit-integer <=> string) without losing any information?

CREATE TABLE pin_to_url ( pin int PRIMARY KEY, url varchar(255) ); SELECT v.*, pu.url FROM visitors v JOIN pin_to_url pu ON pu.pin = v.pin ORDER BY whatever;

Just store the filename alongside the pin into the table and it'll work pretty well.

The only other way of mapping string to pin -- apart from the lookup table I've just typed out -- is enumerating over the possible filenames and hashing each in turn, comparing the result to the pin. There's no way around it with the constraints you stubbornly add.

Oh, by the way, with 100 files and 10k available (random-ish) identification numbers, you might hit the birthday paradox. About 60% probable, I think. You don't want a hashing function -- you want an integer sequence. Databases provide those.

  • Comment on Re^3: Converting a number back to it's original string (that was hashed to generate that number)
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1015013]
help
Chatterbox?
[Corion]: I think I saw virtualsue more recently in person than online :-D
[virtualsue]: It's true that there was a bigger gap between the 2 yr old post and the one before it
[ambrus]: yes, I probably just didn't see you two years ago, because I'm not in perlmonks much
[virtualsue]: Nor am I :-)
[talexb]: virtualsue Heh .. long time no see! :)
[virtualsue]: I have a quiet Perl themed slack workspace
[virtualsue]: The person who talks to me on it the most *hates* Perl but she hates everything
[virtualsue]: If anyone is interested, ping me an email address for an invitation.

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2017-09-26 13:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (295 votes). Check out past polls.

    Notices?