Documentation ¶
Index ¶
- func HashLess(h1, h2 Hash) bool
- func HashXORDistance(h1, h2 Hash) *big.Int
- func PeerIDFromHash(h Hash) (id peer.ID)
- func XOR(a, b []byte) []byte
- func ZeroPrefixLen(id []byte) int
- type Hash
- func HashFromBytes(b []byte) (h Hash, err error)
- func HashFromPeerID(id peer.ID) (h Hash)
- func NewHash(s string) (h Hash, err error)
- func NullHash() (h Hash)
- func SortByDistance(center Hash, toSort []Hash) []Hash
- func Sum(hc HashSpec, data []byte) (hash Hash, err error)
- func UnmarshalHash(reader io.Reader) (hash Hash, err error)
- type HashDistance
- type HashSorterArr
- type HashSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HashXORDistance ¶
Distance returns the distance metric between two hashes
func PeerIDFromHash ¶
PeerIDFromHash copy the bytes from a hash to a peer ID. Hashes and peer ID's are the exact same format, a multihash. NOTE: assumes that the multihash is valid
func XOR ¶
XOR takes two byte slices, XORs them together, returns the resulting slice. taken from https://github.com/ipfs/go-ipfs-util/blob/master/util.go
func ZeroPrefixLen ¶
ZeroPrefixLen returns the number of consecutive zeroes in a byte slice.
Types ¶
type Hash ¶
type Hash string
Hash of Entry's Content
func HashFromBytes ¶
HashFromBytes cast a byte slice to Hash type, and validate the id to make sure it is a multihash.
func HashFromPeerID ¶
HashFromPeerID copy the bytes from a peer ID to Hash. Hashes and peer ID's are the exact same format, a multihash. NOTE: assumes that the multihash is valid
func SortByDistance ¶
SortByDistance takes a center Hash, and a list of Hashes toSort. It returns a new list, where the Hashes toSort have been sorted by their distance to the center Hash.
func UnmarshalHash ¶
UnmarshalHash reads a hash from a binary stream
func (Hash) IsNullHash ¶
IsNullHash checks to see if this hash's value is the null hash
func (Hash) MarshalHash ¶
MarshalHash writes a hash to a binary stream
type HashDistance ¶
hashDistance helper struct for sorting by distance which pre-caches the distance to center so as not to recalculate it on every sort comparison.
type HashSorterArr ¶
type HashSorterArr []*HashDistance
func (HashSorterArr) Len ¶
func (p HashSorterArr) Len() int
func (HashSorterArr) Less ¶
func (p HashSorterArr) Less(a, b int) bool
func (HashSorterArr) Swap ¶
func (p HashSorterArr) Swap(a, b int)