lib/lru_redux/cache.rb in lru_redux-0.0.3 vs lib/lru_redux/cache.rb in lru_redux-0.0.4

- old
+ new

@@ -11,12 +11,14 @@ @head = nil @tail = nil end def max_size=(size) + raise ArgumentError.new(:max_size) if @max_size < 1 @max_size = size while pop_tail + # no op end end def [](key) node = @data[key] @@ -30,12 +32,12 @@ node = @data[key] if node move_to_head(node) node[2] = val else - pop_tail @data[key] = add_to_head(key,val) + pop_tail end val end def each @@ -57,13 +59,11 @@ end a end def delete(k) - node = @data[k] - if node - @data.delete(k) + if node = @data.delete(k) prev = node[0] nex = node[3] prev[3] = nex if prev nex[0] = prev if nex @@ -122,13 +122,14 @@ node[0] = @head @head = node end def pop_tail - if @data.length >= @max_size + if @data.length > @max_size @data.delete(@tail[1]) @tail = @tail[3] @tail[0] = nil + true end end end