Question
put(content, evictionPolicy): Adds Nodes at the beginning of the list. If necessary, uses mru/lru to remove items before adding Parameters: content: contentItem evictionPolicy: str Returns:
put(content, evictionPolicy): Adds Nodes at the beginning of the list. If necessary, uses mru/lru to remove items before adding Parameters: content: contentItem evictionPolicy: str Returns: contentItem inserted find(cid): Search for content in the list. If content is found, Node is moved at the beginning of the list Parameters: cid: int Returns: contentItem is cid is in the list, None otherwise update(cid, content): Updates the content in the list. If content is found and updated, Node is moved at the beginning of the list Parameters: cid: int content: contentItem Returns: contentItem is cid is in the list, None otherwise mruEvict(): Removes the first item of the list Parameters: None Returns: None lruEvict(): Removes the last item of the list Parameters: None Returns: None clear(): Removes all items from the list. Parameters: None Returns: None
class ContentItem: def __init__(self, cid, size, header, content): self.cid = cid self.size = size self.header = header self.content = content
def __str__(self): return ('CONTENT ID: {} SIZE: {} HEADER: {} CONTENT: {}'.format(self.cid, self.size, self.header, self.content))
__repr__=__str__
class Node: def __init__(self, content): self.value = content self.next = None
def __str__(self): return ('CONTENT:{} '.format(self.value))
__repr__=__str__
class CacheList: def __init__(self, size): self.head = None self.tail = None self.maxSize = size self.remainingSize = size self.numItems = 0
def __str__(self): listString = "" current = self.head while current is not None: listString += "[" + str(current.value) + "] " current = current.next return ('REMAINING SPACE:{} ITEMS:{} LIST: {} '.format(self.remainingSize, self.numItems, listString))
__repr__=__str__
def __len__(self): return self.numItems
def put(self, content, evictionPolicy): # YOUR CODE STARTS HERE def find(self, cid): # YOUR CODE STARTS HERE
def update(self, cid, content): # YOUR CODE STARTS HERE
def mruEvict(self): # YOUR CODE STARTS HERE
def lruEvict(self): # YOUR CODE STARTS HERE
def clear(self): # YOUR CODE STARTS HERE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started