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 (h *Hash) Clone() (hash Hash)
- func (h *Hash) Equal(h2 *Hash) bool
- func (h *Hash) IsNullHash() bool
- func (h *Hash) MarshalHash(writer io.Writer) (err error)
- func (h Hash) String() string
- func (h *Hash) Sum(hc HashSpec, data []byte) (err error)
- func (h *Hash) UnmarshalHash(reader io.Reader) (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 ¶
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 (*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)