Skip to content
/ lruhash Public
forked from oldmoe/lruhash

A simple hash with a limited element count, LRU elements will be removed to make room for new ones.

Notifications You must be signed in to change notification settings

Invoca/lruhash

 
 

Repository files navigation

LRUHash

This is a hash class that holds a maximum number of elements. If adding an element causes the hash to grow over this size, the least recently used element is removed. Elements in the hash are maintained in LRU order.

Useful for implementing in-process caches where memory growth control is desired.

Example:

myhash = LRUHash.new
myhash.max = 2

myhash['a'] = 'apples'
myhash['b'] = 'banana'

myhash.length # => 2

myhash['c'] = 'cookie'

myhash.length # => 2

myhash['a'] # => nil

Installation

Add this line to your application’s Gemfile:

gem 'lruhash'

And then execute:

$ bundle

Or install it yourself as:

$ gem install lruhash

Usage

require 'lruhash'

Contributing

  1. Fork it

  2. Create your feature branch (‘git checkout -b my-new-feature`)

  3. Commit your changes (‘git commit -am ’Added some feature’‘)

  4. Push to the branch (‘git push origin my-new-feature`)

  5. Create new Pull Request

Credit

This was forked from github.com/oldmoe/lruhash and modernized. Thanks to oldmoe for the first version.

About

A simple hash with a limited element count, LRU elements will be removed to make room for new ones.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%