def test_buff_ac(self): trie = Trie(ignore_case=True) ids = {w : trie.insert(w) for w in [u"aİİ", u"aai̇", u"aai̇bİ"]} trie.save("trie.bin") with open("trie.bin", "rb") as fi: bs = bytearray(fi.read()) self.assertEqual(len(bs), trie.buff_size()) bs2 = bytearray(trie.buff_size()) trie.to_buff(bs2) self.assertEqual(bs2, bs) self._check_trie_correct(Trie.from_buff(bs2, copy=True), ids) self._check_trie_correct(Trie.from_buff(bs2, copy=False), ids)
def load(path: Path): wpd = WikiPageDetector() wpd._map = pickle_load(path / "wpd_map.gz") with (path / "wpd_trie").open("r+b") as bf: wpd._trie = Trie.from_buff(mmap(bf.fileno(), 0), copy=False) return wpd