3 ms·
For what it's worth, this is not the right way to implement such a site. The author notes that there's a collision problem, but pretends it's not a big deal whe
by aston 19y ago
For what it's worth, this is not the right way to implement such a site. The author notes that there's a collision problem, but pretends it's not a big deal when it actually is. What's the chaining (re-hashing) strategy, and do you really want to pay that cost every time anyone clicks either of the colliding links?
The better implementation is the one that seems stupid, namely start at 1 and increment your link number every time you get a new one. Encode it in something like base 36 (numbers plus lowercase letters), and you're basically done. This method also guarantees that your links are no longer than they need to be.