Skip to content

Instantly share code, notes, and snippets.

@cbetta
Created January 14, 2013 12:30
Show Gist options
  • Select an option

  • Save cbetta/4529736 to your computer and use it in GitHub Desktop.

Select an option

Save cbetta/4529736 to your computer and use it in GitHub Desktop.
require 'bloomfilter'
bf = BloomFilter.new({ 'bits' => 0xff, 'salts' => %w(z A) })
bf.add("foo")
bf.test("foo")
#=> true
bf.to_json
#=> "{\"buckets\":[0,0,512,0,2,0,0,0],\"bucketsize\":31,\"bits\":255,\"salts\":[\"z\",\"A\"]}"
json = "{\"buckets\":[0,0,512,0,2,0,0,0],\"bucketsize\":31,\"bits\":255,\"salts\":[\"z\",\"A\"]}"
data = JSON.parse(json)
var bf = new BloomFilter(data)
bf.test("foo")
//=> false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment