1

我遇到了一个问题,我找不到解决它的好方法。

问题描述:

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. 

(例如“ http://bit.ly/18sy7Fzhttp://www.london24.com/spurs_star_townsend_deemed_hodgson_joke_a_compliment_1_2903643?utm_source=Daily+News&utm_medium=twitter ”)

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 中的每一行进行比较,这样我就可以获得我想要的一切。问题是:太慢了!

谁能帮助我用一种更快的算法来做到这一点?

问题解决:使用哈希表即可,请参考第一个答案!谢谢!

4

1 回答 1

0

将 short_map.txt 文件内容读入一个散列,其中键是长 url,对应的短 url 是它的值。当你想检索一个短网址时,你可以做一个哈希查找,这非常快。

于 2013-11-03T13:09:55.197 回答