Class: Arachni::BloomFilter

Inherits:
Object show all
Defined in:
lib/arachni/bloom_filter.rb

Overview

Lightweight Bloom-filter implementation.

It uses the return value of the #hash method of the given objects instead of the objects themselves.

This leads to decreased memory consumption and faster comparisons during look-ups.

Author:

Instance Method Summary collapse

Constructor Details

#initializeBloomFilter

Returns a new instance of BloomFilter.



29
30
31
# File 'lib/arachni/bloom_filter.rb', line 29

def initialize
    @hash = Hash.new( false )
end

Instance Method Details

#<<(obj) ⇒ Arachni::BloomFilter Also known as: add

Returns self.

Parameters:

  • obj (#hash)

    object to insert

Returns:



38
39
40
41
# File 'lib/arachni/bloom_filter.rb', line 38

def <<( obj )
    @hash[obj.hash] = true
    self
end

#clearObject



71
72
73
# File 'lib/arachni/bloom_filter.rb', line 71

def clear
    @hash.clear
end

#delete(obj) ⇒ Arachni::BloomFilter

Returns self.

Parameters:

  • obj (#hash)

    object to delete

Returns:



49
50
51
52
# File 'lib/arachni/bloom_filter.rb', line 49

def delete( obj )
    @hash.delete( obj.hash )
    self
end

#empty?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/arachni/bloom_filter.rb', line 63

def empty?
    @hash.empty?
end

#include?(obj) ⇒ Bool

Parameters:

  • obj (#hash)

    object to check

Returns:

  • (Bool)


59
60
61
# File 'lib/arachni/bloom_filter.rb', line 59

def include?( obj )
    @hash[obj.hash]
end

#sizeObject



67
68
69
# File 'lib/arachni/bloom_filter.rb', line 67

def size
    @hash.size
end