From 64ce94b142dfa551937a856b7915b90b600e997f Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Tue, 28 Jan 2025 07:18:50 +0100 Subject: [PATCH] String Tree: Fix order of overwrites Signed-off-by: Jan Lindemann --- tools/python/jwutils/stree/StringTree.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/python/jwutils/stree/StringTree.py b/tools/python/jwutils/stree/StringTree.py index 9e66cbf..64e46e9 100644 --- a/tools/python/jwutils/stree/StringTree.py +++ b/tools/python/jwutils/stree/StringTree.py @@ -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]