Class: Bloomin::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/bloomin/filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Filter

Returns a new instance of Filter.



8
9
10
11
12
13
# File 'lib/bloomin/filter.rb', line 8

def initialize(opts = {})
  @size = opts[:size] || 5000000
  @bloom = Array.new(self.size).fill(0)

  load_words
end

Instance Attribute Details

#bloomObject (readonly)

Returns the value of attribute bloom.



5
6
7
# File 'lib/bloomin/filter.rb', line 5

def bloom
  @bloom
end

#sizeObject

Returns the value of attribute size.



6
7
8
# File 'lib/bloomin/filter.rb', line 6

def size
  @size
end

Instance Method Details

#is_word?(word) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bloomin/filter.rb', line 15

def is_word?(word)
  integers = hash(word)
  integers.each do |i|
    if self.bloom[i] == 0
      puts "not a word - #{word}" if debug?
      false
    else
      puts "probably, a word - #{word}, #{probability}" if debug?
      true
    end
  end
end