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

feat: switch to HAMT based on size #91

Merged
merged 9 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: make basic dir constructors private
  • Loading branch information
schomatis committed May 7, 2021
commit 0d6f81a016ee30d290ccf9553d4570f43d27a99b
10 changes: 5 additions & 5 deletions io/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ type HAMTDirectory struct {
dserv ipld.DAGService
}

func NewEmptyBasicDirectory(dserv ipld.DAGService) *BasicDirectory {
return NewBasicDirectoryFromNode(dserv, format.EmptyDirNode())
func newEmptyBasicDirectory(dserv ipld.DAGService) *BasicDirectory {
return newBasicDirectoryFromNode(dserv, format.EmptyDirNode())
}

func NewBasicDirectoryFromNode(dserv ipld.DAGService, node *mdag.ProtoNode) *BasicDirectory {
func newBasicDirectoryFromNode(dserv ipld.DAGService, node *mdag.ProtoNode) *BasicDirectory {
basicDir := new(BasicDirectory)
basicDir.node = node
basicDir.dserv = dserv
Expand All @@ -111,7 +111,7 @@ func NewBasicDirectoryFromNode(dserv ipld.DAGService, node *mdag.ProtoNode) *Bas
// NewDirectory returns a Directory implemented by UpgradeableDirectory
// containing a BasicDirectory that can be converted to a HAMTDirectory.
func NewDirectory(dserv ipld.DAGService) Directory {
return &UpgradeableDirectory{NewEmptyBasicDirectory(dserv)}
return &UpgradeableDirectory{newEmptyBasicDirectory(dserv)}
}

// ErrNotADir implies that the given node was not a unixfs directory
Expand All @@ -132,7 +132,7 @@ func NewDirectoryFromNode(dserv ipld.DAGService, node ipld.Node) (Directory, err

switch fsNode.Type() {
case format.TDirectory:
return NewBasicDirectoryFromNode(dserv, protoBufNode.Copy().(*mdag.ProtoNode)), nil
return newBasicDirectoryFromNode(dserv, protoBufNode.Copy().(*mdag.ProtoNode)), nil
case format.THAMTShard:
shard, err := hamt.NewHamtFromDag(dserv, node)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions io/directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestBasicDirectory_estimatedSize(t *testing.T) {
t.Fatal(err)
}

basicDir := NewEmptyBasicDirectory(ds)
basicDir := newEmptyBasicDirectory(ds)

// Several overwrites should not corrupt the size estimation.
basicDir.AddChild(ctx, "child", child)
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestBasicDirectory_estimatedSize(t *testing.T) {

// Restore a directory from original's node and check estimated size consistency.
basicDirSingleNode, _ := basicDir.GetNode() // no possible error
restoredBasicDir := NewBasicDirectoryFromNode(ds, basicDirSingleNode.(*mdag.ProtoNode))
restoredBasicDir := newBasicDirectoryFromNode(ds, basicDirSingleNode.(*mdag.ProtoNode))
if basicDir.estimatedSize != restoredBasicDir.estimatedSize {
t.Fatalf("restored basic directory size (%d) doesn't match original estimate (%d)",
basicDir.estimatedSize, restoredBasicDir.estimatedSize)
Expand Down