Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bits-and-blooms/bloom
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed Sep 28, 2023
2 parents 99a255d + 4f3fe0e commit a07e154
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bloom.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ type bloomFilterJSON struct {
}

// MarshalJSON implements json.Marshaler interface.
func (f *BloomFilter) MarshalJSON() ([]byte, error) {
func (f BloomFilter) MarshalJSON() ([]byte, error) {
return json.Marshal(bloomFilterJSON{f.m, f.k, f.b})
}

Expand Down
32 changes: 32 additions & 0 deletions bloom_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package bloom

import (
"fmt"
"bytes"
"encoding/binary"
"encoding/gob"
"encoding/json"
"math"
"testing"

"github.com/bits-and-blooms/bitset"
)

// This implementation of Bloom filters is _not_
Expand Down Expand Up @@ -291,6 +294,35 @@ func TestMarshalUnmarshalJSON(t *testing.T) {
if err != nil {
t.Fatal(err.Error())
}
fmt.Println(string(data))

var g BloomFilter
err = json.Unmarshal(data, &g)
if err != nil {
t.Fatal(err.Error())
}
if g.m != f.m {
t.Error("invalid m value")
}
if g.k != f.k {
t.Error("invalid k value")
}
if g.b == nil {
t.Fatal("bitset is nil")
}
if !g.b.Equal(f.b) {
t.Error("bitsets are not equal")
}
}


func TestMarshalUnmarshalJSONValue(t *testing.T) {
f:= BloomFilter{1000, 4, bitset.New(1000)}
data, err := json.Marshal(f)
if err != nil {
t.Fatal(err.Error())
}
fmt.Println(string(data))

var g BloomFilter
err = json.Unmarshal(data, &g)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/bits-and-blooms/bloom/v3
go 1.16

require (
github.com/bits-and-blooms/bitset v1.8.0
github.com/bits-and-blooms/bitset v1.9.0
github.com/twmb/murmur3 v1.1.6
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/bits-and-blooms/bitset v1.3.1 h1:y+qrlmq3XsWi+xZqSaueaE8ry8Y127iMxlMfqcK8p0g=
github.com/bits-and-blooms/bitset v1.3.1/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
github.com/bits-and-blooms/bitset v1.8.0 h1:FD+XqgOZDUxxZ8hzoBFuV9+cGWY9CslN6d5MS5JVb4c=
github.com/bits-and-blooms/bitset v1.8.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
github.com/bits-and-blooms/bitset v1.9.0 h1:g1YivPG8jOtrN013Fe8OBXubkiTwvm7/vG2vXz03ANU=
github.com/bits-and-blooms/bitset v1.9.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
github.com/twmb/murmur3 v1.1.6 h1:mqrRot1BRxm+Yct+vavLMou2/iJt0tNVTTC0QoIjaZg=
github.com/twmb/murmur3 v1.1.6/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ=

0 comments on commit a07e154

Please sign in to comment.