Class: BloomFilter::Native
Instance Attribute Summary collapse
-
#bf ⇒ Object
readonly
Returns the value of attribute bf.
Class Method Summary collapse
Instance Method Summary collapse
- #bitmap ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #include?(*keys) ⇒ Boolean (also: #key?, #[])
-
#initialize(opts = {}) ⇒ Native
constructor
A new instance of Native.
- #insert(key) ⇒ Object (also: #[]=)
- #marshal_dump ⇒ Object
- #marshal_load(ary) ⇒ Object
- #merge!(o) ⇒ Object
- #save(filename) ⇒ Object
- #size ⇒ Object
Methods inherited from Filter
Constructor Details
#initialize(opts = {}) ⇒ Native
Returns a new instance of Native.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/bloomfilter/native.rb', line 5 def initialize(opts = {}) @opts = { :size => 100, :hashes => 4, :seed => Time.now.to_i, :bucket => 3, :raise => false }.merge(opts) # arg 1: m => size : number of buckets in a bloom filter # arg 2: k => hashes : number of hash functions # arg 3: s => seed : seed of hash functions # arg 4: b => bucket : number of bits in a bloom filter bucket # arg 5: r => raise : raise on bucket overflow? @bf = CBloomFilter.new(@opts[:size], @opts[:hashes], @opts[:seed], @opts[:bucket], @opts[:raise]) end |
Instance Attribute Details
#bf ⇒ Object (readonly)
Returns the value of attribute bf.
3 4 5 |
# File 'lib/bloomfilter/native.rb', line 3 def bf @bf end |
Class Method Details
.load(filename) ⇒ Object
54 55 56 |
# File 'lib/bloomfilter/native.rb', line 54 def self.load(filename) Marshal.load(File.open(filename, 'r')) end |
Instance Method Details
#bitmap ⇒ Object
39 40 41 |
# File 'lib/bloomfilter/native.rb', line 39 def bitmap @bf.bitmap end |
#clear ⇒ Object
35 |
# File 'lib/bloomfilter/native.rb', line 35 def clear; @bf.clear; end |
#delete(key) ⇒ Object
34 |
# File 'lib/bloomfilter/native.rb', line 34 def delete(key); @bf.delete(key); end |
#include?(*keys) ⇒ Boolean Also known as: key?, []
28 29 30 |
# File 'lib/bloomfilter/native.rb', line 28 def include?(*keys) @bf.include?(*keys) end |
#insert(key) ⇒ Object Also known as: []=
23 24 25 |
# File 'lib/bloomfilter/native.rb', line 23 def insert(key) @bf.insert(key) end |
#marshal_dump ⇒ Object
50 51 52 |
# File 'lib/bloomfilter/native.rb', line 50 def marshal_dump [@opts, @bf.bitmap] end |
#marshal_load(ary) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/bloomfilter/native.rb', line 43 def marshal_load(ary) opts, bitmap = *ary @bf = Native.new(opts) @bf.bf.load(bitmap) if !bitmap.nil? end |
#merge!(o) ⇒ Object
37 |
# File 'lib/bloomfilter/native.rb', line 37 def merge!(o); @bf.merge!(o.bf); end |
#save(filename) ⇒ Object
58 59 60 61 62 |
# File 'lib/bloomfilter/native.rb', line 58 def save(filename) File.open(filename, 'w') do |f| f << Marshal.dump(self) end end |
#size ⇒ Object
36 |
# File 'lib/bloomfilter/native.rb', line 36 def size; @bf.num_set; end |