lclock

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package lclock implements Lamport logical clocks, with helps to be used in the context of rdocEvery operation has an unique ID in the network. Lamport timestamps ensure that if two operations in different network nodes have occurred concurrently, their order is arbitrary but deterministic

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

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

Clock holds a Lamport logical clock

func ConvertString

func ConvertString(c string) (Clock, error)

ConvertString converts a string to a clock representation, or returns an error if string representation is invalid

func New

func New(seed []byte) Clock

New initializes and returns a new clock. The `seed` is a string which uniquely identifies the clock in the network

func (Clock) CheckTick

func (c Clock) CheckTick(tick string) (bool, error)

CheckTick checks if tick belongs to the clock, or if tick representation is invalid

func (*Clock) ID

func (c *Clock) ID() string

ID returns the id of the clock

func (*Clock) String

func (c *Clock) String() string

func (*Clock) Tick

func (c *Clock) Tick()

Tick increments the clock counter

func (Clock) Timestamp

func (c Clock) Timestamp() string

Timestamp returns a timestamp that uniquely identifies the state (id and counter) in the network

func (*Clock) Update

func (c *Clock) Update(rcv interface{}) error

Update performs a clock update based on another clock or string representation. If the current Clock count.seed value is higher, no changes are done. Othwerise, the clock updates to the upper count

Jump to

Keyboard shortcuts

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