// AddChild implements the `Directory` interface. We check when adding new entries
// if we should switch to HAMTDirectory according to global option(s).
AddChild implements the `Directory` interface. We check when adding new entries
if we should switch to HAMTDirectory according to global option(s).
// AddChild implements the ` Directory ` interface . We check when adding new entries // if we should switch to HAMTDirectory according to global option ( s ) .
func (d *DynamicDirectory) AddChild(ctx context.Context, name string, nd ipld.Node) error {
	hamtDir, ok := d.Directory.(*HAMTDirectory)
	if ok {
		switchToBasic, err := hamtDir.needsToSwitchToBasicDir(ctx, name, nd)
		if err != nil {
			return err
		}
		if switchToBasic {
			basicDir, err := hamtDir.switchToBasic(ctx)
			if err != nil {
				return err
			}
			err = basicDir.AddChild(ctx, name, nd)
			if err != nil {
				return err
			}
			d.Directory = basicDir
			return nil
		}
		return d.Directory.AddChild(ctx, name, nd)
	}
	basicDir := d.Directory.(*BasicDirectory)
	switchToHAMT, err := basicDir.needsToSwitchToHAMTDir(name, nd)
	if err != nil {
		return err
	}
	if !switchToHAMT {
		return basicDir.AddChild(ctx, name, nd)
	}
	hamtDir, err = basicDir.switchToSharding(ctx)
	if err != nil {
		return err
	}
	hamtDir.AddChild(ctx, name, nd)
	if err != nil {
		return err
	}
	d.Directory = hamtDir
	return nil
}
func ( d * DynamicDirectory ) AddChild ( ctx context . Context , name string , nd ipld . Node ) error { hamtDir , ok := d . Directory . ( * HAMTDirectory ) if ok { switchToBasic , err := hamtDir . needsToSwitchToBasicDir ( ctx , name , nd ) if err != nil { return err } if switchToBasic { basicDir , err := hamtDir . switchToBasic ( ctx ) if err != nil { return err } err = basicDir . AddChild ( ctx , name , nd ) if err != nil { return err } d . Directory = basicDir return nil } return d . Directory . AddChild ( ctx , name , nd ) } basicDir := d . Directory . ( * BasicDirectory ) switchToHAMT , err := basicDir . needsToSwitchToHAMTDir ( name , nd ) if err != nil { return err } if ! switchToHAMT { return basicDir . AddChild ( ctx , name , nd ) } hamtDir , err = basicDir . switchToSharding ( ctx ) if err != nil { return err } hamtDir . AddChild ( ctx , name , nd ) if err != nil { return err } d . Directory = hamtDir return nil }
AddChild implements the `Directory` interface.
AddChild implements the ` Directory ` interface .
// We evaluate a switch in the HAMTDirectory case even for an AddChild // as it may overwrite an existing entry and end up actually reducing // the directory size. // BasicDirectory