Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var XORKeySpace = &xorKeySpace{}
XORKeySpace is a KeySpace which: - normalizes identifiers using a cryptographic hash (sha256) - measures distance by XORing keys together
Functions ¶
func ZeroPrefixLen ¶
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 ¶
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.
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.