mGramCounts.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:sequitur-g2p 作者: Holzhaus 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号