Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Rename Prefix in names to CidBuilder when a builder is used.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevina committed Aug 11, 2018
1 parent dc95f6c commit b12f2d8
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 63 deletions.
20 changes: 10 additions & 10 deletions hamt/hamt.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Shard struct {
tableSize int
tableSizeLg2 int

prefix cid.Builder
builder cid.Builder
hashFunc uint64

prefixPadStr string
Expand Down Expand Up @@ -124,25 +124,25 @@ func NewHamtFromDag(dserv ipld.DAGService, nd ipld.Node) (*Shard, error) {
ds.children = make([]child, len(pbnd.Links()))
ds.bitfield.SetBytes(pbd.GetData())
ds.hashFunc = pbd.GetHashType()
ds.prefix = ds.nd.CidBuilder()
ds.builder = ds.nd.CidBuilder()

return ds, nil
}

// SetPrefix sets the CID Prefix
func (ds *Shard) SetPrefix(prefix cid.Builder) {
ds.prefix = prefix
// SetCidBuilder sets the CID Builder
func (ds *Shard) SetCidBuilder(builder cid.Builder) {
ds.builder = builder
}

// Prefix gets the CID Prefix, may be nil if unset
func (ds *Shard) Prefix() cid.Builder {
return ds.prefix
// CidBuilder gets the CID Builder, may be nil if unset
func (ds *Shard) CidBuilder() cid.Builder {
return ds.builder
}

// 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.prefix)
out.SetCidBuilder(ds.builder)

cindex := 0
// TODO: optimized 'for each set bit'
Expand Down Expand Up @@ -494,7 +494,7 @@ func (ds *Shard) modifyValue(ctx context.Context, hv *hashBits, key string, val
if err != nil {
return err
}
ns.prefix = ds.prefix
ns.builder = ds.builder
chhv := &hashBits{
b: hash([]byte(child.key)),
consumed: hv.consumed,
Expand Down
52 changes: 26 additions & 26 deletions importer/helpers/dagbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import (
// DagBuilderHelper wraps together a bunch of objects needed to
// efficiently create unixfs dag trees
type DagBuilderHelper struct {
dserv ipld.DAGService
spl chunker.Splitter
recvdErr error
rawLeaves bool
nextData []byte // the next item to return.
maxlinks int
batch *ipld.Batch
prefix cid.Builder
dserv ipld.DAGService
spl chunker.Splitter
recvdErr error
rawLeaves bool
nextData []byte // the next item to return.
maxlinks int
batch *ipld.Batch
cidBuilder cid.Builder

// Filestore support variables.
// ----------------------------
Expand All @@ -53,8 +53,8 @@ type DagBuilderParams struct {
// instead of using the unixfs TRaw type
RawLeaves bool

// CID Prefix to use if set
Prefix cid.Builder
// CID Builder to use if set
CidBuilder cid.Builder

// DAGService to write blocks to (required)
Dagserv ipld.DAGService
Expand All @@ -73,12 +73,12 @@ type DagBuilderParams struct {
// chunker.Splitter as data source.
func (dbp *DagBuilderParams) New(spl chunker.Splitter) *DagBuilderHelper {
db := &DagBuilderHelper{
dserv: dbp.Dagserv,
spl: spl,
rawLeaves: dbp.RawLeaves,
prefix: dbp.Prefix,
maxlinks: dbp.Maxlinks,
batch: ipld.NewBatch(context.TODO(), dbp.Dagserv),
dserv: dbp.Dagserv,
spl: spl,
rawLeaves: dbp.RawLeaves,
cidBuilder: dbp.CidBuilder,
maxlinks: dbp.Maxlinks,
batch: ipld.NewBatch(context.TODO(), dbp.Dagserv),
}
if fi, ok := spl.Reader().(files.FileInfo); dbp.NoCopy && ok {
db.fullPath = fi.AbsPath()
Expand Down Expand Up @@ -141,13 +141,13 @@ func (db *DagBuilderHelper) NewUnixfsNode() *UnixfsNode {
node: new(dag.ProtoNode),
ufmt: ft.NewFSNode(ft.TFile),
}
n.SetPrefix(db.prefix)
n.SetCidBuilder(db.cidBuilder)
return n
}

// GetPrefix returns the internal `cid.Prefix` set in the builder.
func (db *DagBuilderHelper) GetPrefix() cid.Builder {
return db.prefix
// GetCidBuilder returns the internal `cid.CidBuilder` set in the builder.
func (db *DagBuilderHelper) GetCidBuilder() cid.Builder {
return db.cidBuilder
}

// NewLeaf creates a leaf node filled with data. If rawLeaves is
Expand All @@ -160,13 +160,13 @@ func (db *DagBuilderHelper) NewLeaf(data []byte) (*UnixfsNode, error) {
}

if db.rawLeaves {
if db.prefix == nil {
if db.cidBuilder == nil {
return &UnixfsNode{
rawnode: dag.NewRawNode(data),
raw: true,
}, nil
}
rawnode, err := dag.NewRawNodeWPrefix(data, db.prefix)
rawnode, err := dag.NewRawNodeWPrefix(data, db.cidBuilder)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -194,10 +194,10 @@ func (db *DagBuilderHelper) NewLeafNode(data []byte) (ipld.Node, error) {

if db.rawLeaves {
// Encapsulate the data in a raw node.
if db.prefix == nil {
if db.cidBuilder == nil {
return dag.NewRawNode(data), nil
}
rawnode, err := dag.NewRawNodeWPrefix(data, db.prefix)
rawnode, err := dag.NewRawNodeWPrefix(data, db.cidBuilder)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -229,7 +229,7 @@ func (db *DagBuilderHelper) newUnixfsBlock() *UnixfsNode {
node: new(dag.ProtoNode),
ufmt: ft.NewFSNode(ft.TRaw),
}
n.SetPrefix(db.prefix)
n.SetCidBuilder(db.cidBuilder)
return n
}

Expand Down Expand Up @@ -401,7 +401,7 @@ type FSNodeOverDag struct {
func (db *DagBuilderHelper) NewFSNodeOverDag(fsNodeType pb.Data_DataType) *FSNodeOverDag {
node := new(FSNodeOverDag)
node.dag = new(dag.ProtoNode)
node.dag.SetCidBuilder(db.GetPrefix())
node.dag.SetCidBuilder(db.GetCidBuilder())

node.file = ft.NewFSNode(fsNodeType)

Expand Down
6 changes: 3 additions & 3 deletions importer/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ func NewUnixfsNodeFromDag(nd *dag.ProtoNode) (*UnixfsNode, error) {
}, nil
}

// SetPrefix sets the CID Prefix
func (n *UnixfsNode) SetPrefix(prefix cid.Builder) {
n.node.SetCidBuilder(prefix)
// SetCidBuilder sets the CID Builder
func (n *UnixfsNode) SetCidBuilder(builder cid.Builder) {
n.node.SetCidBuilder(builder)
}

// NumChildren returns the number of children referenced by this UnixfsNode.
Expand Down
32 changes: 16 additions & 16 deletions io/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ var DefaultShardWidth = 256
// (which is the main consumer of this interface).
type Directory interface {

// SetPrefix sets the CID prefix of the root node.
SetPrefix(cid.Builder)
// SetCidBuilder sets the CID Builder of the root node.
SetCidBuilder(cid.Builder)

// AddChild adds a (name, key) pair to the root node.
AddChild(context.Context, string, ipld.Node) error
Expand All @@ -51,8 +51,8 @@ type Directory interface {
// GetNode returns the root of this directory.
GetNode() (ipld.Node, error)

// GetPrefix returns the CID Prefix used.
GetPrefix() cid.Builder
// GetCidBuilder returns the CID Builder used.
GetCidBuilder() cid.Builder
}

// TODO: Evaluate removing `dserv` from this layer and providing it in MFS.
Expand Down Expand Up @@ -127,9 +127,9 @@ func NewDirectoryFromNode(dserv ipld.DAGService, node ipld.Node) (Directory, err
return nil, ErrNotADir
}

// SetPrefix implements the `Directory` interface.
func (d *BasicDirectory) SetPrefix(prefix cid.Builder) {
d.node.SetCidBuilder(prefix)
// SetCidBuilder implements the `Directory` interface.
func (d *BasicDirectory) SetCidBuilder(builder cid.Builder) {
d.node.SetCidBuilder(builder)
}

// AddChild implements the `Directory` interface. It adds (or replaces)
Expand Down Expand Up @@ -179,8 +179,8 @@ func (d *BasicDirectory) GetNode() (ipld.Node, error) {
return d.node, nil
}

// GetPrefix implements the `Directory` interface.
func (d *BasicDirectory) GetPrefix() cid.Builder {
// GetCidBuilder implements the `Directory` interface.
func (d *BasicDirectory) GetCidBuilder() cid.Builder {
return d.node.CidBuilder()
}

Expand All @@ -193,7 +193,7 @@ func (d *BasicDirectory) SwitchToSharding(ctx context.Context) (Directory, error
if err != nil {
return nil, err
}
shard.SetPrefix(d.node.CidBuilder())
shard.SetCidBuilder(d.node.CidBuilder())
hamtDir.shard = shard

for _, lnk := range d.node.Links() {
Expand All @@ -211,9 +211,9 @@ func (d *BasicDirectory) SwitchToSharding(ctx context.Context) (Directory, error
return hamtDir, nil
}

// SetPrefix implements the `Directory` interface.
func (d *HAMTDirectory) SetPrefix(prefix cid.Builder) {
d.shard.SetPrefix(prefix)
// SetCidBuilder implements the `Directory` interface.
func (d *HAMTDirectory) SetCidBuilder(builder cid.Builder) {
d.shard.SetCidBuilder(builder)
}

// AddChild implements the `Directory` interface.
Expand Down Expand Up @@ -251,7 +251,7 @@ func (d *HAMTDirectory) GetNode() (ipld.Node, error) {
return d.shard.Node()
}

// GetPrefix implements the `Directory` interface.
func (d *HAMTDirectory) GetPrefix() cid.Builder {
return d.shard.Prefix()
// GetCidBuilder implements the `Directory` interface.
func (d *HAMTDirectory) GetCidBuilder() cid.Builder {
return d.shard.CidBuilder()
}
8 changes: 4 additions & 4 deletions mod/dagmodifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ func (dm *DagModifier) appendData(nd ipld.Node, spl chunker.Splitter) (ipld.Node
switch nd := nd.(type) {
case *mdag.ProtoNode, *mdag.RawNode:
dbp := &help.DagBuilderParams{
Dagserv: dm.dagserv,
Maxlinks: help.DefaultLinksPerBlock,
Prefix: &dm.Prefix,
RawLeaves: dm.RawLeaves,
Dagserv: dm.dagserv,
Maxlinks: help.DefaultLinksPerBlock,
CidBuilder: dm.Prefix,
RawLeaves: dm.RawLeaves,
}
return trickle.Append(dm.ctx, nd, dbp.New(spl))
default:
Expand Down
8 changes: 4 additions & 4 deletions test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func GetNode(t testing.TB, dserv ipld.DAGService, data []byte, opts NodeOpts) ip
in := bytes.NewReader(data)

dbp := h.DagBuilderParams{
Dagserv: dserv,
Maxlinks: h.DefaultLinksPerBlock,
Prefix: &opts.Prefix,
RawLeaves: opts.RawLeavesUsed,
Dagserv: dserv,
Maxlinks: h.DefaultLinksPerBlock,
CidBuilder: opts.Prefix,
RawLeaves: opts.RawLeavesUsed,
}

node, err := trickle.Layout(dbp.New(SizeSplitterGen(500)(in)))
Expand Down

0 comments on commit b12f2d8

Please sign in to comment.