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

Commit

Permalink
hamt: support using CIDv1 by allowing the prefix to be set
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
  • Loading branch information
kevina committed Apr 26, 2017
1 parent c1e9ccd commit 957da2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 7 additions & 0 deletions hamt/hamt.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
format "github.com/ipfs/go-ipfs/unixfs"
upb "github.com/ipfs/go-ipfs/unixfs/pb"

cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
"gx/ipfs/QmfJHywXQu98UeZtGJBQrPAR6AtmDjjbe3qjTo9piXHPnx/murmur3"
Expand All @@ -50,6 +51,7 @@ type HamtShard struct {
tableSize int
tableSizeLg2 int

prefix *cid.Prefix
hashFunc uint64

prefixPadStr string
Expand Down Expand Up @@ -123,9 +125,14 @@ func NewHamtFromDag(dserv dag.DAGService, nd node.Node) (*HamtShard, error) {
return ds, nil
}

func (ds *HamtShard) SetPrefix(prefix *cid.Prefix) {
ds.prefix = prefix
}

// Node serializes the HAMT structure into a merkledag node with unixfs formatting
func (ds *HamtShard) Node() (node.Node, error) {
out := new(dag.ProtoNode)
out.SetPrefix(ds.prefix)

// TODO: optimized 'for each set bit'
for i := 0; i < ds.tableSize; i++ {
Expand Down
7 changes: 3 additions & 4 deletions io/dirbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ func (d *Directory) SetPrefix(prefix *cid.Prefix) {
if d.dirnode != nil {
d.dirnode.SetPrefix(prefix)
}
// FIXME: Should we do this? -- kevina
//if d.shard != nil {
// d.shard.SetPrefix(prefix)
//}
if d.shard != nil {
d.shard.SetPrefix(prefix)
}
}

// AddChild adds a (name, key)-pair to the root node.
Expand Down

0 comments on commit 957da2c

Please sign in to comment.