-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator.js
More file actions
27 lines (23 loc) · 765 Bytes
/
validator.js
File metadata and controls
27 lines (23 loc) · 765 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
26
27
const bloom = require('./bloom')
function importBF(jsonString) {
var json = JSON.parse(jsonString)
json.seeds = new Uint32Array(json.seeds.split(','))
json.bitset = new Uint8Array(json.bitset.split(','))
var bf = new bloom.BloomFilter(json.m, json.k,
bitset = json.bitset,
seeds = json.seeds,
n = json.n)
return bf
}
function validate(bf, input_element, callback) {
if (bf.Query(input_element.value)) {
callback(false)
return false
} else {
callback(true)
return true
}
}
function buildBFValidator(bf, input_element, callback) {
return function() {validate(bf, input_element, callback)}
}