def delete(self, key): self.root = self.delete_and_delete(self.root, encoding.raw_to_hex(str(key))) self.id -= 1 self.db.put(b'currentNum', str(self.id).encode()) #print("Root after delete:", self.root) self.root_hash()
def update(self, key, value): if value == "": return self.delete_db(key) #print("Update", key, value) #print("Current root:", self.root) self.root = self.update_and_delete(self.root, encoding.raw_to_hex(str(key)), value) #print(type(str(self.id).encode())) self.db.put(str(self.id).encode(), pickle.dumps(value)) self.id += 1 self.db.put(b'currentNum', str(self.id).encode())
def iter_subtree(self, prefix): #get all key, value start with the same prefix node, curr_prefix = self.search_prefix(self.root, encoding.raw_to_hex(prefix), []) print("node:", node) if node == "": return {} res = self._iter_subtree(node) #encoding_prefix = encoding.raw_to_hex(prefix) #print("encoding_prefix:", encoding_prefix) print(node) result = {} for key, value in res.items(): key = [int(k) for k in key.split(',')] total_key = curr_prefix + key print("total:", total_key) print(encoding.raw_to_hex('h7777')) total_key = encoding.hex_to_raw( encoding.terminator(total_key, False)) result[total_key] = value return result
def search(self, key): value = self.get_node_value(self.root, encoding.raw_to_hex(str(key))) return value