Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

README.md

1.23 Kb · 39 lines

Bloom Package

Package implements a Bloom filter, a space-efficient probabilistic data structure used to test whether an element is a member of a set.

A Bloom filter never returns a false negative. If Contains returns false, the element was definitely never added. It may return a false positive, Contains can return true for an element that was never added. This trade-off lets the filter use far less memory than storing the elements themselves, which makes it useful for membership checks such as caches, deduplication, or "have I seen this before?" tests.

Repository can be found at jeronimoalbi/gnome, as part of jeronimoalbi's Gno smart contracts monorepo.

Usage

 1package main
 2
 3import "gno.land/p/g17khqpukees4237dtn3astzapmp462vjhsz6st4/bloom"
 4
 5func main() {
 6	// Create a filter expecting up to 1000 items with a 1% false-positive rate.
 7	b := bloom.New(1000, 0.01)
 8
 9	b.AddString("apple").AddString("banana")
10
11	println("Has apple:", b.ContainsString("apple"))
12	println("Has banana:", b.ContainsString("banana"))
13	println("Has cherry:", b.ContainsString("cherry"))
14}
15
16// Output:
17// Has apple: true
18// Has banana: true
19// Has cherry: false