vclock

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

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

Go to latest
Published: Mar 17, 2020 License: MIT Imports: 4 Imported by: 0

README

vclock

Go Report Card

Vector Clock implementation in golang.


clock := New().Update(NewTag("Alice",1)).Update(NewTag("Fred",5))
fmt.Printf("%s\n",clock.Format(Delimiter)
Alice=1;Fred=5

c0 := New().Update(NewTag("Alice",1)).Update(NewTag("Fred",1))
c1,err := Parse("Alice=3;Fred=1;Samantha=4",Delimiter)
if err != nil {
	panic(err)
}

fmt.Printf("c0:Alice=%d, c1:Alice=%d (should be a difference of 2)\n", c0.Tag("Alice",-1),c1.Tag("Alice",-1))

if c0.Equal(c1) {
	panic("should not be the case")
}

switch c0.RelationshipTo(c1) {
	case Ancestor:
		fmt.Printf("%q is an ancestor to %q\n",c0,c1)
	break
	case Descendant:
		fmt.Printf("%q is a descendant of %q\n",c0,c1)
	break
	case Sibling:
		fmt.Printf("%q is a sibling with %q\n",c0,c1)
	break
	case Unknown:
		fmt.Printf("%q is unrelated to %q\n",c0,c1)
	break
} 

c2 := c0.Update(NewTag("Alice",2))

fmt.Printf("c0:Alice=%d, c2:Alice=%d\n",c0.Tag("Alice",-1),c2.Tag("Alice",-1))

if c2.RelationshipIs(c0,Descendant) {
	fmt.Printf("%q is a descendant of %q\n",c2,c0)
} 

if c0.RelationshipIs(c2,Ancestor) {
	fmt.Printf("%q is an ancestor to %q\n",c0,c2)
}

c2 = c2.Update(NewTag("Fred",2)).Update(NewTag("Daisy",1))

c3 := c1.Merge(c2)
fmt.Printf("%q\n",c3)

c0:Alice=1, c1:Alice=3 (should be a difference of 2)
"Alice=1;Fred=1" is an ancestor to "Alice=3;Fred=1;Samantha=4"
c0:Alice=1, c2:Alice=2
"Alice=2;Fred=1" is a descendant of "Alice=1;Fred=1"
"Alice=1;Fred=1" is an ancestor to "Alice=2;Fred=1"
"Alice=3;Fred=1;Samantha=4" + "Alice=2;Daisy=1;Fred=2" = "Alice=3;Daisy=1;Fred=2;Samantha=4"

Documentation

Overview

mae.earth/pkg/vclock/clock.go mae 12016 Package vclock implements vector clocks

Index

Constants

View Source
const (
	Delimiter = rune(';')

	Unknown    = Relationship(0)
	Ancestor   = Relationship(1)
	Descendant = Relationship(2)
	Sibling    = Relationship(3)
	Unrelated  = Relationship(4)
)

Variables

View Source
var EmptyClock = []Tag{}

EmptyClock

Functions

func Fuzz

func Fuzz(data []byte) int

Fuzz see https://github.com/dvyukov/go-fuzz

Types

type ByUser

type ByUser []Tag

ByUser

func (ByUser) Len

func (bu ByUser) Len() int

func (ByUser) Less

func (bu ByUser) Less(i, j int) bool

func (ByUser) Swap

func (bu ByUser) Swap(i, j int)

type Clock

type Clock []Tag

Clock

func New

func New() Clock

New

func Parse

func Parse(clock string, delimiter rune) (Clock, error)

Parse

func (Clock) Equal

func (c Clock) Equal(other Clock) bool

Equal

func (Clock) Format

func (c Clock) Format(delimiter rune) string

Format

func (Clock) HasTag

func (c Clock) HasTag(tag string) bool

HasTag

func (Clock) HasTags

func (c Clock) HasTags(tags ...string) bool

HasTags

func (Clock) Merge

func (c Clock) Merge(other Clock) Clock

Merge

func (Clock) RelationshipIs

func (c Clock) RelationshipIs(other Clock, r Relationship) bool

RelationshipIs

func (Clock) RelationshipTo

func (c Clock) RelationshipTo(other Clock) Relationship

RelationshipTo

func (Clock) String

func (c Clock) String() string

String

func (Clock) Tag

func (c Clock) Tag(tag string, def int) int

Tag

func (Clock) Update

func (c Clock) Update(tag Tag) Clock

Update

type Relationship

type Relationship byte

Relationship

type Tag

type Tag struct {
	User    string
	Version int
}

Tag

func NewTag

func NewTag(user string, ver int) Tag

NewTag

func (Tag) Next

func (t Tag) Next() Tag

Next

func (Tag) Previous

func (t Tag) Previous() Tag

Previous

Jump to

Keyboard shortcuts

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