Skip to content

mattwiller/dblchk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dblchk

GoDoc

Zero-dependency implementation of a two-bit, single-hash function Bloom filter in Go, achieving significantly better accuracy than a traditional Bloom filter of the same size with excellent performance.

Installation

go get -u github.com/mattwiller/dblchk

Usage

import "github.com/mattwiller/dblchk"

// Create filter with default size (256 KiB): good for up to
// a few hundred of thousand entries with few false positives (< 5-10%)
filter := dblchk.NewFilter(0) 

// Add an item to the filter
filter.Add([]byte("hello, world!"))

// Check whether an item may be included in the filter
if filter.MayContain(item) {
  // Item is (probably) included in the set approximated by the filter
}

Benchmarks

Tested against popular Bloom filter and Cuckoo filter implementations:

goos: linux
goarch: amd64
cpu: 12th Gen Intel(R) Core(TM) i5-12400T

              │    dblchk    │                bloom                 │                  cuckoo                   │
              │    sec/op    │    sec/op     vs base                │     sec/op      vs base                   │
AddElement-12   20.45n ± 16%   26.55n ±  0%  +29.80% (p=0.001 n=10)   5761.50n ±  0%  +28073.59% (p=0.000 n=10)
MayContain-12   21.57n ± 10%   22.72n ±  0%   +5.38% (p=0.022 n=10)     11.99n ±  2%     -44.42% (p=0.000 n=10)

False-Positive Rate

Library Size Number of Entries False Positive Rate
github.com/mattwiller/dblchk 256 KiB 100k 1.3%
github.com/bits-and-blooms/bloom 256 KiB 100k 4.7%
github.com/seiflotfy/cuckoofilter 256 KiB 100k 1.2%

License

Copyright 2026 Matt Willer. Licensed under the 3-Clause BSD License.

About

Space-efficient Bloom-like filter with improved accuracy

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors