How to Create a Unique 64bit Integer from String

Posted by Unknown on Wednesday, August 13, 2014

PHP provides the popular md5() hash function out of the box, which returns 32 a hex character string. It’s a great way to generate a fingerprint for any arbitrary length string. But what if you need to generate an integer fingerprint out of a URL?


Challenge


We faced that challenge in RatingWidget when we had to bind our rating widgets to a unique Int64 IDs based on the website’s page it’s being loaded from. Theoretically we could just store the URLs and query the URL column, but URLs can be very long and creating an index for text column with unknown length is very inefficient.


So if you are working on any kind of dynamic widget development that should load different data based on the URL it’s loaded from, this post will save you tonnes of time.


To simplify the problem, let’s divide it into two sub-challenges:



  1. URL Canonization

  2. String to unique Int64 conversion


Continue reading %How to Create a Unique 64bit Integer from String%




more

{ 0 comments... » How to Create a Unique 64bit Integer from String read them below or add one }

Post a Comment

Popular Posts