Create Tinyurl style hash

后端 未结 2 1781
长发绾君心
长发绾君心 2020-12-10 08:17

does anyone know of an algorithm that generates hashes that look like tinyurl hashes from a string (url)

I think the requirements would be

case sensitive sho

相关标签:
2条回答
  • 2020-12-10 09:17

    Hashes don't guarantee that collisions won't occur (assuming that you have more items to hash than there are possible values of the hash), rather, a good hash algorithm will make it so that collisions don't occur often.

    This is important for URL generation because the total number of URLs that exist is greater than the values that can be stored in a fixed string hash.

    Rather, I believe you see a counter that is incremented and uses a number system with a large base (like 62 for example, for digits 0-9, characters a-z and A-Z) to represent the value of the counter which is unique.

    0 讨论(0)
  • 2020-12-10 09:20

    I don't think tinyurl hashes the strings; they have a database ID (1, 2, 3) which is coverted to base 36 (0-9A-Z): http://en.wikipedia.org/wiki/Base_36

    0 讨论(0)
提交回复
热议问题