bahamat / manta-shortener

A URL shortener that stores keys in manta
Mozilla Public License 2.0
0 stars 0 forks source link

Handle the possibility of collisions? #6

Open bahamat opened 6 years ago

bahamat commented 6 years ago

Although djb2 is hard to reverse, it may be prone to collisions (https://github.com/m9psy/DJB2_collision_generator).

In the event of a collision, what should we do?

One possibility: Considering if #5 is implemented, in the event of a collision we could have numerically indexed link files. E.G.,:

The short url returned would be base/key.index E.G., http://I.no.de/1234.0.

There may be better patterns to handle this.

twhiteman commented 6 years ago

In the case of a collision, an alternative would be:

  1. check if the full url is the same - if it's the same, then just use the existing short url
  2. add an extra digit (e.g. 0) to the end of the short url, and increment that digit until it is unique (in the case of multiple collisions), padding may be required for small inode numbers

So if a collision occurred for inode 123456789, it would be converted to 1234567890, and then 1234567891 for the next collision, and so forth.