Class: HasUnpublishedPassword::ShaBloom
- Inherits:
-
Object
- Object
- HasUnpublishedPassword::ShaBloom
- Defined in:
- lib/has_unpublished_password/sha_bloom.rb
Direct Known Subclasses
Defined Under Namespace
Classes: DefaultConfig
Constant Summary collapse
- BITS_PER_HEX_CHAR =
4
Class Attribute Summary collapse
-
.filter_count ⇒ Object
Returns the value of attribute filter_count.
-
.filter_step ⇒ Object
Returns the value of attribute filter_step.
-
.filter_window ⇒ Object
Returns the value of attribute filter_window.
-
.hash_bits_per_filter ⇒ Object
Returns the value of attribute hash_bits_per_filter.
Class Method Summary collapse
Instance Method Summary collapse
- #add_shahash(hash) ⇒ Object
- #add_value(value) ⇒ Object
- #check_shahash(hash) ⇒ Object
- #check_value(value) ⇒ Object
-
#initialize(filters = nil) ⇒ ShaBloom
constructor
A new instance of ShaBloom.
- #inspect ⇒ Object
- #serialize(pattern, verbose = false) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(filters = nil) ⇒ ShaBloom
Returns a new instance of ShaBloom.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/has_unpublished_password/sha_bloom.rb', line 23 def initialize(filters=nil) unless filters filters = [] self.class.filter_count.times do |i| filters[i] ||= Bitfield.new(2**self.class.hash_bits_per_filter) end end @bitfields = filters end |
Class Attribute Details
.filter_count ⇒ Object
Returns the value of attribute filter_count.
8 9 10 |
# File 'lib/has_unpublished_password/sha_bloom.rb', line 8 def filter_count @filter_count end |
.filter_step ⇒ Object
Returns the value of attribute filter_step.
8 9 10 |
# File 'lib/has_unpublished_password/sha_bloom.rb', line 8 def filter_step @filter_step end |
.filter_window ⇒ Object
Returns the value of attribute filter_window.
8 9 10 |
# File 'lib/has_unpublished_password/sha_bloom.rb', line 8 def filter_window @filter_window end |
.hash_bits_per_filter ⇒ Object
Returns the value of attribute hash_bits_per_filter.
8 9 10 |
# File 'lib/has_unpublished_password/sha_bloom.rb', line 8 def hash_bits_per_filter @hash_bits_per_filter end |
Class Method Details
.deserialize(pattern) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/has_unpublished_password/sha_bloom.rb', line 72 def self.deserialize(pattern) filters = [] filter_count.times do |i| fn = "#{pattern}-p#{i}.bloom" filters << Bitfield.deserialize(fn, 2**hash_bits_per_filter) end new(filters) end |
Instance Method Details
#add_shahash(hash) ⇒ Object
50 51 52 53 54 |
# File 'lib/has_unpublished_password/sha_bloom.rb', line 50 def add_shahash(hash) walk_hash(hash) do |row, idx| row.set(idx) end end |
#add_value(value) ⇒ Object
42 43 44 |
# File 'lib/has_unpublished_password/sha_bloom.rb', line 42 def add_value(value) add_shahash Digest::SHA1.hexdigest value end |
#check_shahash(hash) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/has_unpublished_password/sha_bloom.rb', line 56 def check_shahash(hash) walk_hash(hash) do |row, idx| return false unless row.get(idx) end return true end |
#check_value(value) ⇒ Object
46 47 48 |
# File 'lib/has_unpublished_password/sha_bloom.rb', line 46 def check_value(value) check_shahash Digest::SHA1.hexdigest value end |
#inspect ⇒ Object
34 35 36 |
# File 'lib/has_unpublished_password/sha_bloom.rb', line 34 def inspect to_s end |
#serialize(pattern, verbose = false) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/has_unpublished_password/sha_bloom.rb', line 63 def serialize(pattern, verbose=false) self.class.filter_count.times do |i| fn = "#{pattern}-p#{i}.bloom" bitfields[i].serialize(fn) puts "wrote #{fn}" if verbose puts `du -h #{fn}` if verbose end end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/has_unpublished_password/sha_bloom.rb', line 38 def to_s "#{self.class} filter with #{self.class.filter_count} blocks of size #{2**self.class.hash_bits_per_filter / 8 / 1024}kb" end |