-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNAP.java
61 lines (50 loc) · 1.6 KB
/
NAP.java
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
import java.util.ArrayList;
import utils.*;
/* A Network Access Point (NAP) */
public class NAP {
WeightedBloomFilter bloom; //bloom filter for specifying content attached to the NAP
ArrayList<String> content_ids; //content ids attached to the NAP
int top_pop;
String id;
//constructor
public NAP(int bloom_size, int bloom_hashes, String id,int top_pop,int k_unpop) {
content_ids = new ArrayList<String>();
bloom = new WeightedBloomFilter(bloom_size,bloom_hashes,top_pop,k_unpop);
this.id = id;
this.top_pop = top_pop;
}
/* Attach a content id to this NAP */
public void add_content(String id,int pop){
content_ids.add(id);
bloom.add(id,pop);
}
/* Get # of total content ids in this NAP */
public int total_ids() {
return content_ids.size();
}
/* Get NAP id */
public String id() {
return id;
}
/* Check if content is actually attached to the NAP */
public boolean isAttached(String id) {
return content_ids.contains(id);
}
/* Update with content located on this NAP */
public WeightedBloomFilter update() {
return bloom;
}
/* Get list of content ids in this NAP */
public ArrayList<String> getContent() {
return content_ids;
}
/* toString method */
@Override
public String toString() {
String result = "";
result += "Total ids in NAP #"+id+" = "+content_ids.size()+"\n{";
for(String id : content_ids) result+=id+" ";
result+="}\nBloom Filter = "+bloom;
return result;
}
}