func TrickleLayout(db *h.DagBuilderHelper) (*dag.Node, error) { root := h.NewUnixfsNode() err := db.FillNodeLayer(root) if err != nil { return nil, err } for level := 1; !db.Done(); level++ { for i := 0; i < layerRepeat && !db.Done(); i++ { next := h.NewUnixfsNode() err := fillTrickleRec(db, next, level) if err != nil { return nil, err } err = root.AddChild(next, db) if err != nil { return nil, err } } } out, err := db.Add(root) if err != nil { return nil, err } err = db.Close() if err != nil { return nil, err } return out, nil }
func BalancedLayout(db *h.DagBuilderHelper) (node.Node, error) { var offset uint64 = 0 var root *h.UnixfsNode for level := 0; !db.Done(); level++ { nroot := h.NewUnixfsNode() db.SetPosInfo(nroot, 0) // add our old root as a child of the new root. if root != nil { // nil if it's the first node. if err := nroot.AddChild(root, db); err != nil { return nil, err } } // fill it up. if err := fillNodeRec(db, nroot, level, offset); err != nil { return nil, err } offset = nroot.FileSize() root = nroot } if root == nil { root = h.NewUnixfsNode() } out, err := db.Add(root) if err != nil { return nil, err } err = db.Close() if err != nil { return nil, err } return out, nil }