lpclock

package
v0.0.0-...-6d3478e Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2018 License: MIT Imports: 8 Imported by: 0

README

LPClock

LPClock implements a custom monotonic lamport clock.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoHashPrefix          = errors.New("must have '#' prefix")
	ErrInvalidTickType       = errors.New("invalid tick type received")
	ErrInvalidUUIDFormat     = errors.New("data has invalid UUID format")
	ErrInvalidIdentityFormat = errors.New("identity data has invalid format")
	ErrInvalidIDTimeFormat   = errors.New("ID_Time data has invalid format")
)

Errors ...

Functions

This section is empty.

Types

type Clock

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

Clock exposes a giving monotonic lamport clocking structure which returns custom continouse ticks for giving origin and id.

func Lamport

func Lamport(origin string) *Clock

Lamport returns a new instance of Clock using the LAMPORTTICK has the time tick type.

func New

func New(tickT TickType, origin string) *Clock

New returns a new instance of Clock.

func NewClock

func NewClock(tickT TickType, timeOffset time.Duration, origin string, id string) *Clock

NewClock returns new instance of Clock struct.

func Unix

func Unix(origin string) *Clock

Unix returns a new instance of Clock using the UNIXTICK has the time tick type.

func (*Clock) Now

func (c *Clock) Now() UUID

Now returns new monotonic UUID which is consistently increasing.

type TickType

type TickType int64

TickType used to indicate type of tick value.

const (
	LAMPORTTICK TickType = 1
	UNIXTICK    TickType = 2
)

consts of tick types.

type UUID

type UUID struct {
	ID     string
	Origin string
	Tick   int64
	Type   TickType
}

UUID generates a uuid which runs with a giving length of encoded values.

func (UUID) Equal

func (u UUID) Equal(n UUID) bool

Equal returns true/false if giving UUIDs are a match in tick type, origin and id. It does not compare tick value.

func (UUID) ExactEqual

func (u UUID) ExactEqual(n UUID) bool

ExactEqual returns true/false if giving UUIDs a exact match.

func (UUID) GreaterThan

func (u UUID) GreaterThan(n UUID) bool

GreaterThan validates that the uuid is less than value of provided uuid.

func (UUID) LessThan

func (u UUID) LessThan(n UUID) bool

LessThan validates that the uuid is less than value of provided uuid.

func (UUID) MarshalText

func (u UUID) MarshalText() ([]byte, error)

MarshalText returns byte slice of giving uuid.

func (UUID) String

func (u UUID) String() string

String returns string version of uuid. Format: #TICK_TYPE#ID_LENGTH#OriginID_TIMETICK

func (*UUID) UnmarshalText

func (u *UUID) UnmarshalText(dest []byte) error

UnmarshalText unmarshals giving uuid into appropriate UUID struct.

Jump to

Keyboard shortcuts

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