Skip to content

Commit 20c394a

Browse files
committed
docs(big-data): update find-common-urls (doocs#212)
1 parent 1e5b4ef commit 20c394a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

docs/big-data/find-common-urls.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### 解答思路
88

9+
#### 1. 分治策略
10+
911
每个 URL 占 64B,那么 50 亿个 URL 占用的空间大小约为 320GB。
1012

1113
> 5, 000, 000, 000 _ 64B ≈ 5GB _ 64 = 320GB
@@ -18,7 +20,19 @@
1820

1921
接着遍历 a<sub>i</sub>( `i∈[0,999]` ),把 URL 存储到一个 HashSet 集合中。然后遍历 b<sub>i</sub> 中每个 URL,看在 HashSet 集合中是否存在,若存在,说明这就是共同的 URL,可以把这个 URL 保存到一个单独的文件中。
2022

23+
#### 2. 前缀树
24+
25+
一般而言,URL 的长度差距不会不大,而且前面几个字符,绝大部分相同。这种情况下,非常适合使用**字典树**(trie tree) 这种数据结构来进行存储,降低存储成本的同时,提高查询效率。
26+
27+
> [@ChunelFeng](https://github.com/ChunelFeng) 反馈。[#212](https://github.com/doocs/advanced-java/issues/212)
28+
2129
### 方法总结
2230

31+
#### 分治策略
32+
2333
1. 分而治之,进行哈希取余;
24-
2. 对每个子文件进行 HashSet 统计。
34+
1. 对每个子文件进行 HashSet 统计。
35+
36+
#### 前缀树
37+
38+
1. 利用字符串的公共前缀来降低存储成本,提高查询效率。

0 commit comments

Comments
 (0)