String Tree: Fix order of overwrites

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2025-01-28 07:18:50 +01:00
commit 64ce94b142

View file

@ -104,8 +104,13 @@ class StringTree: # export
if l > 1:
assert len(rest) > 0
return self.children[nibble].__set(rest, content=content)
# last component, a.k.a. leaf
if content is not None:
gc = content if isinstance(content, StringTree) else StringTree('', content=content)
# Make sure no existing grand child is updated. It would reside too
# far up in the grand child OrderedDict, we need it last
if gc.content in self.children[nibble].children:
del self.children[nibble].children[gc.content]
self.children[nibble].children[gc.content] = gc
return self.children[nibble]