Class: Bloomfilter::Bloomfilter
- Inherits:
-
Object
- Object
- Bloomfilter::Bloomfilter
- Defined in:
- lib/bloomfilter.rb
Instance Method Summary collapse
- #<<(k) ⇒ Object
- #count ⇒ Object
- #include?(k) ⇒ Boolean
-
#initialize(options = {}) ⇒ Bloomfilter
constructor
A new instance of Bloomfilter.
- #lock ⇒ Object
- #unlock ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Bloomfilter
Returns a new instance of Bloomfilter.
15 16 17 18 19 20 21 22 23 |
# File 'lib/bloomfilter.rb', line 15 def initialize( = {}) if [:size] && [:false_positive_percentage] @filter = Jar::BloomFilter.new([:false_positive_percentage], [:size]) elsif [:filter] @filter = [:filter] end @lock = Jar::ReentrantLock.new end |
Instance Method Details
#<<(k) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/bloomfilter.rb', line 25 def << (k) lock @filter.add(k) ensure unlock end |
#count ⇒ Object
39 40 41 |
# File 'lib/bloomfilter.rb', line 39 def count @filter.count end |
#include?(k) ⇒ Boolean
32 33 34 35 36 37 |
# File 'lib/bloomfilter.rb', line 32 def include?(k) lock @filter.contains(k) ensure unlock end |
#lock ⇒ Object
43 44 45 |
# File 'lib/bloomfilter.rb', line 43 def lock @lock.lock end |
#unlock ⇒ Object
47 48 49 |
# File 'lib/bloomfilter.rb', line 47 def unlock @lock.unlock end |