ruid

package module
v0.0.0-...-f6f428d Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2017 License: MIT Imports: 11 Imported by: 3

README

ruid

RUID: Recently Unique Identifier. An implementation of Twitter snowflake in golang, generates 64-bit UUID used in 60 years.

Documentation

Index

Constants

View Source
const (
	VIRTUAL_NODES  = 50
	DEFAULT_WEIGHT = 1
)
View Source
const (
	TIMESTAMP_MASK  = 0x1FFFFFFFFFF
	TIMESTAMP_BITS  = 41
	HARDWARE_MASK   = 0x7FF
	HARDWARE_BITS   = 11
	HARDWARE_OFFSET = TIMESTAMP_BITS
	SEQUENCE_OFFSET = HARDWARE_BITS + HARDWARE_OFFSET
)
View Source
const EncodeRUID = "-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"

Variables

View Source
var RUIDEncoding = base64.NewEncoding(EncodeRUID).WithPadding(base64.NoPadding)

Functions

This section is empty.

Types

type ID

type ID interface {
	Lt(ID) bool
	Ge(ID) bool
	Hash() ID
	String() string
	Nonzero() bool
	ByteSize() int
	Serialize(*tygo.ProtoBuf)
}

func RingKey

func RingKey(ident Ident, node string) ID

type Ident

type Ident interface {
	New() ID
	Zero() ID
	Deserialize(*tygo.ProtoBuf) (ID, error)
	GetIDs([]byte) []ID
}

type RUID

type RUID uint64
const ZERO RUID = 0

func FromBytes

func FromBytes(b []byte) RUID

func FromString

func FromString(s string) (RUID, error)

func New

func New() RUID

func (RUID) ByteSize

func (r RUID) ByteSize() (size int)

func (RUID) Bytes

func (r RUID) Bytes() []byte

func (*RUID) Deserialize

func (r *RUID) Deserialize(input *tygo.ProtoBuf) (err error)

func (RUID) Ge

func (r RUID) Ge(o ID) bool

func (RUID) Hash

func (r RUID) Hash() ID

func (RUID) Lt

func (r RUID) Lt(o ID) bool

func (RUID) Nonzero

func (r RUID) Nonzero() bool

func (RUID) Serialize

func (r RUID) Serialize(output *tygo.ProtoBuf)

func (RUID) String

func (r RUID) String() string

type RUIdentity

type RUIdentity int
var RUIdent RUIdentity = 0

func (RUIdentity) Deserialize

func (_ RUIdentity) Deserialize(input *tygo.ProtoBuf) (r ID, err error)

func (RUIdentity) GetIDs

func (_ RUIdentity) GetIDs(bytes []byte) (ids []ID)

func (RUIdentity) New

func (_ RUIdentity) New() ID

func (RUIdentity) Zero

func (_ RUIdentity) Zero() ID

type Ring

type Ring struct {
	// contains filtered or unexported fields
}

func NewRing

func NewRing(ident Ident, nodes ...string) *Ring

func WeightedRing

func WeightedRing(ident Ident, weights map[string]int) *Ring

func (*Ring) Append

func (r *Ring) Append(nodes ...string)

func (*Ring) Get

func (r *Ring) Get(key ID) (node string, ok bool)

func (*Ring) Remove

func (r *Ring) Remove(nodes ...string)

func (*Ring) Update

func (r *Ring) Update(weights map[string]int)

Jump to

Keyboard shortcuts

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