Jump to content

Recommended Posts

Posted (edited)

Hello there!

 

Let's go straight in the topic!

I want to implement an lru cache for educational purposes.

The main LRU cache class will implement an interface which contains the following methods :

Note : V and K are generic references

 

  • V lookUp(K key) : returns the value V with K as its key 
  • void store(V value, K key) : obviously stores the data in the cache 
  • double getHitRatio() 
  • long getNumberOfLookups() 
  • long getNumberOfhits() 
  • long getNumberOfMisses()

 

Sooooo right now i have an alpha implementation implemented as following :

I use a hashmap which i implement (NOTE : i wanna implement each data structure im gonna use by myself)

to store the values, and a queue where i insert the keys.

Each time an item is inserted, i check the size of the queue.

If queue.size() > cacheSize, i pop() all the expired keys and remove their values from the map

 

So after testing it with Strings and 50k entries input i get the freaking huge time of 17seconds!!!!!!! and a hit ratio of 9%(!)

If i remove the removal of the expired keys the time drops to 1 sec and the hit ratio goes to 98%,but the application isnt an lru cahce implementation.....

 

Another implementation suggested by a friend was to use splay trees, cause the least recently used nodes would be near the root.

I also thought to try and implement B Trees , but i aint so fond of it

 

So , what do you guys suggest?

Which data structures should i use for this "project"?

If i need to use a hashmap , is linear probing the type of hash that would fit, since there are no memory issues?

 

Thanks in advance for your help guys,

Regards FelonBIG

Edited by FelonBIG
  • 2 months later...
Posted

well since it's outdated you can lock it.

Also i finished an alpha version of this project which i can share for the community if someone's interested.

Guest
This topic is now closed to further replies.


  • Posts

    • Fix Visual Boundary for AutoFarm when entering a new zone. Fix Assassin Interface Automatic SoulShot usage. Fix Assassin Interface not displaying Castle/Base. Fix Achievements displaying item rewards for CommunityBoard & NPC. Fix Prevent players from purchasing their own Auctioned items. Added ''.raid'' and ''.achievement'' commands. Added support for multiple currencies on Auction Added Search feature to Auction. Added Offline Stores Added '.exit' & '.quit' command to Dungeon System so players can now exit/quit dungeons Added VIP Account System (Alternative XP, SP & Drop Rates, Unlocks Costumes) Added Loot Box System Changed DungeonsManager now displays reward list on dungeon pages. Changed GlobalShop to include pages for all currencies. HTML/XML edits
    • When I teleport to town, my current location is differ from the map. How do I fix this?    
    • A New Chapter Begins We're Rebuilding – Join Our Staff Team After many years of activity, growth, and challenges, it’s finally time for our community to restructure and move forward. We’re ready to turn a new page and evolve into something greater — but we can’t do it without the help of passionate and committed people. That’s why we’re now opening up staff applications for those who want to actively shape the future of our community. If you have the motivation, time, and patience to contribute to something meaningful, this is your chance to step in and make a real impact. What We're Looking For We’re building a fresh and dedicated team of individuals who are ready to support and grow this project. Open roles include: Moderators – to keep the forum clean, safe, and organized Gaming Moderators – to help manage gaming boards (e.g., Lineage, GTA FiveM) Content Creators – to post updates, guides, and articles Community Managers – to engage users and drive activity Technical Staff – for development, backend, and server work We’re not focusing only on Lineage anymore. Our vision is expanding to new areas — including GTA FiveM and other multiplayer games you might have expertise in. If you have a good idea, a server plan, or something new to suggest — we’re open to it. Now’s the time to bring it forward. Requirements We’re looking for individuals who have: A history of activity on the forum (preferred) Available time to contribute consistently A sense of teamwork and responsibility A genuine interest in gaming and community building If you're interested, just send a private message to me or Celestine. (or just reply here) Tell us a few things about yourself and how you’d like to contribute. Let’s bring this community back to life. Let’s rebuild something great — together.   M M G A 
  • Topics

×
×
  • Create New...