Giter VIP home page Giter VIP logo

lru_cache's Introduction

Cache is implemented two ways:

1. lru_cache.rb Using an array of fixed size

Set the cache size during initialization using

lru_cache = LRUCache.new()

Add to the cache

lru_cache.set({"test01" => [1,2,3,4]}) Retrieve from cache lru_cache.get("test01");

Pros: Simple implementation Cons: Inefficient lookup, deletion - O(n) where n is the size of the cache

2. lru_cache_2.rb Using a hash map of fixed size and a linked list

Set the cache size during initialization using

c = Lru_cache.new()

Add to the cache

c.insert({"test01"=> [1,2,3,4]}) Retrieve from cache c.get("test01");

Pros: Constant time lookup, insertion and deletion on average - O(1) Cons: Implementation slightly complicated with a hash map pointing to a linked list If the hashing function is inefficient, it will degrade the lookup to O(n)

To Do:

  • Test accessing same element twice, thereby making it newer in the cache
  • Test corner cases - some are done but more needed
  • Write rspec tests for sanity checks

lru_cache's People

Contributors

anshuj11 avatar jain-anshu avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.