// Evaluate a switch from HAMTDirectory to BasicDirectory in case the size will
// go above the threshold when we are adding or removing an entry.
// In both the add/remove operations any old name will be removed, and for the
// add operation in particular a new entry will be added under that name (otherwise
// nodeToAdd is nil). We compute both (potential) future subtraction and
// addition to the size change.
Evaluate a switch from HAMTDirectory to BasicDirectory in case the size will
go above the threshold when we are adding or removing an entry.
In both the add/remove operations any old name will be removed, and for the
add operation in particular a new entry will be added under that name (otherwise
nodeToAdd is nil). We compute both (potential) future subtraction and
addition to the size change.
// Evaluate a switch from HAMTDirectory to BasicDirectory in case the size will // go above the threshold when we are adding or removing an entry . // In both the add / remove operations any old name will be removed and for the // add operation in particular a new entry will be added under that name ( otherwise // nodeToAdd is nil ) . We compute both ( potential ) future subtraction and // addition to the size change .
func (d *HAMTDirectory) needsToSwitchToBasicDir(ctx context.Context, name string, nodeToAdd ipld.Node) (switchToBasic bool, err error) {
	if HAMTShardingSize == 0 { 
		return false, nil
	}
	operationSizeChange := 0
	entryToRemove, err := d.shard.Find(ctx, name)
	if err != os.ErrNotExist {
		if err != nil {
			return false, err
		}
		operationSizeChange -= linksize.LinkSizeFunction(name, entryToRemove.Cid)
	}
	if nodeToAdd != nil {
		operationSizeChange += linksize.LinkSizeFunction(name, nodeToAdd.Cid())
	}
	if d.sizeChange+operationSizeChange >= 0 {
		return false, nil
	}
	return d.sizeBelowThreshold(ctx, operationSizeChange)
}
func ( d * HAMTDirectory ) needsToSwitchToBasicDir ( ctx context . Context , name string , nodeToAdd ipld . Node ) ( switchToBasic bool , err error ) { if HAMTShardingSize == 0 { return false , nil } operationSizeChange := 0 entryToRemove , err := d . shard . Find ( ctx , name ) if err != os . ErrNotExist { if err != nil { return false , err } operationSizeChange -= linksize . LinkSizeFunction ( name , entryToRemove . Cid ) } if nodeToAdd != nil { operationSizeChange += linksize . LinkSizeFunction ( name , nodeToAdd . Cid ( ) ) } if d . sizeChange + operationSizeChange >= 0 { return false , nil } return d . sizeBelowThreshold ( ctx , operationSizeChange ) }
Evaluate a switch from HAMTDirectory to BasicDirectory in case the size will
go above the threshold when we are adding or removing an entry.
Evaluate a switch from HAMTDirectory to BasicDirectory in case the size will go above the threshold when we are adding or removing an entry .
// Option disabled. // Find if there is an old entry under that name that will be overwritten // (AddEntry) or flat out removed (RemoveEntry). // For the AddEntry case compute the size addition of the new entry. // We won't have reduced the HAMT net size. // We have reduced the directory size, check if went below the // HAMTShardingSize threshold to trigger a switch.