hash

package
v0.0.1-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2017 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashLess

func HashLess(h1, h2 Hash) bool

Less returns whether the first key is smaller than the second.

func HashXORDistance

func HashXORDistance(h1, h2 Hash) *big.Int

Distance returns the distance metric between two hashes

func PeerIDFromHash

func PeerIDFromHash(h Hash) (id peer.ID)

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

func XOR(a, b []byte) []byte

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

func ZeroPrefixLen(id []byte) int

ZeroPrefixLen returns the number of consecutive zeroes in a byte slice.

Types

type Hash

type Hash struct {
	H mh.Multihash
}

Hash of Entry's Content

func HashFromBytes

func HashFromBytes(b []byte) (h Hash, err error)

HashFromBytes cast a byte slice to Hash type, and validate the id to make sure it is a multihash.

func HashFromPeerID

func HashFromPeerID(id peer.ID) (h Hash)

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 NewHash

func NewHash(s string) (h Hash, err error)

NewHash builds a Hash from a b58 string encoded hash

func NullHash

func NullHash() (h Hash)

NullHash builds a null valued hash

func SortByDistance

func SortByDistance(center Hash, toSort []Hash) []Hash

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) Clone

func (h *Hash) Clone() (hash Hash)

Clone returns a copy of a hash

func (*Hash) Equal

func (h *Hash) Equal(h2 *Hash) bool

Equal checks to see if two hashes have the same value

func (*Hash) IsNullHash

func (h *Hash) IsNullHash() bool

IsNullHash checks to see if this hash's value is the null hash

func (*Hash) MarshalHash

func (h *Hash) MarshalHash(writer io.Writer) (err error)

MarshalHash writes a hash to a binary stream

func (Hash) String

func (h Hash) String() string

String encodes a hash to a human readable string

func (*Hash) Sum

func (h *Hash) Sum(hc HashSpec, data []byte) (err error)

Sum builds a digest according to the specs in the Holochain

func (*Hash) UnmarshalHash

func (h *Hash) UnmarshalHash(reader io.Reader) (err error)

UnmarshalHash reads a hash from a binary stream

type HashDistance

type HashDistance struct {
	Hash     interface{}
	Distance *big.Int
}

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)

type HashSpec

type HashSpec struct {
	Code   uint64
	Length int
}

HashSpec holds the info that tells what kind of hash this is

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL