// Only the real data, that is, the hash value of children or leafs, is saved, and the data in
// Branchs does not need to be saved
// If the value of children / leaves of the node is missing (nil value exists to the left of the
// rightmost non nil value), it will not be saved because it is temporary data, For example, the
// proof of the last data synchronized from the data node is meaningless and can only be used to
// verify and generate a new hash
Only the real data, that is, the hash value of children or leafs, is saved, and the data in
Branchs does not need to be saved
If the value of children / leaves of the node is missing (nil value exists to the left of the
rightmost non nil value), it will not be saved because it is temporary data, For example, the
proof of the last data synchronized from the data node is meaningless and can only be used to
verify and generate a new hash
// Only the real data that is the hash value of children or leafs is saved and the data in // Branchs does not need to be saved // If the value of children / leaves of the node is missing ( nil value exists to the left of the // rightmost non nil value ) it will not be saved because it is temporary data For example the // proof of the last data synchronized from the data node is meaningless and can only be used to // verify and generate a new hash
func (n *TreeNode) saveFull(adapter db.DataAdapter) error {
	if n == nil {
		return nil
	}
	if n.isDirty == false {
		return nil
	}
	root, _, _, err := n.HashAtPrefix(nil)
	if err != nil {
		return err
	}
	if root == nil {
		return nil
	}
	saveEntire := false
	lastIndex := -1
	if n.isLeaf {
		hasLeaf, missingLeaf, lastLeaf := n.checkLeafs()
		if hasLeaf == false || missingLeaf == true || lastLeaf < (childrenLength-1) {
			saveEntire = true
			lastIndex = lastLeaf
		}
	} else {
		hasChild, missingChild, lastChild := n.checkChildren()
		if hasChild == false || missingChild == true || lastChild < (childrenLength-1) {
			saveEntire = true
			lastIndex = lastChild
		}
	}
	if saveEntire {
		return n.saveEntireNode(root, lastIndex, adapter)
	}
	buf := common.BytesBufferPool.Get().(*bytes.Buffer)
	defer common.BytesBufferPool.Put(buf)
	buf.Reset()
	if n.isLeaf {
		buf.WriteByte(0x1)
	} else {
		buf.WriteByte(0x0)
	}
	err = n.encodeDescendants(buf)
	if err != nil {
		return err
	}
	if err = adapter.Save(root, buf.Bytes()); err != nil {
		return err
	} else {
	}
	n.isDirty = false
	return err
}
func ( n * TreeNode ) saveFull ( adapter db . DataAdapter ) error { if n == nil { return nil } if n . isDirty == false { return nil } root , _ , _ , err := n . HashAtPrefix ( nil ) if err != nil { return err } if root == nil { return nil } saveEntire := false lastIndex := - 1 if n . isLeaf { hasLeaf , missingLeaf , lastLeaf := n . checkLeafs ( ) if hasLeaf == false || missingLeaf == true || lastLeaf < ( childrenLength - 1 ) { saveEntire = true lastIndex = lastLeaf } } else { hasChild , missingChild , lastChild := n . checkChildren ( ) if hasChild == false || missingChild == true || lastChild < ( childrenLength - 1 ) { saveEntire = true lastIndex = lastChild } } if saveEntire { return n . saveEntireNode ( root , lastIndex , adapter ) } buf := common . BytesBufferPool . Get ( ) . ( * bytes . Buffer ) defer common . BytesBufferPool . Put ( buf ) buf . Reset ( ) if n . isLeaf { buf . WriteByte ( 0x1 ) } else { buf . WriteByte ( 0x0 ) } err = n . encodeDescendants ( buf ) if err != nil { return err } if err = adapter . Save ( root , buf . Bytes ( ) ) ; err != nil { return err } else { } n . isDirty = false return err }
Only the real data, that is, the hash value of children or leafs, is saved, and the data in
Branchs does not need to be saved
If the value of children / leaves of the node is missing (nil value exists to the left of the
rightmost non nil value), it will not be saved because it is temporary data, For example, the
proof of the last data synchronized from the data node is meaningless and can only be used to
verify and generate a new hash
Only the real data that is the hash value of children or leafs is saved and the data in Branchs does not need to be saved If the value of children / leaves of the node is missing ( nil value exists to the left of the rightmost non nil value ) it will not be saved because it is temporary data For example the proof of the last data synchronized from the data node is meaningless and can only be used to verify and generate a new hash
// current node is empty // If there is no leaf data or missing leaf data (i.e. not all nodes), you need to // save the whole node data // save the whole node data // The first byte is not 0xff, which means only the value is stored // log.Infof("save full node(%s) Key:%x", n.NoneRecursiveString(), root)