// Node serializes the HAMT structure into a merkledag node with unixfs formatting
Node serializes the HAMT structure into a merkledag node with unixfs formatting
// Node serializes the HAMT structure into a merkledag node with unixfs formatting
func (ds *Shard) Node() (ipld.Node, error) {
	out := new(dag.ProtoNode)
	out.SetCidBuilder(ds.builder)
	sliceIndex := 0
	for childIndex := 0; childIndex < ds.tableSize; childIndex++ {
		if !ds.childer.has(childIndex) {
			continue
		}
		ch := ds.childer.child(sliceIndex)
		if ch != nil {
			clnk, err := ch.Link()
			if err != nil {
				return nil, err
			}
			err = out.AddRawLink(ds.linkNamePrefix(childIndex)+ch.key, clnk)
			if err != nil {
				return nil, err
			}
		} else {
			lnk := ds.childer.link(sliceIndex)
			label := lnk.Name[ds.maxpadlen:]
			err := out.AddRawLink(ds.linkNamePrefix(childIndex)+label, lnk)
			if err != nil {
				return nil, err
			}
		}
		sliceIndex++
	}
	data, err := format.HAMTShardData(ds.childer.bitfield.Bytes(), uint64(ds.tableSize), HashMurmur3)
	if err != nil {
		return nil, err
	}
	out.SetData(data)
	err = ds.dserv.Add(context.TODO(), out)
	if err != nil {
		return nil, err
	}
	return out, nil
}
func ( ds * Shard ) Node ( ) ( ipld . Node , error ) { out := new ( dag . ProtoNode ) out . SetCidBuilder ( ds . builder ) sliceIndex := 0 for childIndex := 0 ; childIndex < ds . tableSize ; childIndex ++ { if ! ds . childer . has ( childIndex ) { continue } ch := ds . childer . child ( sliceIndex ) if ch != nil { clnk , err := ch . Link ( ) if err != nil { return nil , err } err = out . AddRawLink ( ds . linkNamePrefix ( childIndex ) + ch . key , clnk ) if err != nil { return nil , err } } else { lnk := ds . childer . link ( sliceIndex ) label := lnk . Name [ ds . maxpadlen : ] err := out . AddRawLink ( ds . linkNamePrefix ( childIndex ) + label , lnk ) if err != nil { return nil , err } } sliceIndex ++ } data , err := format . HAMTShardData ( ds . childer . bitfield . Bytes ( ) , uint64 ( ds . tableSize ) , HashMurmur3 ) if err != nil { return nil , err } out . SetData ( data ) err = ds . dserv . Add ( context . TODO ( ) , out ) if err != nil { return nil , err } return out , nil }
Node serializes the HAMT structure into a merkledag node with unixfs formatting
Node serializes the HAMT structure into a merkledag node with unixfs formatting
// TODO: optimized 'for each set bit' // child unloaded, just copy in link with updated name