Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement LRU (Least Recently Used) Cache Policy #14

Open
0xnullifier opened this issue Dec 16, 2024 · 0 comments
Open

Implement LRU (Least Recently Used) Cache Policy #14

0xnullifier opened this issue Dec 16, 2024 · 0 comments
Labels
enhancement New feature or request hard Damn you believe yourself too much (not a thing) I dare you to solve these!

Comments

@0xnullifier
Copy link
Collaborator

What is LRU?
LRU is a cache policy that removes the least recently used items when space is needed
Technical Requirements:

  1. Create a new struct LRUCachePolicy that implements the CachePolicy interface
  2. Use a data structure to keep track of things efficiently maybe something like doubly-linked list + hashmap to track access order efficiently
  3. Implement both required methods:
  • Eject(m *Memoria, requiredSpace uint64) error
  • Insert(m *Memoria, key string, val []byte) error

NOTE You are welcome to use libraries for data structures but in that case this will be scored as a MEDIUM

Example Structure:

type lruNode struct {
   key  string
   next *lruNode
   prev *lruNode
}

type LRUCachePolicy struct {
   nodeMap map[string]*lruNode
   head    *lruNode  
   tail    *lruNode 
}
@0xnullifier 0xnullifier added enhancement New feature or request hard Damn you believe yourself too much (not a thing) I dare you to solve these! labels Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hard Damn you believe yourself too much (not a thing) I dare you to solve these!
Projects
None yet
Development

No branches or pull requests

1 participant