docs: def _set(self, node_hash, keypath, value, if_delete_subtrie=False):
          """
          If if_delete_subtrie is set to True, what it will do is that it take in a keypath
          and traverse til the end of keypath, then delete the whole subtrie of that node.
  
          Note: keypath should be in binary array format, i.e., encoded by encode_to_bin()
          """
          # Empty trie
          if node_hash == BLANK_HASH:
              if value:
                  return self._hash_and_save(
                      encode_kv_node(keypath, self._hash_and_save(encode_leaf_node(value)))
                  )
              else:
                  return BLANK_HASH
          nodetype, left_child, right_child = parse_node(self.db[node_hash])
          # Node is a leaf node
          if nodetype == LEAF_TYPE:
              # Keypath must match, there should be no remaining keypath
              if keypath:
                  raise NodeOverrideError(
                      "Fail to set the value because the prefix of it's key"
                      " is the same as existing key")
              if if_delete_subtrie:
                  return BLANK_HASH
              return self._hash_and_save(encode_leaf_node(value)) if value else BLANK_HASH
          # node is a key-value node
          elif nodetype == KV_TYPE:
              # Keypath too short
              if not keypath:
                  if if_delete_subtrie:
                      return BLANK_HASH
                  else:
                      raise NodeOverrideError(
                          "Fail to set the value because it's key"
                          " is the prefix of other existing key")
              return self._set_kv_node(
                  keypath,
                  node_hash,
                  nodetype,
                  left_child,
                  right_child,
                  value,
                  if_delete_subtrie
              )
          # node is a branch node
          elif nodetype == BRANCH_TYPE:
              # Keypath too short
              if not keypath:
                  if if_delete_subtrie:
                      return BLANK_HASH
                  else:
                      raise NodeOverrideError(
                          "Fail to set the value because it's key"
                          " is the prefix of other existing key")
              return self._set_branch_node(
                  keypath,
                  nodetype,
                  left_child,
                  right_child,
                  value,
                  if_delete_subtrie
              )
          raise Exception("Invariant: This shouldn't ever happen")