Class: Reth::DuplicatesFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/reth/duplicates_filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(max_items = 128) ⇒ DuplicatesFilter

Returns a new instance of DuplicatesFilter.



7
8
9
10
# File 'lib/reth/duplicates_filter.rb', line 7

def initialize(max_items=128)
  @max_items = max_items
  @filter = []
end

Instance Method Details

#include?(v) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/reth/duplicates_filter.rb', line 23

def include?(v)
  @filter.include?(v)
end

#update(data) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/reth/duplicates_filter.rb', line 12

def update(data)
  if @filter.include?(data)
    @filter.push @filter.shift
    false
  else
    @filter.push data
    @filter.shift if @filter.size > @max_items
    true
  end
end