Reputation: 815
I was just reading this question How to code a URL shortener? where the top answer focusses on getting an auto-incremented ID for the long URL and then has functions which creates a short URL from the ID and also a function which goes back to the ID from the short URL.
However, would this not mean that if you input the same long URL again to generate a short URL it would auto-increment to a new ID and therefore create a different short URL?
If you wanted to make sure it returned the same short URL I think this means on the database that is currently storing a big hash table with just 'id' to 'long url' you need another index hash table for the 'long url' to 'id'?
Is there a more efficient way of doing this rather than having to double the memory storage?
Upvotes: 1
Views: 690
Reputation: 394
I have an implementation for this, so basically I am generating a unique UUID
for the specific URL as key
and the actual url as value
.
To make things more clear, here is the Github Link
In your front-end
<b><a href="{{***Value***}}">{{ **Key** }}</a></b>
Upvotes: 0