bloomfilter

package module
Version: v0.0.0-...-bba2d3a Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2020 License: MIT Imports: 3 Imported by: 0

README

bloomfilter

GoDoc

A Bloom filter is a data structure designed to tell you, rapidly and memory-efficiently, whether an element is present in a set. The price paid for this efficiency is that a Bloom filter is a probabilistic data structure: it tells us that the element either definitely is not in the set or may be in the set.

Installation

go get -u github.com/darklord19/bloomfilter

Import

import "github.com/darkLord19/bloomfilter"

Usage

// NewBloomFilter accepts three arguments. First is number of elements you want to track,
// second is acceptable false positive probability, and third is hash you want to use(it must implement hash64 interface)
bf := bloomfilter.NewBloomFilter(10000, 0.10, fnv.New64()) 
bf.Add([]byte("A"))
bf.Add([]byte("B"))
res, err := bf.DoesNotExist([]byte("C"))
elems := bf.GetElementsEstimate()

Documentation

Overview

Package bloomfilter implements bloomfilter data structure.

A Bloom filter is a data structure designed to tell you, rapidly and memory-efficiently, whether an element is present in a set. The price paid for this efficiency is that a Bloom filter is a probabilistic data structure: it tells us that the element either definitely is not in the set or may be in the set.

Example:

package main

import (
	"hash/fnv"

	"github.com/darkLord19/bloomfilter"
)

func main() {
	bf := bloomfilter.New(10000, 0.10, fnv.New64())
	bf.Add([]byte("A"))
	bf.Add([]byte("B"))
	status, err := bf.DoesNotExist([]byte("C"))
	elems := bf.ElementsEstimate()
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BloomFilter

type BloomFilter struct {
	Size                               uint32
	BitArray                           []bool
	NumberOfHashFunctions              uint8
	HashFunction                       hash.Hash64
	AcceptableFalsePositiveProbability float64
	// contains filtered or unexported fields
}

BloomFilter data struct

func New

func New(elements uint32, acceptableFalsePositiveProbability float64, hash hash.Hash64) *BloomFilter

New returns pointer to newly created BloomFilter struct. It accepts three arguments. 1st is number of elements you want to track 2nd is acceptable false positive probability 3rd is the hash function you want to use

func (*BloomFilter) Add

func (b *BloomFilter) Add(element []byte) error

Add inserts new element in bloomfilter instance

func (*BloomFilter) DoesNotExist

func (b *BloomFilter) DoesNotExist(element []byte) (bool, error)

DoesNotExist checks if element does not exist for sure in our dataset

func (*BloomFilter) ElementsEstimate

func (b *BloomFilter) ElementsEstimate() uint32

ElementsEstimate gives approximate number of items in bloom filter

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL