class PIM::LRUCache
Constants
- DEFAULT_MAX_SIZE
Attributes
max_size[R]
Public Class Methods
new(max_size = DEFAULT_MAX_SIZE)
click to toggle source
# File pim.rb, line 2002 def initialize(max_size = DEFAULT_MAX_SIZE) @max_size = max_size @data = {} end
Public Instance Methods
[](key)
click to toggle source
# File pim.rb, line 2024 def [](key) found = true value = @data.delete(key){ found = false } if found @data[key] = value else nil end end
[]=(key,val)
click to toggle source
# File pim.rb, line 2034 def []=(key,val) @data.delete(key) @data[key] = val if @data.length > @max_size @data.delete(@data.first[0]) end val end
clear()
click to toggle source
# File pim.rb, line 2069 def clear @data.clear end
count()
click to toggle source
# File pim.rb, line 2073 def count @data.count end
delete(k)
click to toggle source
# File pim.rb, line 2065 def delete(k) @data.delete(k) end
each() { |pair| ... }
click to toggle source
# File pim.rb, line 2047 def each @data.reverse.each do |pair| yield pair end end
include?(key)
click to toggle source
# File pim.rb, line 2043 def include?(key) @data.include?(key) end
max_size=(size)
click to toggle source
# File pim.rb, line 2013 def max_size=(size) raise ArgumentError.new(:max_size) if size < 1 @max_size = size if @max_size < @data.size @data.keys[0..@max_size-@data.size].each do |k| @data.delete(k) end end return @max_size end
min_size=(size)
click to toggle source
# File pim.rb, line 2007 def min_size=(size) raise ArgumentError.new(:min_size) if size < 1 return @max_size if size <= @max_size return max_size=(size) end
to_a()
click to toggle source
# File pim.rb, line 2053 def to_a @data.to_a.reverse end
to_h()
click to toggle source
# File pim.rb, line 2057 def to_h Hash[@data.to_a] end
to_s()
click to toggle source
# File pim.rb, line 2061 def to_s to_h.to_s end