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
e097157e
Commit
e097157e
authored
Jun 21, 2016
by
Jakub Sztandera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ElementsAdded
parent
cafad0a6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
4 deletions
+15
-4
bbloom.go
bbloom.go
+15
-4
No files found.
bbloom.go
View file @
e097157e
...
...
@@ -103,6 +103,12 @@ type Bloom struct {
size
uint64
setLocs
uint64
shift
uint64
content
uint64
}
func
(
bl
*
Bloom
)
ElementsAdded
()
uint64
{
return
bl
.
content
}
// <--- http://www.cse.yorku.ca/~oz/hash.html
...
...
@@ -125,6 +131,7 @@ type Bloom struct {
// Add
// set the bit(s) for entry; Adds an entry to the Bloom filter
func
(
bl
*
Bloom
)
Add
(
entry
[]
byte
)
{
bl
.
content
++
l
,
h
:=
bl
.
sipHash
(
entry
)
for
i
:=
uint64
(
0
);
i
<
(
*
bl
)
.
setLocs
;
i
++
{
bl
.
set
((
h
+
i
*
l
)
&
(
*
bl
)
.
size
)
...
...
@@ -142,7 +149,7 @@ func (bl *Bloom) AddTS(entry []byte) {
// Has
// check if bit(s) for entry is/are set
// returns true if the entry was added to the Bloom Filter
func
(
bl
Bloom
)
Has
(
entry
[]
byte
)
bool
{
func
(
bl
*
Bloom
)
Has
(
entry
[]
byte
)
bool
{
l
,
h
:=
bl
.
sipHash
(
entry
)
res
:=
true
for
i
:=
uint64
(
0
);
i
<
bl
.
setLocs
;
i
++
{
...
...
@@ -170,12 +177,15 @@ func (bl *Bloom) HasTS(entry []byte) bool {
// returns false if entry was allready registered in the bloomfilter
func
(
bl
*
Bloom
)
AddIfNotHas
(
entry
[]
byte
)
(
added
bool
)
{
l
,
h
:=
bl
.
sipHash
(
entry
)
res
:=
true
contained
:=
true
for
i
:=
uint64
(
0
);
i
<
bl
.
setLocs
;
i
++
{
prev
:=
bl
.
getSet
((
h
+
i
*
l
)
&
bl
.
size
)
res
=
res
&&
prev
contained
=
contained
&&
prev
}
if
!
contained
{
bl
.
content
++
}
return
!
res
return
!
contained
}
// AddIfNotHasTS
...
...
@@ -196,6 +206,7 @@ func (bl *Bloom) Clear() {
for
i
,
_
:=
range
(
*
bl
)
.
bitset
{
bl
.
bitset
[
i
]
=
0
}
bl
.
content
=
0
}
// Set
...
...
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