github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

igrigorik / bloomfilter

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 77
    • 5
  • Source
  • Commits
  • Network (5)
  • Issues (0)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Counting Bloom Filter implemented in Ruby: C version, Redis version (with TTL's) — Read more

  cancel

http://www.igvita.com/2008/12/27/scalable-datasets-bloom-filters-in-ruby/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

correct link in the readme 
Ilya Grigorik (author)
Wed Jan 06 09:55:55 -0800 2010
commit  c7ec3e5ede2ff2dee7f05b094cd868873fcddb4f
tree    38f4f36442b77cf2ea7b4288c765365a22593eaa
parent  003870d0f223c4d9be075550734f9b3acdaa42de
bloomfilter /
name age
history
message
file .gitignore Mon Dec 29 09:54:53 -0800 2008 adding a test task and a test [tenderlove]
file README.rdoc Wed Jan 06 09:55:55 -0800 2010 correct link in the readme [Ilya Grigorik]
file Rakefile Sat Jan 02 18:04:37 -0800 2010 abstract the interface; migrate to gemcutter [Ilya Grigorik]
file VERSION Tue Jan 05 21:40:53 -0800 2010 Version bump to 1.2.0 [Ilya Grigorik]
directory examples/ Tue Jan 05 21:40:11 -0800 2010 update readme with redis examples [Ilya Grigorik]
directory ext/ Sat Jan 02 20:33:58 -0800 2010 redis backend [Ilya Grigorik]
directory lib/ Sat Jan 02 20:33:58 -0800 2010 redis backend [Ilya Grigorik]
directory spec/ Sat Jan 02 20:33:58 -0800 2010 redis backend [Ilya Grigorik]
README.rdoc

BloomFilter

Counting Bloom Filter implemented in Ruby.

Bloom filter is a space-efficient probabilistic data structure that is used to test whether an element is a member of a set. False positives are possible, but false negatives are not. For more detail: en.wikipedia.org/wiki/Bloom_filter

Performance of the Bloom filter depends on a number of variables:

  • size of the bit array
  • size of the counter bucket
  • number of hash functions

To figure out the values for these parameters, refer to:

  • www.igvita.com/2008/12/27/scalable-datasets-bloom-filters-in-ruby/

To learn about applications and reasons for the time based bloom filters, refer to:

  • www.igvita.com/2010/01/06/flow-analysis-time-based-bloom-filters/

Implementation

Instead of using k different hash functions, this implementation seeds the CRC32 hash with k different initial values (0, 1, …, k-1). This may or may not give you a good distribution, it all depends on the data.

Example

  require 'bloomfilter'

  bf = BloomFilter.new(:size => 100, :hashes => 2, :seed => 1, :bucket => 3, :raise => false)
  bf.insert("test")
  bf.include?("test")
  => true
  bf.include?("test2")
  => false
  bf.delete("test")
  bf.include?("test")
  => false

  # Hash with a bloom filter!
  bf["test2"] = "bar"
  bf["test2"]
  => "bar"
  bf["test3"]
  => nil

  bf.stats
  Number of filter bits (m): 10
  Number of filter elements (n): 2
  Number of filter hashes (k) : 2
  Predicted false positive rate = 10.87%

Redis-backed counting Bloom Filter with TTL’s

  bf = BloomFilter.new(:type => :redis, :ttl => 2, :server => {:host => 'localhost'})

  bf.insert('test')
  bf.include?('test')
  => true

  sleep(2)
  bf.include?('test')
  => false

Credits

Tatsuya Mori <valdzone@gmail.com> (Original C implementation: vald.x0.com/sb/)

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server