GithubHelp home page GithubHelp logo

bloomfilter.go's Introduction

bloomfilter.go

A Bloom Filter Implementation in Go

This implementation includes:

  • Standard Bloom Filter
  • Counting Bloom Filter Standard Bloom Filter, except that it supports deletions, by keeping 8-bit counters in each slot. These counters are likely to overflow if we add too many elements.
  • Scalable Bloom Filter This is a Bloom Filter, which can scale. Standard Bloom Filters will get too full at some time. If you keep adding elements any further, the False Positive Rate will go up. Scalable Bloom Filters get rid of this problem, by creating a new bloom filter to insert new elements. The newer bloom filters grow exponentially in size, and hence it will take exponentially more elements to become full. This is similar to how vectors grow.

Usage

  • You can create a new standard bloom filter like this: bf := NewBloomFilter(numHashFuncs, bloomFilterSize int) Where,

    1. numHashFuncs is the number of hash functions to use in the filter.
    2. bloomFilterSize is the size of the bloom filter.
  • Adding a new element is as simple as: bf.Add(elementByteSlice) Where, elementByteSlice is a representation of the element in the byte slice format.

  • Similarily, you can check if the element is present in the Bloom Filter by doing this: bf.Check(elementByteSlice)

  • The Check method is absolutely correct when it returns false. However, when it returns true, it might be wrong with a probability bf.FalsePositiveRate()

  • The scalable bloom filter is exactly the same, except it is created as follows: sbf := NewScalableBloomFilter(numHashFuncs, firstBFSize, maxBloomFilters, growthFactor int, targetFPR float64)

    Where,

    1. firstBFSize is the size of the first Bloom Filter which will be created.
    2. maxBloomFilters is the upper limit on the number of Bloom Filters to create
    3. growthFactor is the rate at which the Bloom Filter size grows.
    4. targetFPR is the maximum false positive rate allowed for each of the constituent bloom filters, after which a new Bloom Filter would be created and used
  • The counting bloom filter is similar, except it is created as follows: cbf := NewCountingBloomFilter(numHashFuncs, cbfSize int)

  • The counting bloom filter also supports deletion: cbf.Remove(elementByteSlice)

Tests

I have written a couple of simple tests, which you can see in bloomfilter_test.go, and run the tests by doing go test

References

Credits

Thanks to Aditya for suggesting the idea and pointers.

Author

Gaurav Menghani

bloomfilter.go's People

Contributors

reddragon avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.