-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathldablooms.lua
More file actions
62 lines (49 loc) · 1.41 KB
/
ldablooms.lua
File metadata and controls
62 lines (49 loc) · 1.41 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
#!/usr/bin/env luajit
local setmetatable = setmetatable
local type = type
local ffi = require('ffi')
require('ldablooms_header')
module(...)
local L = ffi.load('dablooms')
Dablooms = {}
Dablooms.__index = Dablooms
function Dablooms:new(capacity, error_rate, filepath)
local self = {}
setmetatable(self, Dablooms)
if type(capacity) == 'object' then
error_rate = capacity.error_rate
filepath = capacity.filepath
capacity = capacity.capacity
end
self._filter = L.new_scaling_bloom(capacity, error_rate, filepath)
return self
end
function Dablooms:check(key)
return L.scaling_bloom_check(self._filter, key, #key) ~= 0
end
function Dablooms:add(key, id)
return L.scaling_bloom_add(self._filter, key, #key, id)
end
function Dablooms:delete(key, id)
return L.scaling_bloom_remove(self._filter, key, #key, id)
end
function Dablooms:flush()
return L.scaling_bloom_flush(self._filter)
end
function Dablooms:mem_seqnum()
return L.scaling_bloom_mem_seqnum(self._filter)
end
function Dablooms:disk_seqnum()
return L.scaling_bloom_disk_seqnum(self._filter)
end
function load_dabloom(capacity, error_rate, filepath)
local self = {}
setmetatable(self, Dablooms)
if type(capacity) == 'object' then
error_rate = capacity.error_rate
filepath = capacity.filepath
capacity = capacity.capacity
end
self._filter = L.new_scaling_bloom_from_file(capacity, error_rate, filepath)
return self
end