From 6707f0027745c6155e5960b73a9623847c38339c Mon Sep 17 00:00:00 2001 From: Vitalik Buterin Date: Tue, 1 Aug 2017 08:49:08 -0400 Subject: [PATCH] Fixed deletes --- trie_research/new_bintrie.py | 5 ++++- trie_research/new_bintrie_tests.py | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/trie_research/new_bintrie.py b/trie_research/new_bintrie.py index df5a0d2..30b124f 100644 --- a/trie_research/new_bintrie.py +++ b/trie_research/new_bintrie.py @@ -56,7 +56,10 @@ def _get(db, node, keypath): def _update(db, node, keypath, val): if not keypath: - return hash_and_save(db, val) + if val: + return hash_and_save(db, val) + else: + return b'' if not node: return hash_and_save(db, encode_kv_node(keypath, hash_and_save(db, val))) L, R, nodetype = parse_node(db.get(node)) diff --git a/trie_research/new_bintrie_tests.py b/trie_research/new_bintrie_tests.py index dc250c3..ac0af0e 100644 --- a/trie_research/new_bintrie_tests.py +++ b/trie_research/new_bintrie_tests.py @@ -21,12 +21,17 @@ for i in range(3): #print(t.to_dict()) t.update(k, v) assert t.get(k) == v - #t.print_nodes() + if not random.randrange(100): + t.to_dict() assert r1 is None or t.root == r1 r1 = t.root t.update(kvpairs[0][0], kvpairs[0][1]) assert t.root == r1 print(t.get_branch(kvpairs[0][0])) print(encode_hex(t.root)) + for k, v in shuffle_in_place(kvpairs): + t.update(k, b'') + if not random.randrange(100): + t.to_dict() + assert t.root == b'' -t.to_dict()