我遇到了一个问题,我找不到解决它的好方法。
问题描述:
File 1: short_map.txt, contains with over 2millon lines with each line consist of a short url like the one in twitter and its corresponding full web url.
File 2: html_index.txt, contains with about 50k lines with each line stands for a full web url.
(例如“ http://www.redbubble.com/people/tipptoggy/works/10898437-rock-of-cashel ”)
我想在 html_index.txt 文件中获取每个 web url 对应的短 url 并将其输出到一个新的 txt 文件中。
我这样做的方法是读取 html_index.txt 的每一行,然后将其与 short_map.txt 中的每一行进行比较,这样我就可以获得我想要的一切。问题是:太慢了!
谁能帮助我用一种更快的算法来做到这一点?
问题解决:使用哈希表即可,请参考第一个答案!谢谢!