Skip to content

Commit 4fdc74e

Browse files
committed
update readme
1 parent c328cdd commit 4fdc74e

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

cmd/main.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import (
66
"runtime"
77
"time"
88

9+
"github.com/dgraph-io/badger/v3"
910
"github.com/dsa0x/sprout"
1011
bolt "go.etcd.io/bbolt"
1112
)
1213

1314
func main() {
1415
num := 20_000_00
1516
// div := num / 10
16-
// main6()
17+
// main7()
1718
// return
1819
opts := &sprout.BloomOptions{
1920
Err_rate: 0.001,
@@ -118,3 +119,36 @@ func main6() {
118119
}
119120
}
120121
}
122+
func main7() {
123+
num := 2_000_000
124+
db, err := badger.Open(badger.DefaultOptions("badgerstore.db"))
125+
if err != nil {
126+
panic(err)
127+
}
128+
err = db.Update(func(tx *badger.Txn) error {
129+
for i := 0; i < num; i++ {
130+
err := tx.Set([]byte(fmt.Sprintf("i%d-j", i)), []byte("b"))
131+
if err != nil {
132+
return err
133+
}
134+
}
135+
return err
136+
})
137+
for i := 0; i < 100; i++ {
138+
err = db.Update(func(tx *badger.Txn) error {
139+
for j := 0; j < num/100; j++ {
140+
err := tx.Set([]byte(fmt.Sprintf("i%d-j%d", i, j)), []byte("b"))
141+
if err != nil {
142+
return err
143+
}
144+
}
145+
return nil
146+
})
147+
if err != nil {
148+
break
149+
}
150+
}
151+
if err != nil {
152+
log.Fatal(err)
153+
}
154+
}

readme.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@ Sprout also implement a scalable bloom filter described in a paper written by [P
1010

1111
A scalable bloom filter allows you to grow the filter beyond the initial filter capacity, while preserving the desired false positive rate.
1212

13-
### Memory Usage
13+
### Storage Size
1414

1515
Bloom filters are space efficient, as they only store the bits that are set. For a filter with a capacity of 2,000,000 and a error rate of 0.001, the storage size is approximately 3.4MB. That implies that there are approximately 1.8 bytes (~14 bits) per element.
1616
The number of bits per element is as a result of the number of hash functions, which is derived from the capacity and the error rate.
1717

18-
In comparison, adding 2 million elements (with a singly byte value) to a boltdb database uses a storage size of about 108MB (113 bytes per pair).
18+
**Scalable Bloom Filters**: A scalable bloom filter initialized with a capacity of 2,000,000 and an error rate of 0.001, when grown to a capacity of 20,000,000, the total storage size is approximately 37.3MB.
1919

20-
**Scalable Bloom Filters**
20+
**Comparison to Key-Value stores**
2121

22-
A scalable bloom filter initialized with a capacity of 2,000,000 and an error rate of 0.001, when grown to a capacity of 20,000,000, the total storage size is approximately 37.3MB.
22+
Adding 2 million elements (with a single byte value)
23+
24+
| Database | Size |
25+
| -------- | ----- |
26+
| BoltDB | 108MB |
27+
| BadgerDB | 128MB |
28+
| Sprout | 3.4MB |
2329

2430
### Installation
2531

0 commit comments

Comments
 (0)