id

package
v0.0.0-...-364fed7 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

ID implements a 128-bit pastry ID. 128-bit is larger than most applications will need, so utility functions exist to convert into smaller representations.

IDs are converted into a power-of-two base, up to hexadecimal, for message routing.

Index

Constants

This section is empty.

Variables

View Source
var (
	Zero = ID{}
	Max  = ID{
		High: math.MaxUint64,
		Low:  math.MaxUint64,
	}
)

Lowest and highest values

Functions

func Compare

func Compare(a, b ID) int

Compare returns an integer comparing two IDs. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.

Types

type Digits

type Digits []byte

Digits is a set of individual digits of an ID after converting it into a different base.

func (Digits) String

func (d Digits) String() string

String returns the string representation of digits.

type Generator

type Generator interface {
	Get(s string) ID
}

Generator generates IDs based on an input string.

func NewGenerator

func NewGenerator(size int) Generator

NewGenerator returns an ID generator where IDs will be generated from a hash of size (must be one of 8, 16, 32, 64, 128).

type ID

type ID struct {
	High, Low uint64
}

ID is an unsigned 128-bit number used to identify nodes and assign ownership to resources.

func MaxForSize

func MaxForSize(size int) ID

MaxForSize returns the max ID for the given size in bits. size must be multiple of 2 and between 8 and 128 inclusive.

func Parse

func Parse(s string) (ID, error)

Parse parses a string into an ID.

func (ID) Digits

func (id ID) Digits(size, base int) Digits

Digits converts ID into individual digits of a power-of-two base, up to 16. size allows for representing the 128-bit ID as a smaller uint size.

Returns nil if id is too big for size.

func (ID) String

func (id ID) String() string

String returns the base-10 representation of the ID.

Jump to

Keyboard shortcuts

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