vclock

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

package vlock provides methods for maintaining a Vector Clock

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Condition

type Condition int

Condition constants define how to compare a vector clock against another, and may be ORed together when being provided to the Compare method.

const (
	Equal Condition = 1 << iota
	Ancestor
	Descendant
	Concurrent
)

Constants define comparison conditions between pairs of vector clocks

type VClock

type VClock map[string]uint64

VClock are maps of string to uint64 where the string is the id of the process, and the uint64 is the clock value

func FromBytes

func FromBytes(data []byte) (vc VClock, err error)

FromBytes decodes a vector clock

func New

func New() VClock

New returns a new vector clock

func (VClock) Bytes

func (vc VClock) Bytes() []byte

Bytes returns an encoded vector clock

func (VClock) Compare

func (vc VClock) Compare(other VClock, cond Condition) bool

Compare takes another clock and determines if it is Equal, Ancestor, Descendant, or Concurrent with the callee's clock.

func (VClock) Copy

func (vc VClock) Copy() VClock

Copy returns a copy of the clock

func (VClock) CopyFromMap

func (vc VClock) CopyFromMap(otherMap map[string]uint64) VClock

CopyFromMap copies a map to a vector clock

func (VClock) FindTicks

func (vc VClock) FindTicks(id string) (uint64, bool)

FindTicks returns the clock value for a given id, if a value is not found false is returned

func (VClock) GetMap

func (vc VClock) GetMap() map[string]uint64

GetMap returns the map typed vector clock

func (VClock) LastUpdate

func (vc VClock) LastUpdate() (last uint64)

LastUpdate returns the clock value of the oldest clock

func (VClock) Merge

func (vc VClock) Merge(other VClock)

Merge takes the max of all clock values in other and updates the values of the callee

func (VClock) PrintVC

func (vc VClock) PrintVC()

PrintVC prints the callee's vector clock to stdout

func (VClock) ReturnVCString

func (vc VClock) ReturnVCString() string

ReturnVCString returns a string encoding of a vector clock

func (VClock) ReturnVCStringZap

func (vc VClock) ReturnVCStringZap(fieldName string) zap.Field

ReturnVCStringZap returns a zap Field encoding of a vector clock

func (VClock) Set

func (vc VClock) Set(id string, ticks uint64)

Set assigns a clock value to a clock index

func (VClock) Tick

func (vc VClock) Tick(id string)

Tick has replaced the old update

type VClockPayload

type VClockPayload struct {
	Pid     string
	VcMap   map[string]uint64
	Payload interface{}
}

VClockPayload is the data structure that is actually end on the wire

func (*VClockPayload) DecodeMsgpack

func (d *VClockPayload) DecodeMsgpack(dec *msgpack.Decoder) error

DecodeMsgpack is a custom decoder function, needed for msgpack interoperability

func (*VClockPayload) EncodeMsgpack

func (d *VClockPayload) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack is a custom encoder function, needed for msgpack interoperability

func (*VClockPayload) PrintDataBytes

func (d *VClockPayload) PrintDataBytes()

PrintDataBytes prints the Data Stuct as Bytes

func (*VClockPayload) String

func (d *VClockPayload) String() (s string)

String returns VClockPayload's pid as a string

Jump to

Keyboard shortcuts

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