This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Fix HAMT enumeration for in-memory traversal #110
Closed
schomatis
wants to merge
1
commit into
schomatis/directory/unsharding
from
schomatis/fix/enumlinks-from-memory
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ import ( | |
|
||
"github.com/ipfs/go-unixfs/internal" | ||
|
||
"github.com/ipfs/go-cid" | ||
"github.com/multiformats/go-multihash" | ||
"github.com/spaolacci/murmur3" | ||
) | ||
|
||
|
@@ -78,3 +80,48 @@ func murmur3Hash(val []byte) []byte { | |
h.Write(val) | ||
return h.Sum(nil) | ||
} | ||
|
||
// We convert CIDs to arbitrary strings as CIDv1 raw identity hashes. | ||
func packBytesIntoCID(data []byte) cid.Cid { | ||
h, err := multihash.Sum(data, multihash.IDENTITY, -1) | ||
if err != nil { | ||
panic(fmt.Sprintf("error while packing data %s: %s", | ||
data, err)) | ||
} | ||
return cid.NewCidV1(cid.Raw, h) | ||
} | ||
|
||
func unpackBytesFromCID(c cid.Cid) []byte { | ||
if c.Version() != 1 { | ||
panic("trying to unpack CIDv0") | ||
} | ||
decoded, err := multihash.Decode(c.Hash()) | ||
if err != nil { | ||
panic(fmt.Sprintf("error while unpacking data from CID %s: %s", | ||
c, err)) | ||
} | ||
return decoded.Digest | ||
} | ||
|
||
// Coordinate in a HAMT to single out a single node. | ||
// For simplicity this is independent of the hash the node encodes and just | ||
// the position in the nodes. | ||
// See `getLinksHAMTNode` for details. | ||
type hamtPos struct { | ||
// Slice of child positions (from the immediate parent perspective). | ||
// FIXME: We are assuming a shard width <= 256 (the default) to easily | ||
// convert to and from a byte slice. | ||
Comment on lines
+112
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Working on this (extending the |
||
childSlicePos []byte | ||
} | ||
|
||
func (hp *hamtPos) addChildPos(childIndex int) *hamtPos { | ||
return &hamtPos{ append(hp.childSlicePos, byte(childIndex))} | ||
} | ||
|
||
func posFromBytes(data []byte) *hamtPos{ | ||
return &hamtPos{data} | ||
} | ||
|
||
func posToBytes(hp *hamtPos) []byte { | ||
return hp.childSlicePos | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note removal of serialization here. Will add an explicit test.