Class: Tabu

Inherits:
Object
  • Object
show all
Defined in:
lib/rsearch/tabu.rb

Overview

this class maintains a tabu list and kicks elements out if they are too old

Instance Method Summary collapse

Constructor Details

#initialize(size) ⇒ Tabu

Returns a new instance of Tabu.



4
5
6
7
# File 'lib/rsearch/tabu.rb', line 4

def initialize(size)
  @hash = {}
  @max = size
end

Instance Method Details

#include?(elem) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/rsearch/tabu.rb', line 20

def include?(elem)
  !@hash[elem].nil?
end

#insert(elem) ⇒ Object

decrease longevity of all keys and insert new one



10
11
12
13
14
15
16
17
18
# File 'lib/rsearch/tabu.rb', line 10

def insert(elem)
  @hash.each_key do |key|
    @hash[key] -= 1
    if @hash[key] <= 0
      @hash.delete(key)
    end
  end
  @hash[elem] = @max
end