-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBloomJoin.java
More file actions
74 lines (62 loc) · 1.79 KB
/
BloomJoin.java
File metadata and controls
74 lines (62 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class BloomJoin {
private BloomFilterDet bloom;
private HashMap<String, String> map1;
private HashMap<String, String> map2;
private HashMap<String, String> join;
public BloomJoin(String file1, String file2) {
try {
BufferedReader br1 = new BufferedReader(new FileReader(file1));
BufferedReader br2 = new BufferedReader(new FileReader(file2));
this.map1 = new HashMap<String, String>();
this.map2 = new HashMap<String, String>();
String line1 = br1.readLine();
String line2 = br2.readLine();
while(line1 != null && line1.split("\\s+").length == 2) {
this.map1.put(line1.split("\\s+")[0], line1.split("\\s+")[1]);
line1 = br1.readLine();
}
while(line2 != null && line2.split("\\s+").length == 2) {
this.map2.put(line2.split("\\s+")[0], line2.split("\\s+")[1]);
line2 = br2.readLine();
}
br1.close();
br2.close();
} catch(Exception e) {
e.printStackTrace();
}
this.join = new HashMap<String, String>();
this.bloom = new BloomFilterDet(this.map1.size(), 8);
}
public void server1() {
for (String key : map1.keySet()) {
this.bloom.add(key);
}
}
@SuppressWarnings("rawtypes")
public void server2() {
Iterator it = map2.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
if(!bloom.appears((String) pair.getKey())) {
it.remove();
}
}
for (String key : map2.keySet()) {
if(!bloom.appears(key)) {
this.map2.remove(key);
}
}
}
public void join() {
for (String key : map2.keySet()) {
String join1 = this.map1.get(key);
String join2 = this.map2.get(key);
this.join.put(join1, join2);
}
}
}