keyspace

package
v2.2.5+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var XORKeySpace = &xorKeySpace{}

XORKeySpace is a KeySpace which: - normalizes identifiers using a cryptographic hash (sha256) - measures distance by XORing keys together

Functions

func ZeroPrefixLen

func ZeroPrefixLen(id []byte) int

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

Types

type Key

type Key struct {

	// Space is the KeySpace this Key is related to.
	Space KeySpace

	// Original is the original value of the identifier
	Original []byte

	// Bytes is the new value of the identifier, in the KeySpace.
	Bytes []byte
}

Key represents an identifier in a KeySpace. It holds a reference to the associated KeySpace, as well references to both the Original identifier, as well as the new, KeySpace Bytes one.

func SortByDistance

func SortByDistance(sp KeySpace, center Key, toSort []Key) []Key

SortByDistance takes a KeySpace, a center Key, and a list of Keys toSort. It returns a new list, where the Keys toSort have been sorted by their distance to the center Key.

func (Key) Distance

func (k1 Key) Distance(k2 Key) *big.Int

Distance returns this key's distance to another

func (Key) Equal

func (k1 Key) Equal(k2 Key) bool

Equal returns whether this key is equal to another.

func (Key) Less

func (k1 Key) Less(k2 Key) bool

Less returns whether this key comes before another.

type KeySpace

type KeySpace interface {

	// Key converts an identifier into a Key in this space.
	Key([]byte) Key

	// Equal returns whether keys are equal in this key space
	Equal(Key, Key) bool

	// Distance returns the distance metric in this key space
	Distance(Key, Key) *big.Int

	// Less returns whether the first key is smaller than the second.
	Less(Key, Key) bool
}

KeySpace is an object used to do math on identifiers. Each keyspace has its own properties and rules. See XorKeySpace.

Jump to

Keyboard shortcuts

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