# HW4 #Due Date: 04/17/2021, 11:59PM """ ### Collaboration Statement: """ class Node: def __init__(self, content): XXXXXXXXXXself.value = content XXXXXXXXXXself.next = None def __str__(self):...

I


# HW4 #Due Date: 04/17/2021, 11:59PM """ ### Collaboration Statement: """ class Node: def __init__(self, content): self.value = content self.next = None def __str__(self): return ('CONTENT:{}\n'.format(self.value)) __repr__=__str__ class ContentItem: ''' >>> content1 = ContentItem(1000, 10, "Content-Type: 0", "0xA") >>> content2 = ContentItem(1004, 50, "Content-Type: 1", "110010") >>> content3 = ContentItem(1005, 18, "Content-Type: 2", "'CMPSC132' ") >>> content4 = ContentItem(1005, 18, "another header", "111110") >>> hash(content1) 0 >>> hash(content2) 1 >>> hash(content3) 2 >>> hash(content4) 1 ''' def __init__(self, cid, size, header, content): self.cid = cid self.size = size self.header = header self.content = content def __str__(self): return f'CONTENT ID: {self.cid} SIZE: {self.size} HEADER: {self.header} CONTENT: {self.content}' __repr__=__str__ def __eq__(self, other): if isinstance(other, ContentItem): return self.cid == other.cid and self.size == other.size and self.header == other.header and self.content == other.content return False def __hash__(self): # YOUR CODE STARTS HERE pass class CacheList: ''' # An extended version available on Canvas. Make sure you pass this doctest first before running the extended version >>> content1 = ContentItem(1000, 10, "Content-Type: 0", "0xA") >>> content2 = ContentItem(1004, 50, "Content-Type: 1", "110010") >>> content3 = ContentItem(1005, 180, "Content-Type: 2", "'CMPSC132' ") >>> content4 = ContentItem(1006, 18, "another header", "111110") >>> content5 = ContentItem(1008, 2, "items", "11x1110") >>> lst=CacheList(200) >>> lst REMAINING SPACE:200 ITEMS:0 LIST: >>> lst.put(content1, 'mru') 'INSERTED: CONTENT ID: 1000 SIZE: 10 HEADER: Content-Type: 0 CONTENT: 0xA' >>> lst.put(content2, 'lru') 'INSERTED: CONTENT ID: 1004 SIZE: 50 HEADER: Content-Type: 1 CONTENT: 110010' >>> lst.put(content4, 'mru') 'INSERTED: CONTENT ID: 1006 SIZE: 18 HEADER: another header CONTENT: 111110' >>> lst.put(content5, 'mru') 'INSERTED: CONTENT ID: 1008 SIZE: 2 HEADER: items CONTENT: 11x1110' >>> lst.put(content3, 'lru') "INSERTED: CONTENT ID: 1005 SIZE: 180 HEADER: Content-Type: 2 CONTENT: 'CMPSC132' " >>> lst.put(content1, 'mru') 'INSERTED: CONTENT ID: 1000 SIZE: 10 HEADER: Content-Type: 0 CONTENT: 0xA' >>> 1006 in lst True >>> contentExtra = ContentItem(1034, 2, "items", "other content") >>> lst.update(1008, contentExtra) 'UPDATED: CONTENT ID: 1034 SIZE: 2 HEADER: items CONTENT: other content' >>> lst REMAINING SPACE:170 ITEMS:3 LIST: [CONTENT ID: 1034 SIZE: 2 HEADER: items CONTENT: other content] [CONTENT ID: 1006 SIZE: 18 HEADER: another header CONTENT: 111110] [CONTENT ID: 1000 SIZE: 10 HEADER: Content-Type: 0 CONTENT: 0xA] >>> lst.clear() 'Cleared cache!' >>> lst REMAINING SPACE:200 ITEMS:0 LIST: ''' def __init__(self, size): self.head = None self.maxSize = size self.remainingSpace = size self.numItems = 0 def __str__(self): listString = "" current = self.head while current is not None: listString += "[" + str(current.value) + "]\n" current = current.next return 'REMAINING SPACE:{}\nITEMS:{}\nLIST:\n{}'.format(self.remainingSpace, self.numItems, listString) __repr__=__str__ def __len__(self): return self.numItems def put(self, content, evictionPolicy): # YOUR CODE STARTS HERE pass def __contains__(self, cid): # YOUR CODE STARTS HERE pass def update(self, cid, content): # YOUR CODE STARTS HERE pass def mruEvict(self): # YOUR CODE STARTS HERE pass def lruEvict(self): # YOUR CODE STARTS HERE pass def clear(self): # YOUR CODE STARTS HERE pass class Cache: """ # An extended version available on Canvas. Make sure you pass this doctest first before running the extended version >>> cache = Cache() >>> content1 = ContentItem(1000, 10, "Content-Type: 0", "0xA") >>> content2 = ContentItem(1003, 13, "Content-Type: 0", "0xD") >>> content3 = ContentItem(1008, 242, "Content-Type: 0", "0xF2") >>> content4 = ContentItem(1004, 50, "Content-Type: 1", "110010") >>> content5 = ContentItem(1001, 51, "Content-Type: 1", "110011") >>> content6 = ContentItem(1007, 155, "Content-Type: 1", "10011011") >>> content7 = ContentItem(1005, 18, "Content-Type: 2", "'CMPSC132' ") >>> content8 = ContentItem(1002, 14, "Content-Type: 2", "'PSU' ") >>> content9 = ContentItem(1006, 170, "Content-Type: 2", "'Click Me'") >>> cache.insert(content1, 'lru') 'INSERTED: CONTENT ID: 1000 SIZE: 10 HEADER: Content-Type: 0 CONTENT: 0xA' >>> cache.insert(content2, 'lru') 'INSERTED: CONTENT ID: 1003 SIZE: 13 HEADER: Content-Type: 0 CONTENT: 0xD' >>> cache.insert(content3, 'lru') 'Insertion not allowed' >>> cache.insert(content4, 'lru') 'INSERTED: CONTENT ID: 1004 SIZE: 50 HEADER: Content-Type: 1 CONTENT: 110010' >>> cache.insert(content5, 'lru') 'INSERTED: CONTENT ID: 1001 SIZE: 51 HEADER: Content-Type: 1 CONTENT: 110011' >>> cache.insert(content6, 'lru') 'INSERTED: CONTENT ID: 1007 SIZE: 155 HEADER: Content-Type: 1 CONTENT: 10011011' >>> cache.insert(content7, 'lru') "INSERTED: CONTENT ID: 1005 SIZE: 18 HEADER: Content-Type: 2 CONTENT: 'CMPSC132' " >>> cache.insert(content8, 'lru') "INSERTED: CONTENT ID: 1002 SIZE: 14 HEADER: Content-Type: 2 CONTENT: 'PSU' " >>> cache.insert(content9, 'lru') "INSERTED: CONTENT ID: 1006 SIZE: 170 HEADER: Content-Type: 2 CONTENT: 'Click Me'" >>> cache L1 CACHE:
Apr 15, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here