// Lazy load tree
338508
func (imf *ImmutableForest) tree(prefix []byte) (*RWTree, error) {
	// Try cache
	if value, ok := imf.treeCache.Get(string(prefix)); ok {
		return value.(*RWTree), nil
	}
	// Not in caches but non-negative version - we should be able to load into memory
	return imf.loadOrCreateTree(prefix)
}
861966
func NewRWTree(db dbm.DB, cacheSize int) *RWTree {
	tree := NewMutableTree(db, cacheSize)
	return &RWTree{
		tree:          tree,
		ImmutableTree: &ImmutableTree{iavl.NewImmutableTree(db, cacheSize)},
	}
}
1010926
func LazyConvert(s string, a *Args) []string {
	if a == nil {
		args := NewArgs()
		a = &args
	}
	return LazyPinyin(s, *a)
}
1301948
func (muf *MutableForest) Load(version int64) error {
	return muf.commitsTree.Load(version, true)
}
794693
func NewTree(e StorageEngine, c Config) *Tree {
	return &Tree{eng: e, cfg: c}
}
384635
func (d *DecisionTreeNode) Load(filePath string) error {

	reader, err := base.ReadSerializedClassifierStub(filePath)
	if err != nil {
		return err
	}

	return d.LoadWithPrefix(reader, "")
}
243921
func LazyHandler(h LogHandler) LogHandler {
	return FuncHandler(func(r *Record) error {
		for k, v := range r.Context {
			if lz, ok := v.(Lazy); ok {
				value, err := evaluateLazy(lz)
				if err != nil {
					r.Context[errorKey] = "bad lazy " + k
				} else {
					v = value
				}
			}
		}

		return h.Log(r)
	})
}
942853
func (tl traceLogger) LazyTrace(
	ctx context.Context, format string, args ...interface{}) {
	if tr, ok := trace.FromContext(ctx); ok {
		tr.LazyPrintf(format, args...)
	}
}
493205
func (c *Config) LoadAll() (bool, error) {
	c.lock.Lock()
	defer c.lock.Unlock()

	return c.MergeLoaders(c.loaders...)
}
414169
func (c *Commit) Tree() (*Tree, error) {
	return GetTree(c.s, c.TreeHash)
}
1158598
func NewEmptyTree() *Tree {
	t := &Tree{config: &config.Config{}}

	// We do this dummy load so that the tree is marked as "loaded". It
	// should never fail because this is just about a no-op. If it does fail
	// we panic so we can know its a bug.
	if err := t.Load(&Storage{Mode: GetModeGet}); err != nil {
		panic(err)
	}

	return t
}
45056
func (tree *MutableTree) Rollback() {
	if tree.version > 0 {
		tree.ImmutableTree = tree.lastSaved.clone()
	} else {
		tree.ImmutableTree = &ImmutableTree{ndb: tree.ndb, version: 0}
	}
	tree.orphans = map[string]int64{}
}
1094762
func (d *DecisionTreeNode) LoadWithPrefix(reader *base.ClassifierDeserializer, prefix string) error {

	b, err := reader.GetBytesForKey(reader.Prefix(prefix, "tree"))
	if err != nil {
		return err
	}

	err = json.Unmarshal(b, d)
	if err != nil {
		return err
	}

	a, err := reader.GetAttributeForKey(reader.Prefix(prefix, "treeClassAttr"))
	if err != nil {
		return err
	}

	d.ClassAttr = a

	return nil
}
800873
func (o *lazyObject) init() error {
	o.lock.Lock()
	defer o.lock.Unlock()
	if o.loaded {
		return o.err
	}
	o.mapper, o.err = o.loader()
	o.loaded = true
	return o.err
}
336120
func (cmd *Command) RegisterTree(forest ...*CommandTree) {
	for _, tree := range forest {
		cmd.Register(tree.command)
		if tree.forest != nil && len(tree.forest) > 0 {
			tree.command.RegisterTree(tree.forest...)
		}
	}
}
1354885
func (f *Folder) Load() error {
	if err := f.comp.loadPack(f.uuid, "-trees"); err != nil {
		return err
	}
	if err := f.comp.loadPack(f.uuid, "-blobs"); err != nil {
		return err
	}
	return nil
}
952231
func Load(p Persister, id []byte, comparator Comparator) (ReadableTree, error) {
	items, err := p.Load(id)
	if err != nil {
		return nil, err
	}

	if len(items) == 0 || items[0] == nil {
		return nil, ErrTreeNotFound
	}

	rt, err := treeFromBytes(p, items[0].Payload, comparator)
	if err != nil {
		return nil, err
	}

	return rt, nil
}