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

v0 state

Back to all declarations

numBits

untyped bigint

// m: total bits in the filter

Value

(2048 <untyped> bigint)

numBytes

untyped bigint

Value

(256 <untyped> bigint)

numHashes

untyped bigint

// k: hash functions per item (double-hashed from 2 bases)

Value

(5 <untyped> bigint)

maxHistory

untyped bigint

// most recent additions kept for Render display only

Value

(20 <untyped> bigint)

setBits

int

// running count of bits currently set to 1

Value

0

added

int

// total Add calls (may double-count re-adds)

Value

0

history

[]string

// last few added items, for the Render view

Value

<zero>

fnv1a

func(s string, seed uint32) uint32

fnv1a is a minimal FNV-1a 32-bit hash over a string, parameterized by an offset basis so two calls with different seeds behave as independent hash functions for the double-hashing scheme below.

Open
OID
0aef2d…1d54:8
fnv1a details

Inspect func

positions

func(item string) [5]uint32

positions returns the k bit positions an item hashes to.

Open
OID
0aef2d…1d54:10
positions details

Inspect func

setBit

func(pos uint32) bool

setBit sets bit \`pos\` and reports whether it was previously unset.

Open
OID
0aef2d…1d54:11
setBit details

Inspect func

testBit

func(pos uint32) bool

testBit reports whether bit \`pos\` is set.

Open
OID
0aef2d…1d54:12
testBit details

Inspect func

Add

func(item string)

Add inserts \`item\` into the filter. Crossing function: any caller (user or realm) may add, matching this demo's open-membership model.

Open
OID
0aef2d…1d54:13
Add details

Inspect func

MightContain

func(item string) bool

MightContain reports whether \`item\` was possibly added before. A false (definitely-not-a-member) answer is always correct; a true answer can occasionally be a false positive, never a false negative.

Open
OID
0aef2d…1d54:14
MightContain details

Inspect func

FalsePositiveRatePercent

func() float64

FalsePositiveRatePercent estimates the current false-positive rate, in percent, as (bitsSet/m)^k — the standard Bloom filter approximation once bits are randomly distributed. Computed with plain integer/float math to avoid depending on math.Exp/Pow availability.

Open
OID
0aef2d…1d54:15
FalsePositiveRatePercent details

Inspect func

Stats

func() (int, int, int, int)

Stats returns the raw counters backing the Render view and FalsePositiveRatePercent: (itemsAdded, bitsSet, totalBits, hashCount).

Open
OID
0aef2d…1d54:16
Stats details

Inspect func

Render

func(path string) string

Render draws the filter's current stats and recently-added items as Markdown for gnoweb.

Open
OID
0aef2d…1d54:17
Render details

Inspect func
numBits : untyped bigint =(2048 <untyped> bigint)
numBytes : untyped bigint =(256 <untyped> bigint)
numHashes : untyped bigint =(5 <untyped> bigint)
maxHistory : untyped bigint =(20 <untyped> bigint)
bits : [256]uint8 Inspect
setBits : int =0
added : int =0
history : []string =<zero>
fnv1a : func(s string, seed uint32) uint32 Inspect
positions : func(item string) [5]uint32 Inspect
setBit : func(pos uint32) bool Inspect
testBit : func(pos uint32) bool Inspect
Add : func(item string) Inspect
MightContain : func(item string) bool Inspect
FalsePositiveRatePercent : func() float64 Inspect
Stats : func() (int, int, int, int) Inspect
Render : func(path string) string Inspect