forked from robaho/httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBloomSet.java
More file actions
25 lines (24 loc) · 824 Bytes
/
BloomSet.java
File metadata and controls
25 lines (24 loc) · 824 Bytes
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
package robaho.net.httpserver;
/** small set designed for efficient negative contains */
public class BloomSet {
private final int bloomHash;
private OpenAddressMap<String,Boolean> values;
private BloomSet(String... values) {
this.values = new OpenAddressMap<>(values.length*2);
int bloomHash = 0;
for(var v : values) {
bloomHash = bloomHash | v.hashCode();
this.values.put(v,true);
}
this.bloomHash = bloomHash;
}
public static BloomSet of(String... values) {
return new BloomSet(values);
}
public boolean contains(String value) {
return (bloomHash & value.hashCode()) == value.hashCode() && Boolean.TRUE.equals(values.get(value));
}
public Iterable<String> values() {
return values.keys();
}
}