Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
bbloom
Commits
9a1bbb2d
Commit
9a1bbb2d
authored
Aug 23, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
api: split into TS and non TS functions
parent
79a41dc6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
6 deletions
+23
-6
bbloom.go
bbloom.go
+23
-6
No files found.
bbloom.go
View file @
9a1bbb2d
...
...
@@ -235,21 +235,31 @@ func (bl *Bloom) isSet(idx uint64) bool {
return
bl
.
bitset
[
idx
>>
6
]
&
(
1
<<
(
idx
%
64
))
>
0
}
// JSONMarshal
// returns JSON-object (type bloomJSONImExport) as []byte
func
(
bl
*
Bloom
)
JSONMarshal
()
([]
byte
,
error
)
{
bl
.
Mtx
.
RLock
()
defer
bl
.
Mtx
.
RUnlock
()
func
(
bl
*
Bloom
)
marshal
()
bloomJSONImExport
{
bloomImEx
:=
bloomJSONImExport
{}
bloomImEx
.
SetLocs
=
uint64
(
bl
.
setLocs
)
bloomImEx
.
FilterSet
=
make
([]
byte
,
len
(
bl
.
bitset
)
<<
3
)
for
i
,
w
:=
range
bl
.
bitset
{
binary
.
BigEndian
.
PutUint64
(
bloomImEx
.
FilterSet
[
i
<<
3
:
],
w
)
}
data
,
err
:=
json
.
Marshal
(
bloomImEx
)
return
bloomImEx
}
// JSONMarshal
// returns JSON-object (type bloomJSONImExport) as []byte
func
(
bl
*
Bloom
)
JSONMarshal
()
([]
byte
,
error
)
{
data
,
err
:=
json
.
Marshal
(
bl
.
marshal
())
return
data
,
err
}
// JSONMarshalTS is a thread-safe version of JSONMarshal
func
(
bl
*
Bloom
)
JSONMarshalTS
()
([]
byte
,
error
)
{
bl
.
Mtx
.
RLock
()
export
:=
bl
.
marshal
()
bl
.
Mtx
.
RUnlock
()
return
json
.
Marshal
(
export
)
}
// JSONUnmarshal
// takes JSON-Object (type bloomJSONImExport) as []bytes
// returns bloom32 / bloom64 object
...
...
@@ -271,6 +281,13 @@ func (bl *Bloom) FillRatio() float64 {
return
float64
(
count
)
/
float64
(
bl
.
size
+
1
)
}
// FillRatioTS is a thread-save version of FillRatio
func
(
bl
*
Bloom
)
FillRatioTS
()
float64
{
bl
.
Mtx
.
RLock
()
defer
bl
.
Mtx
.
RUnlock
()
return
bl
.
FillRatio
()
}
// // alternative hashFn
// func (bl Bloom) fnv64a(b *[]byte) (l, h uint64) {
// h64 := fnv.New64a()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment