GithubHelp home page GithubHelp logo

lfucache's Introduction

LFU cache

A data structure for Least Frequently Used (LFU) cache. Supports following operations: get and set.

get(key) - Get the value of the key if the key exists in the cache, otherwise return null

set(key, value) - Set or insert the value if the key is not already present. When the cache reaches its capacity, it should invalidate the least frequently used item before inserting a new item. when there is a tie (i.e., two or more keys that have the same frequency), the least recently used key would be evicted.

// Get procedure // 1. Get LFUCacheEntry reference from HashMap // 2. Find Frequency Node from the Entry Node // 3. Remove Entry Node from Frequency Node list and add it to next freuquency Node // list // a. If New frequency Node doesn't exist, create a new one and add its entry // into frequency Node set // b. If Previous Frequency Node list is now empty remove that frequency Node

// Set procedure // 1. If same key already exists // Remove that LFUCacheEntry from Frequency Node & remove frequnecy Node if its // Empty // Remove that key & corresponding LFUCacheEntry from HashMap // If Cache is full remove very first entry from very first frequency Node in list

// 2. Add New LFUCacheEntry into HashMap // 3. Add this new Entry into Frequency Node of frequency 1 // a. Create if such a node doesn't already exist

lfucache's People

Contributors

mtbar131 avatar

Watchers

James Cloos 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.