开源项目 URL shortner

xdite · November 03, 2012 · Last by lgn21st replied at November 04, 2012 · 3085 hits

https://gist.github.com/4007635

這是我在 Facebook World Hack 2012 拿下全球大賞的作品 Papaerclip.io 中,所用的縮址 library。

如果你的系統裡面有很多網址需要作 find & uniq 的話,這是個算是很有效的演算法。

大量网址 find 和 uniq 用CRC32多好啊

@hooopo 量特别大的时候 crc 碰撞率会很高吧...

#2 楼 @jasl 碰撞没关系,find/uniq 的时候只起到一个索引作用,减少比较的范围

PS.目测楼主生成的是 6 位字符串,crc32 生成的是 8 位,楼主的应该碰撞高一些才是。。

贡献一个 Base62 算法,用于将 id 转为 short url: https://gist.github.com/4007764

You need to Sign in before reply, if you don't have an account, please Sign up first.