func newEmptyTile(id []byte) *storagepb.SubtreeProto {
	return &storagepb.SubtreeProto{
		Prefix:        id,
		Depth:         8,
		Leaves:        make(map[string][]byte),
		InternalNodes: make(map[string][]byte),
	}
}
newEmptyTile creates an empty log tile for the passed-in ID.
package cache
import (
	"encoding/binary"
	"fmt"
	"github.com/google/trillian/merkle/compact"
	"github.com/google/trillian/merkle/hashers"
	"github.com/google/trillian/storage/storagepb"
)
const (
	logStrataDepth = 8
	maxLogDepth = 64
)
func PopulateLogTile(st *storagepb.SubtreeProto, hasher hashers.LogHasher) error {
	if st.Depth < 1 {
		return fmt.Errorf("populate log subtree with invalid depth: %d", st.Depth)
	}
	maxLeaves := 1 << uint(st.Depth)
	if st.InternalNodes == nil || len(st.Leaves) == maxLeaves {
		st.InternalNodes = make(map[string][]byte)
	}
	store := func(id compact.NodeID, hash []byte) {
		if id.Level == logStrataDepth && id.Index == 0 {
			return
		}
		if id.Level > 0 && len(st.Leaves) == maxLeaves {
			st.InternalNodes[toSuffix(id)] = hash
		}
	}
	fact := compact.RangeFactory{Hash: hasher.HashChildren}
	cr := fact.NewEmptyRange(0)
	for leafIndex := uint64(0); leafIndex < uint64(len(st.Leaves)); leafIndex++ {
		sfxKey := toSuffix(compact.NewNodeID(0, leafIndex))
		h := st.Leaves[sfxKey]
		if h == nil {
			return fmt.Errorf("unexpectedly got nil for subtree leaf suffix %s", sfxKey)
		}
		if size, expected := cr.End(), leafIndex; size != expected {
			return fmt.Errorf("got size of %d, but expected %d", size, expected)
		}
		if err := cr.Append(h, store); err != nil {
			return err
		}
	}
	if got, want := uint32(len(st.InternalNodes)), st.InternalNodeCount; got != want {
		return fmt.Errorf("log repop got: %d internal nodes, want: %d", got, want)
	}
	return nil
}
func prepareLogTile(st *storagepb.SubtreeProto) error {
	st.InternalNodeCount = uint32(len(st.InternalNodes))
	if st.Depth < 1 {
		return fmt.Errorf("prepare subtree for log write invalid depth: %d", st.Depth)
	}
	maxLeaves := 1 << uint(st.Depth)
	if len(st.Leaves) == maxLeaves {
		st.InternalNodes = nil
	}
	return nil
}
func toSuffix(id compact.NodeID) string {
	depth := logStrataDepth - int(id.Level)
	var index [8]byte
	binary.BigEndian.PutUint64(index[:], id.Index<<(maxLogDepth-depth))
	return newSuffix(uint8(depth), index[:]).String()
}