Class: Bloomer::Scalable
- Inherits:
-
Object
- Object
- Bloomer::Scalable
- Defined in:
- lib/bloomer.rb
Overview
Automatically expanding bloom filter. See gsd.di.uminho.pt/members/cbm/ps/dbloom.pdf
Constant Summary collapse
- S =
2
- R =
Math.log(2) ** 2
Instance Method Summary collapse
- #add(string) ⇒ Object
- #capacity ⇒ Object
- #count ⇒ Object
-
#include?(string) ⇒ Boolean
only return false if no bloomers include string.
-
#initialize(initial_capacity = 256, false_positive_probability = 0.001) ⇒ Scalable
constructor
A new instance of Scalable.
Constructor Details
#initialize(initial_capacity = 256, false_positive_probability = 0.001) ⇒ Scalable
Returns a new instance of Scalable.
66 67 68 69 |
# File 'lib/bloomer.rb', line 66 def initialize(initial_capacity = 256, false_positive_probability = 0.001) @false_positive_probability = false_positive_probability @bloomers = [Bloomer.new(initial_capacity, false_positive_probability * R)] end |
Instance Method Details
#add(string) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/bloomer.rb', line 79 def add string l = @bloomers.last r = l.add(string) if r && (l.count > l.capacity) @bloomers << Bloomer.new(l.capacity * S, @false_positive_probability * (R**@bloomers.size)) end r end |
#capacity ⇒ Object
71 72 73 |
# File 'lib/bloomer.rb', line 71 def capacity @bloomers.last.capacity end |
#count ⇒ Object
75 76 77 |
# File 'lib/bloomer.rb', line 75 def count @bloomers.inject(0) {|i,b|i + b.count} end |
#include?(string) ⇒ Boolean
only return false if no bloomers include string.
89 90 91 |
# File 'lib/bloomer.rb', line 89 def include? string @bloomers.any? { |ea| ea.include? string } end |