本文主要是介绍Lintcode 566 · GFS Client [Python],希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
系统设计题,注意拆分content
'''
Definition of BaseGFSClient
class BaseGFSClient:def readChunk(self, filename, chunkIndex):# Read a chunk from GFSdef writeChunk(self, filename, chunkIndex, content):# Write a chunk to GFS
'''class GFSClient(BaseGFSClient):"""@param: chunkSize: An integer"""def __init__(self, chunkSize):# do intialization if necessaryself.size = chunkSizeself.dic = collections.defaultdict(list)"""@param: filename: a file name@return: conetent of the file given from GFS"""def read(self, filename):# write your code hereif filename not in self.dic:returntemp = ''print(self.dic[filename])for i in range(len(self.dic[filename])):temp += self.dic[filename][i]return temp"""@param: filename: a file name@param: content: a string@return: nothing"""def write(self, filename, content):# write your code hereif filename in self.dic:self.dic[filename] = []i = 0while i < len(content):self.dic[filename].append(content[i:i+self.size])i = min(i+self.size, len(content))#print(len(content))#print(i)
这篇关于Lintcode 566 · GFS Client [Python]的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!