chunk

package
v1.8.22-0...-5b0d3fa Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2019 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSize   = 4096
	MaxPO         = 16
	AddressLength = 32
)

Variables

View Source
var (
	ErrChunkNotFound = errors.New("chunk not found")
	ErrChunkInvalid  = errors.New("invalid chunk")
)
View Source
var ZeroAddr = Address(common.Hash{}.Bytes())

Functions

func NewChunk

func NewChunk(addr Address, data []byte) *chunk

func Proximity

func Proximity(one, other []byte) (ret int)

Proximity returns the proximity order of the MSB distance between x and y

The distance metric MSB(x, y) of two equal length byte sequences x an y is the value of the binary integer cast of the x^y, ie., x and y bitwise xor-ed. the binary cast is big endian: most significant bit first (=MSB).

Proximity(x, y) is a discrete logarithmic scaling of the MSB distance. It is defined as the reverse rank of the integer part of the base 2 logarithm of the distance. It is calculated by counting the number of common leading zeros in the (MSB) binary representation of the x^y.

(0 farthest, 255 closest, 256 self)

Types

type Address

type Address []byte

func (Address) Hex

func (a Address) Hex() string

func (Address) Log

func (a Address) Log() string

func (Address) MarshalJSON

func (a Address) MarshalJSON() (out []byte, err error)

func (Address) String

func (a Address) String() string

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(value []byte) error

type Chunk

type Chunk interface {
	Address() Address
	Data() []byte
}

Jump to

Keyboard shortcuts

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