Class: Tabu
- Inherits:
-
Object
- Object
- Tabu
- 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
- #include?(elem) ⇒ Boolean
-
#initialize(size) ⇒ Tabu
constructor
A new instance of Tabu.
-
#insert(elem) ⇒ Object
decrease longevity of all keys and insert new one.
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
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 |