git-bug: github.com/MichaelMure/git-bug/util/lamport Index | Files

package lamport

import "github.com/MichaelMure/git-bug/util/lamport"

Index

Package Files

clock.go clock_testing.go mem_clock.go persisted_clock.go

Variables

var ErrClockNotExist = errors.New("clock doesn't exist")

type Clock Uses

type Clock interface {
    // Time is used to return the current value of the lamport clock
    Time() Time
    // Increment is used to return the value of the lamport clock and increment it afterwards
    Increment() (Time, error)
    // Witness is called to update our local clock if necessary after
    // witnessing a clock value received from another process
    Witness(time Time) error
}

Clock is a Lamport logical clock

type MemClock Uses

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

MemClock is a thread safe implementation of a lamport clock. It uses efficient atomic operations for all of its functions, falling back to a heavy lock only if there are enough CAS failures.

func NewMemClock Uses

func NewMemClock() *MemClock

NewMemClock create a new clock with the value 1. Value 0 is considered as invalid.

func NewMemClockWithTime Uses

func NewMemClockWithTime(time uint64) *MemClock

NewMemClockWithTime create a new clock with a value.

func (*MemClock) Increment Uses

func (mc *MemClock) Increment() (Time, error)

Increment is used to return the value of the lamport clock and increment it afterwards

func (*MemClock) Time Uses

func (mc *MemClock) Time() Time

Time is used to return the current value of the lamport clock

func (*MemClock) Witness Uses

func (mc *MemClock) Witness(v Time) error

Witness is called to update our local clock if necessary after witnessing a clock value received from another process

type PersistedClock Uses

type PersistedClock struct {
    *MemClock
    // contains filtered or unexported fields
}

func LoadPersistedClock Uses

func LoadPersistedClock(filePath string) (*PersistedClock, error)

LoadPersistedClock load a persisted Lamport clock from a file

func NewPersistedClock Uses

func NewPersistedClock(filePath string) (*PersistedClock, error)

NewPersistedClock create a new persisted Lamport clock

func (*PersistedClock) Increment Uses

func (pc *PersistedClock) Increment() (Time, error)

Increment is used to return the value of the lamport clock and increment it afterwards

func (*PersistedClock) Witness Uses

func (pc *PersistedClock) Witness(time Time) error

Witness is called to update our local clock if necessary after witnessing a clock value received from another process

func (*PersistedClock) Write Uses

func (pc *PersistedClock) Write() error

type Time Uses

type Time uint64

Time is the value of a Clock.

Package lamport imports 8 packages (graph) and is imported by 10 packages. Updated 2020-07-07. Refresh now. Tools for package owners.