From f51e06f4531c2080b8c8cc11db9fe986fb5397fa Mon Sep 17 00:00:00 2001 From: NIC619 Date: Sat, 9 Dec 2017 01:27:05 +0800 Subject: [PATCH] add kv pair override check --- trie_research/new_bintrie.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/trie_research/new_bintrie.py b/trie_research/new_bintrie.py index a22e1a6..8abc7a1 100644 --- a/trie_research/new_bintrie.py +++ b/trie_research/new_bintrie.py @@ -92,6 +92,9 @@ def _update(db, node, keypath, val): L, R, nodetype = parse_node(db.get(node)) # Node is a leaf node if nodetype == LEAF_TYPE: + # Keypath must match, there should be no remaining keypath + if keypath: + raise Exception("Existing kv pair is being effaced because it's key is the prefix of the new key") return hash_and_save(db, encode_leaf_node(val)) if val else b'' # node is a key-value node elif nodetype == KV_TYPE: