Hello,
I was working on a fork of this library as project to learn about Ruby (lirs-cache fork). I ran into to a couple bugs with the legacy (pre 1.9) implementation that I thought I should report and pull request a fix for.
The .delete method currently does not change the head or tail variables if the node is located there. If the node at the tail is then deleted, the .pop_tail method will try removing that node again when max_size is reached. As a result the cache will grow 1 past (or more, if the node linked to tail is deleted) max_size each time this happens. The pull request also has an expanded test to check for this.
Dead locking .each (legacy)
When I try to run the tests they will hang at test_recursion. This pull request changes .each to the cache19 implementation, namely that a new array is created with .to_a and that new array is iterated over. Since .to_a uses the current .each to generate an ordered array, it has been renamed .each_unsafe.
Count changed to use .size (legacy & 1.9)
Count currently uses Hash.count to return the size of the cache. The performance difference is significant.
Other changes
Typo in readme
Unused var 'expected' in .valid? removed. (legacy)
Hello, I was working on a fork of this library as project to learn about Ruby (lirs-cache fork). I ran into to a couple bugs with the legacy (pre 1.9) implementation that I thought I should report and pull request a fix for.
Unbounded Cache (legacy)
Consider:
The .delete method currently does not change the head or tail variables if the node is located there. If the node at the tail is then deleted, the .pop_tail method will try removing that node again when max_size is reached. As a result the cache will grow 1 past (or more, if the node linked to tail is deleted) max_size each time this happens. The pull request also has an expanded test to check for this.
Dead locking .each (legacy)
When I try to run the tests they will hang at test_recursion. This pull request changes .each to the cache19 implementation, namely that a new array is created with .to_a and that new array is iterated over. Since .to_a uses the current .each to generate an ordered array, it has been renamed .each_unsafe.
Count changed to use .size (legacy & 1.9)
Count currently uses Hash.count to return the size of the cache. The performance difference is significant.
Other changes
The branch was passing all tests.
Thanks!