bloom

package
v0.0.0-...-74dcdd4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2023 License: MIT Imports: 2 Imported by: 0

README

布隆过滤器

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

Filter 布隆过滤器

func NewFilter

func NewFilter(n int, p float64) *Filter

NewFilter 初始化一个布隆过滤器; 指定预期样本量n,指定预期失误率p

  1. 根据n和p可以计算出布隆位数(bit)m, 向上取整
  2. 根据M和N,可计算出需要多少个hash函数,记为k,向上取整
  3. 根据1,2信息计算真实失误率为q
  4. 布隆过滤器不支持删除

func (*Filter) Add

func (bf *Filter) Add(element string)

Add 往布隆过滤器中添加一个元素

func (*Filter) Contains

func (bf *Filter) Contains(element string) bool

Contains 检查元素是否可能存在于布隆过滤器中

func (*Filter) P

func (bf *Filter) P() float64

P 获取布隆过滤器的真实失误率

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL