Class: Bloomer::Scalable

Inherits:
Object
  • Object
show all
Defined in:
lib/inferno/ext/bloomer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_with_sufficient_size(length = 256) ⇒ Object



13
14
15
16
# File 'lib/inferno/ext/bloomer.rb', line 13

def self.create_with_sufficient_size(length = 256)
  size = initial_size(length)
  new(size, 0.00001)
end

.initial_size(length) ⇒ Object



18
19
20
21
22
# File 'lib/inferno/ext/bloomer.rb', line 18

def self.initial_size(length)
  size = 2**Math.log2(length).ceil

  size < 256 ? 256 : size
end

Instance Method Details

#add_without_duplication(string) ⇒ Object

Scalable bloom filters report very inaccurate sizes because they contain multiple filters and don’t check them all before adding something. This makes them check all of the filters before adding an element so that the size is more accurate.



7
8
9
10
11
# File 'lib/inferno/ext/bloomer.rb', line 7

def add_without_duplication(string)
  return false if include? string

  add string
end