cyac
cyac copied to clipboard
Trie.get fails in case sensitive Trie after buffer load of saved data
Summary: Previously saved case sensitive data loads without error into trie. However trie.get(val) fails get item, even though iterating through trie.items() show correct item.
Env: Archlinux using python 3.9, Ubuntu 20.0.4 using python 3.8.5 Cyac Version: 1.2 Cython Version:
Steps to reproduce:
- Build a case insensitive trie
- Lookup data key (success)
- Save trie data out to file
- Load trie data from file
- Lookup data key (fails)
The code below will should be run twice:
- Run 1 - generates a two simple tries (one case sensitive, one insensitive) and saves them to two file
- Run 2- creates two tries and then executes the same lookups.
Script below:
from cyac import Trie
import os
import mmap
p=["M3 1AR", "M3 2AR", "M3 3AR"]
if os.path.isfile('./pinsens.bin'):
# Load into new tries
print("* * * Loaded from buffer * * * ")
with open('pinsens.bin', 'r+b') as fins:
bins = mmap.mmap(fins.fileno(), 0)
cins = Trie.from_buff(bins)
bins.flush()
with open('psens.bin', 'r+b') as fsens:
bsens = mmap.mmap(fsens.fileno(), 0)
csen = Trie.from_buff(bsens)
bsens.flush()
else:
print("* * * Clean data")
cins = Trie(ignore_case=True)
csen = Trie()
for x in p:
cins.insert(x)
csen.insert(x)
cins.save('pinsens.bin')
csen.save('psens.bin')
print("Case Insensitive")
print("{} is at {}".format(p[2], cins.get(p[2]))) # correctly returns 2
print("Case Sensitive")
print("{} is at {}".format(p[2], csen.get(p[2]))) # correctly returns 2 in first run, fails in second
for id in csen.items():
print(id)
@Hockeychap Hi, I have fixed it.
Fast fix - thanks. Works and tested with 2 million row trie data set.