def add(self, key, value):
if self.isUnderfull:
if len(self.primary) < self.inMemoryLimit:
heappush(self.primary, (key, value))
return
else:
self.isUnderfull = False
assert self.currentFile is None
self.currentFile = FileWriter(self.newFile())
if key < self.primary[0][0]:
heappush(self.secondary, (key, value))
key, value = heappop(self.primary)
else:
key, value = heapreplace(self.primary, (key, value))
while self.primary and self.primary[0][0] == key:
value += heappop(self.primary)[1]
self.currentFile.write((key, value))
self.nStoredItems += 1
if not self.primary:
self.primary = self.secondary
self.secondary = []
self.currentFile.close()
self.currentFile = None
self.isUnderfull = True
评论列表
文章目录