Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in C++ in in cpin Abstract base classes in C++ can only be used as base classes. Thus, they are allowed to have virtual member

in C++ image text in transcribedimage text in transcribedimage text in transcribedin in cpinimage text in transcribed

Abstract base classes in C++ can only be used as base classes. Thus, they are allowed to have virtual member functions without definitions. A cache is a component that stores data so future requests for that data can be served faster. The data stored in a cache might be the results of an earlier computation, or the duplicates of data stored elsewhere. A cache hit occurs when the requested data can be found in a cache, while a cache miss occurs when it cannot. Cache hits are served by reading data from the cache which is faster than recomputing a result or reading from a slower data store. Thus, the more requests that can be served from the cache, the faster the system performs. One of the popular cache replacement policies is: "least recently used" (LRU). It discards the least recently used items first. For example, if a cache with a capacity to store 5 keys has the following state(arranged from most recently used key to least recently used key) - 5 3 2 14 Now, If the next key comes as 1(which is a cache hit), then the cache state in the same order will be 1 5 3 24 Now, If the next key comes as (which is a cache miss), then the cache state in the same order will be 6 1 5 3 2 You can observe that 4 has been discarded because it was the least recently used key and since the capacity of cache is 5, it could not be retained in the cache any longer. Given an abstract base class Cache with member variables and functions: mp - Map the key to the node in the linked list cp - Capacity tail - Double linked list tail pointer head - Double linked list head pointer set() - Set/insert the value of the key, if present, otherwise add the key as the most recently used key. If the cache has reached its capacity, it should replace the least recently used key with a new key. get() - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1. You have to write a class LRUCache which extends the class Cache and uses the member functions and variables to implement an LRU cache. Input Format First line of input will contain the N number of lines containing get or set commands followed by the capacity M of the cache. The following N lines can either contain get or set commands. An input line starting with get will be followed by a key to be found in the cache. An input line starting with set will be followed by the key and value respectively to be inserted/replaced in the cache. Constraints 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

Machine code is composed of assembly code. True False

Answered: 1 week ago

Question

describe the main employment rights as stated in the law

Answered: 1 week ago