Class: Xor::Filter
- Inherits:
-
Object
- Object
- Xor::Filter
- Defined in:
- lib/xor.rb
Instance Method Summary collapse
- #add(value) ⇒ Object
- #include?(value) ⇒ Boolean
-
#initialize(size) ⇒ Filter
constructor
A new instance of Filter.
Constructor Details
#initialize(size) ⇒ Filter
Returns a new instance of Filter.
5 6 7 8 |
# File 'lib/xor.rb', line 5 def initialize(size) @size = size @hashes = Array.new(size, 0) end |
Instance Method Details
#add(value) ⇒ Object
10 11 12 13 |
# File 'lib/xor.rb', line 10 def add(value) hash1, hash2 = hash(value) @hashes[hash1 % @size] ^= hash2 end |
#include?(value) ⇒ Boolean
15 16 17 18 |
# File 'lib/xor.rb', line 15 def include?(value) hash1, hash2 = hash(value) (@hashes[hash1 % @size] ^ hash2).zero? end |